diff --git a/Gui test/16_filechooser.glade b/Gui test/16_filechooser.glade new file mode 100644 index 0000000..d867d52 --- /dev/null +++ b/Gui test/16_filechooser.glade @@ -0,0 +1,145 @@ + + + + + + + image/* + + + + + image/jpeg + + + + + image/png + + + + 200 + True + False + 5 + + + 300 + 200 + False + + + + True + False + vertical + True + + + Choose an image file... + True + True + True + + + + False + True + 0 + + + + + Choose folder... + True + True + True + + + + False + True + 1 + + + + + + + + + + 800 + 500 + False + dialog + window + window + preview + False + + + + + + + False + vertical + + + False + + + gtk-cancel + True + True + True + True + + + True + True + 2 + + + + + gtk-apply + True + True + True + True + + + True + True + 3 + + + + + False + False + 0 + + + + + + button2 + button1 + + + + True + False + Choose image... + True + + + + button2 + button1 + + + diff --git a/Gui test/16_filechooser.py b/Gui test/16_filechooser.py new file mode 100644 index 0000000..f8be92c --- /dev/null +++ b/Gui test/16_filechooser.py @@ -0,0 +1,95 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import os +import sys +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk, Gio, GdkPixbuf + +class Handler: + + def on_window_destroy(self,window): + window.close() + + def on_dialog_close(self,widget,*event): + widget.hide_on_delete() + return True + + def on_filechooser_dialog_response(self,widget,response): + if response == -6: + print("Cancel") + elif response == -5: + print("File selection: %s" % widget.get_filename()) + self.on_dialog_close(widget) + + def on_filechooser_dialog_file_activated(self,widget): + self.on_filechooser_dialog_response(widget,-5) + + def on_filechooser_dialog_update_preview(self,widget): + if widget.get_filename() != None and os.path.isfile(widget.get_filename()): + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(widget.get_filename(),200,200,True) + app.obj("preview").set_from_pixbuf(pixbuf) + + def on_file_button_clicked(self,widget): + app.obj("filechooser_dialog").show_all() + + def on_dir_button_clicked(self,widget): + + dialog = Gtk.FileChooserDialog("Choose a folder", + app.obj("window"), + Gtk.FileChooserAction.SELECT_FOLDER, + (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, + Gtk.STOCK_APPLY, Gtk.ResponseType.OK)) + dialog.set_default_size(600, 300) + + response = dialog.run() + if response == Gtk.ResponseType.OK: + print("Folder selection: %s" % dialog.get_filename()) + elif response == Gtk.ResponseType.CANCEL: + print("Cancel") + + dialog.destroy() + +class ExampleApp: + + def __init__(self): + + self.app = Gtk.Application.new("org.application.test", Gio.ApplicationFlags(0)) + self.app.connect("activate", self.on_app_activate) + self.app.connect("shutdown", self.on_app_shutdown) + + def on_app_activate(self, app): + builder = Gtk.Builder() + builder.add_from_file("16_filechooser.glade") + builder.connect_signals(Handler()) + + self.obj = builder.get_object + self.obj("window").set_application(app) + self.obj("window").set_wmclass("Filechooser example","Filechooser example") + self.obj("window").show_all() + + #add filters to filechooser dialog + self.obj("filefilter").set_name("Image files") + self.obj("filechooser_dialog").add_filter(self.obj("filefilter")) + self.obj("png_filter").set_name("PNG files") + self.obj("filechooser_dialog").add_filter(self.obj("png_filter")) + self.obj("jpg_filter").set_name("JPG files") + self.obj("filechooser_dialog").add_filter(self.obj("jpg_filter")) + + #add buttons to headerbar of Glade generated dialog + button = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL) + button.set_property("can-default",True) + self.obj("filechooser_dialog").add_action_widget(button, Gtk.ResponseType.CANCEL) + button = Gtk.Button.new_from_stock(Gtk.STOCK_APPLY) + button.set_property("can-default",True) + self.obj("filechooser_dialog").add_action_widget(button, Gtk.ResponseType.OK) + + def on_app_shutdown(self, app): + self.app.quit() + + def run(self, argv): + self.app.run(argv) + +app = ExampleApp() +app.run(sys.argv) diff --git a/Gui test/gtk3_glade_test.py b/Gui test/gtk3_glade_test.py index 06f6b30..f690bba 100644 --- a/Gui test/gtk3_glade_test.py +++ b/Gui test/gtk3_glade_test.py @@ -6,13 +6,23 @@ class Handler: def onDeleteWindow(self, *args): Gtk.main_quit(*args) - def onButtonPressed(self, button): - print("Hello World!") + def on_button1_clicked(self, button): + dialog.set_title('Select source folder') + dialog.set_default_size(800, 400) + + response = dialog.run() + if response == Gtk.ResponseType.OK: + print("Folder selected: " + dialog.get_filename()) + elif response == Gtk.ResponseType.CANCEL: + print("Cancel clicked") + + dialog.destroy() builder = Gtk.Builder() -builder.add_from_file("h2inc_v2.glade") +builder.add_from_file("test.glade") builder.connect_signals(Handler()) +dialog = builder.get_object("filechooserdialog1") window = builder.get_object("window1") window.connect('delete-event', Gtk.main_quit) window.show_all() diff --git a/Gui test/test.glade b/Gui test/test.glade new file mode 100644 index 0000000..8cb0a99 --- /dev/null +++ b/Gui test/test.glade @@ -0,0 +1,433 @@ + + + + + + False + + + True + False + vertical + + + True + False + 5 + 0 + etched-out + + + True + False + 12 + + + True + False + + + True + False + end + 5 + 5 + 5 + Source: + start + + + 0 + 0 + + + + + True + False + False + end + 5 + 5 + 5 + Destination: + 0.059999999999999998 + + + 0 + 1 + + + + + True + True + 5 + 5 + + + 1 + 0 + + + + + True + False + True + 5 + 5 + + + 1 + 1 + + + + + Select source directory... + True + True + True + start + 5 + 5 + 0.52999997138977051 + + + 2 + 0 + + + + + Select destination directory... + True + False + True + True + start + 5 + 5 + + + 2 + 1 + + + + + checkbutton + True + False + True + False + 0 + True + True + + + 0 + 2 + 3 + + + + + + + + + True + False + Select folders + + + + + True + True + 0 + + + + + True + False + False + 5 + 0 + etched-out + + + True + False + 12 + + + True + False + vertical + + + True + False + 5 + 0 + etched-out + + + True + False + 12 + + + True + False + + + True + False + end + 5 + Number of folders: + + + 0 + 0 + + + + + True + False + 0.9882352941176471 + start + 5 + 0 + end + + + 1 + 0 + + + + + True + False + end + 5 + 5 + Number of files: + + + 0 + 1 + + + + + True + False + start + 5 + 5 + 0 + + + 1 + 1 + + + + + + + + + True + False + Source information + + + + + False + True + 0 + + + + + Translate! + True + True + True + start + 5 + 5 + + + False + False + 1 + + + + + True + False + 5 + 0 + etched-out + + + True + False + 12 + + + True + False + + + True + False + end + 5 + 5 + Total progress: + + + 0 + 0 + + + + + True + False + start + 5 + 5 + True + 0 of 0 + + + 1 + 0 + + + + + True + False + 5 + + + 0 + 1 + 2 + + + + + + + + + True + False + Progress + + + + + False + True + 2 + + + + + + + + + True + False + Translation! + + + + + True + True + 1 + + + + + + + False + dialog + select-folder + + + False + vertical + 2 + + + False + end + + + gtk-ok + True + True + True + True + True + + + True + True + 0 + + + + + gtk-cancel + True + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + button4 + button5 + + + diff --git a/Gui test/h2inc_v2.glade~ b/Gui test/test.glade~ similarity index 63% rename from Gui test/h2inc_v2.glade~ rename to Gui test/test.glade~ index 74daa33..a48e0df 100644 --- a/Gui test/h2inc_v2.glade~ +++ b/Gui test/test.glade~ @@ -2,21 +2,80 @@ + + False + dialog + select-folder + + + False + vertical + 2 + + + False + end + + + gtk-ok + True + True + True + True + True + + + True + True + 0 + + + + + gtk-cancel + True + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + button4 + button5 + + False - 5 - 5 - 5 - 5 True False vertical - + True False + 5 + 5 + 5 0 etched-out @@ -25,24 +84,40 @@ False 12 - + True False - + True False end 5 5 - True + 5 Source: - right + start 0 0 - 2 + + + + + True + False + False + end + 5 + 5 + 5 + Destination: + 0.059999999999999998 + + + 0 + 1 @@ -51,48 +126,10 @@ True 5 5 - Select source directory! - 2 + 1 0 - 2 - - - - - Source directory... - True - True - True - start - 5 - 5 - - - 4 - 0 - 2 - - - - - True - False - False - end - 5 - 5 - True - Destination: - right - start - 2.2351741811588166e-10 - - - 0 - 1 - 2 @@ -102,47 +139,65 @@ True 5 5 - Select destination directory! + + + 1 + 1 + + + + + Select source directory... + True + True + True + start + 5 + 5 + 5 + 0.52999997138977051 + 2 - 1 - 2 + 0 - Destination directory... + Select destination directory... True False True True start + 5 + 10 5 5 + - 4 + 2 1 - 2 - Create "include" folder if it does not exist. + checkbutton True False True False - 5 - 5 0 + 0.47999998927116394 + True True 0 2 - 6 + 3 @@ -158,17 +213,18 @@ - False + True True 0 - + True False False - 5 + 5 + 5 5 0 etched-out @@ -178,15 +234,16 @@ False 12 - + True False + vertical - + True False + 10 5 - True 0 etched-out @@ -195,39 +252,63 @@ False 12 - + True False - vertical True False - start + end 5 - 5 - True - Number of folders: 0 + Number of folders: - False - True - 0 + 0 + 0 - + + True + False + 0.98999999999999999 + start + 5 + 0 + end + + + 1 + 0 + + + + + True + False + end + 5 + 5 + Number of files: + + + 0 + 1 + + + + True False start 5 5 - Number of files: 0 + 0 - False - True - 1 + 1 + 1 @@ -243,8 +324,9 @@ - 0 - 0 + False + True + 0 @@ -258,15 +340,16 @@ 5 - 0 - 1 + False + False + 1 - + True False - 5 + 10 5 0 etched-out @@ -276,36 +359,49 @@ False 12 - + True False - vertical + True + False + end + 5 + 5 + Total progress: + + + 0 + 0 + + + + True False start 5 5 - Total progress: + True + 0 of 0 - False - True - 0 + 1 + 0 True False - 5 + 10 5 - False - True - 1 + 0 + 1 + 2 @@ -313,7 +409,7 @@ - + True False Progress @@ -321,8 +417,9 @@ - 0 - 2 + False + True + 2 @@ -330,15 +427,15 @@ - + True False - Translation + Translation! - False + True True 1