Gnome backgrounds, scanner app for VIP Express (circa Jun 2004)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

115 lines
3.0 KiB

  1. # SimpleGladeApp.py
  2. # Module that provides an object oriented abstraction to pygtk and libglade.
  3. # Copyright (C) 2004 Sandino Flores Moreno
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with this library; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. # USA
  18. try:
  19. import os
  20. import sys
  21. import gtk
  22. import gtk.glade
  23. except ImportError:
  24. print "Error importing pygtk2 and pygtk2-libglade"
  25. sys.exit(1)
  26. class SimpleGladeApp(dict):
  27. def __init__(self, glade_filename, main_widget_name=None, domain=None):
  28. gtk.glade.set_custom_handler(self.custom_handler)
  29. if os.path.isfile(glade_filename):
  30. self.glade_path = glade_filename
  31. else:
  32. glade_dir = os.path.split( sys.argv[0] )[0]
  33. self.glade_path = os.path.join(glade_dir, glade_filename)
  34. self.glade = gtk.glade.XML(self.glade_path, main_widget_name, domain)
  35. if main_widget_name:
  36. self.main_widget = self.glade.get_widget(main_widget_name)
  37. else:
  38. self.main_widget = None
  39. self.signal_autoconnect()
  40. self.new()
  41. def signal_autoconnect(self):
  42. signals = {}
  43. for attr_name in dir(self):
  44. attr = getattr(self, attr_name)
  45. if callable(attr):
  46. signals[attr_name] = attr
  47. self.glade.signal_autoconnect(signals)
  48. def custom_handler(self,
  49. glade, function_name, widget_name,
  50. str1, str2, int1, int2):
  51. if hasattr(self, function_name):
  52. handler = getattr(self, function_name)
  53. return handler(str1, str2, int1, int2)
  54. def __getattr__(self, data_name):
  55. if data_name in self:
  56. data = self[data_name]
  57. return data
  58. else:
  59. widget = self.glade.get_widget(data_name)
  60. if widget != None:
  61. self[data_name] = widget
  62. return widget
  63. else:
  64. raise AttributeError, data_name
  65. def __setattr__(self, name, value):
  66. self[name] = value
  67. def new(self):
  68. pass
  69. def on_keyboard_interrupt(self):
  70. pass
  71. def gtk_widget_show(self, widget, *args):
  72. widget.show()
  73. def gtk_widget_hide(self, widget, *args):
  74. widget.hide()
  75. def gtk_widget_grab_focus(self, widget, *args):
  76. widget.grab_focus()
  77. def gtk_widget_destroy(self, widget, *args):
  78. widget.destroy()
  79. def gtk_window_activate_default(self, widget, *args):
  80. widget.activate_default()
  81. def gtk_true(self, *args):
  82. return gtk.TRUE
  83. def gtk_false(self, *args):
  84. return gtk.FALSE
  85. def gtk_main_quit(self, *args):
  86. gtk.main_quit()
  87. def main(self):
  88. gtk.main()
  89. def quit(self):
  90. gtk.main_quit()
  91. def run(self):
  92. try:
  93. self.main()
  94. except KeyboardInterrupt:
  95. self.on_keyboard_interrupt()