Commit 27a417c7 authored by John (J5) Palmieri's avatar John (J5) Palmieri

pass in the demo app so demos can use utility methods like requesting file paths

parent e7daae91
...@@ -65,7 +65,7 @@ class EntryBufferApp: ...@@ -65,7 +65,7 @@ class EntryBufferApp:
self.window.destroy() self.window.destroy()
Gtk.main_quit() Gtk.main_quit()
def main(): def main(demoapp=None):
app = EntryBufferApp() app = EntryBufferApp()
Gtk.main() Gtk.main()
......
...@@ -79,7 +79,7 @@ class EntryBufferApp: ...@@ -79,7 +79,7 @@ class EntryBufferApp:
self.window.destroy() self.window.destroy()
Gtk.main_quit() Gtk.main_quit()
def main(): def main(demoapp=None):
app = EntryBufferApp() app = EntryBufferApp()
Gtk.main() Gtk.main()
......
...@@ -33,6 +33,7 @@ import sys, os ...@@ -33,6 +33,7 @@ import sys, os
global infobar global infobar
global window global window
global messagelabel global messagelabel
global _demoapp
def widget_destroy(widget, button): def widget_destroy(widget, button):
widget.destroy() widget.destroy()
...@@ -305,7 +306,12 @@ def register_stock_icons(): ...@@ -305,7 +306,12 @@ def register_stock_icons():
factory = Gtk.IconFactory() factory = Gtk.IconFactory()
factory.add_default() factory.add_default()
if _demoapp is None:
filename = os.path.join('data', 'gtk-logo-rgb.gif') filename = os.path.join('data', 'gtk-logo-rgb.gif')
else:
filename = _demoapp.find_file('gtk-logo-rgb.gif')
pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename) pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff) transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff)
icon_set = Gtk.IconSet.new_from_pixbuf(transparent) icon_set = Gtk.IconSet.new_from_pixbuf(transparent)
...@@ -317,10 +323,13 @@ class ToolMenuAction(Gtk.Action): ...@@ -317,10 +323,13 @@ class ToolMenuAction(Gtk.Action):
def do_create_tool_item(self): def do_create_tool_item(self):
return Gtk.MenuToolButton() return Gtk.MenuToolButton()
def main(): def main(demoapp=None):
global infobar global infobar
global window global window
global messagelabel global messagelabel
global _demoapp
_demoapp = demoapp
register_stock_icons() register_stock_icons()
......
...@@ -126,7 +126,7 @@ class AssistantApp: ...@@ -126,7 +126,7 @@ class AssistantApp:
None) None)
self.assistant.set_page_header_image(label, pixbuf) self.assistant.set_page_header_image(label, pixbuf)
def main(): def main(demoapp=None):
app = AssistantApp() app = AssistantApp()
Gtk.main() Gtk.main()
......
...@@ -31,9 +31,15 @@ from gi.repository import Gtk, GdkPixbuf, Gdk ...@@ -31,9 +31,15 @@ from gi.repository import Gtk, GdkPixbuf, Gdk
import os import os
class BuilderApp: class BuilderApp:
def __init__(self): def __init__(self, demoapp):
self.demoapp = demoapp
self.builder = Gtk.Builder() self.builder = Gtk.Builder()
if demoapp is None:
filename = os.path.join('data', 'demo.ui') filename = os.path.join('data', 'demo.ui')
else:
filename = demoapp.find_file('demo.ui')
self.builder.add_from_file(filename) self.builder.add_from_file(filename)
self.builder.connect_signals(self) self.builder.connect_signals(self)
...@@ -49,8 +55,8 @@ class BuilderApp: ...@@ -49,8 +55,8 @@ class BuilderApp:
def quit_activate(self, action): def quit_activate(self, action):
Gtk.main_quit() Gtk.main_quit()
def main(): def main(demoapp=None):
app = BuilderApp() app = BuilderApp(demoapp)
Gtk.main() Gtk.main()
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -113,7 +113,7 @@ class ButtonBoxApp: ...@@ -113,7 +113,7 @@ class ButtonBoxApp:
return frame return frame
def main(): def main(demoapp=None):
app = ButtonBoxApp() app = ButtonBoxApp()
Gtk.main() Gtk.main()
......
...@@ -222,15 +222,9 @@ class ClipboardApp: ...@@ -222,15 +222,9 @@ class ClipboardApp:
item.show() item.show()
menu.append(item) menu.append(item)
#FIXME: This doesn't work as we pass a None as a function
# pointer. PyGI doesn't correctly check for
# allow-none on callback parameters
# Fix is waiting for approval -
# https://bugzilla.gnome.org/show_bug.cgi?id=620906
menu.popup(None, None, None, None, 3, event.button.time) menu.popup(None, None, None, None, 3, event.button.time)
def main(): def main(demoapp=None):
app = ClipboardApp() app = ClipboardApp()
Gtk.main() Gtk.main()
......
...@@ -113,7 +113,7 @@ class ColorSelectorApp: ...@@ -113,7 +113,7 @@ class ColorSelectorApp:
dialog.destroy() dialog.destroy()
def main(): def main(demoapp=None):
app = ColorSelectorApp() app = ColorSelectorApp()
Gtk.main() Gtk.main()
......
...@@ -59,7 +59,9 @@ class MaskEntry(Gtk.Entry): ...@@ -59,7 +59,9 @@ class MaskEntry(Gtk.Entry):
self.set_background() self.set_background()
class ComboboxApp: class ComboboxApp:
def __init__(self): def __init__(self, demoapp):
self.demoapp = demoapp
self.window = Gtk.Window() self.window = Gtk.Window()
self.window.set_title('Combo boxes') self.window.set_title('Combo boxes')
self.window.set_border_width(10) self.window.set_border_width(10)
...@@ -274,8 +276,8 @@ class ComboboxApp: ...@@ -274,8 +276,8 @@ class ComboboxApp:
entry.append_text('2\302\275') entry.append_text('2\302\275')
entry.append_text('Three') entry.append_text('Three')
def main(): def main(demoapp=None):
app = ComboboxApp() app = ComboboxApp(demoapp)
Gtk.main() Gtk.main()
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -241,7 +241,7 @@ class DrawingAreaApp: ...@@ -241,7 +241,7 @@ class DrawingAreaApp:
return True return True
def main(): def main(demoapp=None):
app = DrawingAreaApp() app = DrawingAreaApp()
Gtk.main() Gtk.main()
......
...@@ -7,7 +7,7 @@ from gi.repository import Gtk ...@@ -7,7 +7,7 @@ from gi.repository import Gtk
def _quit(*args): def _quit(*args):
Gtk.main_quit() Gtk.main_quit()
def main(): def main(demoapp=None):
window = Gtk.Window() window = Gtk.Window()
window.connect_after('destroy', _quit) window.connect_after('destroy', _quit)
window.show_all() window.show_all()
......
...@@ -148,7 +148,7 @@ class GtkDemoApp(object): ...@@ -148,7 +148,7 @@ class GtkDemoApp(object):
self.load_demos_from_list(demo_file_list, demo_list) self.load_demos_from_list(demo_file_list, demo_list)
def demo_find_file(self, base=''): def find_file(self, base=''):
dir = os.path.join('demos', 'data') dir = os.path.join('demos', 'data')
logo_file = os.path.join(dir, 'gtk-logo-rgb.gif') logo_file = os.path.join(dir, 'gtk-logo-rgb.gif')
base_file = os.path.join(dir, base) base_file = os.path.join(dir, base)
...@@ -165,7 +165,7 @@ class GtkDemoApp(object): ...@@ -165,7 +165,7 @@ class GtkDemoApp(object):
raise IOError('Cannot find demo data file "%s"' % base) raise IOError('Cannot find demo data file "%s"' % base)
def setup_default_icon(self): def setup_default_icon(self):
filename = self.demo_find_file ('gtk-logo-rgb.gif') filename = self.find_file ('gtk-logo-rgb.gif')
pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename) pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff) transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff)
list = [] list = []
...@@ -212,7 +212,7 @@ class GtkDemoApp(object): ...@@ -212,7 +212,7 @@ class GtkDemoApp(object):
def row_activated_cb(self, view, path, col, store): def row_activated_cb(self, view, path, col, store):
(success, treeiter) = store.get_iter(path) (success, treeiter) = store.get_iter(path)
demo = store.get_value(treeiter, 1) demo = store.get_value(treeiter, 1)
demo.module.main() demo.module.main(self)
def create_tree(self): def create_tree(self):
tree_store = Gtk.TreeStore(str, Demo, Pango.Style) tree_store = Gtk.TreeStore(str, Demo, Pango.Style)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment