diff options
Diffstat (limited to 'examples/demo')
-rwxr-xr-x | examples/demo/demo.py | 356 | ||||
-rwxr-xr-x[-rw-r--r--] | examples/demo/demos/appwindow.py | 28 | ||||
-rwxr-xr-x | examples/demo/demos/flowbox.py | 1395 | ||||
-rw-r--r-- | examples/demo/demos/meson.build | 6 | ||||
-rw-r--r-- | examples/demo/meson.build | 12 | ||||
-rw-r--r-- | examples/demo/org.gnome.pygobject-demo.desktop | 10 | ||||
-rw-r--r-- | examples/demo/org.gnome.pygobject-demo.json | 109 | ||||
-rwxr-xr-x | examples/demo/pygobject-demo.py | 80 |
8 files changed, 929 insertions, 1067 deletions
diff --git a/examples/demo/demo.py b/examples/demo/demo.py deleted file mode 100755 index d67935d9..00000000 --- a/examples/demo/demo.py +++ /dev/null @@ -1,356 +0,0 @@ -#!/usr/bin/env python -# -*- Mode: Python; py-indent-offset: 4 -*- -# vim: tabstop=4 shiftwidth=4 expandtab -# -# Copyright (C) 2010 Red Hat, Inc., John (J5) Palmieri <johnp@redhat.com> -# -# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 -# USA - - -import codecs -import os -import sys -import textwrap - -from gi.repository import GLib, GObject, Pango, GdkPixbuf, Gtk, Gio - -try: - from gi.repository import GtkSource - GtkSource # PyFlakes -except ImportError: - GtkSource = None - - -DEMOROOTDIR = os.path.abspath(os.path.dirname(__file__)) -DEMOCODEDIR = os.path.join(DEMOROOTDIR, 'demos') -sys.path.insert(0, DEMOROOTDIR) - - -class Demo(GObject.GObject): - __gtype_name__ = 'GtkDemo' - - def __init__(self, title, module, filename): - super(Demo, self).__init__() - - self.title = title - self.module = module - self.filename = filename - - @classmethod - def new_from_file(cls, path): - relpath = os.path.relpath(path, DEMOROOTDIR) - packagename = os.path.dirname(relpath).replace(os.sep, '.') - modulename = os.path.basename(relpath)[0:-3] - - package = __import__(packagename, globals(), locals(), [modulename], 0) - module = getattr(package, modulename) - - try: - return cls(module.title, module, path) - except AttributeError as e: - raise AttributeError('(%s): %s' % (path, e.message)) - - -class DemoTreeStore(Gtk.TreeStore): - __gtype_name__ = 'GtkDemoTreeStore' - - def __init__(self, *args): - super(DemoTreeStore, self).__init__(str, Demo, Pango.Style) - - self._parent_nodes = {} - - for filename in self._list_dir(DEMOCODEDIR): - fullpath = os.path.join(DEMOCODEDIR, filename) - initfile = os.path.join(os.path.dirname(fullpath), '__init__.py') - - if fullpath != initfile and os.path.isfile(initfile) and fullpath.endswith('.py'): - parentname = os.path.dirname(os.path.relpath(fullpath, DEMOCODEDIR)) - - if parentname: - parent = self._get_parent_node(parentname) - else: - parent = None - - demo = Demo.new_from_file(fullpath) - self.append(parent, (demo.title, demo, Pango.Style.NORMAL)) - - def _list_dir(self, path): - demo_file_list = [] - - for filename in os.listdir(path): - fullpath = os.path.join(path, filename) - - if os.path.isdir(fullpath): - demo_file_list.extend(self._list_dir(fullpath)) - elif os.path.isfile(fullpath): - demo_file_list.append(fullpath) - - return sorted(demo_file_list, key=str.lower) - - def _get_parent_node(self, name): - if name not in self._parent_nodes.keys(): - node = self.append(None, (name, None, Pango.Style.NORMAL)) - self._parent_nodes[name] = node - - return self._parent_nodes[name] - - -class GtkDemoApp(Gtk.Application): - __gtype_name__ = 'GtkDemoWindow' - - def __init__(self): - super(GtkDemoApp, self).__init__(application_id='org.gnome.pygobject.gtkdemo') - - # Use a GResource to hold the CSS files. Resource bundles are created by - # the glib-compile-resources program shipped with Glib which takes an xml - # file that describes the bundle, and a set of files that the xml - # references. These are combined into a binary resource bundle. - base_path = os.path.abspath(os.path.dirname(__file__)) - resource_path = os.path.join(base_path, 'demos/data/demo.gresource') - resource = Gio.Resource.load(resource_path) - - # FIXME: method register() should be without the underscore - # FIXME: see https://bugzilla.gnome.org/show_bug.cgi?id=684319 - # Once the resource has been globally registered it can be used - # throughout the application. - resource._register() - - def on_activate(self, app): - self.window = Gtk.ApplicationWindow.new(self) - self.window.set_title('PyGObject GTK+ Code Demos') - self.window.set_default_size(600, 400) - self.setup_default_icon() - - self.header_bar = Gtk.HeaderBar(show_close_button=True, - subtitle='Foobar') - self.window.set_titlebar(self.header_bar) - - stack = Gtk.Stack(transition_type=Gtk.StackTransitionType.SLIDE_LEFT_RIGHT, - homogeneous=True) - switcher = Gtk.StackSwitcher(stack=stack, halign=Gtk.Align.CENTER) - - self.header_bar.set_custom_title(switcher) - - hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, - homogeneous=False, - spacing=0) - self.window.add(hbox) - - tree = self.create_tree() - hbox.pack_start(child=tree, expand=False, fill=False, padding=0) - hbox.pack_start(child=stack, expand=True, fill=True, padding=0) - - text_widget, info_buffer = self.create_text_view() - stack.add_titled(text_widget, name='info', title='Info') - - self.info_buffer = info_buffer - self.info_buffer.create_tag('title', font='Sans 18') - - text_widget, self.source_buffer = self.create_source_view() - stack.add_titled(text_widget, name='source', title='Source') - - self.window.show_all() - - self.selection_cb(self.tree_view.get_selection(), - self.tree_view.get_model()) - - def find_file(self, base=''): - dir = os.path.join(DEMOCODEDIR, 'data') - logo_file = os.path.join(dir, 'gtk-logo-rgb.gif') - base_file = os.path.join(dir, base) - - if (GLib.file_test(logo_file, GLib.FileTest.EXISTS) and - GLib.file_test(base_file, GLib.FileTest.EXISTS)): - return base_file - else: - filename = os.path.join(DEMOCODEDIR, base) - - if GLib.file_test(filename, GLib.FileTest.EXISTS): - return filename - - # can't find the file - raise IOError('Cannot find demo data file "%s"' % base) - - def setup_default_icon(self): - filename = self.find_file('gtk-logo-rgb.gif') - pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename) - transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff) - list = [] - list.append(transparent) - Gtk.Window.set_default_icon_list(list) - - def selection_cb(self, selection, model): - sel = selection.get_selected() - if sel == (): - return - - treeiter = sel[1] - title = model.get_value(treeiter, 0) - demo = model.get_value(treeiter, 1) - - if demo is None: - return - - # Split into paragraphs based on double newlines and use - # textwrap to strip out all other formatting whitespace - description = '' - for paragraph in demo.module.description.split('\n\n'): - description += '\n'.join(textwrap.wrap(paragraph, 99999)) - description += '\n\n' # Add paragraphs back in - - f = codecs.open(demo.filename, 'rU', 'utf-8') - code = f.read() - f.close() - - # output and style the title - (start, end) = self.info_buffer.get_bounds() - self.info_buffer.delete(start, end) - (start, end) = self.source_buffer.get_bounds() - self.source_buffer.delete(start, end) - - start = self.info_buffer.get_iter_at_offset(0) - end = start.copy() - self.info_buffer.insert(end, title) - start = end.copy() - start.backward_chars(len(title)) - self.info_buffer.apply_tag_by_name('title', start, end) - self.info_buffer.insert(end, '\n') - - # output the description - self.info_buffer.insert(end, description) - - # output the code - start = self.source_buffer.get_iter_at_offset(0) - end = start.copy() - self.source_buffer.insert(end, code) - - def row_activated_cb(self, view, path, col, store): - iter = store.get_iter(path) - demo = store.get_value(iter, 1) - - if demo is not None: - store.set_value(iter, 2, Pango.Style.ITALIC) - try: - demo.module.main(self) - finally: - store.set_value(iter, 2, Pango.Style.NORMAL) - - def create_tree(self): - tree_store = DemoTreeStore() - tree_view = Gtk.TreeView() - self.tree_view = tree_view - tree_view.set_model(tree_store) - selection = tree_view.get_selection() - selection.set_mode(Gtk.SelectionMode.BROWSE) - tree_view.set_size_request(200, -1) - - cell = Gtk.CellRendererText() - column = Gtk.TreeViewColumn(title='Widget (double click for demo)', - cell_renderer=cell, - text=0, - style=2) - - first_iter = tree_store.get_iter_first() - if first_iter is not None: - selection.select_iter(first_iter) - - selection.connect('changed', self.selection_cb, tree_store) - tree_view.connect('row_activated', self.row_activated_cb, tree_store) - - tree_view.append_column(column) - - tree_view.expand_all() - tree_view.set_headers_visible(False) - scrolled_window = Gtk.ScrolledWindow(hadjustment=None, - vadjustment=None) - scrolled_window.set_policy(Gtk.PolicyType.NEVER, - Gtk.PolicyType.AUTOMATIC) - - scrolled_window.add(tree_view) - - label = Gtk.Label(label='Widget (double click for demo)') - - box = Gtk.Notebook() - box.append_page(scrolled_window, label) - - tree_view.grab_focus() - - return box - - def create_scrolled_window(self): - scrolled_window = Gtk.ScrolledWindow(hadjustment=None, - vadjustment=None) - scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, - Gtk.PolicyType.AUTOMATIC) - scrolled_window.set_shadow_type(Gtk.ShadowType.IN) - return scrolled_window - - def create_text_view(self): - text_view = Gtk.TextView() - buffer = Gtk.TextBuffer() - - text_view.set_buffer(buffer) - text_view.set_editable(False) - text_view.set_cursor_visible(False) - - scrolled_window = self.create_scrolled_window() - scrolled_window.add(text_view) - - text_view.set_wrap_mode(Gtk.WrapMode.WORD) - text_view.set_pixels_above_lines(2) - text_view.set_pixels_below_lines(2) - - return scrolled_window, buffer - - def create_source_view(self): - font_desc = Pango.FontDescription('monospace 11') - - if GtkSource: - lang_mgr = GtkSource.LanguageManager() - lang = lang_mgr.get_language('python') - - buffer = GtkSource.Buffer() - buffer.set_language(lang) - buffer.set_highlight_syntax(True) - - view = GtkSource.View() - view.set_buffer(buffer) - view.set_show_line_numbers(True) - - scrolled_window = self.create_scrolled_window() - scrolled_window.add(view) - - else: - scrolled_window, buffer = self.create_text_view() - view = scrolled_window.get_child() - - view.modify_font(font_desc) - view.set_wrap_mode(Gtk.WrapMode.NONE) - return scrolled_window, buffer - - def run(self, argv): - self.connect('activate', self.on_activate) - return super(GtkDemoApp, self).run(argv) - - -def main(argv): - """Entry point for demo manager""" - app = GtkDemoApp() - return app.run(argv) - - -if __name__ == '__main__': - SystemExit(main(sys.argv)) diff --git a/examples/demo/demos/appwindow.py b/examples/demo/demos/appwindow.py index d44ca0da..9dc9eb2a 100644..100755 --- a/examples/demo/demos/appwindow.py +++ b/examples/demo/demos/appwindow.py @@ -25,20 +25,12 @@ Demonstrates a typical application window with menubar, toolbar, statusbar. """ import os - -from gi.repository import GdkPixbuf, Gtk +import sys import gi gi.require_version('Gtk', '4.0') from gi.repository import Gtk - -infobar = None -window = None -messagelabel = None -_demoapp = None - - def widget_destroy(widget, button): widget.destroy() @@ -266,27 +258,25 @@ ui_info = """ </ui> """ +def get_content() -> Gtk.Widget: + box = Gtk.Box() + button = Gtk.Button.new_with_label("Test") + box.add(button) + + return box def _quit(*args): Gtk.main_quit() def main(demoapp=None): - global infobar - global window - global messagelabel - global _demoapp - - _demoapp = demoapp - window = Gtk.Window() window.set_title('Application Window') window.set_icon_name('gtk-open') window.set_default_size(200, 200) window.connect_after('destroy', _quit) - button = Gtk.Button.new_with_label("Test") - window.add(button) + content = get_content() + window.add(content) - window.show() Gtk.main() diff --git a/examples/demo/demos/flowbox.py b/examples/demo/demos/flowbox.py index 0485b7c0..1080155f 100755 --- a/examples/demo/demos/flowbox.py +++ b/examples/demo/demos/flowbox.py @@ -27,6 +27,707 @@ support sorting and filtering. The children of a GtkFlowBox are regular widgets. from gi.repository import Gtk, Gdk +def get_content(): + flowbox = Gtk.FlowBox() + flowbox.set_valign(Gtk.Align.START) + flowbox.set_max_children_per_line(30) + flowbox.set_selection_mode(Gtk.SelectionMode.NONE) + + content = create_flowbox(flowbox) + + return flowbox + +def color_swatch_new(str_color): + rgba = Gdk.RGBA() + rgba.parse(str_color) + + text_str = 'white' # default is white + if max(rgba.red, rgba.green, rgba.blue) > 0.6: + text_str = 'black' + + label = Gtk.Label(label=str_color) + + style = f'.{str_color} {{ color: {text_str}; background-color: {str_color}; }}' + css_provider = Gtk.CssProvider() + css_provider.load_from_data(str.encode(style)) + display = Gdk.Display.get_default() + style_context = label.get_style_context() + style_context.add_provider_for_display(display, css_provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) + return label + +def create_flowbox(flowbox): + colors = [ + 'AliceBlue', + 'AntiqueWhite', + 'AntiqueWhite1', + 'AntiqueWhite2', + 'AntiqueWhite3', + 'AntiqueWhite4', + 'aqua', + 'aquamarine', + 'aquamarine1', + 'aquamarine2', + 'aquamarine3', + 'aquamarine4', + 'azure', + 'azure1', + 'azure2', + 'azure3', + 'azure4', + 'beige', + 'bisque', + 'bisque1', + 'bisque2', + 'bisque3', + 'bisque4', + 'black', + 'BlanchedAlmond', + 'blue', + 'blue1', + 'blue2', + 'blue3', + 'blue4', + 'BlueViolet', + 'brown', + 'brown1', + 'brown2', + 'brown3', + 'brown4', + 'burlywood', + 'burlywood1', + 'burlywood2', + 'burlywood3', + 'burlywood4', + 'CadetBlue', + 'CadetBlue1', + 'CadetBlue2', + 'CadetBlue3', + 'CadetBlue4', + 'chartreuse', + 'chartreuse1', + 'chartreuse2', + 'chartreuse3', + 'chartreuse4', + 'chocolate', + 'chocolate1', + 'chocolate2', + 'chocolate3', + 'chocolate4', + 'coral', + 'coral1', + 'coral2', + 'coral3', + 'coral4', + 'CornflowerBlue', + 'cornsilk', + 'cornsilk1', + 'cornsilk2', + 'cornsilk3', + 'cornsilk4', + 'crimson', + 'cyan', + 'cyan1', + 'cyan2', + 'cyan3', + 'cyan4', + 'DarkBlue', + 'DarkCyan', + 'DarkGoldenrod', + 'DarkGoldenrod1', + 'DarkGoldenrod2', + 'DarkGoldenrod3', + 'DarkGoldenrod4', + 'DarkGray', + 'DarkGreen', + 'DarkGrey', + 'DarkKhaki', + 'DarkMagenta', + 'DarkOliveGreen', + 'DarkOliveGreen1', + 'DarkOliveGreen2', + 'DarkOliveGreen3', + 'DarkOliveGreen4', + 'DarkOrange', + 'DarkOrange1', + 'DarkOrange2', + 'DarkOrange3', + 'DarkOrange4', + 'DarkOrchid', + 'DarkOrchid1', + 'DarkOrchid2', + 'DarkOrchid3', + 'DarkOrchid4', + 'DarkRed', + 'DarkSalmon', + 'DarkSeaGreen', + 'DarkSeaGreen1', + 'DarkSeaGreen2', + 'DarkSeaGreen3', + 'DarkSeaGreen4', + 'DarkSlateBlue', + 'DarkSlateGray', + 'DarkSlateGray1', + 'DarkSlateGray2', + 'DarkSlateGray3', + 'DarkSlateGray4', + 'DarkSlateGrey', + 'DarkTurquoise', + 'DarkViolet', + 'DeepPink', + 'DeepPink1', + 'DeepPink2', + 'DeepPink3', + 'DeepPink4', + 'DeepSkyBlue', + 'DeepSkyBlue1', + 'DeepSkyBlue2', + 'DeepSkyBlue3', + 'DeepSkyBlue4', + 'DimGray', + 'DimGrey', + 'DodgerBlue', + 'DodgerBlue1', + 'DodgerBlue2', + 'DodgerBlue3', + 'DodgerBlue4', + 'firebrick', + 'firebrick1', + 'firebrick2', + 'firebrick3', + 'firebrick4', + 'FloralWhite', + 'ForestGreen', + 'fuchsia', + 'gainsboro', + 'GhostWhite', + 'gold', + 'gold1', + 'gold2', + 'gold3', + 'gold4', + 'goldenrod', + 'goldenrod1', + 'goldenrod2', + 'goldenrod3', + 'goldenrod4', + 'gray', + 'gray0', + 'gray1', + 'gray2', + 'gray3', + 'gray4', + 'gray5', + 'gray6', + 'gray7', + 'gray8', + 'gray9', + 'gray10', + 'gray11', + 'gray12', + 'gray13', + 'gray14', + 'gray15', + 'gray16', + 'gray17', + 'gray18', + 'gray19', + 'gray20', + 'gray21', + 'gray22', + 'gray23', + 'gray24', + 'gray25', + 'gray26', + 'gray27', + 'gray28', + 'gray29', + 'gray30', + 'gray31', + 'gray32', + 'gray33', + 'gray34', + 'gray35', + 'gray36', + 'gray37', + 'gray38', + 'gray39', + 'gray40', + 'gray41', + 'gray42', + 'gray43', + 'gray44', + 'gray45', + 'gray46', + 'gray47', + 'gray48', + 'gray49', + 'gray50', + 'gray51', + 'gray52', + 'gray53', + 'gray54', + 'gray55', + 'gray56', + 'gray57', + 'gray58', + 'gray59', + 'gray60', + 'gray61', + 'gray62', + 'gray63', + 'gray64', + 'gray65', + 'gray66', + 'gray67', + 'gray68', + 'gray69', + 'gray70', + 'gray71', + 'gray72', + 'gray73', + 'gray74', + 'gray75', + 'gray76', + 'gray77', + 'gray78', + 'gray79', + 'gray80', + 'gray81', + 'gray82', + 'gray83', + 'gray84', + 'gray85', + 'gray86', + 'gray87', + 'gray88', + 'gray89', + 'gray90', + 'gray91', + 'gray92', + 'gray93', + 'gray94', + 'gray95', + 'gray96', + 'gray97', + 'gray98', + 'gray99', + 'gray100', + 'green', + 'green1', + 'green2', + 'green3', + 'green4', + 'GreenYellow', + 'grey', + 'grey0', + 'grey1', + 'grey2', + 'grey3', + 'grey4', + 'grey5', + 'grey6', + 'grey7', + 'grey8', + 'grey9', + 'grey10', + 'grey11', + 'grey12', + 'grey13', + 'grey14', + 'grey15', + 'grey16', + 'grey17', + 'grey18', + 'grey19', + 'grey20', + 'grey21', + 'grey22', + 'grey23', + 'grey24', + 'grey25', + 'grey26', + 'grey27', + 'grey28', + 'grey29', + 'grey30', + 'grey31', + 'grey32', + 'grey33', + 'grey34', + 'grey35', + 'grey36', + 'grey37', + 'grey38', + 'grey39', + 'grey40', + 'grey41', + 'grey42', + 'grey43', + 'grey44', + 'grey45', + 'grey46', + 'grey47', + 'grey48', + 'grey49', + 'grey50', + 'grey51', + 'grey52', + 'grey53', + 'grey54', + 'grey55', + 'grey56', + 'grey57', + 'grey58', + 'grey59', + 'grey60', + 'grey61', + 'grey62', + 'grey63', + 'grey64', + 'grey65', + 'grey66', + 'grey67', + 'grey68', + 'grey69', + 'grey70', + 'grey71', + 'grey72', + 'grey73', + 'grey74', + 'grey75', + 'grey76', + 'grey77', + 'grey78', + 'grey79', + 'grey80', + 'grey81', + 'grey82', + 'grey83', + 'grey84', + 'grey85', + 'grey86', + 'grey87', + 'grey88', + 'grey89', + 'grey90', + 'grey91', + 'grey92', + 'grey93', + 'grey94', + 'grey95', + 'grey96', + 'grey97', + 'grey98', + 'grey99', + 'grey100', + 'honeydew', + 'honeydew1', + 'honeydew2', + 'honeydew3', + 'honeydew4', + 'HotPink', + 'HotPink1', + 'HotPink2', + 'HotPink3', + 'HotPink4', + 'IndianRed', + 'IndianRed1', + 'IndianRed2', + 'IndianRed3', + 'IndianRed4', + 'indigo', + 'ivory', + 'ivory1', + 'ivory2', + 'ivory3', + 'ivory4', + 'khaki', + 'khaki1', + 'khaki2', + 'khaki3', + 'khaki4', + 'lavender', + 'LavenderBlush', + 'LavenderBlush1', + 'LavenderBlush2', + 'LavenderBlush3', + 'LavenderBlush4', + 'LawnGreen', + 'LemonChiffon', + 'LemonChiffon1', + 'LemonChiffon2', + 'LemonChiffon3', + 'LemonChiffon4', + 'LightBlue', + 'LightBlue1', + 'LightBlue2', + 'LightBlue3', + 'LightBlue4', + 'LightCoral', + 'LightCyan', + 'LightCyan1', + 'LightCyan2', + 'LightCyan3', + 'LightCyan4', + 'LightGoldenrod', + 'LightGoldenrod1', + 'LightGoldenrod2', + 'LightGoldenrod3', + 'LightGoldenrod4', + 'LightGoldenrodYellow', + 'LightGray', + 'LightGreen', + 'LightGrey', + 'LightPink', + 'LightPink1', + 'LightPink2', + 'LightPink3', + 'LightPink4', + 'LightSalmon', + 'LightSalmon1', + 'LightSalmon2', + 'LightSalmon3', + 'LightSalmon4', + 'LightSeaGreen', + 'LightSkyBlue', + 'LightSkyBlue1', + 'LightSkyBlue2', + 'LightSkyBlue3', + 'LightSkyBlue4', + 'LightSlateBlue', + 'LightSlateGray', + 'LightSlateGrey', + 'LightSteelBlue', + 'LightSteelBlue1', + 'LightSteelBlue2', + 'LightSteelBlue3', + 'LightSteelBlue4', + 'LightYellow', + 'LightYellow1', + 'LightYellow2', + 'LightYellow3', + 'LightYellow4', + 'lime', + 'LimeGreen', + 'linen', + 'magenta', + 'magenta1', + 'magenta2', + 'magenta3', + 'magenta4', + 'maroon', + 'maroon1', + 'maroon2', + 'maroon3', + 'maroon4', + 'MediumAquamarine', + 'MediumBlue', + 'MediumOrchid', + 'MediumOrchid1', + 'MediumOrchid2', + 'MediumOrchid3', + 'MediumOrchid4', + 'MediumPurple', + 'MediumPurple1', + 'MediumPurple2', + 'MediumPurple3', + 'MediumPurple4', + 'MediumSeaGreen', + 'MediumSlateBlue', + 'MediumSpringGreen', + 'MediumTurquoise', + 'MediumVioletRed', + 'MidnightBlue', + 'MintCream', + 'MistyRose', + 'MistyRose1', + 'MistyRose2', + 'MistyRose3', + 'MistyRose4', + 'moccasin', + 'NavajoWhite', + 'NavajoWhite1', + 'NavajoWhite2', + 'NavajoWhite3', + 'NavajoWhite4', + 'navy', + 'NavyBlue', + 'OldLace', + 'olive', + 'OliveDrab', + 'OliveDrab1', + 'OliveDrab2', + 'OliveDrab3', + 'OliveDrab4', + 'orange', + 'orange1', + 'orange2', + 'orange3', + 'orange4', + 'OrangeRed', + 'OrangeRed1', + 'OrangeRed2', + 'OrangeRed3', + 'OrangeRed4', + 'orchid', + 'orchid1', + 'orchid2', + 'orchid3', + 'orchid4', + 'PaleGoldenrod', + 'PaleGreen', + 'PaleGreen1', + 'PaleGreen2', + 'PaleGreen3', + 'PaleGreen4', + 'PaleTurquoise', + 'PaleTurquoise1', + 'PaleTurquoise2', + 'PaleTurquoise3', + 'PaleTurquoise4', + 'PaleVioletRed', + 'PaleVioletRed1', + 'PaleVioletRed2', + 'PaleVioletRed3', + 'PaleVioletRed4', + 'PapayaWhip', + 'PeachPuff', + 'PeachPuff1', + 'PeachPuff2', + 'PeachPuff3', + 'PeachPuff4', + 'peru', + 'pink', + 'pink1', + 'pink2', + 'pink3', + 'pink4', + 'plum', + 'plum1', + 'plum2', + 'plum3', + 'plum4', + 'PowderBlue', + 'purple', + 'purple1', + 'purple2', + 'purple3', + 'purple4', + 'red', + 'red1', + 'red2', + 'red3', + 'red4', + 'RosyBrown', + 'RosyBrown1', + 'RosyBrown2', + 'RosyBrown3', + 'RosyBrown4', + 'RoyalBlue', + 'RoyalBlue1', + 'RoyalBlue2', + 'RoyalBlue3', + 'RoyalBlue4', + 'SaddleBrown', + 'salmon', + 'salmon1', + 'salmon2', + 'salmon3', + 'salmon4', + 'SandyBrown', + 'SeaGreen', + 'SeaGreen1', + 'SeaGreen2', + 'SeaGreen3', + 'SeaGreen4', + 'seashell', + 'seashell1', + 'seashell2', + 'seashell3', + 'seashell4', + 'sienna', + 'sienna1', + 'sienna2', + 'sienna3', + 'sienna4', + 'silver', + 'SkyBlue', + 'SkyBlue1', + 'SkyBlue2', + 'SkyBlue3', + 'SkyBlue4', + 'SlateBlue', + 'SlateBlue1', + 'SlateBlue2', + 'SlateBlue3', + 'SlateBlue4', + 'SlateGray', + 'SlateGray1', + 'SlateGray2', + 'SlateGray3', + 'SlateGray4', + 'SlateGrey', + 'snow', + 'snow1', + 'snow2', + 'snow3', + 'snow4', + 'SpringGreen', + 'SpringGreen1', + 'SpringGreen2', + 'SpringGreen3', + 'SpringGreen4', + 'SteelBlue', + 'SteelBlue1', + 'SteelBlue2', + 'SteelBlue3', + 'SteelBlue4', + 'tan', + 'tan1', + 'tan2', + 'tan3', + 'tan4', + 'teal', + 'thistle', + 'thistle1', + 'thistle2', + 'thistle3', + 'thistle4', + 'tomato', + 'tomato1', + 'tomato2', + 'tomato3', + 'tomato4', + 'turquoise', + 'turquoise1', + 'turquoise2', + 'turquoise3', + 'turquoise4', + 'violet', + 'VioletRed', + 'VioletRed1', + 'VioletRed2', + 'VioletRed3', + 'VioletRed4', + 'wheat', + 'wheat1', + 'wheat2', + 'wheat3', + 'wheat4', + 'white', + 'WhiteSmoke', + 'yellow', + 'yellow1', + 'yellow2', + 'yellow3', + 'yellow4', + 'YellowGreen', + ] + + for color in colors: + button = color_swatch_new(color) + flowbox.add(button) class FlowBoxApp: def __init__(self): @@ -44,703 +745,13 @@ class FlowBoxApp: scrolled = Gtk.ScrolledWindow() scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) - flowbox = Gtk.FlowBox() - flowbox.set_valign(Gtk.Align.START) - flowbox.set_max_children_per_line(30) - flowbox.set_selection_mode(Gtk.SelectionMode.NONE) - - self.create_flowbox(flowbox) + content = get_content() - scrolled.add(flowbox) + scrolled.add(content) window.add(scrolled) window.show_all() - def color_swatch_new(self, str_color): - rgba = Gdk.RGBA() - rgba.parse(str_color) - - text_rgba = Gdk.RGBA() # default is white - if max(rgba.red, rgba.green, rgba.blue) > 0.6: - text_rgba.parse('black') - - label = Gtk.Label(label=str_color) - label.override_background_color(0, rgba) - label.override_color(0, text_rgba) - return label - - def create_flowbox(self, flowbox): - colors = [ - 'AliceBlue', - 'AntiqueWhite', - 'AntiqueWhite1', - 'AntiqueWhite2', - 'AntiqueWhite3', - 'AntiqueWhite4', - 'aqua', - 'aquamarine', - 'aquamarine1', - 'aquamarine2', - 'aquamarine3', - 'aquamarine4', - 'azure', - 'azure1', - 'azure2', - 'azure3', - 'azure4', - 'beige', - 'bisque', - 'bisque1', - 'bisque2', - 'bisque3', - 'bisque4', - 'black', - 'BlanchedAlmond', - 'blue', - 'blue1', - 'blue2', - 'blue3', - 'blue4', - 'BlueViolet', - 'brown', - 'brown1', - 'brown2', - 'brown3', - 'brown4', - 'burlywood', - 'burlywood1', - 'burlywood2', - 'burlywood3', - 'burlywood4', - 'CadetBlue', - 'CadetBlue1', - 'CadetBlue2', - 'CadetBlue3', - 'CadetBlue4', - 'chartreuse', - 'chartreuse1', - 'chartreuse2', - 'chartreuse3', - 'chartreuse4', - 'chocolate', - 'chocolate1', - 'chocolate2', - 'chocolate3', - 'chocolate4', - 'coral', - 'coral1', - 'coral2', - 'coral3', - 'coral4', - 'CornflowerBlue', - 'cornsilk', - 'cornsilk1', - 'cornsilk2', - 'cornsilk3', - 'cornsilk4', - 'crimson', - 'cyan', - 'cyan1', - 'cyan2', - 'cyan3', - 'cyan4', - 'DarkBlue', - 'DarkCyan', - 'DarkGoldenrod', - 'DarkGoldenrod1', - 'DarkGoldenrod2', - 'DarkGoldenrod3', - 'DarkGoldenrod4', - 'DarkGray', - 'DarkGreen', - 'DarkGrey', - 'DarkKhaki', - 'DarkMagenta', - 'DarkOliveGreen', - 'DarkOliveGreen1', - 'DarkOliveGreen2', - 'DarkOliveGreen3', - 'DarkOliveGreen4', - 'DarkOrange', - 'DarkOrange1', - 'DarkOrange2', - 'DarkOrange3', - 'DarkOrange4', - 'DarkOrchid', - 'DarkOrchid1', - 'DarkOrchid2', - 'DarkOrchid3', - 'DarkOrchid4', - 'DarkRed', - 'DarkSalmon', - 'DarkSeaGreen', - 'DarkSeaGreen1', - 'DarkSeaGreen2', - 'DarkSeaGreen3', - 'DarkSeaGreen4', - 'DarkSlateBlue', - 'DarkSlateGray', - 'DarkSlateGray1', - 'DarkSlateGray2', - 'DarkSlateGray3', - 'DarkSlateGray4', - 'DarkSlateGrey', - 'DarkTurquoise', - 'DarkViolet', - 'DeepPink', - 'DeepPink1', - 'DeepPink2', - 'DeepPink3', - 'DeepPink4', - 'DeepSkyBlue', - 'DeepSkyBlue1', - 'DeepSkyBlue2', - 'DeepSkyBlue3', - 'DeepSkyBlue4', - 'DimGray', - 'DimGrey', - 'DodgerBlue', - 'DodgerBlue1', - 'DodgerBlue2', - 'DodgerBlue3', - 'DodgerBlue4', - 'firebrick', - 'firebrick1', - 'firebrick2', - 'firebrick3', - 'firebrick4', - 'FloralWhite', - 'ForestGreen', - 'fuchsia', - 'gainsboro', - 'GhostWhite', - 'gold', - 'gold1', - 'gold2', - 'gold3', - 'gold4', - 'goldenrod', - 'goldenrod1', - 'goldenrod2', - 'goldenrod3', - 'goldenrod4', - 'gray', - 'gray0', - 'gray1', - 'gray2', - 'gray3', - 'gray4', - 'gray5', - 'gray6', - 'gray7', - 'gray8', - 'gray9', - 'gray10', - 'gray11', - 'gray12', - 'gray13', - 'gray14', - 'gray15', - 'gray16', - 'gray17', - 'gray18', - 'gray19', - 'gray20', - 'gray21', - 'gray22', - 'gray23', - 'gray24', - 'gray25', - 'gray26', - 'gray27', - 'gray28', - 'gray29', - 'gray30', - 'gray31', - 'gray32', - 'gray33', - 'gray34', - 'gray35', - 'gray36', - 'gray37', - 'gray38', - 'gray39', - 'gray40', - 'gray41', - 'gray42', - 'gray43', - 'gray44', - 'gray45', - 'gray46', - 'gray47', - 'gray48', - 'gray49', - 'gray50', - 'gray51', - 'gray52', - 'gray53', - 'gray54', - 'gray55', - 'gray56', - 'gray57', - 'gray58', - 'gray59', - 'gray60', - 'gray61', - 'gray62', - 'gray63', - 'gray64', - 'gray65', - 'gray66', - 'gray67', - 'gray68', - 'gray69', - 'gray70', - 'gray71', - 'gray72', - 'gray73', - 'gray74', - 'gray75', - 'gray76', - 'gray77', - 'gray78', - 'gray79', - 'gray80', - 'gray81', - 'gray82', - 'gray83', - 'gray84', - 'gray85', - 'gray86', - 'gray87', - 'gray88', - 'gray89', - 'gray90', - 'gray91', - 'gray92', - 'gray93', - 'gray94', - 'gray95', - 'gray96', - 'gray97', - 'gray98', - 'gray99', - 'gray100', - 'green', - 'green1', - 'green2', - 'green3', - 'green4', - 'GreenYellow', - 'grey', - 'grey0', - 'grey1', - 'grey2', - 'grey3', - 'grey4', - 'grey5', - 'grey6', - 'grey7', - 'grey8', - 'grey9', - 'grey10', - 'grey11', - 'grey12', - 'grey13', - 'grey14', - 'grey15', - 'grey16', - 'grey17', - 'grey18', - 'grey19', - 'grey20', - 'grey21', - 'grey22', - 'grey23', - 'grey24', - 'grey25', - 'grey26', - 'grey27', - 'grey28', - 'grey29', - 'grey30', - 'grey31', - 'grey32', - 'grey33', - 'grey34', - 'grey35', - 'grey36', - 'grey37', - 'grey38', - 'grey39', - 'grey40', - 'grey41', - 'grey42', - 'grey43', - 'grey44', - 'grey45', - 'grey46', - 'grey47', - 'grey48', - 'grey49', - 'grey50', - 'grey51', - 'grey52', - 'grey53', - 'grey54', - 'grey55', - 'grey56', - 'grey57', - 'grey58', - 'grey59', - 'grey60', - 'grey61', - 'grey62', - 'grey63', - 'grey64', - 'grey65', - 'grey66', - 'grey67', - 'grey68', - 'grey69', - 'grey70', - 'grey71', - 'grey72', - 'grey73', - 'grey74', - 'grey75', - 'grey76', - 'grey77', - 'grey78', - 'grey79', - 'grey80', - 'grey81', - 'grey82', - 'grey83', - 'grey84', - 'grey85', - 'grey86', - 'grey87', - 'grey88', - 'grey89', - 'grey90', - 'grey91', - 'grey92', - 'grey93', - 'grey94', - 'grey95', - 'grey96', - 'grey97', - 'grey98', - 'grey99', - 'grey100', - 'honeydew', - 'honeydew1', - 'honeydew2', - 'honeydew3', - 'honeydew4', - 'HotPink', - 'HotPink1', - 'HotPink2', - 'HotPink3', - 'HotPink4', - 'IndianRed', - 'IndianRed1', - 'IndianRed2', - 'IndianRed3', - 'IndianRed4', - 'indigo', - 'ivory', - 'ivory1', - 'ivory2', - 'ivory3', - 'ivory4', - 'khaki', - 'khaki1', - 'khaki2', - 'khaki3', - 'khaki4', - 'lavender', - 'LavenderBlush', - 'LavenderBlush1', - 'LavenderBlush2', - 'LavenderBlush3', - 'LavenderBlush4', - 'LawnGreen', - 'LemonChiffon', - 'LemonChiffon1', - 'LemonChiffon2', - 'LemonChiffon3', - 'LemonChiffon4', - 'LightBlue', - 'LightBlue1', - 'LightBlue2', - 'LightBlue3', - 'LightBlue4', - 'LightCoral', - 'LightCyan', - 'LightCyan1', - 'LightCyan2', - 'LightCyan3', - 'LightCyan4', - 'LightGoldenrod', - 'LightGoldenrod1', - 'LightGoldenrod2', - 'LightGoldenrod3', - 'LightGoldenrod4', - 'LightGoldenrodYellow', - 'LightGray', - 'LightGreen', - 'LightGrey', - 'LightPink', - 'LightPink1', - 'LightPink2', - 'LightPink3', - 'LightPink4', - 'LightSalmon', - 'LightSalmon1', - 'LightSalmon2', - 'LightSalmon3', - 'LightSalmon4', - 'LightSeaGreen', - 'LightSkyBlue', - 'LightSkyBlue1', - 'LightSkyBlue2', - 'LightSkyBlue3', - 'LightSkyBlue4', - 'LightSlateBlue', - 'LightSlateGray', - 'LightSlateGrey', - 'LightSteelBlue', - 'LightSteelBlue1', - 'LightSteelBlue2', - 'LightSteelBlue3', - 'LightSteelBlue4', - 'LightYellow', - 'LightYellow1', - 'LightYellow2', - 'LightYellow3', - 'LightYellow4', - 'lime', - 'LimeGreen', - 'linen', - 'magenta', - 'magenta1', - 'magenta2', - 'magenta3', - 'magenta4', - 'maroon', - 'maroon1', - 'maroon2', - 'maroon3', - 'maroon4', - 'MediumAquamarine', - 'MediumBlue', - 'MediumOrchid', - 'MediumOrchid1', - 'MediumOrchid2', - 'MediumOrchid3', - 'MediumOrchid4', - 'MediumPurple', - 'MediumPurple1', - 'MediumPurple2', - 'MediumPurple3', - 'MediumPurple4', - 'MediumSeaGreen', - 'MediumSlateBlue', - 'MediumSpringGreen', - 'MediumTurquoise', - 'MediumVioletRed', - 'MidnightBlue', - 'MintCream', - 'MistyRose', - 'MistyRose1', - 'MistyRose2', - 'MistyRose3', - 'MistyRose4', - 'moccasin', - 'NavajoWhite', - 'NavajoWhite1', - 'NavajoWhite2', - 'NavajoWhite3', - 'NavajoWhite4', - 'navy', - 'NavyBlue', - 'OldLace', - 'olive', - 'OliveDrab', - 'OliveDrab1', - 'OliveDrab2', - 'OliveDrab3', - 'OliveDrab4', - 'orange', - 'orange1', - 'orange2', - 'orange3', - 'orange4', - 'OrangeRed', - 'OrangeRed1', - 'OrangeRed2', - 'OrangeRed3', - 'OrangeRed4', - 'orchid', - 'orchid1', - 'orchid2', - 'orchid3', - 'orchid4', - 'PaleGoldenrod', - 'PaleGreen', - 'PaleGreen1', - 'PaleGreen2', - 'PaleGreen3', - 'PaleGreen4', - 'PaleTurquoise', - 'PaleTurquoise1', - 'PaleTurquoise2', - 'PaleTurquoise3', - 'PaleTurquoise4', - 'PaleVioletRed', - 'PaleVioletRed1', - 'PaleVioletRed2', - 'PaleVioletRed3', - 'PaleVioletRed4', - 'PapayaWhip', - 'PeachPuff', - 'PeachPuff1', - 'PeachPuff2', - 'PeachPuff3', - 'PeachPuff4', - 'peru', - 'pink', - 'pink1', - 'pink2', - 'pink3', - 'pink4', - 'plum', - 'plum1', - 'plum2', - 'plum3', - 'plum4', - 'PowderBlue', - 'purple', - 'purple1', - 'purple2', - 'purple3', - 'purple4', - 'red', - 'red1', - 'red2', - 'red3', - 'red4', - 'RosyBrown', - 'RosyBrown1', - 'RosyBrown2', - 'RosyBrown3', - 'RosyBrown4', - 'RoyalBlue', - 'RoyalBlue1', - 'RoyalBlue2', - 'RoyalBlue3', - 'RoyalBlue4', - 'SaddleBrown', - 'salmon', - 'salmon1', - 'salmon2', - 'salmon3', - 'salmon4', - 'SandyBrown', - 'SeaGreen', - 'SeaGreen1', - 'SeaGreen2', - 'SeaGreen3', - 'SeaGreen4', - 'seashell', - 'seashell1', - 'seashell2', - 'seashell3', - 'seashell4', - 'sienna', - 'sienna1', - 'sienna2', - 'sienna3', - 'sienna4', - 'silver', - 'SkyBlue', - 'SkyBlue1', - 'SkyBlue2', - 'SkyBlue3', - 'SkyBlue4', - 'SlateBlue', - 'SlateBlue1', - 'SlateBlue2', - 'SlateBlue3', - 'SlateBlue4', - 'SlateGray', - 'SlateGray1', - 'SlateGray2', - 'SlateGray3', - 'SlateGray4', - 'SlateGrey', - 'snow', - 'snow1', - 'snow2', - 'snow3', - 'snow4', - 'SpringGreen', - 'SpringGreen1', - 'SpringGreen2', - 'SpringGreen3', - 'SpringGreen4', - 'SteelBlue', - 'SteelBlue1', - 'SteelBlue2', - 'SteelBlue3', - 'SteelBlue4', - 'tan', - 'tan1', - 'tan2', - 'tan3', - 'tan4', - 'teal', - 'thistle', - 'thistle1', - 'thistle2', - 'thistle3', - 'thistle4', - 'tomato', - 'tomato1', - 'tomato2', - 'tomato3', - 'tomato4', - 'turquoise', - 'turquoise1', - 'turquoise2', - 'turquoise3', - 'turquoise4', - 'violet', - 'VioletRed', - 'VioletRed1', - 'VioletRed2', - 'VioletRed3', - 'VioletRed4', - 'wheat', - 'wheat1', - 'wheat2', - 'wheat3', - 'wheat4', - 'white', - 'WhiteSmoke', - 'yellow', - 'yellow1', - 'yellow2', - 'yellow3', - 'yellow4', - 'YellowGreen', - ] - - for color in colors: - button = self.color_swatch_new(color) - flowbox.add(button) def main(demoapp=None): diff --git a/examples/demo/demos/meson.build b/examples/demo/demos/meson.build new file mode 100644 index 00000000..1654d784 --- /dev/null +++ b/examples/demo/demos/meson.build @@ -0,0 +1,6 @@ +demo_sources = [ + 'appwindow.py', + 'flowbox.py', +] + +install_data(demo_sources, install_dir: get_option('bindir')) diff --git a/examples/demo/meson.build b/examples/demo/meson.build new file mode 100644 index 00000000..477b3ef0 --- /dev/null +++ b/examples/demo/meson.build @@ -0,0 +1,12 @@ +if get_option('demos') +subdir('demos') + +demo_app_sources = [ + 'pygobject-demo.py', +] +# desktop file +install_data('org.gnome.pygobject-demo.desktop', + install_dir: join_paths(get_option('datadir'), 'applications')) +install_data(demo_app_sources, install_dir: get_option('bindir')) + +endif
\ No newline at end of file diff --git a/examples/demo/org.gnome.pygobject-demo.desktop b/examples/demo/org.gnome.pygobject-demo.desktop new file mode 100644 index 00000000..1cbe6a63 --- /dev/null +++ b/examples/demo/org.gnome.pygobject-demo.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=PYGobject Demo +Comment=A demo of PyGObject. +Exec=pygobject-demo.py +Icon=pygobject-demo +Terminal=false +Type=Application +StartupNotify=true +Categories=Development;GTK; +NoDisplay=true
\ No newline at end of file diff --git a/examples/demo/org.gnome.pygobject-demo.json b/examples/demo/org.gnome.pygobject-demo.json new file mode 100644 index 00000000..a468b972 --- /dev/null +++ b/examples/demo/org.gnome.pygobject-demo.json @@ -0,0 +1,109 @@ +{ + "app-id" : "org.gnome.pygobject-demo", + "runtime" : "org.gnome.Platform", + "runtime-version" : "master", + "sdk" : "org.gnome.Sdk", + "command" : "pygobject-demo.py", + "finish-args" : [ + "--device=dri", + "--share=ipc", + "--socket=x11", + "--socket=wayland", + "--talk-name=org.gnome.OnlineAccounts", + "--filesystem=host", + "--talk-name=org.gtk.vfs", + "--talk-name=org.gtk.vfs.*", + "--filesystem=xdg-run/dconf", + "--filesystem=~/.config/dconf:ro", + "--talk-name=ca.desrt.dconf", + "--env=DCONF_USER_CONFIG_DIR=.config/dconf" + ], + "build-options" : { + "build-args" : [ + "--share=network" + ], + "cflags" : "-O2 -g", + "cxxflags" : "-O2 -g", + "env" : { + "V" : "1", + "GI_TYPELIB_PATH" : "/app/lib/girepository-1.0/", + "PYTHONPATH": "/app/lib/python3.7/site-packages" + } + }, + "modules" : [ + { + "name" : "pytest", + "buildsystem" : "simple", + "build-commands" : [ + "/usr/bin/pip3 --disable-pip-version-check install --prefix=/app --verbose ." + ], + "sources" : [ + { + "type" : "git", + "url" : "https://github.com/pytest-dev/pytest", + "tag" : "3.7.2" + } + ] + }, + { + "name" : "wayland", + "buildsystem" : "autotools", + "builddir" : true, + "config-opts" : [ + "--disable-documentation" + ], + "sources" : [ + { + "type" : "git", + "url" : "https://github.com/wayland-project/wayland.git" + } + ] + }, + { + "name" : "graphene", + "buildsystem" : "meson", + "builddir" : true, + "config-opts" : [ + "--libdir=/app/lib", + "-Dtests=false", + "-Dbenchmarks=false" + ], + "sources" : [ + { + "type" : "git", + "url" : "https://github.com/ebassi/graphene.git" + } + ] + }, + { + "name" : "gtk", + "buildsystem" : "meson", + "builddir" : true, + "config-opts" : [ + "--libdir=/app/lib" + ], + "sources" : [ + { + "type" : "git", + "url" : "https://gitlab.gnome.org/GNOME/gtk.git", + "tag" : "3.94.0" + } + ] + }, + { + "name" : "pygobject-demo.py", + "buildsystem" : "meson", + "builddir" : true, + "config-opts" : [ + "--libdir=/app/lib", + "-Ddemos=true" + ], + "sources" : [ + { + "type" : "git", + "url" : "https://gitlab.gnome.org/GNOME/pygobject.git" + } + ] + } + ] +} diff --git a/examples/demo/pygobject-demo.py b/examples/demo/pygobject-demo.py new file mode 100755 index 00000000..6a31f600 --- /dev/null +++ b/examples/demo/pygobject-demo.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# pygobject-demo.py +# +# Copyright 2018 Carlos Soriano <csoriano@redhat.com> +# +# 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 3 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, see <http://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import gi +gi.require_version('Gtk', '4.0') +from gi.repository import Gtk, Gio + +from typing import Dict, Any +import appwindow +import flowbox + +class PyDemoApplication(Gtk.Application): + __gtype_name__ = 'PyDemoApplication' + + def __init__(self) -> None: + super().__init__(application_id='org.gnome.pygobject-demo', + flags=Gio.ApplicationFlags.FLAGS_NONE) + + def do_activate(self) -> None: + win: Gtk.Window = self.get_active_window() + if not win: + win = PyDemoWindow(application=self) + win.present() + +class PyDemoWindow(Gtk.ApplicationWindow): + __gtype_name__ = 'PyDemoWindow' + + def __init__(self, **kwargs: Dict[str, Any]) -> None: + super().__init__(**kwargs) + self.set_default_size(600, 400) + self._main_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + self.add(self._main_box) + self._sidebar = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self._main_box.add(self._sidebar) + self._stack = Gtk.Stack() + self._main_box.add(self._stack) + + self.add_demos() + + def add_demos(self): + button = Gtk.Button(label='Basics') + button.connect("clicked", lambda _: self._stack.set_visible_child_name('basics')) + button.vexpand = False + button.valign = Gtk.Align.START + self._sidebar.add(button) + self._stack.add_named(appwindow.get_content(), 'basics') + + button = Gtk.Button(label='Flowbox') + button.connect("clicked", lambda _: self._stack.set_visible_child_name('flowbox')) + button.vexpand = False + button.valign = Gtk.Align.START + self._sidebar.add(button) + self._stack.add_named(flowbox.get_content(), 'flowbox') + + +def main(demoapp=None): + app = PyDemoApplication() + + return app.run() + + +if __name__ == '__main__': + main() |