diff --git a/src/Python/Scripts/GTK/multiple-draw-areas/app.py b/src/Python/Scripts/GTK/multiple-draw-areas/app.py new file mode 100644 index 0000000..72aef6d --- /dev/null +++ b/src/Python/Scripts/GTK/multiple-draw-areas/app.py @@ -0,0 +1,106 @@ +#!/usr/bin/python3 + + + +from setproctitle import setproctitle +import gi, os, faulthandler, signal, inspect, gi, cairo + +gi.require_version('Gtk', '3.0') + +from gi.repository import Gtk as gtk +from gi.repository import Gdk as gdk +from gi.repository import GdkPixbuf as gbuf + + +class SupportMixin: + def setFile(self): + dialog = gtk.FileChooserDialog(title="Please choose a file", action=gtk.FileChooserAction.OPEN) + dialog.add_buttons(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, gtk.STOCK_OPEN, gtk.ResponseType.OK) + + response = dialog.run() + if response == gtk.ResponseType.OK: + self.file = dialog.get_filename() + self.setupSurfaceData(self.file) + elif response == gtk.ResponseType.CANCEL: + pass + + dialog.destroy() + + def setupSurfaceData(self, file): + pb = gbuf.Pixbuf.new_from_file(file) + if pb: + self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, pb.get_width(), pb.get_height()) + context = cairo.Context(self.surface) + + gdk.cairo_set_source_pixbuf(cr=context, pixbuf=pb, pixbuf_x=0, pixbuf_y=0) + context.paint() + + self.drawArea.set_size_request(width=pb.get_width(), height=pb.get_height()) + self.drawArea.queue_draw() + + +class Main_Draw_Area(SupportMixin): + def __init__(self, _builder): + self.surface = None + self.file = None + self.drawArea = _builder.get_object("drawArea1") + + def setMainFile(self, widget): + self.setFile() + + def onDraw1(self, area, context): + if self.surface is not None: + context.set_source_surface(self.surface, 0.0, 0.0) + context.paint() + + return False + + +class File_Select_Draw_Area(SupportMixin): + def __init__(self, _builder): + self.surface = None + self.file = None + self.drawArea = _builder.get_object("drawArea2") + + def setPopupFile(self, widget): + self.setFile() + + def onDraw2(self, area, context): + if self.surface is not None: + context.set_source_surface(self.surface, 0.0, 0.0) + context.paint() + return False + + +class Window(): + def __init__(self): + setproctitle('double_draw_areas') + SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__)) + "/" + GLADE_FILE = "main.glade" + self.builder = gtk.Builder() + + self.builder.add_from_file(SCRIPT_PTH + GLADE_FILE) + handlers = {} + classes = [self, Main_Draw_Area(self.builder), File_Select_Draw_Area(self.builder)] + for c in classes: + methods = None + try: + methods = inspect.getmembers(c, predicate=inspect.ismethod) + handlers.update(methods) + except Exception as e: + pass + + self.builder.connect_signals(handlers) + self.fileSelectionPopup = self.builder.get_object("fileSelectionPopup") + window = self.builder.get_object("main_window") + window.connect("delete_event", gtk.main_quit) + window.show() + + def openFileSelectionPopup(self, widget): + self.fileSelectionPopup.popup() + + +if __name__ == '__main__': + faulthandler.enable() # For better debug info + window = Window() + gtk.main() diff --git a/src/Python/Scripts/GTK/multiple-draw-areas/main.glade b/src/Python/Scripts/GTK/multiple-draw-areas/main.glade new file mode 100644 index 0000000..db4e6fe --- /dev/null +++ b/src/Python/Scripts/GTK/multiple-draw-areas/main.glade @@ -0,0 +1,364 @@ + + + + + + False + 800 + 800 + + + + True + False + True + True + + + True + False + vertical + + + + + + 0 + 0 + 10 + + + + + True + False + vertical + + + + + + 0 + 9 + 10 + + + + + True + False + vertical + + + + + + 0 + 1 + 8 + + + + + True + False + vertical + + + + + + 9 + 1 + 8 + + + + + True + True + in + 600 + 600 + + + True + False + + + True + False + + + + + + + + 3 + 1 + 6 + 8 + + + + + Open + True + True + True + + + + 1 + 1 + + + + + File Selection + True + True + True + + + + 1 + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 500 + 500 + False + openFileSelection + right + + + + True + False + True + True + + + True + False + vertical + + + + + + 0 + 0 + 10 + + + + + True + False + vertical + + + + + + 9 + 0 + 10 + + + + + True + False + vertical + + + + + + 1 + 0 + 8 + + + + + True + False + vertical + + + + + + 1 + 9 + 8 + + + + + True + True + in + + + True + False + + + True + False + + + + + + + + 3 + 3 + 6 + 6 + + + + + Select File + True + True + True + + + + 1 + 1 + 2 + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +