Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharlie <charlie@tutorius-dev.(none)>2009-10-21 02:32:47 (GMT)
committer Charlie <charlie@tutorius-dev.(none)>2009-10-21 02:32:47 (GMT)
commit2b4eaea8f46e846799595b3c7015f77c6156532b (patch)
tree28887f96b7f4e6fd400c42722ed2b7e5a229a28d
parent0e08abfd82ddf96e9f816cb65a3fe08f518f4f27 (diff)
Some functionnalitie of the workshop ready to be demoed
-rw-r--r--activity/Workshop.activity/Workshop.py204
-rw-r--r--activity/Workshop.activity/WorkshopController.py21
-rw-r--r--activity/Workshop.activity/WorkshopListItem.py16
-rw-r--r--activity/Workshop.activity/WorkshopModel.py51
4 files changed, 188 insertions, 104 deletions
diff --git a/activity/Workshop.activity/Workshop.py b/activity/Workshop.activity/Workshop.py
index 270b82c..1ca6be2 100644
--- a/activity/Workshop.activity/Workshop.py
+++ b/activity/Workshop.activity/Workshop.py
@@ -1,85 +1,98 @@
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.mainView = WorkshopMain()
- self.detailView = WorkshopDetail(None)
+ 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()
-
- 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
- """
- pass
-
-
- 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
- """
- pass
-
- 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
- """
- pass
-
- def display_main_view(self):
- """
- Displays the main view of the Workshop
- """
- pass
-
- def display_info_dialog(self,tutorial):
- """
- Displays the infos dialog on a tutorial
-
- @param tutorial the tutorial to edit
- """
- pass
+ 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):
+ def __init__(self,controller):
gtk.VBox.__init__(self,False,10)
+ self.controller = controller
+
self.set_border_width(10)
- self.search_bar = SearchBar()
+ self.search_bar = SearchBar(self.controller)
self.pack_start(self.search_bar,False,False)
sep = gtk.HSeparator()
@@ -89,9 +102,6 @@ class WorkshopMain(gtk.VBox):
self.list_container= gtk.VBox()
- item = WorkshopListItem()
- self.list_container.pack_start(item,False,False)
- item.show()
self.main_container.add_with_viewport(self.list_container)
self.pack_start(self.main_container)
@@ -99,11 +109,36 @@ class WorkshopMain(gtk.VBox):
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):
+ 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")
@@ -112,7 +147,8 @@ class SearchBar(gtk.HBox):
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)
@@ -125,14 +161,26 @@ class SearchBar(gtk.HBox):
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):
+ 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)
@@ -150,15 +198,15 @@ class WorkshopDetail(gtk.VBox):
label_holder = gtk.VBox(False,10)
- self.title_label = gtk.Label("Title")
+ self.title_label = gtk.Label(tutorial.name)
self.title_label.set_alignment(0.0,0.5)
- self.author_label = gtk.Label("by Me")
+ 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(3.5)
+ self.rating = Rating(tutorial.rating)
second_row.pack_start(icon,False,False)
second_row.pack_start(label_holder)
@@ -166,7 +214,7 @@ class WorkshopDetail(gtk.VBox):
self.desc_view = gtk.TextView()
self.desc_buff = gtk.TextBuffer()
- self.desc_buff.set_text('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tincidunt orci in eli t semper aliquam. Pellentesque ut lectus arcu. Mauris arcu dolor, venenatis eget tincidunt vitae, tincidunt ac urna. Quisque sodales odio in risus alique t laoreet. In commodo porttitor arcu, a viverra dui faucibus nec. Donec neque leo, aliquet eget luctus et, viverra sed turpis. Pellentesque sed turpis qu am, in placerat mi. Etiam est lorem, tempus sed tempus quis, tempor ut magna. Aenean velit eros, ornare quis rutrum vitae, lacinia et urna. Morbi iaculis molestie tempus. Proin egestas luctus diam. Suspendisse pretium adipiscing magna, non varius purus molestie vitae. Maecenas laoreet adipiscing nulla eu consequat. Morbi et felis a nunc fermentum tincidunt eget et enim. Phasellus ligula lorem, vulputate a ullamcorper non, pretium nec libero')
+ 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)
@@ -228,12 +276,10 @@ class WorkshopDetail(gtk.VBox):
self.unpublish_button.show()
fifth_row.show()
- self.title_label.set_markup(self.title_text % {"title":"Tutorial Title"})
- self.author_label.set_markup(self.author_text % {"author":"Tutorial author"})
-
- def realize_cb(self,widget,data=None):
- widget.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
-
+ 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
diff --git a/activity/Workshop.activity/WorkshopController.py b/activity/Workshop.activity/WorkshopController.py
index 50c1fb4..ba192cf 100644
--- a/activity/Workshop.activity/WorkshopController.py
+++ b/activity/Workshop.activity/WorkshopController.py
@@ -4,7 +4,8 @@ WorkshopController
This module handles user action from the workshop view
"""
-
+import logging
+from WorkshopModel import Tutorial
class WorkshopController():
def __init__(self,view,model):
self.view = view
@@ -17,16 +18,18 @@ class WorkshopController():
@param widget the widget that sent the query
@param keyword the keyword for the query, empty to get all tutorials
"""
- pass
+ self.model.query(keyword)
- def sort_selection_changed(self,widget,sort):
+ def sort_selection_changed(self,widget,data):
"""
Handles selection changes in the sorting selection
@param widget the widget that sent the query
@param sort the property to use to sort tutorial
"""
- pass
+ sorting = widget.get_active_text()
+ self.view.change_sorting(sorting)
+
def launch_tutorial_triggered(self,widget,tutorial):
"""
@@ -44,7 +47,7 @@ class WorkshopController():
@param widget the widget that made the call
@param tutorial the tutorial to
"""
- pass
+ self.view.display_detail(tutorial)
def back_pressed(self,widget,data):
"""
@@ -53,7 +56,7 @@ class WorkshopController():
@param widget the widget that made the call
@param data not used
"""
- pass
+ self.view.display_main_view()
def rate_tutorial(self,widget,data):
"""
@@ -95,7 +98,7 @@ class WorkshopController():
@param widget the widget that made the call
@param tutorial the tutorial to delete
"""
- pass
+ self.model.delete_tutorial(tutorial)
def publish_tutorial(self,widget,tutorial):
"""
@@ -104,7 +107,7 @@ class WorkshopController():
@param widget the widget that made the call
@param tutorial the tutorial to publish
"""
- pass
+ self.model.publish_tutorial(tutorial)
def unpublish_tutorial(self,widget,tutorial):
"""
@@ -113,4 +116,4 @@ class WorkshopController():
@param widget the widget that made the call
@param tutorial the tutorial to unpublish
"""
- pass
+ self.model.unpublish_tutorial(tutorial)
diff --git a/activity/Workshop.activity/WorkshopListItem.py b/activity/Workshop.activity/WorkshopListItem.py
index d8a6e60..0828f2c 100644
--- a/activity/Workshop.activity/WorkshopListItem.py
+++ b/activity/Workshop.activity/WorkshopListItem.py
@@ -1,12 +1,16 @@
import gtk
class WorkshopListItem(gtk.Alignment):
- def __init__(self):
+ def __init__(self,tutorial,controller):
gtk.Alignment.__init__(self,0.0,0.0,1.0,1.0)
+ self.tutorial = tutorial
+ self.controller = controller
+
self.title_text = '<span size="xx-large">%(title)s</span>'
self.table = gtk.Table(3,3,False)
- self.lbl_title = gtk.Label('Tutorial')
- self.lbl_desc = gtk.Label('Tutorial test to see the display of the stuffiasdjalskjdlak laskjdlak alskdjalkdj ldkajdlkasj laksjdlkajd lk slakjdlkajdalkdjalkjd alksdjalskjd lkajsdlka lk lkdajdlkajdlkaj kjaslkdjakd ')
+
+ self.lbl_title = gtk.Label('')
+ self.lbl_desc = gtk.Label(tutorial.description)
self.lbl_desc.set_line_wrap(True)
self.btn_launch = gtk.Button('Launch')
launch_align= gtk.Alignment(0.0,1.0,0.0,0.0)
@@ -14,7 +18,7 @@ class WorkshopListItem(gtk.Alignment):
self.btn_details = gtk.Button('Details')
self.icon = gtk.Image()
self.icon.set_from_file('icon.svg')
- self.rating = Rating(2.5)
+ self.rating = Rating(tutorial.rating)
self.table.attach(self.icon,0,1,0,1,0,0)
self.table.attach(self.lbl_title,1,2,0,1,yoptions=0)
@@ -26,7 +30,7 @@ class WorkshopListItem(gtk.Alignment):
self.table.set_row_spacing(1,10)
self.lbl_title.set_alignment(0.0,0.5)
- self.lbl_title.set_markup(self.title_text % {'title':'Tutorial title'})
+ self.lbl_title.set_markup(self.title_text % {'title':tutorial.name})
self.lbl_desc.set_alignment(0.0,0.5)
self.table.show()
@@ -39,6 +43,8 @@ class WorkshopListItem(gtk.Alignment):
self.rating.show()
self.add(self.table)
+
+ self.btn_details.connect("clicked",self.controller.show_details,self.tutorial)
class Rating(gtk.HBox):
def __init__(self,rating):
diff --git a/activity/Workshop.activity/WorkshopModel.py b/activity/Workshop.activity/WorkshopModel.py
index fdfa21b..79e8f74 100644
--- a/activity/Workshop.activity/WorkshopModel.py
+++ b/activity/Workshop.activity/WorkshopModel.py
@@ -4,6 +4,8 @@ WorkshopModel
This module is the model of the Workshop Activity
"""
+#import sugar.tutorius.vault
+
class WorkshopModel():
def __init__(self,view):
self.view = view
@@ -15,7 +17,21 @@ class WorkshopModel():
@param keyword the keyword for the query
"""
- pass
+ t1 = Tutorial({'name':'tuto 1',"description":"This is the description","rating":5})
+ t2 = Tutorial({'name':'tuto 2',"description":"This is the description of another","rating":4})
+ t3 = Tutorial({'name':'tuto 3',"description":"This is the description oh the last","rating":3})
+ t4 = Tutorial({'name':'tuto 4',"description":"This is the description oh the last","rating":1})
+ t5 = Tutorial({'name':'tuto 5',"description":"This is the description oh the last","rating":1})
+ t6 = Tutorial({'name':'tuto 6',"description":"This is the description oh the last","rating":1})
+ t7 = Tutorial({'name':'tuto 7',"description":"This is the description oh the last","rating":1})
+ tutorial_list = [t1,t2,t3,t4,t5,t6,t7]
+
+## vault_return = vault.query({},{},{})
+## tutorial_list = []
+## for tuto in vault_return:
+## tutorial_list.append(Tutorial(tuto))
+
+ self.view.set_tutorial_list(tutorial_list)
def delete_tutorial(self,tutorial):
"""
@@ -60,31 +76,43 @@ class Tutorial():
def __init__(self,metadata_dict):
self.__original_dict = metadata_dict
self.__update_dict = metadata_dict
- if 'Description' in self.__original_dict:
- self.__description = self.__original_dict['Description']
+
+ if 'name' in self.__original_dict:
+ self.__name = self.__original_dict['name']
+ else:
+ self.__description = name
+
+ if 'description' in self.__original_dict:
+ self.__description = self.__original_dict['description']
else:
self.__description = None
- if 'Author' in self.__original_dict:
- self.__author = self.__original_dict['Author']
+ if 'author' in self.__original_dict:
+ self.__author = self.__original_dict['author']
else:
self.__author = None
- if 'Rating' in self.__original_dict:
- self.__rating = self.original_dict['Rating']
+ if 'rating' in self.__original_dict:
+ self.__rating = self.__original_dict['rating']
else:
self.__rating = None
- if 'PublishedState' in self.__original_dict:
- self.__published_state = original_dict['PublishedState']
+ if 'publish_state' in self.__original_dict:
+ self.__published_state = original_dict['publish_state']
else:
self.__published_state = None
- if 'TutorialId' in self.__original_dict:
- self.__id = original_state['TutorialId']
+ if 'guid' in self.__original_dict:
+ self.__id = original_state['guid']
else:
self.__id = None
+ def get_name(self):
+ return self.__name
+
+ def set_name(self,name):
+ self.__name = name
+
def get_description(self):
return self.__description
@@ -123,6 +151,7 @@ class Tutorial():
def get_updated_metadata(self):
return self.__update_dict
+ name = property(get_name,set_name)
description = property(get_description,set_description)
author = property(get_author,set_author)
rating = property(get_rating,set_rating)