[d-feet] Move window logic to own file and use GtkApplicationWindow
- From: Thomas Bechtold <toabctl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [d-feet] Move window logic to own file and use GtkApplicationWindow
- Date: Sun, 19 May 2013 07:28:51 +0000 (UTC)
commit a116a307a39188c9fdf7d990cfca42d1ada38a80
Author: Thomas Bechtold <thomasbechtold jpberlin de>
Date: Sun May 19 09:23:56 2013 +0200
Move window logic to own file and use GtkApplicationWindow
data/ui/mainwindow.ui | 155 ++++++++++++++++++--------------------
src/dfeet/application.py | 154 ++------------------------------------
src/dfeet/window.py | 185 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 265 insertions(+), 229 deletions(-)
---
diff --git a/data/ui/mainwindow.ui b/data/ui/mainwindow.ui
index 18619f2..83a390c 100644
--- a/data/ui/mainwindow.ui
+++ b/data/ui/mainwindow.ui
@@ -81,116 +81,107 @@
</object>
</child>
</object>
- <object class="GtkWindow" id="appwindow1">
- <property name="width_request">300</property>
- <property name="height_request">200</property>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="title" translatable="yes" context="yes">D-Feet D-Bus debugger</property>
- <property name="default_width">640</property>
- <property name="default_height">480</property>
- <property name="icon_name">d-feet</property>
<child>
- <object class="GtkVBox" id="vbox1">
+ <object class="GtkMenuBar" id="menubar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkMenuBar" id="menubar1">
+ <object class="GtkMenuItem" id="menuitem_file">
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
- <child>
- <object class="GtkMenuItem" id="menuitem_file">
+ <property name="label" translatable="yes">File</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu" id="menu1">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label" translatable="yes">File</property>
- <property name="use_underline">True</property>
- <child type="submenu">
- <object class="GtkMenu" id="menu1">
+ <child>
+ <object class="GtkMenuItem" id="menuitem_systembus">
+ <property name="related_action">action_systembus_connect</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
- <child>
- <object class="GtkMenuItem" id="menuitem_systembus">
- <property name="related_action">action_systembus_connect</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="menuitem_sessionbus">
- <property name="related_action">action_sessionbus_connect</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
- <child>
- <object class="GtkMenuItem" id="menuitem_otherbus">
- <property name="related_action">action_otherbus_connect</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
- <child>
- <object class="GtkSeparatorMenuItem" id="menuitem1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
- <child>
- <object class="GtkImageMenuItem" id="menuitem_close">
- <property name="related_action">action_close</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="use_underline">True</property>
- <property name="use_stock">True</property>
- </object>
- </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="menuitem_sessionbus">
+ <property name="related_action">action_sessionbus_connect</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="menuitem_otherbus">
+ <property name="related_action">action_otherbus_connect</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="menuitem1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="menuitem_close">
+ <property name="related_action">action_close</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
</object>
</child>
</object>
</child>
- <child>
- <object class="GtkMenuItem" id="menuitem_help">
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="menuitem_help">
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Help</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu" id="menu2">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label" translatable="yes">Help</property>
- <property name="use_underline">True</property>
- <child type="submenu">
- <object class="GtkMenu" id="menu2">
+ <child>
+ <object class="GtkMenuItem" id="menuitem_about">
+ <property name="related_action">action_about</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
- <child>
- <object class="GtkMenuItem" id="menuitem_about">
- <property name="related_action">action_about</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
</object>
</child>
</object>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
</child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkNotebook" id="display_notebook">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="scrollable">True</property>
<child>
- <object class="GtkNotebook" id="display_notebook">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="scrollable">True</property>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
+ <placeholder/>
</child>
</object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
</child>
</object>
</interface>
diff --git a/src/dfeet/application.py b/src/dfeet/application.py
index 6835c50..53f775f 100644
--- a/src/dfeet/application.py
+++ b/src/dfeet/application.py
@@ -3,42 +3,11 @@ from __future__ import print_function
from gi.repository import Gtk, Gio, GObject
-from dfeet.bus_watch import BusWatch
-from dfeet.settings import Settings
-from dfeet.uiloader import UILoader
-from dfeet.addconnectiondialog import AddConnectionDialog
-from dfeet.executemethoddialog import ExecuteMethodDialog
-
-
-class NotebookTabLabel(Gtk.Box):
- __gsignals__ = {
- "close-clicked": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()),
- }
-
- def __init__(self, label_text):
- Gtk.Box.__init__(self)
- self.set_orientation(Gtk.Orientation.HORIZONTAL)
- self.set_spacing(5)
- # label
- label = Gtk.Label(label_text)
- self.pack_start(label, True, True, 0)
- # close button
- button = Gtk.Button()
- button.set_relief(Gtk.ReliefStyle.NONE)
- button.set_focus_on_click(False)
- button.add(Gtk.Image.new_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU))
- button.connect("clicked", self.__button_clicked)
- self.pack_end(button, False, False, 0)
- self.show_all()
-
- def __button_clicked(self, button, data=None):
- self.emit("close-clicked")
+from dfeet.window import DFeetWindow
class DFeetApp(Gtk.Application):
- HISTORY_MAX_SIZE = 10
-
def __init__(self, package, version, data_dir):
self.package = package
self.version = version
@@ -46,120 +15,11 @@ class DFeetApp(Gtk.Application):
Gtk.Application.__init__(self, application_id="org.gnome.d-feet",
flags=Gio.ApplicationFlags.FLAGS_NONE)
- self.connect("activate", self.on_application_activate_cb)
-
- signal_dict = {
- 'action_systembus_connect_activate_cb': self.__systembus_connect_cb,
- 'action_sessionbus_connect_activate_cb': self.__sessionbus_connect_cb,
- 'action_otherbus_connect_activate_cb': self.__otherbus_connect_cb,
- 'action_close_activate_cb': self.__close_cb,
- 'action_about_activate_cb': self.__action_about_activate_cb,
- }
-
- settings = Settings.get_instance()
-
- ui = UILoader(self.data_dir, UILoader.UI_MAINWINDOW)
- self.main_window = ui.get_root_widget()
- self.main_window.connect('delete-event', self.__quit_dfeet)
- self.main_window.set_default_size(int(settings.general['windowwidth']),
- int(settings.general['windowheight']))
-
- self.notebook = ui.get_widget('display_notebook')
- self.notebook.show_all()
- self.notebook_page_widget = ui.get_widget('box_notebook_page')
- self.about_dialog = ui.get_widget('aboutdialog')
- #create bus history list and load entries from settings
- self.__bus_history = []
- for bus in settings.general['addbus_list']:
- if bus != '':
- self.__bus_history.append(bus)
-
- ui.connect_signals(signal_dict)
- #add a System- and Session Bus tab
- self.__systembus_connect_cb(None)
- self.__sessionbus_connect_cb(None)
-
- def on_application_activate_cb(self, data=None):
- self.main_window.show()
- self.add_window(self.main_window)
-
- @property
- def bus_history(self):
- return self.__bus_history
-
- @bus_history.setter
- def bus_history(self, history_new):
- self.__bus_history = history_new
-
- def __systembus_connect_cb(self, action):
- """connect to system bus"""
- bw = BusWatch(self.data_dir, Gio.BusType.SYSTEM)
- self.__notebook_append_page(bw.paned_buswatch, "System Bus")
-
- def __sessionbus_connect_cb(self, action):
- """connect to session bus"""
- bw = BusWatch(self.data_dir, Gio.BusType.SESSION)
- self.__notebook_append_page(bw.paned_buswatch, "Session Bus")
-
- def __otherbus_connect_cb(self, action):
- """connect to other bus"""
- dialog = AddConnectionDialog(self.data_dir, self.main_window, self.bus_history)
- result = dialog.run()
- if result == Gtk.ResponseType.OK:
- address = dialog.address
- if address == 'Session Bus':
- self.__sessionbus_connect_cb(None)
- return
- elif address == 'System Bus':
- self.__systembus_connect_cb(None)
- return
- else:
- try:
- bw = BusWatch(self.data_dir, address)
- self.__notebook_append_page(bw.paned_buswatch, address)
- # Fill history
- if address in self.bus_history:
- self.bus_history.remove(address)
- self.bus_history.insert(0, address)
- # Truncating history
- if (len(self.bus_history) > self.HISTORY_MAX_SIZE):
- 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()
-
- def __action_about_activate_cb(self, action):
- """show the about dialog"""
- self.about_dialog.set_visible(True)
- self.about_dialog.run()
- self.about_dialog.set_visible(False)
-
- def __notebook_append_page(self, widget, text):
- """add a page to the notebook"""
- ntl = NotebookTabLabel(text)
- page_nbr = self.notebook.append_page(widget, ntl)
- ntl.connect("close-clicked", self.__notebook_page_close_clicked_cb, widget)
-
- def __notebook_page_close_clicked_cb(self, button, widget):
- """remove a page from the notebook"""
- nbr = self.notebook.page_num(widget)
- self.notebook.remove_page(nbr)
-
- def __close_cb(self, action):
- """quit program"""
- self.__quit_dfeet(self.main_window, None)
-
- def __quit_dfeet(self, main_window, event):
- """quit d-feet application and store some settings"""
- settings = Settings.get_instance()
- size = main_window.get_size()
- pos = main_window.get_position()
-
- settings.general['windowwidth'] = size[0]
- settings.general['windowheight'] = size[1]
- self.bus_history = self.bus_history[0:self.HISTORY_MAX_SIZE]
+ #Note that the function in C activate() becomes do_activate() in Python
+ def do_activate(self):
+ win = DFeetWindow(self, self.package, self.version, self.data_dir)
- settings.general['addbus_list'] = self.bus_history
- settings.write()
- self.quit()
+ #Note that the function in C startup() becomes do_startup() in Python
+ def do_startup(self):
+ Gtk.Application.do_startup(self)
diff --git a/src/dfeet/window.py b/src/dfeet/window.py
new file mode 100644
index 0000000..1a7ae1c
--- /dev/null
+++ b/src/dfeet/window.py
@@ -0,0 +1,185 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 Thomas Bechtold <thomasbechtold jpberlin de>
+
+# This file is part of D-Feet.
+
+# D-Feet is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# D-Feet is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with D-Feet. If not, see <http://www.gnu.org/licenses/>.
+
+from gi.repository import GObject, Gtk, Gio
+
+import gettext
+from gettext import gettext as _
+gettext.textdomain('d-feet')
+
+from dfeet.bus_watch import BusWatch
+from dfeet.settings import Settings
+from dfeet.uiloader import UILoader
+from dfeet.addconnectiondialog import AddConnectionDialog
+from dfeet.executemethoddialog import ExecuteMethodDialog
+
+
+class NotebookTabLabel(Gtk.Box):
+ __gsignals__ = {
+ "close-clicked": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()),
+ }
+
+ def __init__(self, label_text):
+ Gtk.Box.__init__(self)
+ self.set_orientation(Gtk.Orientation.HORIZONTAL)
+ self.set_spacing(5)
+ # label
+ label = Gtk.Label(label_text)
+ self.pack_start(label, True, True, 0)
+ # close button
+ button = Gtk.Button()
+ button.set_relief(Gtk.ReliefStyle.NONE)
+ button.set_focus_on_click(False)
+ button.add(Gtk.Image.new_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU))
+ button.connect("clicked", self.__button_clicked)
+ self.pack_end(button, False, False, 0)
+ self.show_all()
+
+ def __button_clicked(self, button, data=None):
+ self.emit("close-clicked")
+
+
+class DFeetWindow(Gtk.ApplicationWindow):
+ """the main window"""
+
+ HISTORY_MAX_SIZE = 10
+
+ def __init__(self, app, package, version, data_dir):
+ Gtk.Window.__init__(self, application=app)
+ self.package = package
+ self.version = version
+ self.data_dir = data_dir
+ #setup the window
+ self.set_default_size(600, 480)
+ self.set_title(self.package)
+ self.set_icon_name(package)
+
+ signal_dict = {
+ 'action_systembus_connect_activate_cb': self.__systembus_connect_cb,
+ 'action_sessionbus_connect_activate_cb': self.__sessionbus_connect_cb,
+ 'action_otherbus_connect_activate_cb': self.__otherbus_connect_cb,
+ 'action_close_activate_cb': self.__close_cb,
+ 'action_about_activate_cb': self.__action_about_activate_cb,
+ }
+
+ #get settings
+ settings = Settings.get_instance()
+
+ ui = UILoader(self.data_dir, UILoader.UI_MAINWINDOW)
+ vbox1 = ui.get_widget('vbox1')
+ self.add(vbox1)
+ self.connect('delete-event', self.__quit_dfeet)
+ self.set_default_size(int(settings.general['windowwidth']),
+ int(settings.general['windowheight']))
+
+ self.notebook = ui.get_widget('display_notebook')
+ self.notebook.show_all()
+ self.notebook_page_widget = ui.get_widget('box_notebook_page')
+ self.about_dialog = ui.get_widget('aboutdialog')
+ #create bus history list and load entries from settings
+ self.__bus_history = []
+ for bus in settings.general['addbus_list']:
+ if bus != '':
+ self.__bus_history.append(bus)
+
+ ui.connect_signals(signal_dict)
+ #add a System- and Session Bus tab
+ self.__systembus_connect_cb(None)
+ self.__sessionbus_connect_cb(None)
+
+ self.show_all()
+
+ @property
+ def bus_history(self):
+ return self.__bus_history
+
+ @bus_history.setter
+ def bus_history(self, history_new):
+ self.__bus_history = history_new
+
+ def __systembus_connect_cb(self, action):
+ """connect to system bus"""
+ bw = BusWatch(self.data_dir, Gio.BusType.SYSTEM)
+ self.__notebook_append_page(bw.paned_buswatch, "System Bus")
+
+ def __sessionbus_connect_cb(self, action):
+ """connect to session bus"""
+ bw = BusWatch(self.data_dir, Gio.BusType.SESSION)
+ self.__notebook_append_page(bw.paned_buswatch, "Session Bus")
+
+ def __otherbus_connect_cb(self, action):
+ """connect to other bus"""
+ dialog = AddConnectionDialog(self.data_dir, self, self.bus_history)
+ result = dialog.run()
+ if result == Gtk.ResponseType.OK:
+ address = dialog.address
+ if address == 'Session Bus':
+ self.__sessionbus_connect_cb(None)
+ return
+ elif address == 'System Bus':
+ self.__systembus_connect_cb(None)
+ return
+ else:
+ try:
+ bw = BusWatch(self.data_dir, address)
+ self.__notebook_append_page(bw.paned_buswatch, address)
+ # Fill history
+ if address in self.bus_history:
+ self.bus_history.remove(address)
+ self.bus_history.insert(0, address)
+ # Truncating history
+ if (len(self.bus_history) > self.HISTORY_MAX_SIZE):
+ 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()
+
+ def __action_about_activate_cb(self, action):
+ """show the about dialog"""
+ self.about_dialog.set_visible(True)
+ self.about_dialog.run()
+ self.about_dialog.set_visible(False)
+
+ def __notebook_append_page(self, widget, text):
+ """add a page to the notebook"""
+ ntl = NotebookTabLabel(text)
+ page_nbr = self.notebook.append_page(widget, ntl)
+ ntl.connect("close-clicked", self.__notebook_page_close_clicked_cb, widget)
+
+ def __notebook_page_close_clicked_cb(self, button, widget):
+ """remove a page from the notebook"""
+ nbr = self.notebook.page_num(widget)
+ self.notebook.remove_page(nbr)
+
+ def __close_cb(self, action):
+ """quit program"""
+ self.__quit_dfeet(self, None)
+
+ def __quit_dfeet(self, main_window, event):
+ """quit d-feet application and store some settings"""
+ settings = Settings.get_instance()
+ size = main_window.get_size()
+ pos = main_window.get_position()
+
+ settings.general['windowwidth'] = size[0]
+ settings.general['windowheight'] = size[1]
+
+ self.bus_history = self.bus_history[0:self.HISTORY_MAX_SIZE]
+
+ settings.general['addbus_list'] = self.bus_history
+ settings.write()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]