-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This prevents the blocking of GUI main thread
- Loading branch information
1 parent
4105f62
commit 74a84c4
Showing
3 changed files
with
125 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from gi.repository import Gtk, GObject | ||
|
||
class RunningDialog(Gtk.Dialog): | ||
|
||
def __init__(self, parent, event): | ||
Gtk.Dialog.__init__(self, "Simulation", parent, Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT|Gtk.DialogFlags.USE_HEADER_BAR, | ||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)) | ||
|
||
self.event = event | ||
|
||
self.set_default_size(150, 100) | ||
self.set_default_response(Gtk.ResponseType.CANCEL) | ||
|
||
self.progress_bar = Gtk.ProgressBar() | ||
self.progress_bar.activity_mode = True | ||
self.progress_bar.pulse() | ||
self.progress_bar.set_text("Running simulation") | ||
self.progress_bar.set_show_text(True) | ||
|
||
self.label = Gtk.Label(label="Running simulation") | ||
self.label.set_vexpand(True) | ||
|
||
self.spinner = Gtk.Spinner() | ||
self.spinner.start() | ||
self.spinner.set_vexpand(True) | ||
|
||
self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) | ||
self.hbox.pack_start(self.spinner, True, True, 18) | ||
self.hbox.pack_start(self.label, True, True, 18) | ||
|
||
|
||
box = self.get_content_area() | ||
box.add(self.hbox) | ||
|
||
self.timeout_id = GObject.timeout_add(50, self.on_timeout, None) | ||
|
||
self.show_all() | ||
|
||
def on_timeout(self, user_data): | ||
""" | ||
Update value on the progress bar | ||
""" | ||
self.progress_bar.pulse() | ||
if self.event.is_set(): # if thread finished | ||
self.response(1) # 1 is an application-defined response type | ||
return True | ||
|
||
|
||
if __name__ == "__main__": | ||
win = Gtk.Window() | ||
dialog = RunningDialog(win) | ||
dialog.run() | ||
dialog.destroy() | ||
win.destroy() | ||
|
||
|