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:
self.window.destroy()
Gtk.main_quit()
def main():
def main(demoapp=None):
app = EntryBufferApp()
Gtk.main()
......
......@@ -79,7 +79,7 @@ class EntryBufferApp:
self.window.destroy()
Gtk.main_quit()
def main():
def main(demoapp=None):
app = EntryBufferApp()
Gtk.main()
......
......@@ -33,6 +33,7 @@ import sys, os
global infobar
global window
global messagelabel
global _demoapp
def widget_destroy(widget, button):
widget.destroy()
......@@ -305,7 +306,12 @@ def register_stock_icons():
factory = Gtk.IconFactory()
factory.add_default()
filename = os.path.join('data', 'gtk-logo-rgb.gif')
if _demoapp is None:
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)
transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff)
icon_set = Gtk.IconSet.new_from_pixbuf(transparent)
......@@ -317,10 +323,13 @@ class ToolMenuAction(Gtk.Action):
def do_create_tool_item(self):
return Gtk.MenuToolButton()
def main():
def main(demoapp=None):
global infobar
global window
global messagelabel
global _demoapp
_demoapp = demoapp
register_stock_icons()
......
......@@ -126,7 +126,7 @@ class AssistantApp:
None)
self.assistant.set_page_header_image(label, pixbuf)
def main():
def main(demoapp=None):
app = AssistantApp()
Gtk.main()
......
......@@ -31,9 +31,15 @@ from gi.repository import Gtk, GdkPixbuf, Gdk
import os
class BuilderApp:
def __init__(self):
def __init__(self, demoapp):
self.demoapp = demoapp
self.builder = Gtk.Builder()
filename = os.path.join('data', 'demo.ui')
if demoapp is None:
filename = os.path.join('data', 'demo.ui')
else:
filename = demoapp.find_file('demo.ui')
self.builder.add_from_file(filename)
self.builder.connect_signals(self)
......@@ -49,8 +55,8 @@ class BuilderApp:
def quit_activate(self, action):
Gtk.main_quit()
def main():
app = BuilderApp()
def main(demoapp=None):
app = BuilderApp(demoapp)
Gtk.main()
if __name__ == '__main__':
......
......@@ -113,7 +113,7 @@ class ButtonBoxApp:
return frame
def main():
def main(demoapp=None):
app = ButtonBoxApp()
Gtk.main()
......
......@@ -222,15 +222,9 @@ class ClipboardApp:
item.show()
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)
def main():
def main(demoapp=None):
app = ClipboardApp()
Gtk.main()
......
......@@ -113,7 +113,7 @@ class ColorSelectorApp:
dialog.destroy()
def main():
def main(demoapp=None):
app = ColorSelectorApp()
Gtk.main()
......
......@@ -59,7 +59,9 @@ class MaskEntry(Gtk.Entry):
self.set_background()
class ComboboxApp:
def __init__(self):
def __init__(self, demoapp):
self.demoapp = demoapp
self.window = Gtk.Window()
self.window.set_title('Combo boxes')
self.window.set_border_width(10)
......@@ -274,8 +276,8 @@ class ComboboxApp:
entry.append_text('2\302\275')
entry.append_text('Three')
def main():
app = ComboboxApp()
def main(demoapp=None):
app = ComboboxApp(demoapp)
Gtk.main()
if __name__ == '__main__':
......
......@@ -241,7 +241,7 @@ class DrawingAreaApp:
return True
def main():
def main(demoapp=None):
app = DrawingAreaApp()
Gtk.main()
......
......@@ -7,7 +7,7 @@ from gi.repository import Gtk
def _quit(*args):
Gtk.main_quit()
def main():
def main(demoapp=None):
window = Gtk.Window()
window.connect_after('destroy', _quit)
window.show_all()
......
......@@ -148,7 +148,7 @@ class GtkDemoApp(object):
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')
logo_file = os.path.join(dir, 'gtk-logo-rgb.gif')
base_file = os.path.join(dir, base)
......@@ -165,7 +165,7 @@ class GtkDemoApp(object):
raise IOError('Cannot find demo data file "%s"' % base)
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)
transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff)
list = []
......@@ -212,7 +212,7 @@ class GtkDemoApp(object):
def row_activated_cb(self, view, path, col, store):
(success, treeiter) = store.get_iter(path)
demo = store.get_value(treeiter, 1)
demo.module.main()
demo.module.main(self)
def create_tree(self):
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