[d-feet/gtk-template] properly handle init_template for composite widgets
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [d-feet/gtk-template] properly handle init_template for composite widgets
- Date: Mon, 4 Feb 2019 17:08:13 +0000 (UTC)
commit 741f73faeb838c95f805af14bb54c3772a83c98f
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Mon Feb 4 18:07:32 2019 +0100
properly handle init_template for composite widgets
init_template is not properly handled on pygobject side.
Along other small fixes from my the latest commit
data/ui/addconnectiondialog.ui | 4 +-
data/ui/bus.ui | 1 +
data/ui/executedialog.ui | 28 +++++---------
data/ui/introspection.ui | 32 +---------------
data/ui/mainwindow.ui | 79 ++++++++++++++++++++++++++++++++++++----
src/dfeet/addconnectiondialog.py | 8 ++--
src/dfeet/application.py | 3 +-
src/dfeet/bus_watch.py | 12 +++---
src/dfeet/executemethoddialog.py | 8 +---
src/dfeet/introspection.py | 41 +++++++++++----------
src/dfeet/window.py | 19 +++-------
11 files changed, 126 insertions(+), 109 deletions(-)
---
diff --git a/data/ui/addconnectiondialog.ui b/data/ui/addconnectiondialog.ui
index e7ca4ac..e37f00c 100644
--- a/data/ui/addconnectiondialog.ui
+++ b/data/ui/addconnectiondialog.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
- <requires lib="gtk+" version="3.2"/>
+ <requires lib="gtk+" version="3.10"/>
<template class="AddConnectionDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
@@ -56,8 +56,8 @@
<object class="GtkComboBoxText" id="address_combo_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="active">0</property>
<property name="has_entry">True</property>
+ <property name="active_id">0</property>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can_focus">False</property>
diff --git a/data/ui/bus.ui b/data/ui/bus.ui
index 223cb2e..62fb460 100644
--- a/data/ui/bus.ui
+++ b/data/ui/bus.ui
@@ -35,6 +35,7 @@
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="shadow_type">none</property>
<child>
<object class="GtkListBox" id="bus_listbox">
<property name="visible">True</property>
diff --git a/data/ui/executedialog.ui b/data/ui/executedialog.ui
index b039a1c..b385e5c 100644
--- a/data/ui/executedialog.ui
+++ b/data/ui/executedialog.ui
@@ -2,6 +2,13 @@
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.12"/>
+ <object class="GtkAdjustment" id="adjustment1">
+ <property name="lower">1</property>
+ <property name="upper">100</property>
+ <property name="value">1</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
<template class="ExecuteMethodDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Execute D-Bus Method</property>
@@ -336,9 +343,7 @@
<object class="GtkLabel" id="label_method_name">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="margin_left">5</property>
- <property name="margin_start">5</property>
+ <property name="halign">baseline</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
<property name="selectable">True</property>
@@ -399,9 +404,7 @@
<object class="GtkLabel" id="label_object_path">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="margin_left">5</property>
- <property name="margin_start">5</property>
+ <property name="halign">baseline</property>
<property name="use_markup">True</property>
<property name="selectable">True</property>
</object>
@@ -415,8 +418,6 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
- <property name="margin_left">5</property>
- <property name="margin_start">5</property>
<property name="use_markup">True</property>
<property name="selectable">True</property>
</object>
@@ -444,9 +445,7 @@
<object class="GtkLabel" id="label_bus_name">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="margin_left">5</property>
- <property name="margin_start">5</property>
+ <property name="halign">baseline</property>
<property name="use_markup">True</property>
<property name="selectable">True</property>
</object>
@@ -479,11 +478,4 @@
<placeholder/>
</child>
</template>
- <object class="GtkAdjustment" id="adjustment1">
- <property name="lower">1</property>
- <property name="upper">100</property>
- <property name="value">1</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
</interface>
diff --git a/data/ui/introspection.ui b/data/ui/introspection.ui
index e551dc7..bcdb9d9 100644
--- a/data/ui/introspection.ui
+++ b/data/ui/introspection.ui
@@ -1,35 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.1 -->
+<!-- Generated with glade 3.22.0 -->
<interface>
- <requires lib="gtk+" version="3.20"/>
- <object class="GtkMessageDialog" id="messagedialog">
- <property name="can_focus">False</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</property>
- <property name="border_width">5</property>
- <property name="type_hint">dialog</property>
- <property name="skip_taskbar_hint">True</property>
- <property name="message_type">error</property>
- <property name="buttons">close</property>
- <child internal-child="vbox">
- <object class="GtkBox" id="messagedialog-vbox">
- <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="messagedialog-action_area">
- <property name="can_focus">False</property>
- </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>
- </object>
- </child>
- </object>
+ <requires lib="gtk+" version="3.12"/>
<object class="GtkTreeStore" id="treestore">
<columns>
<!-- column-name gchararray1 -->
diff --git a/data/ui/mainwindow.ui b/data/ui/mainwindow.ui
index 55844c6..c621a62 100644
--- a/data/ui/mainwindow.ui
+++ b/data/ui/mainwindow.ui
@@ -1,23 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
- <requires lib="gtk+" version="3.10"/>
+ <requires lib="gtk+" version="3.12" />
+ <object class="GtkPopoverMenu" id="popover1">
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin">6</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action_name">win.connect-system-bus</property>
+ <property name="text" translatable="yes">Connect to System Bus</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action_name">win.connect-session-bus</property>
+ <property name="text" translatable="yes">Connect to Session Bus</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action_name">win.connect-other-bus</property>
+ <property name="text" translatable="yes">Connect to other Bus</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action_name">win.close-bus</property>
+ <property name="text" translatable="yes">Close Bus</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action_name">app.help</property>
+ <property name="text" translatable="yes">Help</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action_name">app.about</property>
+ <property name="text" translatable="yes">About D-Feet</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+
<template class="DFeetWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="default_width">600</property>
<property name="default_height">480</property>
- <signal name="delete-event" handler="window_deleted" swapped="no"/>
- <signal name="destroy" handler="window_destroyed" swapped="no"/>
+ <property name="icon_name">org.gnome.dfeet</property>
+ <signal name="delete-event" handler="window_deleted" swapped="no" />
<child>
<object class="GtkStack" id="buses_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_duration">300</property>
<property name="transition_type">slide-left-right</property>
- <signal name="add" handler="stack_child_added" swapped="no"/>
- <signal name="remove" handler="stack_child_removed" swapped="no"/>
+ <signal name="add" handler="stack_child_added" swapped="no" />
+ <signal name="remove" handler="stack_child_removed" swapped="no" />
<child>
- <placeholder/>
+ <placeholder />
</child>
</object>
</child>
@@ -40,7 +103,7 @@
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="valign">center</property>
- <property name="action_name">win.gear-menu</property>
+ <property name="popover">popover1</property>
<child>
<object class="GtkImage" id="gear_image">
<property name="visible">True</property>
@@ -60,4 +123,4 @@
</object>
</child>
</template>
-</interface>
+</interface>
\ No newline at end of file
diff --git a/src/dfeet/addconnectiondialog.py b/src/dfeet/addconnectiondialog.py
index 4699cb3..226e907 100644
--- a/src/dfeet/addconnectiondialog.py
+++ b/src/dfeet/addconnectiondialog.py
@@ -9,6 +9,7 @@ class AddConnectionDialog(Gtk.Dialog):
address_combo_box = Gtk.Template.Child()
def __init__(self, parent, address_bus_history=[]):
super(AddConnectionDialog, self).__init__()
+ self.init_template('AddConnectionDialog')
self.set_transient_for(parent)
address_combo_box_store = Gtk.ListStore(str)
@@ -16,11 +17,8 @@ class AddConnectionDialog(Gtk.Dialog):
for el in address_bus_history:
address_combo_box_store.append([el])
- self.address_combo_box.set_entry_text_column(0)
self.address_combo_box.set_model(address_combo_box_store)
- self.dialog.add_button('gtk-cancel', Gtk.ResponseType.CANCEL)
- self.dialog.add_button('gtk-connect', Gtk.ResponseType.OK)
@property
def address(self):
@@ -32,7 +30,7 @@ class AddConnectionDialog(Gtk.Dialog):
entry = self.address_combo_box.get_child()
return entry.get_text()
- def run(self):
+ def start(self):
response = self.run()
if response == Gtk.ResponseType.CANCEL:
return response
@@ -46,5 +44,5 @@ class AddConnectionDialog(Gtk.Dialog):
else:
return Gtk.ResponseType.OK
- def destroy(self):
+ def quit(self):
self.destroy()
diff --git a/src/dfeet/application.py b/src/dfeet/application.py
index ff0a6ed..7a22dc5 100644
--- a/src/dfeet/application.py
+++ b/src/dfeet/application.py
@@ -19,7 +19,8 @@ class DFeetApp(Gtk.Application):
# Note that the function in C activate() becomes do_activate() in Python
def do_activate(self):
- self._main_win = DFeetWindow(self, self.version)
+ self._main_win = DFeetWindow()
+ self._main_win.set_application(self)
# Note that the function in C startup() becomes do_startup() in Python
def do_startup(self):
diff --git a/src/dfeet/bus_watch.py b/src/dfeet/bus_watch.py
index 358af2d..8e5bcf4 100644
--- a/src/dfeet/bus_watch.py
+++ b/src/dfeet/bus_watch.py
@@ -20,13 +20,13 @@ class BusNameBox(Gtk.Box):
self.__icon_table = IconTable.get_instance()
self.__icon_image = Gtk.Image.new_from_pixbuf(self.__icon_table.default_icon)
- self.__hbox = Gtk.Box(orientation=Gtk.Box.Orientation.HORIZONTAL,
+ self.__hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
spacing=5, halign=Gtk.Align.START)
self.pack_start(self.__hbox, True, True, 0)
# icon
self.__hbox.pack_start(self.__icon_image, True, True, 0)
# other information
- self.__vbox_right = Gtk.Box(orientation=Gtk.Box.Orientation.VERTICAL,
+ self.__vbox_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
spacing=5, expand=True)
self.__hbox.pack_start(self.__vbox_right, True, True, 0)
@@ -123,10 +123,10 @@ class BusWatch(Gtk.Box):
"""watch for a given bus"""
def __init__(self, bus_address):
+ super(BusWatch, self).__init__()
+ self.init_template('BusWatch')
self.__bus_address = bus_address
-
- # create a listbox for all the busnames
- listbox = Gtk.Template.Child('scrolledwindow_listbox').get_children()
+
self.bus_listbox.set_sort_func(self.__listbox_sort_by_name, None)
self.bus_listbox.set_filter_func(self.__listbox_filter_by_name, None)
@@ -198,7 +198,7 @@ class BusWatch(Gtk.Box):
bus_name_box.bus_name,
bus_name_box.unique_name,
connection_is_bus=True)
- self.pack_end(self.__addr_info.introspect_box, True, True, 0)
+ self.pack_end(self.__addr_info, True, True, 0)
self.show_all()
def __name_owner_changed_cb(self, connection, sender_name,
diff --git a/src/dfeet/executemethoddialog.py b/src/dfeet/executemethoddialog.py
index 6b4d9d1..fd45183 100644
--- a/src/dfeet/executemethoddialog.py
+++ b/src/dfeet/executemethoddialog.py
@@ -28,6 +28,7 @@ class ExecuteMethodDialog(Gtk.Dialog):
def __init__(self, connection, connection_is_bus, bus_name,
method_obj, parent_window):
super(ExecuteMethodDialog, self).__init__()
+ self.init_template('ExecuteMethodDialog')
self.set_transient_for(parent_window)
@@ -124,12 +125,7 @@ class ExecuteMethodDialog(Gtk.Dialog):
# output the exception
self.source_textview.get_buffer().set_text(str(e))
self.prettyprint_textview.get_buffer().set_text(pformat(str(e)))
-
- def run(self):
- response = self.run()
- if response == Gtk.ResponseType.DELETE_EVENT or response == Gtk.ResponseType.CLOSE:
- self.destroy()
-
+
@Gtk.Template.Callback('execute_dialog_close_cb')
def close_cb(self, widget):
self.destroy()
diff --git a/src/dfeet/introspection.py b/src/dfeet/introspection.py
index 96da597..b199032 100644
--- a/src/dfeet/introspection.py
+++ b/src/dfeet/introspection.py
@@ -35,12 +35,13 @@ class AddressInfo(Gtk.Box):
def __init__(self, address, name, unique_name, connection_is_bus=True):
super(AddressInfo, self).__init__()
+ self.init_template('AddressInfo')
self.address = address # can be Gio.BusType.SYSTEM or Gio.BusType.SYSTEM or other address
self.name = name # the well-known name or None
self.unique_name = unique_name # the unique name or None
self.connection_is_bus = connection_is_bus # is it a bus or a p2p connection?
-
+
self.treemodel.set_sort_func(0, self.__sort_model)
self.treemodel.set_sort_column_id(0, Gtk.SortType.ASCENDING)
@@ -147,7 +148,7 @@ class AddressInfo(Gtk.Box):
def introspect_start(self):
"""introspect the given bus name and update the tree model"""
# cleanup current tree model
- self.__treemodel.clear()
+ self.treemodel.clear()
# Statistics
self.__get_stats()
@@ -178,58 +179,58 @@ class AddressInfo(Gtk.Box):
tree_iter = None
if len(node_info.interfaces) > 0:
node_obj = DBusNode(self.name, object_path, node_info)
- tree_iter = self.__treemodel.append(tree_iter, ["%s" % object_path, node_obj])
- # tree_iter = self.__treemodel.append(tree_iter, ["Hallo", None])
+ tree_iter = self.treemodel.append(tree_iter, ["%s" % object_path, node_obj])
+ # tree_iter = self.treemodel.append(tree_iter, ["Hallo", None])
# append interfaces to tree model
- name_iter = self.__treemodel.append(tree_iter,
+ name_iter = self.treemodel.append(tree_iter,
["<b>Interfaces</b>", None])
for iface in node_info.interfaces:
iface_obj = DBusInterface(node_obj, iface)
- iface_iter = self.__treemodel.append(
+ iface_iter = self.treemodel.append(
name_iter,
["%s" % iface.name, iface_obj])
# interface methods
if len(iface.methods) > 0:
- iface_methods_iter = self.__treemodel.append(
+ iface_methods_iter = self.treemodel.append(
iface_iter, ["<b>Methods</b>", None])
for iface_method in iface.methods:
method_obj = DBusMethod(iface_obj, iface_method)
- self.__treemodel.append(
+ self.treemodel.append(
iface_methods_iter,
["%s" % method_obj.markup_str, method_obj])
# interface signals
if len(iface.signals) > 0:
- iface_signals_iter = self.__treemodel.append(
+ iface_signals_iter = self.treemodel.append(
iface_iter, ["<b>Signals</b>", None])
for iface_signal in iface.signals:
signal_obj = DBusSignal(iface_obj, iface_signal)
- self.__treemodel.append(
+ self.treemodel.append(
iface_signals_iter,
["%s" % signal_obj.markup_str, signal_obj])
# interface properties
if len(iface.properties) > 0:
- iface_properties_iter = self.__treemodel.append(
+ iface_properties_iter = self.treemodel.append(
iface_iter, ["<b>Properties</b>", None])
for iface_property in iface.properties:
property_obj = DBusProperty(iface_obj, iface_property)
- self.__treemodel.append(
+ self.treemodel.append(
iface_properties_iter,
["%s" % property_obj.markup_str, property_obj])
# interface annotations
if len(iface.annotations) > 0:
- iface_annotations_iter = self.__treemodel.append(
+ iface_annotations_iter = self.treemodel.append(
iface_iter, ["<b>Annotations</b>", None])
for iface_annotation in iface.annotations:
annotation_obj = DBusAnnotation(iface_obj, iface_annotation)
- self.__treemodel.append(
+ self.treemodel.append(
iface_annotations_iter,
["%s" % (annotation_obj.markup_str), annotation_obj])
# are more nodes left?
if len(node_info.nodes) > 0:
for node in node_info.nodes:
- # node_iter = self.__treemodel.append(tree_iter, [node.path, node])
+ # node_iter = self.treemodel.append(tree_iter, [node.path, node])
if object_path == "/":
object_path = ""
object_path_new = object_path + "/" + node.path
@@ -263,9 +264,9 @@ class AddressInfo(Gtk.Box):
# The stats interface might not be enabled. Ignore.
pass
else:
- stats_iter = self.__treemodel.append(None, ["<b>Statistics</b>", None])
+ stats_iter = self.treemodel.append(None, ["<b>Statistics</b>", None])
for k, v in sorted(res[0].items()):
- self.__treemodel.append(stats_iter, [k + " = " + str(v), None])
+ self.treemodel.append(stats_iter, [k + " = " + str(v), None])
def __get_match_rules_cb(self, connection, result_async, data):
"""callback when the GetAllMatchRules dbus function call finished"""
@@ -278,9 +279,9 @@ class AddressInfo(Gtk.Box):
if self.unique_name not in res[0]:
return
- rules_iter = self.__treemodel.append(None, ["<b>Match rules</b>", None])
+ rules_iter = self.treemodel.append(None, ["<b>Match rules</b>", None])
for v in res[0][self.unique_name]:
- self.__treemodel.append(rules_iter, [v, None])
+ self.treemodel.append(rules_iter, [v, None])
def __get_stats(self):
if self.name == 'org.freedesktop.DBus':
@@ -325,7 +326,7 @@ if __name__ == "__main__":
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.set_default_size(1024, 768)
- win.add(ai.introspect_box)
+ win.add(ai)
win.show_all()
try:
Gtk.main()
diff --git a/src/dfeet/window.py b/src/dfeet/window.py
index 6c0249a..c85c4b9 100644
--- a/src/dfeet/window.py
+++ b/src/dfeet/window.py
@@ -36,15 +36,12 @@ class DFeetWindow(Gtk.ApplicationWindow):
HISTORY_MAX_SIZE = 10
- def __init__(self, app, version):
- Gtk.ApplicationWindow.__init__(self, application=app)
- self.version = version
+ def __init__(self):
+ super(DFeetWindow, self).__init__()
+ self.init_template('DFeetWindow')
+
self.session_bus = None
self.system_bus = None
-
- # setup the window
- self.set_icon_name(app.props.application_id)
-
# create actions
action = Gio.SimpleAction.new('connect-system-bus', None)
action.connect('activate', self.__action_connect_system_bus_cb)
@@ -110,10 +107,6 @@ class DFeetWindow(Gtk.ApplicationWindow):
action.connect('activate', self.__action_connect_session_bus_cb)
self.add_action(action)
- @Gtk.Template.Callback('window_destroyed')
- def __on_destroy(self, data=None):
- self.buses_stack.disconnect(None)
-
def __action_connect_system_bus_cb(self, action, parameter):
"""connect to system bus"""
try:
@@ -141,7 +134,7 @@ class DFeetWindow(Gtk.ApplicationWindow):
def __action_connect_other_bus_cb(self, action, parameter):
"""connect to other bus"""
dialog = AddConnectionDialog(self, self.bus_history)
- result = dialog.run()
+ result = dialog.start()
if result == Gtk.ResponseType.OK:
address = dialog.address
if address == 'Session Bus':
@@ -163,7 +156,7 @@ class DFeetWindow(Gtk.ApplicationWindow):
self.bus_history = self.bus_history[0:self.HISTORY_MAX_SIZE]
except Exception as e:
print("can not connect to '%s': %s" % (address, str(e)))
- dialog.destroy()
+ dialog.quit()
def __action_close_bus_cb(self, action, parameter):
"""close current bus"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]