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