def decrease(self):
self.value-=1.0
fraction=self.value/self.max_value
self.progressbar.set_fraction(fraction)
self.map()
while Gtk.events_pending():
Gtk.main_iteration()
python类main_iteration()的实例源码
def main():
sl = SL();os.system("mkdir /tmp/site");os.system("echo False > /tmp/site/site-log.txt")
if sl.run() == Gtk.ResponseType.ACCEPT:
sl.hide()
#if sl.button.get_label()!='Select folder':
folder = '/tmp/site/';
extension = sl.entry10.get_text()
url = sl.entry11.get_text()
if len(url)>0:
urls = get_file_urls(url,extension)
total = len(urls)
if total>0:
print(urls)
workers = []
print(1)
cua = queue.Queue(maxsize=total+2)
progreso = Progreso('Downloading from %s'%url,None,total)
total_workers = total if NUM_THREADS > total else NUM_THREADS
for i in range(total_workers):
worker = Worker(cua,folder)
worker.connect('downloaded',progreso.increase)
worker.start()
workers.append(worker)
print(2)
for aurl in urls:
cua.put(aurl)
# block until all tasks are done
print(3)
cua.join()
# stop workers
print(4)
for i in range(total_workers):
cua.put(None)
for worker in workers:
worker.join()
while Gtk.events_pending():
Gtk.main_iteration()
os.system("echo True > /tmp/site/site-log.txt")
def set_value(self,value):
if value >=0 and value<=self.max_value:
self.value = value
fraction=self.value/self.max_value
self.progressbar.set_fraction(fraction)
self.map()
while Gtk.events_pending():
Gtk.main_iteration()
if self.value==self.max_value:
self.hide()
def increase(self,w,a):
self.value+=1.0
fraction=self.value/self.max_value
self.progressbar.set_fraction(fraction)
while Gtk.events_pending():
Gtk.main_iteration()
if self.value==self.max_value:
self.hide()
def decrease(self):
self.value-=1.0
fraction=self.value/self.max_value
self.progressbar.set_fraction(fraction)
self.map()
while Gtk.events_pending():
Gtk.main_iteration()
def main():
sl = SL();os.system("mkdir /tmp/site");os.system("echo False > /tmp/site/site-log.txt")
if sl.run() == Gtk.ResponseType.ACCEPT:
sl.hide()
#if sl.button.get_label()!='Select folder':
folder = '/tmp/site/';
extension = sl.entry10.get_text()
url = sl.entry11.get_text()
if len(url)>0:
urls = get_file_urls(url,extension)
total = len(urls)
if total>0:
print(urls)
workers = []
print(1)
cua = queue.Queue(maxsize=total+2)
progreso = Progreso('Downloading from %s'%url,None,total)
total_workers = total if NUM_THREADS > total else NUM_THREADS
for i in range(total_workers):
worker = Worker(cua,folder)
worker.connect('downloaded',progreso.increase)
worker.start()
workers.append(worker)
print(2)
for aurl in urls:
cua.put(aurl)
# block until all tasks are done
print(3)
cua.join()
# stop workers
print(4)
for i in range(total_workers):
cua.put(None)
for worker in workers:
worker.join()
while Gtk.events_pending():
Gtk.main_iteration()
os.system("echo True > /tmp/site/site-log.txt")
def compile(self, *args):
self.parent.running = True
if os.path.isfile(os.path.join(self.path, '.pyide-project.json')):
with open(os.path.join(self.path, '.pyide-project.json'), 'r') as f:
## Do stuff
print('Found file')
project = json.load(f)
if os.path.exists(os.path.join(self.path, 'Makefile')):
self.stateEntry.set_text('Running...')
Gtk.main_iteration()
self.parent.openTerminal()
# with open(os.path.join(self.path, 'Makefile'), 'r') as f:
# command = f.readlines()
# for l in command:
# self.parent.terminal.feed_child(l, len(l))
self.parent.terminal.feed_child("make all\n", len("make all\n"))
self._quit()
else:
self.p = ProjectSettingsWindow(self.parent, self.compileBtn, self.stateEntry, self.path, self)
## Create the file and then compile
# pyideProject = json.JSONEncoder({
# ''
# })
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 wait_for_thread(thread):
while thread.is_alive():
while Gtk.events_pending():
Gtk.main_iteration()
return
def write(self, s, tag=None):
if tag:
self.g_textbuffer.insert_with_tags_by_name(
self.g_textbuffer.get_end_iter(),
s,
tag)
else:
self.g_textbuffer.insert(self.g_textbuffer.get_end_iter(), s)
self.g_textview.scroll_to_iter(
self.g_textbuffer.get_end_iter(),
0.0, False, 0.5, 0.5)
# This is needed to make the window update:
while Gtk.events_pending():
Gtk.main_iteration()
def screenshot(windowtitle, lang, fn):
while Gtk.events_pending():
Gtk.main_iteration()
time.sleep(2)
while Gtk.events_pending():
Gtk.main_iteration()
fn = "help/%s/figures/%s" % (lang, fn)
cmd = u'import -window %s %s' % (windowtitle, fn)
print cmd
os.system(cmd.encode("utf-8"))
compress(fn)
def show_progress(self, txt):
self.g_infolabel.set_text(txt)
while Gtk.events_pending():
Gtk.main_iteration()
def display_error_message(self, msg, title=None, secondary_text=None):
if solfege.splash_win and solfege.splash_win.props.visible:
solfege.splash_win.hide()
reshow_splash = True
else:
reshow_splash = False
if not isinstance(msg, unicode):
msg = msg.decode(locale.getpreferredencoding(), 'replace')
m = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR,
Gtk.ButtonsType.CLOSE, None)
m.set_markup(gu.escape(msg))
if title:
m.set_title(title)
if secondary_text:
m.format_secondary_text(secondary_text)
m.run()
m.destroy()
if reshow_splash:
solfege.splash_win.show()
while Gtk.events_pending():
Gtk.main_iteration()
def on_plugin_object_cleaned(self, plugin, cruft, count, user_data):
while Gtk.events_pending():
Gtk.main_iteration()
plugin_iter, cruft_dict = user_data
self.result_model.remove(cruft_dict[cruft])
self.janitor_model[plugin_iter][self.JANITOR_DISPLAY]
remain = len(cruft_dict) - count
if remain:
self.janitor_model[plugin_iter][self.JANITOR_DISPLAY] = "<b>[%d] %s</b>" % (remain, plugin.get_title())
else:
self.janitor_model[plugin_iter][self.JANITOR_DISPLAY] = "[0] %s" % plugin.get_title()
def hide_progress(self):
"""Hides the progress bar"""
self.widgets.get_object('progress_dialog').hide()
while Gtk.events_pending():
Gtk.main_iteration()
def toggle_spinner_popup(self, force):
wizard = self.widgets.get_object('wizard')
popup = self.widgets.get_object('spinner_popup')
if force:
wizard.set_sensitive(False)
self.spinner.start()
popup.show()
else:
self.spinner.stop()
popup.hide()
wizard.set_sensitive(True)
while Gtk.events_pending():
Gtk.main_iteration()
def on_learn_from_file_clicked(self, dummy_widget):
'''
The button to learn from a user supplied text file
has been clicked.
'''
SETUP_UI.learn_from_file_button.set_sensitive(False)
filename = u''
chooser = Gtk.FileChooserDialog(
_('Open File ...'), SETUP_UI.builder.get_object('main_dialog'),
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
response = chooser.run()
if response == Gtk.ResponseType.OK:
filename = chooser.get_filename()
chooser.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if filename and os.path.isfile(filename):
if SETUP_UI.tabsqlitedb.read_training_data_from_file(filename):
dialog = Gtk.MessageDialog(
parent=SETUP_UI.builder.get_object('main_dialog'),
flags=Gtk.DialogFlags.MODAL,
message_type=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
message_format=(
_("Learned successfully from file %(filename)s.")
%{'filename': filename}))
else:
dialog = Gtk.MessageDialog(
parent=SETUP_UI.builder.get_object('main_dialog'),
flags=Gtk.DialogFlags.MODAL,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.OK,
message_format=(
_("Learning from file %(filename)s failed.")
%{'filename': filename}))
dialog.run()
dialog.destroy()
SETUP_UI.learn_from_file_button.set_sensitive(True)
def info(self, first, second):
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,\
Gtk.ButtonsType.NONE, None, title=first)
self.fix_dialog(dialog, second)
dialog.show_now()
while Gtk.events_pending(): Gtk.main_iteration()
return dialog
def replace_xml_files(xmls_with_path, words, progress_bar=None, status_bar=None, meanings=None):
global current_progress_in_percent
xml_file_count = len(xmls_with_path)
files_processed = 0
for xml in xmls_with_path:
# content = open(xml).read()
# print("Processing: " + xml)
xml_file_contents = read_contents(xml)
# print(xml_file_contents)
for i in range(0, len(words)):
word = words[i]
# print(word)
if meanings:
meaning = meanings[i]
xml_file_contents = highlight_content(
xml_file_contents, word, meaning)
else:
xml_file_contents = highlight_content(
xml_file_contents, word)
# print(xml_file_contents)
write_content(xml, xml_file_contents)
files_processed = files_processed + 1
current_progress_in_percent = (files_processed / xml_file_count)
msg = "processing " + os.path.basename(xml)
if status_bar and progress_bar:
status_bar.push(1, msg)
progress_bar.set_fraction(current_progress_in_percent)
while Gtk.events_pending():
Gtk.main_iteration()
# do_something_with_progress(current_progress_in_percent)
def cb_button_trilogy(self, button):
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
os.system('cd "' + current_dir + '/game" && ' + \
'xterm -fg green -bg black -fn 10x20 -e ./trilogy.sh')
self.main_window.show()