mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-26 00:54:43 +00:00
added
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2670 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
b334d6cedf
commit
0dddb08557
1 changed files with 124 additions and 0 deletions
124
gui/SimpleGladeApp.py
Normal file
124
gui/SimpleGladeApp.py
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
# -*- coding: ascii -*-
|
||||
# Copyright (C) 2004 Sandino Flores Moreno
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
# USA
|
||||
"Module that provides an object oriented abstraction to pygtk and libglade."
|
||||
|
||||
import os
|
||||
import sys
|
||||
import weakref
|
||||
try:
|
||||
import gtk
|
||||
import gtk.glade
|
||||
except ImportError:
|
||||
print >> sys.stderr, "Error importing pygtk2 and pygtk2-libglade"
|
||||
sys.exit(1)
|
||||
|
||||
class SimpleGladeApp (dict):
|
||||
|
||||
def __init__ (self, glade_filename,
|
||||
main_widget_name=None, domain=None, **kwargs):
|
||||
if os.path.isfile(glade_filename):
|
||||
self.glade_path = glade_filename
|
||||
else:
|
||||
glade_dir = os.path.split(sys.argv[0])[0]
|
||||
self.glade_path = os.path.join(glade_dir, glade_filename)
|
||||
for key, value in kwargs.items():
|
||||
try:
|
||||
setattr(self, key, weakref.proxy(value))
|
||||
except TypeError:
|
||||
setattr(self, key, value)
|
||||
self.glade = None
|
||||
gtk.glade.set_custom_handler(self.custom_handler)
|
||||
self.glade = gtk.glade.XML(self.glade_path, main_widget_name, domain)
|
||||
if main_widget_name:
|
||||
self.main_widget = self.glade.get_widget(main_widget_name)
|
||||
else:
|
||||
self.main_widget = None
|
||||
self.signal_autoconnect()
|
||||
self.new()
|
||||
|
||||
def signal_autoconnect (self):
|
||||
signals = {}
|
||||
for attr_name in dir(self):
|
||||
attr = getattr(self, attr_name)
|
||||
if callable(attr):
|
||||
signals[attr_name] = attr
|
||||
self.glade.signal_autoconnect(signals)
|
||||
|
||||
def custom_handler (self,
|
||||
glade, function_name, widget_name,
|
||||
str1, str2, int1, int2):
|
||||
if hasattr(self, function_name):
|
||||
handler = getattr(self, function_name)
|
||||
return handler(str1, str2, int1, int2)
|
||||
|
||||
def __getattr__ (self, data_name):
|
||||
if data_name in self:
|
||||
return self[data_name]
|
||||
else:
|
||||
widget = self.glade.get_widget(data_name)
|
||||
if widget is not None:
|
||||
self[data_name] = widget
|
||||
return widget
|
||||
else:
|
||||
raise AttributeError, data_name
|
||||
|
||||
def __setattr__ (self, name, value):
|
||||
self[name] = value
|
||||
|
||||
def new (self):
|
||||
pass
|
||||
|
||||
def on_keyboard_interrupt (self):
|
||||
pass
|
||||
|
||||
def gtk_widget_show (self, widget, *args):
|
||||
widget.show()
|
||||
|
||||
def gtk_widget_hide (self, widget, *args):
|
||||
widget.hide()
|
||||
|
||||
def gtk_widget_grab_focus (self, widget, *args):
|
||||
widget.grab_focus()
|
||||
|
||||
def gtk_widget_destroy (self, widget, *args):
|
||||
widget.destroy()
|
||||
|
||||
def gtk_window_activate_default (self, widget, *args):
|
||||
widget.activate_default()
|
||||
|
||||
def gtk_true (self, *args):
|
||||
return gtk.TRUE
|
||||
|
||||
def gtk_false (self, *args):
|
||||
return gtk.FALSE
|
||||
|
||||
def gtk_main_quit (self, *args):
|
||||
gtk.main_quit()
|
||||
|
||||
def main (self):
|
||||
gtk.gdk.threads_init()
|
||||
gtk.main()
|
||||
|
||||
def quit (self):
|
||||
gtk.main_quit()
|
||||
|
||||
def run (self):
|
||||
try:
|
||||
self.main()
|
||||
except KeyboardInterrupt:
|
||||
self.on_keyboard_interrupt()
|
||||
Loading…
Reference in a new issue