diff --git a/Gui test/gtk_test_2.py b/Gui test/gtk_test_2.py
new file mode 100644
index 0000000..4130fe1
--- /dev/null
+++ b/Gui test/gtk_test_2.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python3.5
+
+# You are free to use and/or change this code for
+# your own needs.
+
+# Original code (c)2018 Jan Lerking
+# Program to convert C-header (*.h) files to nasm include files (*.inc),
+# for direct usage in assembly programming using nasm/yasm.
+
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk
+
+class FileChooserWindow(Gtk.Window):
+
+ def __init__(self):
+ Gtk.Window.__init__(self, title="FileChooser Example")
+
+ box = Gtk.Box(spacing=6)
+ self.add(box)
+
+ button1 = Gtk.Button("Choose File")
+ button1.connect("clicked", self.on_file_clicked)
+ box.add(button1)
+
+ button2 = Gtk.Button("Choose Folder")
+ button2.connect("clicked", self.on_folder_clicked)
+ box.add(button2)
+
+ def on_file_clicked(self, widget):
+ dialog = Gtk.FileChooserDialog("Please choose a file", self,
+ Gtk.FileChooserAction.OPEN,
+ (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+ Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
+
+ self.add_filters(dialog)
+
+ response = dialog.run()
+ if response == Gtk.ResponseType.OK:
+ print("Open clicked")
+ print("File selected: " + dialog.get_filename())
+ elif response == Gtk.ResponseType.CANCEL:
+ print("Cancel clicked")
+
+ dialog.destroy()
+
+ def add_filters(self, dialog):
+ filter_text = Gtk.FileFilter()
+ filter_text.set_name("Text files")
+ filter_text.add_mime_type("text/plain")
+ dialog.add_filter(filter_text)
+
+ filter_py = Gtk.FileFilter()
+ filter_py.set_name("Python files")
+ filter_py.add_mime_type("text/x-python")
+ dialog.add_filter(filter_py)
+
+ filter_any = Gtk.FileFilter()
+ filter_any.set_name("Any files")
+ filter_any.add_pattern("*")
+ dialog.add_filter(filter_any)
+
+ def on_folder_clicked(self, widget):
+ dialog = Gtk.FileChooserDialog("Please choose a folder", self,
+ Gtk.FileChooserAction.SELECT_FOLDER,
+ (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+ "Select", Gtk.ResponseType.OK))
+ dialog.set_default_size(800, 400)
+
+ response = dialog.run()
+ if response == Gtk.ResponseType.OK:
+ print("Select clicked")
+ print("Folder selected: " + dialog.get_filename())
+ elif response == Gtk.ResponseType.CANCEL:
+ print("Cancel clicked")
+
+ dialog.destroy()
+
+win = FileChooserWindow()
+win.connect("delete-event", Gtk.main_quit)
+win.show_all()
+Gtk.main()
\ No newline at end of file
diff --git a/Gui test/gtk_test_3.py b/Gui test/gtk_test_3.py
new file mode 100644
index 0000000..40c0015
--- /dev/null
+++ b/Gui test/gtk_test_3.py
@@ -0,0 +1,80 @@
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk
+import time
+from multiprocessing import Process, Value, Lock, Pool
+
+class Counter(object):
+ def __init__(self, initval=0.0):
+ self.val = Value('d', initval)
+ self.lock = Lock()
+
+ def increment(self):
+ with self.lock:
+ self.val.value += 1/2542
+ print(self.val.value)
+
+ def value(self):
+ with self.lock:
+ return self.val.value
+
+class MyWindow(Gtk.Window):
+
+ def __init__(self):
+ Gtk.Window.__init__(self, title = 'Hello World')
+
+ #self.val = 0
+
+ self.box = Gtk.Box(spacing=6)
+ self.add(self.box)
+
+ self.button1 = Gtk.Button(label = 'Hello')
+ self.button1.connect('clicked', self.on_button1_clicked)
+ self.box.pack_start(self.button1, True, True, 0)
+
+ self.button2 = Gtk.Button(label = 'Goodbye')
+ self.button2.connect('clicked', self.on_button2_clicked)
+ self.box.pack_start(self.button2, True, True, 0)
+
+ self.pbar = Gtk.ProgressBar()
+ self.pbar.set_fraction(0.0)
+ self.box.pack_start(self.pbar, True, True, 0)
+
+ def on_button1_clicked(self, widget):
+ print('Hello')
+ #procs = [Process(target=self.func, args=(counter,)) for i in range(10)]
+
+ #for p in procs: p.start()
+ #for p in procs: p.join()
+ p = Pool(2)
+ p.map(self.func, range(2542))
+ print (counter.value())
+
+ #while counter.val.value <10:
+ #self.update_pbar(self.pbar)
+ print('Goodbye')
+ Gtk.main_quit()
+
+ def on_button2_clicked(self, widget):
+ print('Goodbye')
+ Gtk.main_quit()
+
+ def update_pbar(self, widget, value):
+ #self.val += 0.1
+ self.pbar.set_fraction(value)
+ #time.sleep(0.5)
+ while Gtk.events_pending():
+ Gtk.main_iteration()
+
+ def func(self, data):
+ #for i in range(2542):
+ time.sleep(0.01)
+ counter.increment()
+ #while counter.value() <1:
+ #self.update_pbar(self.pbar, counter.value())
+
+counter = Counter(0.0)
+win = MyWindow()
+win.connect('delete-event', Gtk.main_quit)
+win.show_all()
+Gtk.main()
diff --git a/Gui test/gtk_test_4.py b/Gui test/gtk_test_4.py
new file mode 100644
index 0000000..08672c9
--- /dev/null
+++ b/Gui test/gtk_test_4.py
@@ -0,0 +1,118 @@
+import gobject
+import pygtk
+pygtk.require('2.0')
+import gtk
+import multiprocessing
+import threading
+import time
+
+gtk.gdk.threads_init()
+
+class Listener(gobject.GObject):
+ __gsignals__ = {
+ 'updated' : (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_FLOAT, gobject.TYPE_STRING)),
+ 'finished': (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ ())
+ }
+
+ def __init__(self, queue):
+ gobject.GObject.__init__(self)
+ self.queue = queue
+
+ def go(self):
+ print("Listener has started")
+ while True:
+ # Listen for results on the queue and process them accordingly
+ data = self.queue.get()
+ # Check if finished
+ if data[1]=="finished":
+ print("Listener is finishing.")
+ self.emit("finished")
+ return
+ else:
+ self.emit('updated', data[0], data[1])
+
+gobject.type_register(Listener)
+
+class Worker():
+ def __init__(self, queue):
+ self.queue = queue
+
+ def go(self):
+ print("The worker has started doing some work (counting from 0 to 9)")
+ for i in range(10):
+ proportion = (float(i+1))/10
+ self.queue.put((proportion, "working..."))
+ time.sleep(0.5)
+ self.queue.put((1.0, "finished"))
+ print("The worker has finished.")
+
+
+class Interface:
+ def __init__(self):
+ self.process = None
+ self.progress = gtk.ProgressBar()
+ button = gtk.Button("Go!")
+ button.connect("clicked", self.go)
+ vbox = gtk.VBox(spacing=5)
+ vbox.pack_start(self.progress)
+ vbox.pack_start(button)
+ vbox.show_all()
+ self.frame = vbox
+
+ def main(self):
+ window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ window.set_border_width(10)
+ window.add(self.frame)
+ window.show()
+ window.connect("destroy", self.destroy)
+
+ gtk.main()
+
+ def destroy(self, widget, data=None):
+ gtk.main_quit()
+
+
+ def callbackDisplay(self, obj, fraction, text, data=None):
+ self.progress.set_fraction(fraction)
+ self.progress.set_text(text)
+
+ def callbackFinished(self, obj, data=None):
+ if self.process==None:
+ raise RuntimeError("No worker process started")
+ print("all done; joining worker process")
+ self.process.join()
+ self.process = None
+
+ self.progress.set_fraction(1.0)
+ self.progress.set_text("done")
+
+ def go(self, widget, data=None):
+ if self.process!=None:
+ return
+
+ print("Creating shared Queue")
+ queue = multiprocessing.Queue()
+
+ print("Creating Worker")
+ worker = Worker(queue)
+
+ print("Creating Listener")
+ listener = Listener(queue)
+ listener.connect("updated",self.callbackDisplay)
+ listener.connect("finished",self.callbackFinished)
+
+ print("Starting Worker")
+ self.process = multiprocessing.Process(target=worker.go, args=())
+ self.process.start()
+
+ print("Starting Listener")
+ thread = threading.Thread(target=listener.go, args=())
+ thread.start()
+
+if __name__ == '__main__':
+ gui = Interface()
+ gui.main()
\ No newline at end of file
diff --git a/Gui test/gtk_test_5.py b/Gui test/gtk_test_5.py
new file mode 100644
index 0000000..044ed36
--- /dev/null
+++ b/Gui test/gtk_test_5.py
@@ -0,0 +1,166 @@
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk, GObject as gobject
+import time
+from multiprocessing import Process, Value, Lock, Pool, Queue
+import threading
+
+gobject.threads_init()
+
+class Listener(gobject.GObject):
+ __gsignals__ = {
+ 'updated' : (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_FLOAT, gobject.TYPE_STRING)),
+ 'finished': (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ ())
+ }
+
+ def __init__(self, queue):
+ gobject.GObject.__init__(self)
+ self.queue = queue
+
+ def go(self):
+ print("Listener has started")
+ while True:
+ # Listen for results on the queue and process them accordingly
+ data = self.queue.get()
+ # Check if finished
+ if data[1]=="finished":
+ print("Listener is finishing.")
+ self.emit("finished")
+ return
+ else:
+ self.emit('updated', data[0], data[1])
+
+gobject.type_register(Listener)
+
+class Worker():
+ def __init__(self, queue):
+ self.queue = queue
+
+ def go(self):
+ print("The worker has started doing some work (counting from 0 to 9)")
+ for i in range(2542):
+ proportion = (float(i+1))/2542
+ self.queue.put((proportion, "working..."))
+ time.sleep(0.01)
+ self.queue.put((1.0, "finished"))
+ print("The worker has finished.")
+
+class Counter(object):
+ def __init__(self, initval=0.0):
+ self.val = Value('d', initval)
+ self.lock = Lock()
+
+ def increment(self):
+ with self.lock:
+ self.val.value += 1/2542
+ print(self.val.value)
+
+ def value(self):
+ with self.lock:
+ return self.val.value
+
+class MyWindow(Gtk.Window):
+
+ def __init__(self):
+ Gtk.Window.__init__(self, title = 'Hello World')
+
+ #self.val = 0
+ self.process = None
+
+ self.box = Gtk.Box(spacing=6)
+ self.add(self.box)
+
+ self.button1 = Gtk.Button(label = 'Hello')
+ self.button1.connect('clicked', self.go)
+ self.box.pack_start(self.button1, True, True, 0)
+
+ self.button2 = Gtk.Button(label = 'Goodbye')
+ self.button2.connect('clicked', self.on_button2_clicked)
+ self.box.pack_start(self.button2, True, True, 0)
+
+ self.pbar = Gtk.ProgressBar()
+ self.pbar.set_fraction(0.0)
+ self.box.pack_start(self.pbar, True, True, 0)
+
+ def callbackDisplay(self, obj, fraction, text, data=None):
+ self.pbar.set_fraction(fraction)
+ self.pbar.set_text(text)
+
+ def callbackFinished(self, obj, data=None):
+ if self.process==None:
+ raise RuntimeError("No worker process started")
+ print("all done; joining worker process")
+ self.process.join()
+ self.process = None
+
+ self.pbar.set_fraction(1.0)
+ self.pbar.set_text("done")
+
+ print('Goodbye')
+ Gtk.main_quit()
+
+ def go(self, widget, data=None):
+ if self.process!=None:
+ return
+
+ print("Creating shared Queue")
+ queue = Queue()
+
+ print("Creating Worker")
+ worker = Worker(queue)
+
+ print("Creating Listener")
+ listener = Listener(queue)
+ listener.connect("updated",self.callbackDisplay)
+ listener.connect("finished",self.callbackFinished)
+
+ print("Starting Worker")
+ self.process = Process(target=worker.go, args=())
+ self.process.start()
+
+ print("Starting Listener")
+ thread = threading.Thread(target=listener.go, args=())
+ thread.start()
+
+ #def on_button1_clicked(self, widget):
+ #print('Hello')
+ #procs = [Process(target=self.func, args=(counter,)) for i in range(10)]
+
+ #for p in procs: p.start()
+ #for p in procs: p.join()
+ #p = Pool(2)
+ #p.map(self.func, range(2542))
+ #print (counter.value())
+
+ #while counter.val.value <10:
+ #self.update_pbar(self.pbar)
+ #print('Goodbye')
+ #Gtk.main_quit()
+
+ def on_button2_clicked(self, widget):
+ print('Goodbye')
+ Gtk.main_quit()
+
+ #def update_pbar(self, widget, value):
+ #self.val += 0.1
+ #self.pbar.set_fraction(value)
+ #time.sleep(0.5)
+ #while Gtk.events_pending():
+ #Gtk.main_iteration()
+
+ #def func(self, data):
+ #for i in range(2542):
+ #time.sleep(0.01)
+ #counter.increment()
+ #while counter.value() <1:
+ #self.update_pbar(self.pbar, counter.value())
+
+#counter = Counter(0.0)
+win = MyWindow()
+win.connect('delete-event', Gtk.main_quit)
+win.show_all()
+Gtk.main()
diff --git a/Gui test/h2inc (copy).xml b/Gui test/h2inc (copy).xml
new file mode 100644
index 0000000..4702fd7
--- /dev/null
+++ b/Gui test/h2inc (copy).xml
@@ -0,0 +1,393 @@
+
+
+
+
+
+
+ False
+ 5
+ 5
+ 5
+ 5
+
+
+ True
+ False
+
+
+ True
+ False
+ 0
+ etched-out
+
+
+ True
+ False
+ 12
+
+
+ True
+ False
+
+
+ True
+ False
+ end
+ 5
+ 5
+ 5
+ True
+ Source:
+ right
+
+
+ 0
+ 0
+ 2
+
+
+
+
+ True
+ True
+ 5
+ 5
+ 5
+ 5
+ Select source directory!
+
+
+ 2
+ 0
+ 2
+
+
+
+
+ Source directory...
+ True
+ True
+ True
+ start
+ 5
+ 5
+ 5
+ 5
+
+
+ 4
+ 0
+ 2
+
+
+
+
+ True
+ False
+ False
+ end
+ 5
+ 5
+ 5
+ True
+ Destination:
+ right
+ start
+ 2.2351741811588166e-10
+
+
+ 0
+ 1
+ 2
+
+
+
+
+ True
+ False
+ True
+ 5
+ 5
+ 5
+ 5
+ Select destination directory!
+
+
+ 2
+ 1
+ 2
+
+
+
+
+ Destination directory...
+ True
+ False
+ True
+ True
+ start
+ 5
+ 5
+ 5
+ 5
+
+
+ 4
+ 1
+ 2
+
+
+
+
+ Create "include" folder if it does not exist.
+ True
+ False
+ True
+ False
+ 5
+ 5
+ 0
+ True
+
+
+ 0
+ 2
+ 6
+
+
+
+
+
+
+
+
+ True
+ False
+ Select folders
+
+
+
+
+ 0
+ 0
+ 5
+
+
+
+
+ True
+ False
+ False
+ 5
+ 5
+ 0
+ etched-out
+
+
+ True
+ False
+ 12
+
+
+ True
+ False
+
+
+ True
+ False
+ 5
+ 5
+ True
+ 0
+ etched-out
+
+
+ True
+ False
+ 12
+
+
+ True
+ False
+ vertical
+
+
+ True
+ False
+ start
+ 5
+ 5
+ True
+ Number of folders: 0
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ False
+ start
+ 5
+ 5
+ Number of files: 0
+
+
+ False
+ True
+ 1
+
+
+
+
+
+
+
+
+ True
+ False
+ Source information
+
+
+
+
+ 0
+ 0
+
+
+
+
+ Translate!
+ True
+ True
+ True
+ start
+ 5
+ 5
+
+
+ 0
+ 1
+
+
+
+
+ True
+ False
+ 5
+ 5
+ 5
+ 0
+ etched-out
+
+
+ True
+ False
+ 12
+
+
+ True
+ False
+ vertical
+
+
+ True
+ False
+ start
+ 5
+ 5
+ Total progress:
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ False
+ 5
+ 5
+ 5
+
+
+ False
+ True
+ 1
+
+
+
+
+
+
+
+
+ True
+ False
+ Progress
+
+
+
+
+ 0
+ 2
+
+
+
+
+
+
+
+
+ True
+ False
+ Translation
+
+
+
+
+ 0
+ 1
+ 5
+
+
+
+
+
+
diff --git a/Gui test/h2inc.glade~ b/Gui test/h2inc.glade~
new file mode 100644
index 0000000..ad6a6e9
--- /dev/null
+++ b/Gui test/h2inc.glade~
@@ -0,0 +1,367 @@
+
+
+
+
+
+ False
+ 5
+ 5
+ 5
+ 5
+
+
+ True
+ False
+ 5
+ 5
+ 5
+ 5
+ True
+ True
+
+
+ True
+ False
+ 0
+ etched-out
+
+
+ True
+ False
+ 12
+
+
+ True
+ False
+
+
+ True
+ False
+ end
+ 5
+ 5
+ 5
+ True
+ Source:
+ right
+
+
+ 0
+ 0
+ 2
+
+
+
+
+ True
+ True
+ 5
+ 5
+ 5
+ 5
+ Select source directory!
+
+
+ 2
+ 0
+ 2
+
+
+
+
+ Source directory...
+ True
+ True
+ True
+ start
+ 5
+ 5
+ 5
+ 5
+
+
+ 4
+ 0
+ 2
+
+
+
+
+ True
+ False
+ False
+ end
+ 5
+ 5
+ 5
+ True
+ Destination:
+ right
+ start
+ 2.2351741811588166e-10
+
+
+ 0
+ 1
+ 2
+
+
+
+
+ True
+ False
+ True
+ 5
+ 5
+ 5
+ 5
+ Select destination directory!
+
+
+ 2
+ 1
+ 2
+
+
+
+
+ Destination directory...
+ True
+ False
+ True
+ True
+ start
+ 5
+ 5
+ 5
+ 5
+
+
+ 4
+ 1
+ 2
+
+
+
+
+ Create "include" folder if it does not exist.
+ True
+ False
+ True
+ False
+ 5
+ 5
+ 0
+ True
+
+
+ 0
+ 2
+ 6
+
+
+
+
+
+
+
+
+ True
+ False
+ Select folders
+
+
+
+
+ 0
+ 0
+ 5
+
+
+
+
+ True
+ False
+ False
+ 5
+ 5
+ 0
+ etched-out
+
+
+ True
+ False
+ 12
+
+
+ True
+ False
+
+
+ True
+ False
+ 5
+ 5
+ True
+ 0
+ etched-out
+
+
+ True
+ False
+ 12
+
+
+ True
+ False
+ vertical
+
+
+ True
+ False
+ start
+ 5
+ 5
+ True
+ Number of folders: 0
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ False
+ start
+ 5
+ 5
+ Number of files: 0
+
+
+ False
+ True
+ 1
+
+
+
+
+
+
+
+
+ True
+ False
+ Source information
+
+
+
+
+ 0
+ 0
+
+
+
+
+ Translate!
+ True
+ True
+ True
+ start
+ 5
+ 5
+
+
+ 0
+ 1
+
+
+
+
+ True
+ False
+ 5
+ 5
+ 5
+ 0
+ etched-out
+
+
+ True
+ False
+ 12
+
+
+ True
+ False
+ vertical
+
+
+ True
+ False
+ start
+ 5
+ 5
+ Total progress:
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ False
+ 5
+ 5
+ 5
+
+
+ False
+ True
+ 1
+
+
+
+
+
+
+
+
+ True
+ False
+ Progress
+
+
+
+
+ 0
+ 2
+
+
+
+
+
+
+
+
+ True
+ False
+ Translation
+
+
+
+
+ 0
+ 1
+ 5
+
+
+
+
+
+
diff --git a/Gui test/h2inc_gtk.py b/Gui test/h2inc_gtk.py
index 48bcd28..7f1c7d2 100644
--- a/Gui test/h2inc_gtk.py
+++ b/Gui test/h2inc_gtk.py
@@ -9,11 +9,58 @@
import os
import sys
-import multiprocessing as mp
import io
import gi
gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk, Gio, GdkPixbuf
+from gi.repository import Gtk, Gio, GObject as gobject
+import time
+from multiprocessing import Process, Value, Lock, Pool, Queue
+import threading
+
+gobject.threads_init()
+
+class Listener(gobject.GObject):
+ __gsignals__ = {
+ 'updated' : (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_FLOAT, gobject.TYPE_STRING, gobject.TYPE_INT)),
+ 'finished': (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ ())
+ }
+
+ def __init__(self, queue):
+ gobject.GObject.__init__(self)
+ self.queue = queue
+
+ def go(self):
+ print("Listener has started")
+ while True:
+ # Listen for results on the queue and process them accordingly
+ data = self.queue.get()
+ # Check if finished
+ if data[1]=="finished":
+ print("Listener is finishing.")
+ self.emit("finished")
+ return
+ else:
+ self.emit('updated', data[0], data[1], data[2])
+
+gobject.type_register(Listener)
+
+class Worker():
+ def __init__(self, queue, filecnt, filelist):
+ self.queue = queue
+ self.filecnt = filecnt
+
+ def go(self):
+ print("The worker has started doing some work (counting from 0 to 9)")
+ for i in range(self.filecnt):
+ proportion = (float(i+1))/self.filecnt
+ self.queue.put((proportion, "working...", i))
+ process_file(filelist[i])
+ self.queue.put((1.0, "finished"))
+ print("The worker has finished.")
tupline = []
preproc = ()
@@ -22,8 +69,9 @@ folderlist = []
cnt = 0
srcdir = ''
destdir = ''
-num_cores = mp.cpu_count()
+#num_cores = multiprocessing.cpu_count()
fileindex = 0
+filecnt = 0
def sourcedir_filecnt(sourcedir):
### Return the number of files, ending with '.h', in sourcedir - including subdirectories ###
@@ -110,12 +158,66 @@ def process_file(data):
newfile.write(outfile)
newfile.close()
-def async_process(num):
- pool = mp.Pool(processes=num)
- pool.map(process_file, filelist)
+class ExampleApp:
-class Handler:
+ global app
+ global destlabel
+ def __init__(self):
+
+ self.filecnt = 0
+ self.fileindex = 0
+ self.process = None
+ self.app = Gtk.Application.new("org.h2inc", Gio.ApplicationFlags(0))
+ self.app.connect("activate", self.on_app_activate)
+ self.app.connect("shutdown", self.on_app_shutdown)
+ app = self.app
+
+ def on_app_activate(self, app):
+ builder = Gtk.Builder()
+ builder.add_from_file("h2inc.glade")
+ builder.connect_signals(self)
+
+ self.obj = builder.get_object
+ self.obj("window").set_application(app)
+ self.obj("window").set_wmclass("h2inc_gtk","h2inc_gtk")
+ self.obj("window").show_all()
+
+ button = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
+ button.set_property("can-default",True)
+ self.obj("filechooser_dialog").add_action_widget(button, Gtk.ResponseType.CANCEL)
+ button = Gtk.Button.new_from_stock(Gtk.STOCK_APPLY)
+ button.set_property("can-default",True)
+ self.obj("filechooser_dialog").add_action_widget(button, Gtk.ResponseType.OK)
+
+ def on_app_shutdown(self, app):
+ self.app.quit()
+
+ def run(self, argv):
+ self.app.run(argv)
+
+ def callbackDisplay(self, obj, fraction, text, index, data=None):
+ self.obj("progress_label").set_text("{} of {}".format(index+1, self.filecnt))
+ self.obj("progressbar").set_fraction(fraction)
+ self.obj("progressbar").set_text(text)
+
+ def callbackFinished(self, obj, data=None):
+ if self.process==None:
+ raise RuntimeError("No worker process started")
+ print("all done; joining worker process")
+ self.process.join()
+ self.process = None
+
+ self.obj("progressbar").set_fraction(1.0)
+ self.obj("progressbar").set_text("done")
+ self.obj("sourceframe").set_sensitive(True)
+ self.obj("translate_button").set_sensitive(True)
+ self.obj("destination_label").set_sensitive(True)
+ self.obj("destination_entry").set_sensitive(True)
+ self.obj("destination_button").set_sensitive(True)
+ self.obj("include_checkbutton").set_sensitive(True)
+ self.obj("translation_frame").set_sensitive(True)
+
def on_window_destroy(self,window):
window.close()
@@ -130,17 +232,6 @@ class Handler:
print("File selection: %s" % widget.get_filename())
self.on_dialog_close(widget)
- def on_filechooser_dialog_file_activated(self,widget):
- self.on_filechooser_dialog_response(widget,-5)
-
- def on_filechooser_dialog_update_preview(self,widget):
- if widget.get_filename() != None and os.path.isfile(widget.get_filename()):
- pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(widget.get_filename(),200,200,True)
- app.obj("preview").set_from_pixbuf(pixbuf)
-
- def on_file_button_clicked(self,widget):
- app.obj("filechooser_dialog").show_all()
-
def on_source_button_clicked(self,widget):
dialog = Gtk.FileChooserDialog("Select source directory!",
@@ -152,15 +243,15 @@ class Handler:
response = dialog.run()
if response == Gtk.ResponseType.OK:
- filecnt = sourcedir_filecnt(dialog.get_filename())
- if filecnt >0:
- print(filecnt)
+ self.filecnt = sourcedir_filecnt(dialog.get_filename())
+ if self.filecnt >0:
+ print(self.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))
+ app.obj("numfiles_label").set_text(str(self.filecnt))
+ app.obj("progress_label").set_text("{} of {}".format(fileindex, self.filecnt))
foldercnt = sourcedir_foldercnt(dialog.get_filename())
if foldercnt >0:
app.obj("numfolders_label").set_text(str(foldercnt))
@@ -192,51 +283,31 @@ class Handler:
dialog.destroy()
- def on_translate_button_clicked(self, widget):
+ def on_translate_button_clicked(self, widget, data=None):
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
- global destlabel
-
- def __init__(self):
- self.app = Gtk.Application.new("org.h2inc", Gio.ApplicationFlags(0))
- self.app.connect("activate", self.on_app_activate)
- self.app.connect("shutdown", self.on_app_shutdown)
- app = self.app
+ if self.process!=None:
+ return
- def on_app_activate(self, app):
- builder = Gtk.Builder()
- builder.add_from_file("h2inc.glade")
- builder.connect_signals(Handler())
+ print("Creating shared Queue")
+ queue = Queue()
- self.obj = builder.get_object
- self.obj("window").set_application(app)
- self.obj("window").set_wmclass("h2inc_gtk","h2inc_gtk")
- self.obj("window").show_all()
+ print("Creating Worker")
+ worker = Worker(queue, self.filecnt, filelist)
- button = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
- button.set_property("can-default",True)
- self.obj("filechooser_dialog").add_action_widget(button, Gtk.ResponseType.CANCEL)
- button = Gtk.Button.new_from_stock(Gtk.STOCK_APPLY)
- button.set_property("can-default",True)
- self.obj("filechooser_dialog").add_action_widget(button, Gtk.ResponseType.OK)
+ print("Creating Listener")
+ listener = Listener(queue)
+ listener.connect("updated",self.callbackDisplay)
+ listener.connect("finished",self.callbackFinished)
- def on_app_shutdown(self, app):
- self.app.quit()
+ print("Starting Worker")
+ self.process = Process(target=worker.go, args=())
+ self.process.start()
- def run(self, argv):
- self.app.run(argv)
+ print("Starting Listener")
+ thread = threading.Thread(target=listener.go, args=())
+ thread.start()
app = ExampleApp()
app.run(sys.argv)
diff --git a/Multiprocessing test/mp_test_1.py b/Multiprocessing test/mp_test_1.py
new file mode 100644
index 0000000..00183ad
--- /dev/null
+++ b/Multiprocessing test/mp_test_1.py
@@ -0,0 +1,18 @@
+from multiprocessing import Process
+import os
+
+def info(title):
+ print(title)
+ print('module name:', __name__)
+ print('parent process:', os.getppid())
+ print('process id:', os.getpid())
+
+def f(name):
+ info('function f')
+ print('hello', name)
+
+if __name__ == '__main__':
+ info('main line')
+ p = Process(target=f, args=('bob',))
+ p.start()
+ p.join()
\ No newline at end of file
diff --git a/old_h2inc/__pycache__/h2inc_gui_old.cpython-35.pyc b/old_h2inc/__pycache__/h2inc_gui_old.cpython-35.pyc
new file mode 100644
index 0000000..ffc4e35
Binary files /dev/null and b/old_h2inc/__pycache__/h2inc_gui_old.cpython-35.pyc differ
diff --git a/old_h2inc/__pycache__/h2inc_gui_old.cpython-36.pyc b/old_h2inc/__pycache__/h2inc_gui_old.cpython-36.pyc
new file mode 100644
index 0000000..f92413a
Binary files /dev/null and b/old_h2inc/__pycache__/h2inc_gui_old.cpython-36.pyc differ
diff --git a/old_h2inc/__pycache__/h2inc_old.cpython-36.pyc b/old_h2inc/__pycache__/h2inc_old.cpython-36.pyc
new file mode 100644
index 0000000..289d139
Binary files /dev/null and b/old_h2inc/__pycache__/h2inc_old.cpython-36.pyc differ