Commit f16972d7 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

Use Gtk.Template for widgets

This uses pygobject!52 in order to clean the code
It also moves the ui's to a gresource file to avoid having the pkgdatadir sent to all the widgets

During the migration, I have also updated some depcreated widgets.
parent a54814c0
Pipeline #56082 failed with stages
in 3 minutes and 57 seconds
subdir('icons')
subdir('ui')
desktop_conf = configuration_data()
desktop_conf.set('PACKAGE', df_name)
......@@ -37,3 +36,11 @@ install_data(
df_namespace + '.gschema.xml',
install_dir: gio_schemasdir,
)
gnome.compile_resources(
df_namespace,
df_namespace + '.gresource.xml',
gresource_bundle: true,
install_dir: df_datadir / meson.project_name(),
install: true
)
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/dfeet">
<file compressed="true" preprocess="xml-stripblanks" alias="addconnectiondialog.ui">ui/addconnectiondialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="bus.ui">ui/bus.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="executedialog.ui">ui/executedialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="introspection.ui">ui/introspection.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="mainwindow.ui">ui/mainwindow.ui</file>
</gresource>
</gresources>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkDialog" id="add_connection_dialog1">
<requires lib="gtk+" version="3.2"/>
<template class="AddConnectionDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Add a Connection</property>
......@@ -14,23 +15,13 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkHBox" id="hbox1">
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog1-action_area">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">See http://dbus.freedesktop.org/doc/dbus-specification.html#addresses</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Address:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
<placeholder/>
</child>
<child>
<placeholder/>
......@@ -39,26 +30,51 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog1-action_area">
<child>
<object class="GtkBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">See http://dbus.freedesktop.org/doc/dbus-specification.html#addresses</property>
<property name="label" translatable="yes">Address:</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
<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>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can_focus">False</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</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>
......@@ -76,5 +92,8 @@
</child>
</object>
</child>
</object>
<child type="titlebar">
<placeholder/>
</child>
</template>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkBox" id="box_bus">
<requires lib="gtk+" version="3.10"/>
<template class="BusWatch" parent="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="spacing">5</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<child>
<object class="GtkBox" id="box_left">
<property name="visible">True</property>
......@@ -16,11 +15,11 @@
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkSearchEntry" id="entry_filter">
<object class="GtkSearchEntry" id="bus_search_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char"></property>
<property name="invisible_char_set">True</property>
<signal name="changed" handler="bus_name_filter_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
......@@ -33,7 +32,19 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<placeholder/>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkListBox" id="bus_listbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<signal name="row-selected" handler="listbox_row_selected" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
<packing>
......@@ -62,5 +73,5 @@
<property name="position">1</property>
</packing>
</child>
</object>
</template>
</interface>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkBox" id="box_introspectview">
<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>
<object class="GtkTreeStore" id="treestore">
<columns>
<!-- column-name gchararray1 -->
<column type="gchararray"/>
<!-- column-name GObject1 -->
<column type="GObject"/>
</columns>
</object>
<template class="AddressInfo" parent="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
......@@ -20,14 +57,12 @@
<property name="halign">start</property>
<property name="label" translatable="yes">Unique name:</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
......@@ -37,14 +72,12 @@
<property name="halign">start</property>
<property name="label" translatable="yes">Name:</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
......@@ -58,8 +91,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
......@@ -73,8 +104,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
......@@ -84,14 +113,12 @@
<property name="halign">start</property>
<property name="label" translatable="yes">Address:</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
......@@ -105,8 +132,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
......@@ -134,20 +159,21 @@
<child>
<object class="GtkButton" id="button_reload">
<property name="visible">True</property>
<property name="valign">center</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="valign">center</property>
<signal name="clicked" handler="button_reload_clicked_cb" swapped="no"/>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage" id="reload_image">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="can_focus">False</property>
<property name="icon_name">view-refresh-symbolic</property>
<property name="icon_size">1</property>
</object>
</child>
<style>
<class name="image-button"/>
</style>
</object>
<packing>
<property name="expand">False</property>
......@@ -202,41 +228,5 @@
<property name="position">1</property>
</packing>
</child>
</object>
<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>
<object class="GtkTreeStore" id="treestore">
<columns>
<!-- column-name gchararray1 -->
<column type="gchararray"/>
<!-- column-name GObject1 -->
<column type="GObject"/>
</columns>
</object>
</template>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<!-- interface-requires gtk+ 3.10 -->
<menu id="gear_menu">
<section>
<item>
<attribute name="label" translatable="yes">Connect to System Bus</attribute>
<attribute name="action">win.connect-system-bus</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Connect to Session Bus</attribute>
<attribute name="action">win.connect-session-bus</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Connect to other Bus</attribute>
<attribute name="action">win.connect-other-bus</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">Close Bus</attribute>
<attribute name="action">win.close-bus</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">About D-Feet</attribute>
<attribute name="action">app.about</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Help</attribute>
<attribute name="action">app.help</attribute>
<attribute name="accel">F1</attribute>
</item>
</section>
</menu>
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
<requires lib="gtk+" version="3.10"/>
<template class="DFeetWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="show-close-button">True</property>
<child type="title">
<object class="GtkStackSwitcher" id="stack_switcher">
<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"/>
<child>
<object class="GtkStack" id="buses_stack">
<property name="visible">True</property>
<property name="valign">center</property>
<property name="stack">buses_stack</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"/>
<child>
<placeholder/>
</child>
</object>
</child>
<child>
<object class="GtkMenuButton" id="gear_menu_button">
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
<property name="valign">center</property>
<property name="can_focus">False</property>
<property name="sensitive">True</property>
<property name="action_name">win.gear-menu</property>
<property name="menu_model">gear_menu</property>
<style>
<class name="image-button"/>
</style>
<property name="show_close_button">True</property>
<child type="title">
<object class="GtkStackSwitcher" id="stack_switcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="stack">buses_stack</property>
</object>
</child>
<child>
<object class="GtkImage" id="gear_image">
<object class="GtkMenuButton" id="gear_menu_button">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_name">open-menu-symbolic</property>
<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>
<child>
<object class="GtkImage" id="gear_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">open-menu-symbolic</property>
<property name="icon_size">1</property>
</object>
</child>
<style>
<class name="image-button"/>
</style>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
<object class="GtkStack" id="buses_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition-type">slide-left-right</property>
<property name="transition-duration">300</property>
</object>
</template>
</interface>
ui_data = files(
'addconnectiondialog.ui',
'bus.ui',
'executedialog.ui',
'introspection.ui',
'mainwindow.ui',
)
install_data(
ui_data,
install_dir: df_pkgdatadir / 'ui',
)
......@@ -42,8 +42,7 @@ locale.textdomain("@GETTEXT_PACKAGE@")
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
from dfeet.application import DFeetApp
from gi.repository import Gio, Gtk, GObject
if __name__ == "__main__":
......@@ -53,6 +52,10 @@ if __name__ == "__main__":
data_dir = os.path.join(os.path.dirname(__file__), "..", "data")
Gtk.IconTheme.get_default().prepend_search_path(
os.path.join(os.path.dirname(__file__), "..", "data", "icons"))
resource = Gio.resource_load(os.path.join(data_dir, 'org.gnome.dfeet.gresource'))
Gio.Resource._register(resource)
#start the application
app = DFeetApp(package="@PACKAGE_NAME@", version="@PACKAGE_VERSION@", data_dir=data_dir)
from dfeet.application import DFeetApp
app = DFeetApp(package="@PACKAGE_NAME@", version="@PACKAGE_VERSION@")
sys.exit(app.run(sys.argv))
# -*- coding: utf-8 -*-
from gi.repository import Gtk, Gio
from dfeet.uiloader import UILoader
@Gtk.Template(resource_path='/org/gnome/dfeet/addconnectiondialog.ui')
class AddConnectionDialog(Gtk.Dialog):
__gtype_name__ = 'AddConnectionDialog'
class AddConnectionDialog:
def __init__(self, data_dir, parent, address_bus_history=[]):
ui = UILoader(data_dir, UILoader.UI_ADDCONNECTIONDIALOG)
self.dialog = ui.get_root_widget()
self.dialog.set_transient_for(parent)
# get the hbox and add address combo box with model
hbox1 = ui.get_widget('hbox1')
self.address_combo_box_store = Gtk.ListStore(str)
self.address_combo_box = Gtk.ComboBox.new_with_model_and_entry(
self.address_combo_box_store)
self.address_combo_box.set_entry_text_column(0)
self.label_status = ui.get_widget('label_status')
hbox1.pack_start(self.address_combo_box, True, True, 0)
hbox1.show_all()
label_status = Gtk.Template.Child()
address_combo_box = Gtk.Template.Child()
def __init__(self, parent, address_bus_history=[]):
super(AddConnectionDialog, self).__init__()
self.set_transient_for(parent)
address_combo_box_store = Gtk.ListStore(str)
# add history to model
for el in address_bus_history:
self.address_combo_box_store.append([el])
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)
......@@ -39,7 +33,7 @@ class AddConnectionDialog:
return entry.get_text()
def run(self):
response = self.dialog.run()
response = self.run()
if response == Gtk.ResponseType.CANCEL:
return response
elif response == Gtk.ResponseType.OK:
......@@ -53,4 +47,4 @@ class AddConnectionDialog:
return Gtk.ResponseType.OK
def destroy(self):
self.dialog.destroy()
self.destroy()
......@@ -11,16 +11,15 @@ _ = gettext.gettext
class DFeetApp(Gtk.Application):
def __init__(self, package, version, data_dir):
def __init__(self, package, version):
self.package = package
self.version = version
self.data_dir = data_dir
Gtk.Application.__init__(self, application_id="org.gnome.dfeet",
flags=Gio.ApplicationFlags.FLAGS_NONE)
# Note that the function in C activate() becomes do_activate() in Python
def do_activate(self):
self._main_win = DFeetWindow(self, self.version, self.data_dir)
self._main_win = DFeetWindow(self, self.version)
# Note that the function in C startup() becomes do_startup() in Python
def do_startup(self):
......
......@@ -3,15 +3,15 @@ from __future__ import print_function
from gi.repository import GObject, Gtk, Gio
from dfeet.uiloader import UILoader
from dfeet.introspection import AddressInfo
from dfeet.wnck_utils import IconTable
class BusNameBox(Gtk.VBox):
class BusNameBox(Gtk.Box):
"""class to represent a BusName (eg 'org.freedesktop.NetworkManager')"""
def __init__(self, bus_name, unique_name):
super(BusNameBox, self).__init__(spacing=5, expand=True)
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=5, expand=True)
self.__bus_name =