/usr/share/pybliographer/Pyblio/GnomeUI/Utils.py is in pybliographer 1.2.14-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | # This file is part of pybliographer
#
# Copyright (C) 1998-2004 Frederic GOBRY
# Email : gobry@pybliographer.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
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
''' Utility functions for Gnome Interface management. '''
import os
import gtk, pango
import gtk.glade
from gnome import ui
from Pyblio import Config, version
import gconf
class Callback:
''' This class provides a simple requested that asks the user a
queation and waits for an answer. '''
def __init__ (self, question, parent = None):
self.dialog = \
gtk.MessageDialog (parent,
gtk.DIALOG_MODAL |
gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,
gtk.BUTTONS_YES_NO,
question)
return
def answer (self):
res = self.dialog.run () == gtk.RESPONSE_YES
self.dialog.destroy ()
return res
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 wigets whose name starts with _w_
as instance attributes. Therefore, after init, the instance can refer to:
self._w_main
if the glade file defined a _w_main widget.
This class must be derived and the following class variables must
be given some sensible value:
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.
gladeinfo = { 'file': None,
'root': None,
'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)
for w in self.xml.get_widget_prefix ('_w_'):
setattr (self, w.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']
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)
if 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']
w, h = root.get_size ()
config.set_int (cfg + 'width', w)
config.set_int (cfg + 'height', h)
return
config = gconf.client_get_default ()
cursor = {
'clock' : gtk.gdk.Cursor (gtk.gdk.WATCH),
'normal': gtk.gdk.Cursor (gtk.gdk.LEFT_PTR),
}
def set_cursor (self, name):
window = self.get_toplevel ().window
if not window: return
window.set_cursor (cursor [name])
while gtk.events_pending ():
gtk.main_iteration (False)
return
##_tooltips = gtk.Tooltips ()
##def set_tip (w, text):
## _tooltips.set_tip (w, text)
## return
##if Config.get ('gnome/tooltips').data:
## _tooltips.enable ()
##else:
## _tooltips.disable ()
def popup_add (menu, item, action = None, argument = None):
''' Helper to add a new menu entry '''
tmp = gtk.MenuItem (item)
if action:
tmp.connect ('activate', action, argument)
tmp.show ()
menu.append (tmp)
return tmp
def error_dialog (title, err, parent = None):
dialog = \
gtk.MessageDialog (parent,
gtk.DIALOG_MODAL |
gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_ERROR,
message_format = title)
b = dialog.add_button (gtk.STOCK_OK, gtk.RESPONSE_OK)
b.set_property ('has_default', True)
buff = gtk.TextBuffer ()
title = buff.create_tag ('title', weight = pango.WEIGHT_BOLD)
text = gtk.TextView ()
text.set_editable (False)
text.set_cursor_visible (False)
text.set_buffer (buff)
text.set_size_request (400, 200)
iter = buff.get_start_iter ()
buff.insert_with_tags (iter, _("The following errors occured:\n"),
title)
buff.insert (iter, str (err))
holder = gtk.ScrolledWindow ()
holder.set_policy (gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
holder.add (text)
dialog.vbox.pack_start (holder)
holder.show_all ()
dialog.run ()
dialog.destroy ()
return
|