Updated h2inc_gtk.py

This commit is contained in:
2018-05-07 19:34:16 +02:00
parent 8f53d0d085
commit d87239bc76
2 changed files with 38 additions and 4 deletions
-2
View File
@@ -86,7 +86,6 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="margin_top">5</property> <property name="margin_top">5</property>
<property name="margin_bottom">5</property> <property name="margin_bottom">5</property>
<property name="text" translatable="yes">/usr/include</property>
</object> </object>
<packing> <packing>
<property name="left_attach">2</property> <property name="left_attach">2</property>
@@ -142,7 +141,6 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="margin_top">5</property> <property name="margin_top">5</property>
<property name="margin_bottom">5</property> <property name="margin_bottom">5</property>
<property name="text" translatable="yes">~/include</property>
</object> </object>
<packing> <packing>
<property name="left_attach">2</property> <property name="left_attach">2</property>
+38 -2
View File
@@ -73,8 +73,10 @@ destdir = ''
#num_cores = multiprocessing.cpu_count() #num_cores = multiprocessing.cpu_count()
fileindex = 0 fileindex = 0
filecnt = 0 filecnt = 0
incinc = False incinc = ''
defdir = False defdir = False
defsrc = 'usr/include'
defdest = '~'
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 ###
@@ -181,7 +183,9 @@ class ExampleApp:
self.obj("window").set_wmclass("h2inc_gtk","h2inc_gtk") self.obj("window").set_wmclass("h2inc_gtk","h2inc_gtk")
self.obj("window").show_all() self.obj("window").show_all()
self.obj("default_dir_checkbutton").set_active(False) self.obj("default_dir_checkbutton").set_active(False)
self.obj("default_dir_checkbutton").emit("toggled")
self.obj("include_checkbutton").set_active(True) self.obj("include_checkbutton").set_active(True)
self.obj("include_checkbutton").emit("toggled")
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)
@@ -236,6 +240,7 @@ class ExampleApp:
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_APPLY, Gtk.ResponseType.OK)) Gtk.STOCK_APPLY, Gtk.ResponseType.OK))
dialog.set_default_size(600, 300) dialog.set_default_size(600, 300)
Gtk.FileChooser.set_filename(dialog, srcdir)
response = dialog.run() response = dialog.run()
if response == Gtk.ResponseType.OK: if response == Gtk.ResponseType.OK:
@@ -258,6 +263,7 @@ class ExampleApp:
def on_destination_button_clicked(self,widget): def on_destination_button_clicked(self,widget):
global destdir global destdir
global incinc
dialog = Gtk.FileChooserDialog("Select destination directory!", dialog = Gtk.FileChooserDialog("Select destination directory!",
self.obj("window"), self.obj("window"),
@@ -273,6 +279,9 @@ class ExampleApp:
self.obj("include_checkbutton").set_sensitive(True) self.obj("include_checkbutton").set_sensitive(True)
self.obj("translation_frame").set_sensitive(True) self.obj("translation_frame").set_sensitive(True)
print(srcdir) print(srcdir)
if self.obj("include_checkbutton").get_active() == True:
incinc = '/include'
destdir = destdir+incinc
print(destdir) print(destdir)
elif response == Gtk.ResponseType.CANCEL: elif response == Gtk.ResponseType.CANCEL:
print("Cancel") print("Cancel")
@@ -280,12 +289,39 @@ class ExampleApp:
dialog.destroy() dialog.destroy()
def on_include_checkbutton_toggled(self, widget): def on_include_checkbutton_toggled(self, widget):
global destdir
global incinc global incinc
incinc = self.obj("include_checkbutton").get_active() if self.obj("include_checkbutton").get_active() == True:
incinc = '/include'
destdir = destdir+incinc
if self.obj("include_checkbutton").get_active() == False:
incinc = ''
destdir = destdir.replace('/include', '')
self.obj("destination_entry").set_text(destdir)
print(destdir)
def on_default_dir_checkbutton_toggled(self, widget): def on_default_dir_checkbutton_toggled(self, widget):
global defdir global defdir
global srcdir
global destdir
global incinc
defdir = self.obj("default_dir_checkbutton").get_active() defdir = self.obj("default_dir_checkbutton").get_active()
if defdir == True:
srcdir = defsrc
self.obj("source_entry").set_text(srcdir)
destdir = defdest+incinc
self.obj("destination_entry").set_text(destdir)
self.obj("include_checkbutton").set_sensitive(True)
self.obj("source_label").set_sensitive(False)
self.obj("source_entry").set_sensitive(False)
self.obj("source_button").set_sensitive(False)
self.obj("translation_frame").set_sensitive(True)
filecnt = sourcedir_filecnt(defsrc)
if filecnt >0:
print(filecnt)
foldercnt = sourcedir_foldercnt(defsrc)
if foldercnt >0:
self.obj("numfolders_label").set_text(str(foldercnt))
def on_translate_button_clicked(self, widget, data=None): def on_translate_button_clicked(self, widget, data=None):
self.obj("sourceframe").set_sensitive(False) self.obj("sourceframe").set_sensitive(False)