1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import wx
20
21 from timelinelib.canvas.data.exceptions import TimelineIOError
22 from timelinelib.repositories.dbwrapper import DbWrapperCategoryRepository
23 from timelinelib.wxgui.dialogs.editcategory.view import EditCategoryDialog
24 import timelinelib.wxgui.utils as gui_utils
25
26
28
29 - def __init__(self, parent, timeline, allow_add=False, allow_edit=False, **kwargs):
30 wx.Choice.__init__(self, parent, wx.ID_ANY, **kwargs)
31 self.timeline = timeline
32 self.category_repository = DbWrapperCategoryRepository(self.timeline)
33 self.allow_add = allow_add
34 self.allow_edit = allow_edit
35 self.Bind(wx.EVT_CHOICE, self._on_choice)
36 self._clear()
37
38 - def Populate(self, exclude=None, select=None):
43
48
52
54 self.Clear()
55 self.add_category_item_index = None
56 self.edit_categoris_item_index = None
57 self.last_real_category_index = None
58 self.current_category_selection = self.GetSelection()
59
65
67 self.Append("", None)
68 self._append_tree(tree)
69 self.last_real_category_index = self.GetCount() - 1
70 if self.allow_add or self.allow_edit:
71 self.Append("", None)
72 if self.allow_add:
73 self.add_category_item_index = self.GetCount()
74 self.Append(_("Add new"), None)
75 if self.allow_edit:
76 self.edit_categoris_item_index = self.GetCount()
77 self.Append(_("Edit categories"), None)
78
83
85 new_selection_index = event.GetSelection()
86 if new_selection_index > self.last_real_category_index:
87 self.SetSelection(self.current_category_selection)
88 if new_selection_index == self.add_category_item_index:
89 self._add_category()
90 elif new_selection_index == self.edit_categoris_item_index:
91 self._edit_categories()
92 else:
93 self.current_category_selection = new_selection_index
94
104
107