[pybliographer/wip/gtk3: 5/42] utils: Port GladeWindow class to GtkBuilder
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pybliographer/wip/gtk3: 5/42] utils: Port GladeWindow class to GtkBuilder
- Date: Sat, 7 Oct 2017 01:18:06 +0000 (UTC)
commit a4fc1752cd26dea1cd41285a49371b8320d26f3e
Author: Germán Poo-Caamaño <gpoo gnome org>
Date: Wed May 29 20:15:53 2013 -0700
utils: Port GladeWindow class to GtkBuilder
Signed-off-by: Germán Poo-Caamaño <gpoo gnome org>
Pyblio/GnomeUI/Utils.py | 56 ++++++++++++++++++++++++----------------------
1 files changed, 29 insertions(+), 27 deletions(-)
---
diff --git a/Pyblio/GnomeUI/Utils.py b/Pyblio/GnomeUI/Utils.py
index fa4a9f3..9bef032 100644
--- a/Pyblio/GnomeUI/Utils.py
+++ b/Pyblio/GnomeUI/Utils.py
@@ -1,8 +1,9 @@
+# -*- coding: utf-8 -*-
# This file is part of pybliographer
#
-# Copyright (C) 1998-2004 Frederic GOBRY
-# Email : gobry pybliographer org
-#
+# Copyright (C) 1998-2004 Frederic GOBRY <gobry pybliographer org>
+# Copyright (C) 2013 Germán Poo-Caamaño <gpoo gnome org>
+#
# This program 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 2
@@ -63,7 +64,6 @@ class Callback:
glade_root = os.path.join(os.path.dirname(__file__), 'glade')
class GladeWindow:
-
''' A Helper class that builds a graphical interface provided by a
Glade XML file. This class binds the methods with
signal_autoconnect, and imports widgets whose name starts with _w_
@@ -78,10 +78,8 @@ class GladeWindow:
glade_file : name of the glade file (with no directory info)
root_widget : name of the root widget
-
'''
-
# This is a class variable that contains the file name to load for
# each instance of a subclass.
@@ -90,45 +88,49 @@ class GladeWindow:
'name': None
}
- def __init__ (self, parent = None, window = None):
-
- gp = os.path.join(glade_root, self.gladeinfo ['file'])
- self.xml = Gtk.glade.XML (gp, window, domain = "pybliographer")
- self.xml.signal_autoconnect (self)
+ def __init__(self, parent=None, window=None):
+ gp = os.path.join(glade_root, self.gladeinfo['file'])
+ self.xml = Gtk.Builder()
+ self.xml.set_translation_domain('pybliographer')
+ self.xml.add_from_file(gp)
+ self.xml.connect_signals(self)
- for w in self.xml.get_widget_prefix ('_w_'):
- setattr (self, w.name, w)
+ for w in self.xml.get_objects():
+ if isinstance(w, Gtk.Buildable):
+ name = Gtk.Buildable.get_name(w)
+ if name.startswith('_w_'):
+ setattr(self, name, w)
# Set the parent window. The root widget is not necessarily
# exported as an instance attribute.
- root = self.xml.get_widget (self.gladeinfo ['root'])
- cfg = '/apps/pybliographic/%s/' % self.gladeinfo ['name']
+ root = self.xml.get_object(self.gladeinfo['root'])
+ cfg = '/apps/pybliographic/%s/' % self.gladeinfo['name']
- w = config.get_int (cfg + 'width') or -1
- h = config.get_int (cfg + 'height') or -1
+ w = config.get_int(cfg + 'width') or -1
+ h = config.get_int(cfg + 'height') or -1
if w != -1 and h != -1:
- root.set_default_size (w, h)
- root.resize (w, h)
+ root.set_default_size(w, h)
+ root.resize(w, h)
if parent:
- root.set_transient_for (parent)
+ root.set_transient_for(parent)
return
- def size_save (self):
- root = self.xml.get_widget (self.gladeinfo ['root'])
- cfg = '/apps/pybliographic/%s/' % self.gladeinfo ['name']
+ def size_save(self):
+ root = self.xml.get_object(self.gladeinfo['root'])
+ cfg = '/apps/pybliographic/%s/' % self.gladeinfo['name']
- w, h = root.get_size ()
+ w, h = root.get_size()
- config.set_int (cfg + 'width', w)
- config.set_int (cfg + 'height', h)
+ config.set_int(cfg + 'width', w)
+ config.set_int(cfg + 'height', h)
return
-config = GConf.Client.get_default ()
+config = GConf.Client.get_default()
cursor = {
'clock' : Gdk.Cursor.new(Gdk.CursorType.WATCH),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]