Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Workshop.activity/Workshop.py
blob: 1ca6be27ff1cec189bab1d96706ba9ba3018727b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
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))