Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Workshop.activity/Workshop.py
diff options
context:
space:
mode:
Diffstat (limited to 'Workshop.activity/Workshop.py')
-rw-r--r--Workshop.activity/Workshop.py285
1 files changed, 285 insertions, 0 deletions
diff --git a/Workshop.activity/Workshop.py b/Workshop.activity/Workshop.py
new file mode 100644
index 0000000..1ca6be2
--- /dev/null
+++ b/Workshop.activity/Workshop.py
@@ -0,0 +1,285 @@
+import gtk
+
+from WorkshopListItem import WorkshopListItem,Rating
+from WorkshopModel import WorkshopModel
+from WorkshopController import WorkshopController
+
+class WorkshopView(gtk.Alignment):
+ def __init__(self):
+ gtk.Alignment.__init__(self,0.0,0.0,1.0,1.0)
+ self.model = WorkshopModel(self)
+ self.controller = WorkshopController(self,self.model)
+
+ self.mainView = WorkshopMain(self.controller)
+ self.detailView = WorkshopDetail(None,self.controller)
+
+ self.add(self.mainView)
+
+ self.mainView.show()
+ self.detailView.show()
+
+ self.controller.tutorial_query(None,None)
+
+ def set_tutorial_list(self,tutorial_list):
+ """
+ Set the list of tutorial to display in the main View
+ Refresh the View
+
+ @param tutorial_list the list of tutorial
+ """
+ self.mainView.set_tutorial_list(tutorial_list)
+
+
+ def change_sorting(self,sorting_key):
+ """
+ Sort the list of tutorial base on the sorting_key
+
+ @param sorting_key the tutorial metadata to use to sort the tutorials
+ """
+ self.mainView.change_sorting(sorting_key)
+
+ def refresh_tutorial_info(self):
+ """
+ Tell the view to refresh the content of the tutorial list because some info have changed
+
+ Call this function when information about tutorial have changed, but the tutorial to display are the same
+ """
+ pass
+
+ def toggle_tutorial_publish(self,tutorial,published):
+ """
+ Change the publish/unpublish status of the tutorial on the view
+
+ @param tutorial the tutorial to change the status
+ @param published True if the tutorial is published, False if not
+ """
+ pass
+
+ def display_detail(self,tutorial):
+ """
+ Displays the detail view of a tutorial
+
+ @param tutorial the tutorial to display
+ """
+ self.mainView.hide()
+ self.remove(self.mainView)
+ print tutorial.name
+ self.detailView = WorkshopDetail(tutorial,self.controller)
+ self.add(self.detailView)
+ self.detailView.show()
+
+ def display_main_view(self):
+ """
+ Displays the main view of the Workshop
+ """
+ self.detailView.hide()
+ self.remove(self.detailView)
+ self.add(self.mainView)
+ self.mainView.show()
+
+ def display_info_dialog(self,tutorial):
+ """
+ Displays the infos dialog on a tutorial
+
+ @param tutorial the tutorial to edit
+ """
+ pass
+
+class WorkshopMain(gtk.VBox):
+ def __init__(self,controller):
+ gtk.VBox.__init__(self,False,10)
+
+ self.controller = controller
+
+ self.set_border_width(10)
+ self.search_bar = SearchBar(self.controller)
+ self.pack_start(self.search_bar,False,False)
+
+ sep = gtk.HSeparator()
+ self.pack_start(sep,False,False)
+ self.main_container = gtk.ScrolledWindow()
+ self.main_container.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
+
+ self.list_container= gtk.VBox()
+
+ self.main_container.add_with_viewport(self.list_container)
+ self.pack_start(self.main_container)
+
+ self.search_bar.show()
+ self.list_container.show()
+ self.main_container.show()
+ sep.show()
+ self.tutorial_list = []
+ self.sorting_key = 'Name'
+
+
+ def change_sorting(self,sorting):
+ self.sorting_key = sorting
+ self.sort_tutorial()
+
+ def sort_tutorial(self):
+ self.tutorial_list.sort(lambda x, y:
+ cmp(str(getattr(x,self.sorting_key.lower())).lower(),str(getattr(y,self.sorting_key.lower())).lower()))
+ self.refresh_tutorial_display()
+
+ def set_tutorial_list(self,tutorial_list):
+ self.tutorial_list = tutorial_list
+ self.sort_tutorial()
+
+ def refresh_tutorial_display(self):
+ for child in self.list_container.get_children():
+ self.list_container.remove(child)
+ for tuto in self.tutorial_list:
+ item = WorkshopListItem(tuto,self.controller)
+ self.list_container.pack_start(item)
+ item.show()
+
+class SearchBar(gtk.HBox):
+ def __init__(self,controller):
+ gtk.HBox.__init__(self,False,10)
+ self.set_border_width(5)
+ self.controller = controller
+
+ self.search_entry = gtk.Entry(400)
+ self.search_button = gtk.Button("Go")
+ self.separator = gtk.VSeparator()
+ self.sort_label = gtk.Label("Sort by")
+ self.sort_combo = gtk.combo_box_new_text()
+ self.sort_combo.insert_text(0,"Name")
+ self.sort_combo.insert_text(1,"Rating")
+ self.sort_combo.set_active(0)
+ self.selected_sorting = self.sort_combo.get_active_text()
+
+ self.pack_start(self.search_entry,padding=5)
+ self.pack_start(self.search_button,False,False,padding=10)
+ self.pack_start(self.separator,False,False,padding=10)
+ self.pack_start(self.sort_label,False,False,padding=5)
+ self.pack_start(self.sort_combo,)
+
+ self.search_entry.show()
+ self.search_button.show()
+ self.separator.show()
+ self.sort_label.show()
+ self.sort_combo.show()
+
+ self.search_button.connect("clicked",self.controller.tutorial_query,self.search_entry.get_text())
+ self.sort_combo.connect("changed",self.controller.sort_selection_changed,None)
+
+ def get_sorting(self):
+ return self.selected_sorting
+
+ sorting = property(get_sorting)
+
+
+
+class WorkshopDetail(gtk.VBox):
+ def __init__(self,tutorial,controller):
+ if tutorial is None:
+ return
+
+ self.title_text = '<span size="xx-large">%(title)s</span>'
+ self.author_text = '<span size="large">by %(author)s</span>'
+ self.desc_text = 'Description: %(description)s'
+ self.controller = controller
+ gtk.VBox.__init__(self,False,10)
+ self.set_border_width(10)
+
+ first_row = gtk.HBox(False)
+ back_image = gtk.Image()
+ back_image.set_from_file('arrow_back.png')
+ self.back_button = gtk.Button("Back")
+ self.back_button.set_image(back_image)
+
+ first_row.pack_start(self.back_button,False,False)
+
+ second_row = gtk.HBox(False)
+ icon = gtk.Image()
+ icon.set_from_file('icon.svg')
+
+ label_holder = gtk.VBox(False,10)
+
+ self.title_label = gtk.Label(tutorial.name)
+ self.title_label.set_alignment(0.0,0.5)
+ self.author_label = gtk.Label(tutorial.author)
+ self.author_label.set_alignment(0.05,0.5)
+
+ label_holder.pack_start(self.title_label)
+ label_holder.pack_start(self.author_label)
+
+ self.rating = Rating(tutorial.rating)
+
+ second_row.pack_start(icon,False,False)
+ second_row.pack_start(label_holder)
+ second_row.pack_end(self.rating,False,False)
+
+ self.desc_view = gtk.TextView()
+ self.desc_buff = gtk.TextBuffer()
+ self.desc_buff.set_text(tutorial.description)
+ self.desc_view.set_buffer(self.desc_buff)
+ self.desc_view.set_editable(False)
+ self.desc_view.set_wrap_mode(gtk.WRAP_WORD)
+ self.desc_view.set_cursor_visible(False)
+ self.desc_view.connect("realize",self.realize_cb,None)
+ self.desc_view.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("gray") )
+
+ fourth_row = gtk.HBox(False,15)
+ self.launch_button = gtk.Button('Launch')
+ self.launch_button.get_child().set_markup(self.title_text %{"title":"Launch"})
+ self.edit_button = gtk.Button('Edit')
+ self.edit_button.get_child().set_markup(self.title_text %{"title":"Edit"})
+ self.update_button = gtk.Button('Update')
+ self.update_button.get_child().set_markup(self.title_text %{"title":"Update"})
+ self.info_button = gtk.Button('Infos')
+ self.info_button.get_child().set_markup(self.title_text %{"title":"Infos"})
+ self.delete_button = gtk.Button('Delete')
+ self.delete_button.get_child().set_markup(self.title_text %{"title":"Delete"})
+
+ fourth_row.pack_start(self.launch_button,False,False)
+ fourth_row.pack_start(self.edit_button,False,False)
+ fourth_row.pack_start(self.update_button,False,False)
+ fourth_row.pack_start(self.info_button,False,False)
+ fourth_row.pack_end(self.delete_button,False,False)
+
+ fifth_row = gtk.HBox(False,15)
+ self.publish_button = gtk.Button('')
+ self.publish_button.get_child().set_markup(self.title_text %{"title":"Publish"})
+ self.unpublish_button = gtk.Button('')
+ self.unpublish_button.get_child().set_markup(self.title_text %{"title":"Unpublish"})
+
+ fifth_row.pack_start(self.publish_button,False,False)
+ fifth_row.pack_start(self.unpublish_button,False,False)
+
+ self.pack_start(first_row,False,False)
+ self.pack_start(second_row,False,False)
+ self.pack_start(self.desc_view)
+ self.pack_end(fifth_row,False,False)
+ self.pack_end(fourth_row,False,False)
+
+
+ self.back_button.show()
+ first_row.show()
+ self.title_label.show()
+ self.author_label.show()
+ self.rating.show()
+ label_holder.show()
+ second_row.show()
+ icon.show()
+ self.desc_view.show()
+ self.launch_button.show()
+ self.edit_button.show()
+ self.update_button.show()
+ self.info_button.show()
+ self.delete_button.show()
+ fourth_row.show()
+
+ self.publish_button.show()
+ self.unpublish_button.show()
+ fifth_row.show()
+
+ self.title_label.set_markup(self.title_text % {"title":tutorial.name})
+ self.author_label.set_markup(self.author_text % {"author":tutorial.author})
+
+ self.back_button.connect("clicked",self.controller.back_pressed,None)
+
+ def realize_cb(self,widget,data=None):
+ widget.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)) \ No newline at end of file