def __init__(self, object): gtk.Notebook.__init__(self) self.object = object self._field_widgets = {} #: the widgets for each field self._field_category = {} #: maps the field_id to it's category self._category_changed_counter = {} #: number of changed fields in the category self._category_apply_buttons = {} # apply buttons for each category self._category_reset_buttons = {} # apply buttons for each category widgetfactory = FormWidgetFactory() for (category_id, category) in enumerate(self.categories): self._category_changed_counter[category_id] = 0 num_rows = len(category[1]) + 1 table = gtk.Table(rows=num_rows, columns=1, homogeneous=False) vbox = gtk.VBox() vbox.pack_start(table, expand=False, fill=True, padding=5) self.append_page(vbox, gtk.Label(category[0])) row = 0 for (field_id, field_label) in category[1]: self._field_category[field_id] = category_id # create the label label = gtk.Label() label.set_markup("<b>"+field_label+":</b>") label.set_justify(gtk.JUSTIFY_LEFT) label.set_alignment(0.0, 0.0) table.attach(label, left_attach = 0, right_attach = 1, top_attach = row, bottom_attach = row + 1, xoptions=gtk.FILL, yoptions=gtk.EXPAND | gtk.FILL, xpadding=10, ypadding=7) # now, on to the field itself widget = widgetfactory.create_widget(self.object, field_id) widget.connect('changed', self._changed_callback, field_id) table.attach(widget, left_attach = 1, right_attach = 2, top_attach = row, bottom_attach = row + 1, xoptions=gtk.FILL, yoptions=gtk.EXPAND, xpadding=10, ypadding=0) self._field_widgets[field_id] = widget row += 1 # build reset and apply buttons hbuttonbox = gtk.HButtonBox() hbuttonbox.set_layout(gtk.BUTTONBOX_END) hbuttonbox.set_spacing(20) vbox.pack_end(hbuttonbox, expand=False, fill=False, padding=5) apply_button = gtk.Button(stock=gtk.STOCK_APPLY) hbuttonbox.add(apply_button) apply_button.connect('clicked', self._apply_callback, category_id) self._category_apply_buttons[category_id] = apply_button reset_button = gtk.Button(stock=gtk.STOCK_REVERT_TO_SAVED) hbuttonbox.add(reset_button) reset_button.connect('clicked', self._reset_callback, category_id) self._category_reset_buttons[category_id] = reset_button self.reset_category(category_id) self.show_all()
Resources.register_iconset('condensation-server-connected', 'images/icons/server-connected.svg') Resources.register_iconset('condensation-server-disconnected', 'images/icons/server-disconnected.svg') Resources.register_iconset('condensation-vhost-disabled', 'images/icons/vhost-disabled.svg') Resources.register_iconset('condensation-vhost-enabled', 'images/icons/vhost-enabled.svg') gtk.stock_add([ ('condensation', 'Condensation', 0, 0, 'Condensation'), ('condensation-configuration', '_Configuration', 0, 0, 'Condensation'), ('condensation-install-key', '_Install Key', 0, 0, 'Condensation'), ('condensation-server-connected', 'Server Connected', 0, 0, 'Condensation'), ('condensation-server-disconnected', 'Server Disconnected', 0, 0, 'Condensation'), ('condensation-vhost-disabled', 'VHost Disabled', 0, 0, 'Condensation'), ('condensation-vhost-enabled', 'VHost Enabled', 0, 0, 'Condensation'), ]) # register viewmanagers ViewManager.register_viewmanager('Main', CondensationViewManager) ViewManager.register_viewmanager("Server", ServerViewManager) ViewManager.register_viewmanager("VHost", VHostViewManager) # register views ViewManager.register_view('Server', ServerConfigView) ViewManager.register_view('VHost', VHostConfigView) # register form-widgets FormWidgetFactory.register_widget(BooleanFormWidget) FormWidgetFactory.register_widget(IntegerListFormWidget) FormWidgetFactory.register_widget(StringFormWidget) FormWidgetFactory.register_widget(StringListFormWidget)