updated h2inc_gtk.py and h2inc.glade

This commit is contained in:
2018-02-25 10:51:04 +01:00
parent 4b1ad6d614
commit b434526b31
2 changed files with 31 additions and 16 deletions
+3 -3
View File
@@ -252,7 +252,7 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkLabel" id="label6"> <object class="GtkLabel" id="numfolders_label">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">start</property> <property name="halign">start</property>
@@ -268,7 +268,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="label7"> <object class="GtkLabel" id="numfiles_label">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">start</property> <property name="halign">start</property>
@@ -369,7 +369,7 @@
</object> </object>
</child> </child>
<child type="label"> <child type="label">
<object class="GtkLabel" id="label8"> <object class="GtkLabel" id="progress_label">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="margin_left">5</property> <property name="margin_left">5</property>
+28 -13
View File
@@ -24,7 +24,6 @@ sourcedir = ''
destdir = '' destdir = ''
num_cores = mp.cpu_count() num_cores = mp.cpu_count()
def sourcedir_filecnt(sourcedir): def sourcedir_filecnt(sourcedir):
### Return the number of files, ending with '.h', in sourcedir - including subdirectories ### ### Return the number of files, ending with '.h', in sourcedir - including subdirectories ###
cnt = 0 cnt = 0
@@ -158,15 +157,29 @@ class Handler:
cnt = sourcedir_filecnt(dialog.get_filename()) cnt = sourcedir_filecnt(dialog.get_filename())
if cnt >0: if cnt >0:
print(cnt) print(cnt)
builder = Gtk.Builder() app.obj("source_entry").set_text(dialog.get_filename())
builder.add_from_file("h2inc.glade") app.obj("destination_label").set_sensitive(True)
obj = builder.get_object app.obj("destination_entry").set_sensitive(True)
obj("destination_label").set_sensitive(True) app.obj("destination_button").set_sensitive(True)
obj("destination_entry").set_sensitive(True) elif response == Gtk.ResponseType.CANCEL:
obj("destination_button").set_sensitive(True) print("Cancel")
obj("include_checkbutton").set_sensitive(True)
while Gtk.events_pending(): dialog.destroy()
Gtk.main_iteration()
def on_destination_button_clicked(self,widget):
dialog = Gtk.FileChooserDialog("Select destination directory!",
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:
destdir = dialog.get_filename()
app.obj("destination_entry").set_text(dialog.get_filename())
app.obj("include_checkbutton").set_sensitive(True)
elif response == Gtk.ResponseType.CANCEL: elif response == Gtk.ResponseType.CANCEL:
print("Cancel") print("Cancel")
@@ -174,24 +187,26 @@ class Handler:
class ExampleApp: class ExampleApp:
global app
global destlabel
def __init__(self): def __init__(self):
self.app = Gtk.Application.new("org.h2inc", Gio.ApplicationFlags(0)) self.app = Gtk.Application.new("org.h2inc", Gio.ApplicationFlags(0))
self.app.connect("activate", self.on_app_activate) self.app.connect("activate", self.on_app_activate)
self.app.connect("shutdown", self.on_app_shutdown) self.app.connect("shutdown", self.on_app_shutdown)
app = self.app
def on_app_activate(self, app): def on_app_activate(self, app):
builder = Gtk.Builder() builder = Gtk.Builder()
#builder.add_from_file("16_filechooser.glade")
builder.add_from_file("h2inc.glade") builder.add_from_file("h2inc.glade")
builder.connect_signals(Handler()) builder.connect_signals(Handler())
self.obj = builder.get_object self.obj = builder.get_object
self.obj("window").set_application(app) self.obj("window").set_application(app)
self.obj("window").set_wmclass("Filechooser example","Filechooser example") self.obj("window").set_wmclass("h2inc_gtk","h2inc_gtk")
self.obj("window").show_all() self.obj("window").show_all()
#add buttons to headerbar of Glade generated dialog
button = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL) button = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
button.set_property("can-default",True) button.set_property("can-default",True)
self.obj("filechooser_dialog").add_action_widget(button, Gtk.ResponseType.CANCEL) self.obj("filechooser_dialog").add_action_widget(button, Gtk.ResponseType.CANCEL)