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.db.exceptions import TimelineIOError
22 from timelinelib.db.objects.category import sort_categories
23 from timelinelib.wxgui.dialogs.categorieseditor import CategoriesEditor
24 from timelinelib.wxgui.dialogs.categoryeditor import WxCategoryEdtiorDialog
25 import timelinelib.wxgui.utils as gui_utils
26
27
29
33
34 - def select(self, select_category):
35
36
37
38 self.Clear()
39 self.Append("", None)
40 selection_set = False
41 current_item_index = 1
42 for cat in sort_categories(self.timeline.get_categories()):
43 self.Append(cat.name, cat)
44 if cat == select_category:
45 self.SetSelection(current_item_index)
46 selection_set = True
47 current_item_index += 1
48 self.last_real_category_index = current_item_index - 1
49 self.add_category_item_index = self.last_real_category_index + 2
50 self.edit_categoris_item_index = self.last_real_category_index + 3
51 self.Append("", None)
52 self.Append(_("Add new"), None)
53 self.Append(_("Edit categories"), None)
54 if not selection_set:
55 self.SetSelection(0)
56 self.current_category_selection = self.GetSelection()
57
59 selection = self.GetSelection()
60 category = self.GetClientData(selection)
61 return category
62
64 new_selection_index = e.GetSelection()
65 if new_selection_index > self.last_real_category_index:
66 self.SetSelection(self.current_category_selection)
67 if new_selection_index == self.add_category_item_index:
68 self._add_category()
69 elif new_selection_index == self.edit_categoris_item_index:
70 self._edit_categories()
71 else:
72 self.current_category_selection = new_selection_index
73
78 def handle_success(dialog):
79 if dialog.GetReturnCode() == wx.ID_OK:
80 try:
81 self.select(dialog.get_edited_category())
82 except TimelineIOError, e:
83 gui_utils.handle_db_error_in_dialog(self, e)
84 gui_utils.show_modal(create_category_editor,
85 gui_utils.create_dialog_db_error_handler(self),
86 handle_success)
87
91 def handle_success(dialog):
92 try:
93 prev_index = self.GetSelection()
94 prev_category = self.GetClientData(prev_index)
95 self.select(prev_category)
96 except TimelineIOError, e:
97 gui_utils.handle_db_error_in_dialog(self, e)
98 gui_utils.show_modal(create_categories_editor,
99 gui_utils.create_dialog_db_error_handler(self),
100 handle_success)
101