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
24
25
26
27 BORDER = 5
28
29 ID_ERROR = wx.NewId()
30
31
33
35 self.name = name
36 self.ext_data = {}
37 self.ext_names = []
38 self._extract_ext_info(extensions)
39
41 return "%s (%s)|%s" % (
42 self.name,
43 ", ".join(["*." + e for e in self.ext_names]),
44 ";".join(["*." + e for e in self.ext_names]))
45
47 path = dialog.GetPath()
48 for ext_name in self.ext_names:
49 if path.endswith("." + ext_name):
50 return path
51 return "%s.%s" % (path, self.ext_names[0])
52
54 split_path = path.split(".")
55 if len(split_path) > 1:
56 ext_name = split_path[-1]
57 return self.ext_data.get(ext_name, None)
58 return None
59
61 for ext in extensions:
62 if isinstance(ext, tuple):
63 name, data = ext
64 self.ext_data[name] = data
65 self.ext_names.append(name)
66 else:
67 self.ext_names.append(ext)
68
69
71 """
72 Transform flat list of categories to a tree based on parent attribute.
73
74 The top-level categories have the given parent and each level in the tree
75 is sorted.
76
77 If remove is given then the subtree with remove as root will not be
78 included.
79
80 The tree is represented as a list of tuples, (cat, sub-tree), where cat is
81 the parent category and subtree is the same tree representation of the
82 children.
83 """
84 children = [child for child in category_list
85 if (child.parent is parent and child is not remove)]
86 sorted_children = sort_categories(children)
87 tree = [(x, category_tree(category_list, x, remove))
88 for x in sorted_children]
89 return tree
90
91
92 -def show_modal(fn_create_dialog, fn_handle_db_error, fn_success=None):
93 """Show a modal dialog using error handling pattern."""
94 try:
95 dialog = fn_create_dialog()
96 except TimelineIOError, e:
97 fn_handle_db_error(e)
98 else:
99 dialog_result = dialog.ShowModal()
100 if dialog_result == ID_ERROR:
101 fn_handle_db_error(dialog.error)
102 elif fn_success:
103 fn_success(dialog)
104 dialog.Destroy()
105
106
110 return handler
111
112
114 if dialog.IsShown():
115
116
117
118 dialog.error = error
119 dialog.EndModal(ID_ERROR)
120 else:
121
122
123 raise error
124
125
127 ctrl.SetFocus()
128 if hasattr(ctrl, "SelectAll"):
129 ctrl.SelectAll()
130
131
133 """Display an error message in a modal dialog box"""
134 dial = wx.MessageDialog(parent, message, _("Error"), wx.OK | wx.ICON_ERROR)
135 dial.ShowModal()
136
137
139 """Ask a yes/no question and return the reply."""
140 return wx.MessageBox(question, _("Question"),
141 wx.YES_NO|wx.CENTRE|wx.NO_DEFAULT, parent)
142
143
145 parent.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
146
147
149 parent.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
150
151
167