def __init__(self, app): super(SnapperGUI, self).__init__() self.builder = Gtk.Builder() self.builder.add_from_file( pkg_resources.resource_filename("snappergui", "glade/mainWindow.glade")) self.statusbar = self.builder.get_object("statusbar") self.snapshotsTreeView = self.builder.get_object("snapstreeview") self.configsGroup = self.builder.get_object("configsGroup") self.window = self.builder.get_object("applicationwindow1") self.stack = self.builder.get_object("stack1") self.builder.connect_signals(self) self.window.set_application(app) self.configView = {} for config in snapper.ListConfigs(): name = str(config[0]) self.configView[name] = snapshotsView(name) self.stack.add_titled(self.configView[name].scrolledwindow, name, name) self.configView[name].selection.connect( "changed", self.on_snapshots_selection_changed) self.init_dbus_signal_handlers() self.window.show()
def __init__(self, parent): super(createSnapshot, self).__init__() builder = Gtk.Builder() builder.add_from_file( pkg_resources.resource_filename("snappergui", "glade/createSnapshot.glade")) self.dialog = builder.get_object("dialogCreate") self.userdataTree = builder.get_object("userdatatreeview") self.dialog.set_transient_for(parent) builder.connect_signals(self) self.config = "" self.description = "" self.cleanup = "" self.userdata = {} configscombo = Gtk.ListStore(str) for config in snapper.ListConfigs(): configscombo.append([str(config[0])]) combobox = builder.get_object("configsCombo") combobox.set_model(configscombo) if len(configscombo) != 0: combobox.set_active(0) builder.get_object("cleanupcombo").set_active(0)
def __init__(self, parent, config_name): super(createSnapshot, self).__init__() builder = Gtk.Builder() builder.add_from_file(pkg_resources.resource_filename("snappergui", "glade/createSnapshot.glade")) self.dialog = builder.get_object("dialogCreate") self.userdataTree = builder.get_object("userdatatreeview") self.userdataTree.get_model().append([self.TYPE_HERE, ""]) self.dialog.set_transient_for(parent) builder.connect_signals(self) self.config = "" self.description = "" self.cleanup = "" self.userdata = {} configscombo = Gtk.ListStore(str) combobox = builder.get_object("configsCombo") combobox.set_model(configscombo) for i, config in enumerate(snapper.ListConfigs()): name = str(config[0]) configscombo.append([name]) if name == config_name: combobox.set_active(i) builder.get_object("cleanupcombo").set_active(0)
def get_changed_settings(self): changed = {} currentConfig = str( snapper.ListConfigs()[self.notebook.get_current_page()][0]) for k, v in self.widgets.items(): currentValue = self.get_current_value(k) if currentValue and v[ 2 + self.notebook.get_current_page()] != currentValue: changed[k] = currentValue return changed
def on_save_settings(self, widget): currentConfig = str( snapper.ListConfigs()[self.notebook.get_current_page()][0]) try: snapper.SetConfig(currentConfig, self.get_changed_settings()) except dbus.exceptions.DBusException as error: if (str(error).find("error.no_permission") != -1): dialog = Gtk.MessageDialog( self.dialog, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "This user does not have permission to edit this configuration" ) dialog.run() dialog.destroy()
def on_response(self, widget, response): if response == Gtk.ResponseType.OK: currentConfig = str(snapper.ListConfigs()[self.notebook.get_current_page()][0]) try: snapper.SetConfig(currentConfig, self.get_changed_settings(currentConfig)) except dbus.exceptions.DBusException as error: if str(error).find("error.no_permission") != -1: self.dialog.destroy() dialog = Gtk.MessageDialog(self.parent, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK, "You don't have permission to edit configurations") dialog.run() dialog.destroy()
def init_configs_stack(self): self._stack = Stack(transition_type=StackTransitionType.CROSSFADE, transition_duration=300, visible=True) self._stack.set_transition_type( Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) for config in snapper.ListConfigs(): name = str(config[0]) self.configView[name] = snapshotsView(name) self._stack.add_titled(self.configView[name].scrolledwindow, name, name) self.configView[name].selection.connect( "changed", self.on_snapshots_selection_changed)
def __init__(self, widget, parent): self.parent = parent builder = Gtk.Builder() builder.add_from_file(pkg_resources.resource_filename("snappergui", "glade/propertiesDialog.glade")) self.dialog = builder.get_object("dialogProperties") self.notebook = builder.get_object("notebookProperties") builder.connect_signals(self) self.dialog.set_transient_for(parent) self.tabs = {} for config in snapper.ListConfigs(): currentTab = PropertiesTab(config) self.tabs[str(config[0])] = currentTab self.notebook.append_page(currentTab.configsGrid, Gtk.Label.new(config[0])) self.notebook.show_all()
def __init__(self, parent): builder = Gtk.Builder() builder.add_from_file( pkg_resources.resource_filename("snappergui", "glade/propertiesDialog.glade")) self.dialog = builder.get_object("dialogProperties") self.notebook = builder.get_object("notebookProperties") builder.connect_signals(self) # key : value = [widget, grid line, ...] later will be appended the settings for each config self.widgets = { "SUBVOLUME": [Gtk.Entry, 0], "FSTYPE": [Gtk.Entry, 1], "ALLOW_USERS": [Gtk.Entry, 2], "ALLOW_GROUPS": [Gtk.Entry, 3], "TIMELINE_CREATE": [Gtk.Switch, 4], "TIMELINE_CLEANUP": [Gtk.Switch, 5], "TIMELINE_LIMIT_HOURLY": [Gtk.SpinButton, 6], "TIMELINE_LIMIT_DAILY": [Gtk.SpinButton, 7], "TIMELINE_LIMIT_MONTHLY": [Gtk.SpinButton, 8], "TIMELINE_LIMIT_YEARLY": [Gtk.SpinButton, 9], "TIMELINE_MIN_AGE": [Gtk.SpinButton, 10], "EMPTY_PRE_POST_CLEANUP": [Gtk.Switch, 11], "EMPTY_PRE_POST_MIN_AGE": [Gtk.SpinButton, 12], "NUMBER_LIMIT": [Gtk.SpinButton, 13], "NUMBER_MIN_AGE": [Gtk.SpinButton, 14], "NUMBER_CLEANUP": [Gtk.Switch, 15], "BACKGROUND_COMPARISON": [Gtk.Switch, 16], "NUMBER_LIMIT_IMPORTANT": [Gtk.SpinButton, 17], "SYNC_ACL": [Gtk.Switch, 18] } # array that will hold the grids for each tab/config self.grid = [] tab = 0 for aux, config in enumerate(snapper.ListConfigs()): # VerticalBox to hold a label and the grid vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) vbox.pack_start(Gtk.Label("Subvolume to snapshot: " + config[1]), False, False, 0) # Grig to hold de pairs key and value self.grid.append( Gtk.Grid(orientation=Gtk.Orientation.VERTICAL, column_homogeneous=False)) vbox.pack_start(self.grid[tab], True, True, 0) for k, v in config[2].items(): # Label that holds the key label = Gtk.Label(k, selectable=True) self.grid[tab].attach(label, 0, self.widgets[k][1], 1, 1) self.widgets[k].append(str(v)) # Values are set here depending on their types if self.widgets[k][0] == Gtk.Entry: widget = self.widgets[k][0](text=v) elif self.widgets[k][0] == Gtk.SpinButton: adjustment = Gtk.Adjustment(0, 0, 5000, 1, 10, 0) widget = self.widgets[k][0](adjustment=adjustment) widget.set_value(int(v)) elif self.widgets[k][0] == Gtk.Switch: widget = self.widgets[k][0]() if v == "yes": widget.set_active(True) elif v == "no": widget.set_active(False) widget.set_halign(Gtk.Align.CENTER) self.grid[tab].attach_next_to(widget, label, Gtk.PositionType.RIGHT, 1, 1) tab += 1 # add a new page to the notebook with the name of the config and the content self.notebook.append_page(vbox, Gtk.Label.new(config[0])) self.notebook.show_all()
def on_main_destroy(self, args): for config in snapper.ListConfigs(): for snapshot in snapper.ListSnapshots(config[0]): if snapshot[6] != '': snapper.UmountSnapshot(config[0], snapshot[0], 'true')