updated h2inc_gtk.py and h2inc.glade
This commit is contained in:
+32
-14
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user