From b448eb6fd4f8a8ec7108b224629350391cb0779f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Thu, 17 Aug 2023 23:46:40 +0200 Subject: [PATCH] gui: multiple fixes and warnings removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jaroslav Škarvada --- tuned-gui.glade | 228 ++++++++++++++++++++++++++++++++- tuned-gui.py | 140 ++++++++++++++------ tuned/gtk/gui_plugin_loader.py | 2 +- 3 files changed, 329 insertions(+), 41 deletions(-) diff --git a/tuned-gui.glade b/tuned-gui.glade index 6409663..d56bd32 100644 --- a/tuned-gui.glade +++ b/tuned-gui.glade @@ -134,6 +134,137 @@ buttonCancel1 + + True + False + + + True + False + Add Value + True + + + + + + True + False + Add Custom Value + True + + + + + + True + False + + + + + True + False + Delete Value + True + + + + + + False + dialog + + + False + vertical + 2 + + + False + end + + + gtk-add + True + True + True + True + 0.40999999642372131 + 0.60000002384185791 + bottom + + + False + True + 0 + + + + + gtk-cancel + True + True + True + True + + + False + True + 1 + + + + + False + True + end + 0 + + + + + True + False + vertical + + + True + False + Choose plugin value to add: + + + False + True + 0 + + + + + True + True + Value ... + + + False + True + 1 + + + + + False + True + 1 + + + + + + button3 + button4 + + False dialog @@ -230,6 +361,99 @@ buttonCloseAddPlugin + + False + dialog + + + False + vertical + 2 + + + False + end + + + gtk-add + True + True + True + True + 0.40999999642372131 + 0.60000002384185791 + bottom + + + False + True + 0 + + + + + gtk-cancel + True + True + True + True + + + False + True + 1 + + + + + False + True + end + 0 + + + + + True + False + vertical + + + True + False + Choose plugin value to add: + + + False + True + 0 + + + + + True + False + + + False + True + 1 + + + + + False + True + 1 + + + + + + button1 + button2 + + False dialog @@ -1561,6 +1785,8 @@ False + 600 + 500 @@ -1601,7 +1827,7 @@ - False + True True 1 diff --git a/tuned-gui.py b/tuned-gui.py index 720a969..9a3b4c5 100755 --- a/tuned-gui.py +++ b/tuned-gui.py @@ -41,7 +41,7 @@ except ValueError: "to be installed.") try: - from gi.repository import Gtk, GObject + from gi.repository import Gtk, GObject, GLib except ImportError: raise ImportError("Gtk3 backend requires pygobject to be installed.") @@ -116,8 +116,8 @@ class Base(object): self.builder = Gtk.Builder() try: self.builder.add_from_file(GLADEUI) - except GObject.GError as e: - print("Error loading '%s'" % GLADEUI, file=sys.stderr) + except GLib.GError as e: + print("Error loading '%s', error: '%s'" % (GLADEUI, e), file=sys.stderr) sys.exit(1) # @@ -251,15 +251,12 @@ class Base(object): self.active_profile = None try: self._gobj('summaryProfileName').set_text(self.active_profile.name) - except: + except AttributeError: self.error_dialog('No active profile set', '') try: self._gobj('summaryIncludedProfileName').set_text(self.active_profile.options['include' ]) - except: - - # keyerror probably - + except (AttributeError, KeyError): self._gobj('summaryIncludedProfileName').set_text('None') row = Gtk.ListBoxRow() @@ -278,32 +275,33 @@ class Base(object): self._gobj('listboxSummaryOfActiveProfile').add(sep) sep.show() - for u in self.active_profile.units: - row = Gtk.ListBoxRow() - hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, - spacing=0) - hbox.set_homogeneous(True) - row.add(hbox) - label = Gtk.Label() - label.set_markup(u) - label.set_justify(Gtk.Justification.LEFT) - hbox.pack_start(label, False, True, 1) + if self.active_profile: + for u in self.active_profile.units: + row = Gtk.ListBoxRow() + hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, + spacing=0) + hbox.set_homogeneous(True) + row.add(hbox) + label = Gtk.Label() + label.set_markup(u) + label.set_justify(Gtk.Justification.LEFT) + hbox.pack_start(label, False, True, 1) - grid = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, - spacing=0) - grid.set_homogeneous(True) - for o in self.active_profile.units[u].options: - label_option = Gtk.Label() - label_option.set_markup(o + ' = ' + '' - + self.active_profile.units[u].options[o] - + '') - grid.pack_start(label_option, False, True, 0) + grid = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, + spacing=0) + grid.set_homogeneous(True) + for o in self.active_profile.units[u].options: + label_option = Gtk.Label() + label_option.set_markup(o + ' = ' + '' + + self.active_profile.units[u].options[o] + + '') + grid.pack_start(label_option, False, True, 0) - hbox.pack_start(grid, False, True, 0) - self._gobj('listboxSummaryOfActiveProfile').add(row) - separator = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL) - self._gobj('listboxSummaryOfActiveProfile').add(separator) - separator.show() + hbox.pack_start(grid, False, True, 0) + self._gobj('listboxSummaryOfActiveProfile').add(row) + separator = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL) + self._gobj('listboxSummaryOfActiveProfile').add(separator) + separator.show() self._gobj('listboxSummaryOfActiveProfile').show_all() @@ -414,8 +412,8 @@ class Base(object): self._gobj('notebookPlugins').append_page_menu( self.treeview_for_data( config_options, plugin), - Gtk.Label(plugin), - Gtk.Label(plugin) + Gtk.Label(label = plugin), + Gtk.Label(label = plugin) ) self._gobj('notebookPlugins').show_all() @@ -632,7 +630,7 @@ class Base(object): for (name, unit) in list(profile.units.items()): self._gobj('notebookPlugins').append_page_menu(self.treeview_for_data(unit.options, unit.name), - Gtk.Label(unit.name), Gtk.Label(unit.name)) + Gtk.Label(label = unit.name), Gtk.Label(label = unit.name)) self._gobj('notebookPlugins').show_all() self._gobj('windowProfileEditor').show() @@ -642,11 +640,11 @@ class Base(object): """ treestore = Gtk.ListStore(GObject.TYPE_STRING, - GObject.TYPE_STRING) + GObject.TYPE_STRING) for (option, value) in list(data.items()): treestore.append([str(value), option]) - treeview = Gtk.TreeView(treestore) + treeview = Gtk.TreeView(model = treestore) renderer = Gtk.CellRendererText() column_option = Gtk.TreeViewColumn('Option', renderer, text=0) column_value = Gtk.TreeViewColumn('Value', renderer, text=1) @@ -801,8 +799,8 @@ class Base(object): if event.button == 3: popup = Gtk.Menu() - popup.append(Gtk.MenuItem('add')) - popup.append(Gtk.MenuItem('delete')) + popup.append(Gtk.MenuItem(label = 'add')) + popup.append(Gtk.MenuItem(label = 'delete')) time = event.time self._gobj('menuAddPluginValue').popup( None, @@ -821,6 +819,70 @@ class Base(object): return True return False + def add_plugin_value_to_treeview(self, action): + notebook_plugins = self._gobj('notebookPlugins') + current_plugin = \ + notebook_plugins.get_tab_label(notebook_plugins.get_nth_page(notebook_plugins.get_current_page())).get_text() + current_plugin_options = \ + self.plugin_loader.plugins.get(current_plugin) + curent_plugin_values_model = \ + notebook_plugins.get_nth_page(notebook_plugins.get_current_page()).get_model() + + treestore_plugins_values = Gtk.ListStore(GObject.TYPE_STRING) + + for (vl_name, vl_val) in current_plugin_options.items(): + if not self.liststore_contains_item(curent_plugin_values_model, + vl_name): + treestore_plugins_values.append([vl_name]) + + dialog_add_plugin_value = \ + self.builder.get_object('dialogAddPluginValue') + dialog_add_plugin_value.connect('destroy', lambda d: \ + dialog_add_plugin_value.hide()) + combobox = self.builder.get_object('comboboxPluginsValues') + combobox.set_model(treestore_plugins_values) + + response = dialog_add_plugin_value.run() + dialog_add_plugin_value.hide() + + if response == 1: + active = combobox.get_active_text() + curent_plugin_values_model.append([current_plugin_options.get(active), + active]) + return True + return False + + def add_custom_plugin_value_to_treeview(self, action): + notebook_plugins = self._gobj('notebookPlugins') + curent_plugin_values_model = \ + notebook_plugins.get_nth_page(notebook_plugins.get_current_page()).get_model() + + dialog_add_custom_plugin_value = \ + self.builder.get_object('dialogAddCustomPluginValue') + text = self.builder.get_object('entry2') + dialog_add_custom_plugin_value.connect('destroy', lambda d: \ + dialog_add_custom_plugin_value.hide()) + + response = dialog_add_custom_plugin_value.run() + dialog_add_custom_plugin_value.hide() + + if response == 1: + curent_plugin_values_model.append(['', text.get_text()]) + return True + return False + + def delete_plugin_value_to_treeview(self, action): + notebook_plugins = self._gobj('notebookPlugins') + curent_plugin_values_tree = \ + notebook_plugins.get_nth_page(notebook_plugins.get_current_page()) + + (model, iter) = \ + curent_plugin_values_tree.get_selection().get_selected() + if model is None or iter is None: + return False + model.remove(iter) + return True + def _start_tuned(self): self._su_execute(['service', 'tuned', 'start']) time.sleep(10) diff --git a/tuned/gtk/gui_plugin_loader.py b/tuned/gtk/gui_plugin_loader.py index 309b312..b455c40 100644 --- a/tuned/gtk/gui_plugin_loader.py +++ b/tuned/gtk/gui_plugin_loader.py @@ -53,7 +53,7 @@ class GuiPluginLoader(): self._prefix = 'plugin_' self._sufix = '.py' self._dbus_controller = DBusController(consts.DBUS_BUS, - consts.DBUS_INTERFACE, consts.DBUS_OBJECT + consts.DBUS_INTERFACE, consts.DBUS_OBJECT ) self._get_plugins()