updated h2inc_gtk.py and h2inc.glade

This commit is contained in:
2018-02-25 12:30:23 +01:00
parent b434526b31
commit 1a978407c0
2 changed files with 111 additions and 41 deletions

View File

@@ -212,7 +212,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkFrame" id="frame1"> <object class="GtkFrame" id="translation_frame">
<property name="visible">True</property> <property name="visible">True</property>
<property name="sensitive">False</property> <property name="sensitive">False</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@@ -252,14 +252,33 @@
<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="numfolders_label"> <object class="GtkGrid" id="grid1">
<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> <child>
<property name="margin_top">5</property> <object class="GtkLabel" id="label3">
<property name="margin_bottom">5</property> <property name="visible">True</property>
<property name="hexpand">True</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Number of folders: 0</property> <property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Number of folders: </property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="numfolders_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@@ -268,13 +287,33 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="numfiles_label"> <object class="GtkGrid" id="grid5">
<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> <child>
<property name="margin_top">5</property> <object class="GtkLabel" id="label7">
<property name="margin_bottom">5</property> <property name="visible">True</property>
<property name="label" translatable="yes">Number of files: 0</property> <property name="can_focus">False</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Number of files: </property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="numfiles_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@@ -302,7 +341,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="button3"> <object class="GtkButton" id="translate_button">
<property name="label" translatable="yes">Translate!</property> <property name="label" translatable="yes">Translate!</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@@ -310,6 +349,7 @@
<property name="halign">start</property> <property name="halign">start</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>
<signal name="clicked" handler="on_translate_button_clicked" after="yes" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
@@ -331,37 +371,49 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="left_padding">12</property> <property name="left_padding">12</property>
<child> <child>
<object class="GtkBox" id="box3"> <object class="GtkGrid" id="grid4">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="hexpand">True</property>
<child> <child>
<object class="GtkLabel" id="label9"> <object class="GtkLabel" id="label2">
<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>
<property name="margin_top">5</property> <property name="hexpand">False</property>
<property name="margin_bottom">5</property> <property name="label" translatable="yes">Total progress: </property>
<property name="label" translatable="yes">Total progress:</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="left_attach">0</property>
<property name="fill">True</property> <property name="top_attach">0</property>
<property name="position">0</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkProgressBar" id="progressbar1"> <object class="GtkLabel" id="progress_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">0 of 0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkProgressBar" id="progressbar">
<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_right">5</property> <property name="margin_right">5</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="hexpand">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="left_attach">0</property>
<property name="fill">True</property> <property name="top_attach">1</property>
<property name="position">1</property> <property name="width">2</property>
</packing> </packing>
</child> </child>
</object> </object>
@@ -369,7 +421,7 @@
</object> </object>
</child> </child>
<child type="label"> <child type="label">
<object class="GtkLabel" id="progress_label"> <object class="GtkLabel" id="label20">
<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>

View File

@@ -20,14 +20,17 @@ preproc = ()
filelist = [] filelist = []
folderlist = [] folderlist = []
cnt = 0 cnt = 0
sourcedir = '' srcdir = ''
destdir = '' destdir = ''
num_cores = mp.cpu_count() num_cores = mp.cpu_count()
fileindex = 0
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
global filelist global filelist
global srcdir
srcdir = sourcedir
for folderName, subfolders, files in os.walk(sourcedir): for folderName, subfolders, files in os.walk(sourcedir):
for file in files: for file in files:
if file.lower().endswith('.h'): if file.lower().endswith('.h'):
@@ -55,16 +58,12 @@ def sourcedir_foldercnt(sourcedir):
# print(len(folderlist)) # print(len(folderlist))
return cnt return cnt
def process_files():
def process_files(gui, source, dest): print(srcdir)
global sourcedir print(destdir)
global destdir
sourcedir = source
destdir = dest
pool = mp.Pool(processes=num_cores) pool = mp.Pool(processes=num_cores)
pool.map(process_file, filelist) pool.map(process_file, filelist)
def process_file(data): def process_file(data):
outfile = '' outfile = ''
inputfile = data inputfile = data
@@ -99,8 +98,8 @@ def process_file(data):
outfile = outfile + lines outfile = outfile + lines
fh.close() fh.close()
outputfile = os.path.splitext(inputfile)[0] + '.inc' outputfile = os.path.splitext(inputfile)[0] + '.inc'
outputfile = str(outputfile).replace(sourcedir, destdir) outputfile = str(outputfile).replace(srcdir, destdir)
# print(outputfile) print(outputfile)
if not os.path.exists(os.path.dirname(outputfile)): if not os.path.exists(os.path.dirname(outputfile)):
try: try:
os.makedirs(os.path.dirname(outputfile)) os.makedirs(os.path.dirname(outputfile))
@@ -111,7 +110,6 @@ def process_file(data):
newfile.write(outfile) newfile.write(outfile)
newfile.close() newfile.close()
def async_process(num): def async_process(num):
pool = mp.Pool(processes=num) pool = mp.Pool(processes=num)
pool.map(process_file, filelist) pool.map(process_file, filelist)
@@ -154,19 +152,25 @@ class Handler:
response = dialog.run() response = dialog.run()
if response == Gtk.ResponseType.OK: if response == Gtk.ResponseType.OK:
cnt = sourcedir_filecnt(dialog.get_filename()) filecnt = sourcedir_filecnt(dialog.get_filename())
if cnt >0: if filecnt >0:
print(cnt) print(filecnt)
app.obj("source_entry").set_text(dialog.get_filename()) app.obj("source_entry").set_text(dialog.get_filename())
app.obj("destination_label").set_sensitive(True) app.obj("destination_label").set_sensitive(True)
app.obj("destination_entry").set_sensitive(True) app.obj("destination_entry").set_sensitive(True)
app.obj("destination_button").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: elif response == Gtk.ResponseType.CANCEL:
print("Cancel") print("Cancel")
dialog.destroy() dialog.destroy()
def on_destination_button_clicked(self,widget): def on_destination_button_clicked(self,widget):
global destdir
dialog = Gtk.FileChooserDialog("Select destination directory!", dialog = Gtk.FileChooserDialog("Select destination directory!",
app.obj("window"), app.obj("window"),
@@ -180,11 +184,25 @@ class Handler:
destdir = dialog.get_filename() destdir = dialog.get_filename()
app.obj("destination_entry").set_text(dialog.get_filename()) app.obj("destination_entry").set_text(dialog.get_filename())
app.obj("include_checkbutton").set_sensitive(True) app.obj("include_checkbutton").set_sensitive(True)
app.obj("translation_frame").set_sensitive(True)
print(srcdir)
print(destdir)
elif response == Gtk.ResponseType.CANCEL: elif response == Gtk.ResponseType.CANCEL:
print("Cancel") print("Cancel")
dialog.destroy() 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: class ExampleApp:
global app global app