1
0
Fork 0

gui: multiple fixes and warnings removal

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2023-08-17 23:46:40 +02:00
parent 3d4a5cd20e
commit b448eb6fd4
3 changed files with 329 additions and 41 deletions

View file

@ -134,6 +134,137 @@
<action-widget response="-1">buttonCancel1</action-widget>
</action-widgets>
</object>
<object class="GtkMenu" id="menuAddPluginValue">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="AddPluginValueMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Add Value</property>
<property name="use_underline">True</property>
<signal name="activate" handler="add_plugin_value_to_treeview" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="AddCustomPluginValueItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Add Custom Value</property>
<property name="use_underline">True</property>
<signal name="activate" handler="add_custom_plugin_value_to_treeview" swapped="no"/>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="DeleteValueMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Delete Value</property>
<property name="use_underline">True</property>
<signal name="activate" handler="delete_plugin_value_to_treeview" swapped="no"/>
</object>
</child>
</object>
<object class="GtkDialog" id="dialogAddCustomPluginValue">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox8">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area8">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button3">
<property name="label">gtk-add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="xalign">0.40999999642372131</property>
<property name="yalign">0.60000002384185791</property>
<property name="image_position">bottom</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button4">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box13">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="Choose plugin value to add:1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Choose plugin value to add:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">Value ...</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="1">button3</action-widget>
<action-widget response="-1">button4</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="dialogAddPlugin">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
@ -230,6 +361,99 @@
<action-widget response="-1">buttonCloseAddPlugin</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="dialogAddPluginValue">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox5">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area5">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="xalign">0.40999999642372131</property>
<property name="yalign">0.60000002384185791</property>
<property name="image_position">bottom</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box12">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="Choose plugin value to add:">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Choose plugin value to add:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="comboboxPluginsValues">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="1">button1</action-widget>
<action-widget response="-1">button2</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="dialogYesNo">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
@ -1561,6 +1785,8 @@
</object>
<object class="GtkWindow" id="windowProfileEditorRaw">
<property name="can_focus">False</property>
<property name="width-request">600</property>
<property name="height-request">500</property>
<signal name="delete-event" handler="on_delete_event" swapped="no"/>
<child>
<placeholder/>
@ -1601,7 +1827,7 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>

View file

@ -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 + ' = ' + '<b>'
+ self.active_profile.units[u].options[o]
+ '</b>')
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 + ' = ' + '<b>'
+ self.active_profile.units[u].options[o]
+ '</b>')
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)

View file

@ -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()