def watch_process(self, io, condition, process_name):
if condition is GLib.IO_HUP:
self.progressbar.pulse()
self.n_files -= 1
if self.n_files == 0:
self.config_save_crop(self.crop)
return False
while Gtk.events_pending():
Gtk.main_iteration_do(False)
return True
python类main_iteration_do()的实例源码
def watch_process(self, io, condition, process_name):
if condition is GLib.IO_HUP:
self.progressbar.pulse()
self.n_files_to_copy -= 1
if self.n_files_to_copy == 0:
message_dialog = Gtk.MessageDialog(
self.main_window,
0,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
_("Done!"),
width_request = 360
)
content_area = message_dialog.get_content_area()
content_area.set_property('margin-left', 10)
content_area.set_property('margin-right', 10)
content_area.set_property('margin-top', 10)
content_area.set_property('margin-bottom', 10)
action_area = message_dialog.get_action_area()
action_area.set_property('spacing', 10)
self.main_window.hide()
message_dialog.run()
message_dialog.destroy()
Gtk.main_quit()
return False
while Gtk.events_pending():
Gtk.main_iteration_do(False)
return True
def append_queue_tab(self):
self.notebook.append_page(self.queue_tab_scrolled_window, self.queue_tab)
self.notebook.set_tab_reorderable(self.queue_tab_scrolled_window, True)
self.notebook.set_tab_detachable(self.queue_tab_scrolled_window, True)
self.notebook.show_all()
while Gtk.events_pending():
Gtk.main_iteration_do(False)
def update_gui():
"""Updates GUI by completing all tasks in the main event loop"""
while Gtk.events_pending():
Gtk.main_iteration_do(True)
def decorate_gtk_mainfunc(function):
def decorated_function(*args, **kwargs):
run_mainloop(function, Gtk.main_quit, None, *args, **kwargs)
return decorated_function
# We could override Gtk.main_iteration and Gtk.main_iteration_do too,
# but that does not seem to be necessary (because they don't dispatch
# our event handler, but instead return; this means that the exception
# is raised anyways).
def repaint():
'''Easy function to clean up the event queue and force a repaint.'''
# I've been unable to find any other way to repaint the interface. :-(
while Gtk.events_pending():
# Blocking: True/false
Gtk.main_iteration_do(False)
def run(self):
while not self.ended:
gtk.main_iteration_do(False)
def launch_fsaa_settings(self):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration_do(False)
os.system(wineloader + ' ' + game_dir + '/br2fsaaConfig.exe')
self.main_window.show()
def cb_button_config(self, button):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration_do(False)
os.system(wineloader + ' ' + game_dir + '/bin/Final/Config.exe')
self.main_window.show()
def cb_button_patch(self, button):
if os.path.exists(game_dir + '/' + 'br2fsaaConfig.exe'):
self.launch_fsaa_settings()
else:
patch_path = download_dir + '/_distr/bloodrayne_2/BR2_FSAA_Patch_1.666.rar'
if not os.path.exists(patch_path):
message_dialog = Gtk.MessageDialog(
self.main_window,
0,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
_("Patch not found in download directory.")
)
content_area = message_dialog.get_content_area()
content_area.set_property('margin-left', 10)
content_area.set_property('margin-right', 10)
content_area.set_property('margin-top', 10)
content_area.set_property('margin-bottom', 10)
self.main_window.hide()
message_dialog.run()
message_dialog.destroy()
self.main_window.show()
else:
self.button_patch.set_sensitive(False)
while Gtk.events_pending():
Gtk.main_iteration_do(False)
command = ['7z', 'e', '-aoa', '-o' + game_dir, patch_path]
self.pid, stdin, stdout, stderr = GLib.spawn_async(command,
flags=GLib.SpawnFlags.SEARCH_PATH|GLib.SpawnFlags.DO_NOT_REAP_CHILD,
standard_output=True,
standard_error=True)
io = GLib.IOChannel(stdout)
self.source_id_out = io.add_watch(GLib.IO_IN|GLib.IO_HUP,
self.watch_process,
'extracting',
priority=GLib.PRIORITY_HIGH)
def cb_button_patch(self, button):
patch_path = download_dir + '/_distr/pathologic/Pathologic_Widescreen_Addon.exe'
if not os.path.exists(patch_path):
message_dialog = Gtk.MessageDialog(
self.main_window,
0,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
_("Addon not found in download directory.")
)
content_area = message_dialog.get_content_area()
content_area.set_property('margin-left', 10)
content_area.set_property('margin-right', 10)
content_area.set_property('margin-top', 10)
content_area.set_property('margin-bottom', 10)
self.main_window.hide()
message_dialog.run()
message_dialog.destroy()
self.main_window.show()
else:
self.button_config.set_sensitive(False)
self.button_patch.set_visible(False)
self.progressbar.set_visible(True)
while Gtk.events_pending():
Gtk.main_iteration_do(False)
command = ['innoextract', patch_path, '-d', game_dir + '/tmp']
self.pid, stdin, stdout, stderr = GLib.spawn_async(command,
flags=GLib.SpawnFlags.SEARCH_PATH|GLib.SpawnFlags.DO_NOT_REAP_CHILD,
standard_output=True,
standard_error=True)
io = GLib.IOChannel(stdout)
self.source_id_out = io.add_watch(GLib.IO_IN|GLib.IO_HUP,
self.watch_process,
'extracting',
priority=GLib.PRIORITY_HIGH)