From 1a978407c056853f64f3b5c90b51cebd9041f3c7 Mon Sep 17 00:00:00 2001 From: Jan Lerking Date: Sun, 25 Feb 2018 12:30:23 +0100 Subject: [PATCH] updated h2inc_gtk.py and h2inc.glade --- Gui test/h2inc.glade | 106 +++++++++++++++++++++++++++++++----------- Gui test/h2inc_gtk.py | 46 ++++++++++++------ 2 files changed, 111 insertions(+), 41 deletions(-) diff --git a/Gui test/h2inc.glade b/Gui test/h2inc.glade index 8db104c..128c53f 100644 --- a/Gui test/h2inc.glade +++ b/Gui test/h2inc.glade @@ -212,7 +212,7 @@ - + True False False @@ -252,14 +252,33 @@ False vertical - + True False - start - 5 - 5 - True - Number of folders: 0 + + + True + False + 5 + 5 + Number of folders: + + + 0 + 0 + + + + + True + False + 0 + + + 1 + 0 + + False @@ -268,13 +287,33 @@ - + True False - start - 5 - 5 - Number of files: 0 + + + True + False + 5 + 5 + Number of files: + + + 0 + 0 + + + + + True + False + 0 + + + 1 + 0 + + False @@ -302,7 +341,7 @@ - + Translate! True True @@ -310,6 +349,7 @@ start 5 5 + 0 @@ -331,37 +371,49 @@ False 12 - + True False - vertical + True - + True False start - 5 - 5 - Total progress: + False + Total progress: - False - True - 0 + 0 + 0 - + + True + False + start + True + 0 of 0 + + + 1 + 0 + + + + True False 5 5 5 + True - False - True - 1 + 0 + 1 + 2 @@ -369,7 +421,7 @@ - + True False 5 diff --git a/Gui test/h2inc_gtk.py b/Gui test/h2inc_gtk.py index 262a0cb..48bcd28 100644 --- a/Gui test/h2inc_gtk.py +++ b/Gui test/h2inc_gtk.py @@ -20,14 +20,17 @@ preproc = () filelist = [] folderlist = [] cnt = 0 -sourcedir = '' +srcdir = '' destdir = '' num_cores = mp.cpu_count() +fileindex = 0 def sourcedir_filecnt(sourcedir): ### Return the number of files, ending with '.h', in sourcedir - including subdirectories ### cnt = 0 global filelist + global srcdir + srcdir = sourcedir for folderName, subfolders, files in os.walk(sourcedir): for file in files: if file.lower().endswith('.h'): @@ -55,16 +58,12 @@ def sourcedir_foldercnt(sourcedir): # print(len(folderlist)) return cnt - -def process_files(gui, source, dest): - global sourcedir - global destdir - sourcedir = source - destdir = dest +def process_files(): + print(srcdir) + print(destdir) pool = mp.Pool(processes=num_cores) pool.map(process_file, filelist) - def process_file(data): outfile = '' inputfile = data @@ -99,8 +98,8 @@ def process_file(data): outfile = outfile + lines fh.close() outputfile = os.path.splitext(inputfile)[0] + '.inc' - outputfile = str(outputfile).replace(sourcedir, destdir) - # print(outputfile) + outputfile = str(outputfile).replace(srcdir, destdir) + print(outputfile) if not os.path.exists(os.path.dirname(outputfile)): try: os.makedirs(os.path.dirname(outputfile)) @@ -111,7 +110,6 @@ def process_file(data): newfile.write(outfile) newfile.close() - def async_process(num): pool = mp.Pool(processes=num) pool.map(process_file, filelist) @@ -154,19 +152,25 @@ class Handler: response = dialog.run() if response == Gtk.ResponseType.OK: - cnt = sourcedir_filecnt(dialog.get_filename()) - if cnt >0: - print(cnt) + filecnt = sourcedir_filecnt(dialog.get_filename()) + if filecnt >0: + print(filecnt) app.obj("source_entry").set_text(dialog.get_filename()) app.obj("destination_label").set_sensitive(True) app.obj("destination_entry").set_sensitive(True) app.obj("destination_button").set_sensitive(True) + app.obj("numfiles_label").set_text(str(filecnt)) + app.obj("progress_label").set_text("{} of {}".format(fileindex, filecnt)) + foldercnt = sourcedir_foldercnt(dialog.get_filename()) + if foldercnt >0: + app.obj("numfolders_label").set_text(str(foldercnt)) elif response == Gtk.ResponseType.CANCEL: print("Cancel") dialog.destroy() def on_destination_button_clicked(self,widget): + global destdir dialog = Gtk.FileChooserDialog("Select destination directory!", app.obj("window"), @@ -180,11 +184,25 @@ class Handler: destdir = dialog.get_filename() app.obj("destination_entry").set_text(dialog.get_filename()) app.obj("include_checkbutton").set_sensitive(True) + app.obj("translation_frame").set_sensitive(True) + print(srcdir) + print(destdir) elif response == Gtk.ResponseType.CANCEL: print("Cancel") dialog.destroy() + def on_translate_button_clicked(self, widget): + app.obj("sourceframe").set_sensitive(False) + app.obj("translate_button").set_sensitive(False) + process_files() + + def update_pbar(self, widget): + self.val += 1/filecnt + self.pbar.set_fraction(self.val) + while Gtk.events_pending(): + Gtk.main_iteration() + class ExampleApp: global app