def work(self):
while Gtk.events_pending():
Gtk.main_iteration()
# again = False
msg = self.web_recv()
if msg:
try:
msg = from_json(msg)
print('This is the message %s' % (msg))
except BaseException:
msg = None
# again = True
if msg == 'exit':
self.close_application(None)
# ###################################################################
# ########################BROWSER####################################
# ###################################################################
python类events_pending()的实例源码
def title_changed(self, widget, frame, title):
if title != 'null':
self.message_queue.put(title)
while Gtk.events_pending():
Gtk.main_iteration()
msg = self.web_recv()
if msg:
try:
msg = from_json(msg)
print('This is the message %s' % (msg))
if msg['status'] == 'ready':
self.web_send('title="%s";subtitle="%s";humidity=%s;\
cloudiness=%s;temperature=%s;draw_graph(title,subtitle,temperature,humidity,\
cloudiness);' % (self.title, self.subtitle, self.humidity, self.cloudiness,
self.temperature))
elif msg['status'] == 'exit':
self.close_application(None)
except BaseException:
pass
def __init__(self,title,parent,max_value):
#
Gtk.Dialog.__init__(self,title,parent)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_size_request(330, 40)
self.set_resizable(False)
self.connect('destroy', self.close)
#
vbox1 = Gtk.VBox(spacing = 5)
vbox1.set_border_width(5)
self.get_content_area().add(vbox1)
#
self.progressbar = Gtk.ProgressBar()
vbox1.pack_start(self.progressbar,True,True,0)
#
self.show_all()
#
self.max_value=max_value
self.value=0.0
self.map()
while Gtk.events_pending():
Gtk.main_iteration()
def start_app(datadir):
global splash_win
if not options.no_splash:
solfege.splash_win = splash_win = SplashWin()
time.sleep(0.1)
Gdk.flush()
while Gtk.events_pending():
Gtk.main_iteration()
else:
solfege.splash_win = splash_win = None
style_provider = Gtk.CssProvider()
with open("solfege.css", "r") as f:
css = f.read()
try:
style_provider.load_from_data(css)
except GObject.GError, e:
print e
pass
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(), style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
GObject.timeout_add(1, start_gui, datadir)
Gtk.main()
def on_find_object(self, plugin, cruft, count, iters):
while Gtk.events_pending():
Gtk.main_iteration()
plugin_iter, result_iter = iters
self.result_model.append(result_iter, (False,
cruft.get_icon(),
cruft.get_name(),
cruft.get_name(),
cruft.get_size_display(),
plugin,
cruft))
self.result_view.expand_row(self.result_model.get_path(result_iter), True)
# Update the janitor title
if count:
self.janitor_model[plugin_iter][self.JANITOR_DISPLAY] = "<b>[%d] %s</b>" % (count, plugin.get_title())
else:
self.janitor_model[plugin_iter][self.JANITOR_DISPLAY] = "[0] %s" % plugin.get_title()
def update_progress_gui(self, progress_text, progress):
"""Updates the progressbar to show what we are working on"""
progressbar = self.widgets.get_object('progressbar')
self.widgets.get_object('progress_dialog').show()
if float(progress) < 0:
progressbar.pulse()
else:
progressbar.set_fraction(float(progress)/100)
if progress_text != None:
self.widgets.get_object('action').set_markup("<i>" +\
_(progress_text)+"</i>")
while Gtk.events_pending():
Gtk.main_iteration()
return True
def on_delete_learned_data_clicked(self, dummy_widget):
'''
The button requesting to delete all data learned from
user input or text files has been clicked.
'''
SETUP_UI.delete_learned_data_button.set_sensitive(False)
confirm_question = Gtk.Dialog(
title=_('Are you sure?'),
parent=SETUP_UI.builder.get_object('main_dialog'),
buttons=(
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
box = confirm_question.get_content_area()
box.add(Gtk.Label(
_('Do you really want to delete all language \n'
+ 'data learned from typing or reading files?')))
confirm_question.show_all()
response = confirm_question.run()
confirm_question.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response == Gtk.ResponseType.OK:
SETUP_UI.tabsqlitedb.remove_all_phrases()
SETUP_UI.delete_learned_data_button.set_sensitive(True)
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
def launch_game(self):
self.switch_monitor('ON')
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
if self.launcher_type == 'gog':
launch_command = self.install_dir + '/' + self.game_name + '/start_gog.sh'
else:
launch_command = self.install_dir + '/' + self.game_name + '/start_gn.sh'
os.system(self.command_before)
os.system(launch_command)
os.system(self.command_after)
self.switch_monitor('OFF')
self.config_save()
sys.exit()
def cb_button_settings(self, button):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
launch_command = self.install_dir + '/' + self.game_name + '/settings.sh ' + \
self.install_dir + ' ' + nebula_dir
os.system(launch_command)
self.config_save()
os.execl(sys.executable, 'python', __file__, self.game_name)
def cb_button_wine_settings(self, button):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
self.set_wineprefix()
self.create_link()
self.set_environ()
self.set_win_ver_command()
self.set_additions_command()
launch_command = 'python2 ' + nebula_dir + '/settings_wine.py'
full_command = self.win_ver_command + '\n' + \
self.additions_command + '\n' + \
launch_command
os.system(full_command)
self.main_window.show()
def cb_button_settings(self, button):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
self.set_wineprefix()
self.create_link()
self.set_environ()
self.set_win_ver_command()
self.set_additions_command()
launch_command = self.install_dir + '/' + self.game_name + '/settings.sh'
full_command = self.win_ver_command + '\n' + \
self.additions_command + '\n' + \
launch_command
os.system(full_command)
self.config_save()
self.exe_path = self.get_new_exe_path()
os.execl(sys.executable, 'python', __file__, self.game_name, self.exe_path)
def launch_game(self):
self.switch_monitor('ON')
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
self.set_environ()
self.set_win_ver_command()
self.set_mouse_capture_command()
self.set_additions_command()
self.set_launch_command()
exe_name, exe_path_no_exe = self.get_exe_path()
cd_command = 'cd "' + self.install_dir + '/' + self.game_name + \
'/game/' + exe_path_no_exe + '"'
full_command = cd_command + '\n' + \
self.win_ver_command + '\n' + \
self.mouse_capture_command + '\n' + \
self.additions_command + '\n' + \
self.launch_command
os.system(self.command_before)
os.system(full_command)
os.system(self.command_after)
self.switch_monitor('OFF')
sys.exit()
def launch_game(self):
output = self.combobox_monitor.get_active_text().split()[0]
os.system('xrandr --output '+ output + ' --primary')
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
dosbox_bin = self.set_dosbox_bin()
self.create_link()
launch_command = dosbox_bin + ' -conf ' + \
os.getenv('HOME') + '/.games_nebula/config/dosbox.conf' + \
' -conf ' + self.install_dir + '/' + self.game_name + '/dosbox.conf' + \
' -conf ' + self.install_dir + '/' + self.game_name + '/dosbox_game.conf'
os.system(self.command_before)
os.system('export SDL_VIDEO_FULLSCREEN_HEAD=0 && ' + launch_command)
os.system(self.command_after)
output = self.monitor_primary.split()[0]
os.system('xrandr --output '+ output + ' --primary')
self.config_save()
sys.exit()
def cb_button_settings(self, button):
output = self.combobox_monitor.get_active_text().split()[0]
os.system('xrandr --output '+ output + ' --primary')
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
dosbox_bin = self.set_dosbox_bin()
self.create_link()
launch_command = dosbox_bin + ' -conf ' + \
os.getenv('HOME') + '/.games_nebula/config/dosbox.conf' + \
' -conf ' + self.install_dir + '/' + self.game_name + '/dosbox.conf' + \
' -conf ' + self.install_dir + '/' + self.game_name + '/dosbox_settings.conf'
os.system('export SDL_VIDEO_FULLSCREEN_HEAD=0 && ' + launch_command)
output = self.monitor_primary.split()[0]
os.system('xrandr --output '+ output + ' --primary')
self.main_window.show()
def cb_button_settings(self, button):
output = self.combobox_monitor.get_active_text().split()[0]
os.system('xrandr --output '+ output + ' --primary')
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
if self.scummvm == 'global':
if global_scummvm == 'system':
launch_command = 'scummvm --no-fullscreen -c ' + self.install_dir \
+ '/' + self.game_name + '/scummvmrc'
if global_scummvm == 'path':
launch_command = global_scummvm_path + '/' + global_scummvm_version + \
'/bin/scummvm --no-fullscreen -c ' + self.install_dir \
+ '/' + self.game_name + '/scummvmrc'
elif self.scummvm == 'system':
launch_command = 'scummvm --no-fullscreen -c ' + self.install_dir \
+ '/' + self.game_name + '/scummvmrc'
elif self.scummvm == 'path':
launch_command = self.scummvm_path + '/' + self.scummvm_version + \
'/bin/scummvm --no-fullscreen -c ' + self.install_dir \
+ '/' + self.game_name + '/scummvmrc'
os.system(launch_command)
output = self.monitor_primary.split()[0]
os.system('xrandr --output '+ output + ' --primary')
self.main_window.show()
def launch_game(self):
output = self.combobox_monitor.get_active_text().split()[0]
os.system('xrandr --output '+ output + ' --primary')
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
if self.scummvm == 'global':
if global_scummvm == 'system':
scummvm_bin = 'scummvm'
if global_scummvm == 'path':
scummvm_bin = global_scummvm_path + '/' + global_scummvm_version + '/bin/scummvm'
elif self.scummvm == 'system':
scummvm_bin = 'scummvm'
elif self.scummvm == 'path':
scummvm_bin = self.scummvm_path + '/' + self.scummvm_version + '/bin/scummvm'
launch_command = scummvm_bin + ' -c ' + self.install_dir + '/' +\
self.game_name + '/scummvmrc ' + self.scummvm_game_name
os.system(self.command_before)
os.system(launch_command)
os.system(self.command_after)
output = self.monitor_primary.split()[0]
os.system('xrandr --output '+ output + ' --primary')
self.config_save()
sys.exit()
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 mylib_launch_game(self, button):
self.switch_monitor('ON')
self.main_window.hide()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
game_name = button.get_name()
self.set_environ(game_name, self.mylib_download_dir, self.mylib_install_dir)
start_path = self.mylib_install_dir + '/' + game_name + '/start.sh'
os.system('chmod +x ' + start_path)
os.system(start_path)
self.switch_monitor('OFF')
self.main_window.show()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.show()
def goglib_launch_game(self, button):
self.switch_monitor('ON')
self.main_window.hide()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
game_name = button.get_name()
self.set_environ(game_name, self.goglib_download_dir, self.goglib_install_dir)
start_file_path = self.goglib_install_dir + '/' + game_name + '/start.sh'
os.system('chmod +x ' + start_file_path)
os.system(start_file_path)
self.switch_monitor('OFF')
self.main_window.show()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.show()
def cb_button_wine_settings(self, button):
self.main_window.hide()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
if self.wine == 'system':
os.environ['WINELOADER'] = 'wine'
elif self.wine == 'path':
wine_path = self.wine_path + '/' + self.wine_version
os.environ['WINE'] = wine_path + '/bin/wine'
os.environ['WINELOADER'] = wine_path + '/bin/wine'
os.environ['WINESERVER'] = wine_path + '/bin/wineserver'
os.environ['WINEDLLPATH'] = wine_path + '/lib'
os.environ['WINEPREFIX'] = os.getenv('HOME') + '/.games_nebula/wine_prefix'
os.system('python2 ' + nebula_dir + '/settings_wine.py')
self.main_window.show()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.show()
def cb_button_winetricks_cache(self, button):
self.main_window.hide()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
os.system('python2 ' + nebula_dir + '/winetricks_cache_backup.py')
self.main_window.show()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.show()
def cb_button_get_scripts(self, button):
lib = button.get_name()
if lib == 'goglib':
overwrite = self.checkbutton_goglib_scripts.get_active()
elif lib == 'mylib':
overwrite = self.checkbutton_mylib_scripts.get_active()
self.main_window.hide()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
mylib_has_new_scripts = os.system('python2 ' + nebula_dir + '/get_scripts.py ' + lib + ' ' + str(overwrite))
# Ugly but works
if mylib_has_new_scripts == 0:
print("No new scripts.")
else:
print("New scripts downloaded!")
os.execl(sys.executable, 'python2', __file__)
self.main_window.show()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.show()
def cb_button_dosbox_settings(self, button):
self.main_window.hide()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
if self.dosbox == 'system':
dosbox_bin = 'dosbox'
elif self.dosbox == 'path':
dosbox_bin = self.dosbox_path + '/' + self.dosbox_version + '/bin/dosbox'
dosbox_version = self.check_dosbox_version(dosbox_bin)
dosbox_global_config = os.getenv('HOME') + '/.games_nebula/config/dosbox.conf'
os.system('python2 ' + nebula_dir + '/settings_dosbox.py ' \
+ dosbox_global_config + ' global ' + dosbox_version)
# TODO Use if special config tool for svn-daum build exists (settings_dosbox_svn_daum.py)
#~ if (dosbox_version == 'stable') or (dosbox_version == 'svn'):
#~ os.system('python2 ' + nebula_dir + '/settings_dosbox.py ' + \
#~ dosbox_global_config + ' global ' + dosbox_version)
#~ elif dosbox_version == 'svn_daum':
#~ os.system('python2 ' + nebula_dir + '/dosbox_settings_svn_daum.py ' + \
#~ dosbox_global_config + ' global ' + dosbox_version)
self.main_window.show()
if len(self.additional_windows_list) != 0:
for window in self.additional_windows_list:
window.show()
def cb_button_add_remove(self, button):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
command = '$WINELOADER uninstaller'
os.system(command)
self.main_window.show()
def cb_button_controllers(self, button):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
command = '$WINELOADER control joy.cpl'
os.system(command)
self.main_window.show()
def cb_button_winetricks(self, button):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
command = 'winetricks --gui'
os.system(command)
self.main_window.show()
def set_wait_cursor(self):
self.get_root_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH))
while Gtk.events_pending():
Gtk.main_iteration()
def set_normal_cursor(self):
self.get_root_window().set_cursor(Gdk.Cursor(Gdk.CursorType.ARROW))
while Gtk.events_pending():
Gtk.main_iteration()
def __init__(self, lat=39.36873, lon=-2.417274645879, units='F'):
self.images = {}
self.echo = True
Gtk.Window.__init__(self)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_title(comun.APP)
self.set_default_size(900, 600)
self.set_icon_from_file(comun.ICON)
self.connect('destroy', self.close_application)
#
vbox = Gtk.VBox(spacing=5)
self.get_content_area().add(vbox)
hbox1 = Gtk.HBox()
vbox.pack_start(hbox1, True, True, 0)
self.scrolledwindow1 = Gtk.ScrolledWindow()
self.scrolledwindow1.set_policy(
Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.scrolledwindow1.set_shadow_type(Gtk.ShadowType.IN)
hbox1.pack_start(self.scrolledwindow1, True, True, 0)
self.viewer = WebKit.WebView()
self.scrolledwindow1.add(self.viewer)
self.scrolledwindow1.set_size_request(900, 600)
self.viewer.connect('title-changed', self.title_changed)
self.viewer.open('file://' + comun.HTML)
self.lat = lat
self.lon = lon
self.units = units
self.set_focus(self.viewer)
self.show_all()
self.message_queue = queue.Queue()
while Gtk.events_pending():
Gtk.main_iteration()
self.show_all()
self.inicialize()
self.run()
self.destroy()
# ###################################################################
# #########################ENGINE####################################
# ###################################################################