Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Workshop.activity/TutorialStoreResults.py
blob: 3a7f78d0972e417c753f7e0dbe342df903e1142a (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
import sys, os
import gtk
from Workshop import WorkshopListItem
from Rating import Rating
import operator
import logging


class TutorialStoreResults(gtk.VBox):
    def __init__(self,controller):
        """Constructor
        
        @param controller The controller to attach the view to
        """
        gtk.VBox.__init__(self,False,10)
        
        back_image = gtk.Image()
        back_image.set_from_file('arrow_back.png')
        self.back_button = gtk.Button("Prev")
        self.back_button.set_image(back_image)
        
        next_image = gtk.Image()
        next_image.set_from_file('arrow_next.png')
        self.next_button = gtk.Button("Next")
        self.next_button.set_image(next_image)
        
        self.arrow_box = gtk.HBox()
        self.arrow_box.pack_start(self.back_button,False,False)
        self.arrow_box.pack_end(self.next_button,False,False)
        self.back_button.set_sensitive(False)

        self.controller = controller
        self.tutorial_list = []
        
        #by default tutorials are sorted by name
        self.sorting_key = 'Name'

        self.set_border_width(10)
        
        #create the list item container with a scroll bar if necessary
        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.pack_end(self.arrow_box,False,False)
        
        self.back_button.connect("clicked",self.controller.prev_page,None)
        self.next_button.connect("clicked",self.controller.next_page,None)

        #Show the components
        self.list_container.show()
        self.main_container.show()
        self.arrow_box.show_all()
        
    def set_button_sensitive(self,back,next):
        self.back_button.set_sensitive(back)
        self.next_button.set_sensitive(next)

    def change_sorting(self,sorting):
        """
        Changes the property by which tutorial are sorted
        
        @param sorting The property by which tutorials will be sorted
        """
        logging.info("Change_sorting was called")
        self.sorting_key = sorting
        self.sort_tutorial()
    
    def sort_tutorial(self):
        """
        Sorts the tutorials
        """
        #if tutorials are sorted by rating they are in the reverse order
        self.tutorial_list.sort(key=operator.attrgetter(self.sorting_key.lower()))
        self.refresh_tutorial_display()
        
    def set_tutorial_list(self,tutorial_list):
        """
        Set the list of tutorial to display
        
        @param tutorial_list the tutorial list
        """
        self.tutorial_list = tutorial_list
        self.sort_tutorial()
        
    def refresh_tutorial_display(self):
        """
        Refresh the tutorial content by deleting every item and recreating them
        """
        #delete every tutorial list item
        for child in self.list_container.get_children():
            self.list_container.remove(child)
            
        #Creates and add a new item for every tutorial
        for tuto in self.tutorial_list:
            item = TutorialStoreListItem(tuto,self.controller)
            self.list_container.pack_start(item)
            item.show()
            if self.tutorial_list[-1] != tuto:
                sep = gtk.HSeparator()
                self.list_container.pack_start(sep)
                sep.show()
            
class TutorialStoreListItem(WorkshopListItem):
    def __init__(self,tutorial,controller):
        WorkshopListItem.__init__(self,tutorial,controller)

        self.last_row = gtk.HBox(False,15)
        self.btn_detail = gtk.Button('Details')
        self.last_row.pack_end(self.btn_detail,False,False)

        self.table.attach(self.last_row,1,3,2,3,yoptions = 0)

        self.last_row.show_all()
        
        #connect the buttons
        self.btn_detail.connect("clicked",self.controller.show_details,self.tutorial)