1 from gi.repository
import Gtk
as gtk
2 from gi.repository
import GObject
as gobject
10 def __init__(self, action_callback, edit_config=None):
14 self.
window = gtk.Window(gtk.WindowType.TOPLEVEL)
15 self.window.set_title(
'%s Configuration' % (
'Edit' if self.
edit_config else 'Create'))
16 self.window.set_border_width(10)
17 self.window.set_default_size(500, 350)
22 props_frame = gtk.Frame(label=
'Properties')
24 grid.set_column_spacing(3)
25 name_label = gtk.Label(
'Name:')
27 self.name_entry.set_width_chars(50)
29 self.name_entry.set_text(self.edit_config.name)
32 name_label_hbox = gtk.HBox()
33 align = gtk.Alignment()
35 name_label_hbox.pack_start(align,
True,
True, 0)
36 name_label_hbox.pack_start(name_label,
False,
False, 0)
38 grid.attach(name_label_hbox, 0, 0, 1, 1)
40 name_entry_hbox = gtk.HBox()
41 name_entry_hbox.pack_start(self.
name_entry,
False,
False, 0)
43 grid.attach(name_entry_hbox, 1, 0, 1, 1)
45 desc_label = gtk.Label(
'Description:')
47 self.desc_entry.set_width_chars(50)
49 self.desc_entry.set_text(self.edit_config.desc)
51 desc_label_hbox = gtk.HBox()
52 align = gtk.Alignment()
54 desc_label_hbox.pack_start(align,
True,
True, 0)
55 desc_label_hbox.pack_start(desc_label,
False,
False, 0)
57 grid.attach(desc_label_hbox, 0, 1, 1, 1)
59 desc_entry_hbox = gtk.HBox()
60 desc_entry_hbox.pack_start(self.
desc_entry,
False,
False, 0)
62 grid.attach(desc_entry_hbox, 1, 1, 1, 1)
66 vbox.pack_start(props_frame,
False,
False, 0)
69 outputs_frame = gtk.Frame(label=
'Outputs')
70 outputs_vbox = gtk.VBox()
71 existing_outputs = self.edit_config.outputs
if self.
edit_config else []
73 scrolled_win = gtk.ScrolledWindow()
74 scrolled_win.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC)
76 outputs_vbox.pack_start(scrolled_win,
True,
True, 0)
78 outputs_button_box = gtk.HButtonBox()
79 outputs_button_box.set_layout(gtk.ButtonBoxStyle.EDGE)
81 add_button = UIUtils.create_button(
'Add Output', UIUtils.BUTTON_ICONS.ADD, UIUtils.BUTTON_ICON_SIZES.PX22)
83 outputs_button_box.pack_start(add_button,
True,
True, 0)
85 edit_button = UIUtils.create_button(
'Edit Output', UIUtils.BUTTON_ICONS.EDIT, UIUtils.BUTTON_ICON_SIZES.PX22)
86 edit_button.connect(
'clicked',
lambda w: self.
_edit_output())
87 outputs_button_box.pack_start(edit_button,
True,
True, 0)
89 remove_button = UIUtils.create_button(
'Remove Output', UIUtils.BUTTON_ICONS.REMOVE, UIUtils.BUTTON_ICON_SIZES.PX22)
91 outputs_button_box.pack_start(remove_button,
True,
True, 0)
93 outputs_vbox.pack_start(outputs_button_box,
False,
False, 0)
94 outputs_frame.add(outputs_vbox)
96 vbox.pack_start(outputs_frame,
True,
True, 0)
99 button_box = gtk.HButtonBox()
100 button_box.set_layout(gtk.ButtonBoxStyle.EDGE)
101 cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL)
102 cancel_button.connect(
'clicked',
lambda w: self.window.destroy())
103 button_box.pack_start(cancel_button,
False,
False, 0)
105 ok_button = gtk.Button(stock=gtk.STOCK_OK)
107 button_box.pack_start(ok_button,
False,
False, 0)
109 vbox.pack_end(button_box,
False,
False, 0)
111 self.window.add(vbox)
112 self.window.show_all()
115 return self.name_entry.get_text() !=
''
121 model = self.outputs_treeview.get_model()
123 while row < len(model):
124 outputs.append(model[row][4])
127 name = self.name_entry.get_text()
128 desc = self.desc_entry.get_text()
134 created = self.edit_config.created
135 self.edit_config.db_delete(db)
142 self.window.destroy()
146 UIUtils.show_message_dialog(
'Please make sure that all of the fields have been filled out.', gtk.MessageType.WARNING)
151 while i < len(output.filters):
152 filters_str += output.filters[i].get_filter_desc_str()
153 if i < len(output.filters) - 1:
154 filters_str +=
' and\n'
163 self.outputs_treeview.get_model().append([new_output.name,
165 'Linked' if new_output.chained
else 'Unlinked',
171 model, it = self.outputs_treeview.get_selection().get_selected()
176 UIUtils.show_message_dialog(
'Please select a row.', gtk.MessageType.WARNING)
179 model = self.outputs_treeview.get_model()
182 model.set_value(row_it, 0, edited_output.name)
183 model.set_value(row_it, 1, edited_output.desc)
184 model.set_value(row_it, 2,
'Linked' if edited_output.chained
else 'Unlinked')
186 model.set_value(row_it, 4, edited_output)
189 model, it = self.outputs_treeview.get_selection().get_selected()
191 if UIUtils.show_confirm_dialog(
'Are you sure you want to delete this output?'):
194 UIUtils.show_message_dialog(
'Please select a row.', gtk.MessageType.WARNING)
199 list_store = gtk.ListStore(gobject.TYPE_STRING,
203 gobject.TYPE_PYOBJECT,
207 for cur_output
in existing_outputs:
208 list_store.append([cur_output.name,
210 'Linked' if cur_output.chained
else 'Unlinked',
219 treeview = gtk.TreeView(list_store)
222 col_names = [
'Name',
'Description',
'Link Segs',
'Filters']
223 for i
in range(len(col_names)):
224 col = gtk.TreeViewColumn(col_names[i], gtk.CellRendererText(), text=i)
225 col.set_resizable(
True)
226 col.set_min_width( UIUtils.calc_treeview_col_min_width(col_names[i]) )
227 treeview.append_column(col)