本文整理汇总了Python中gi.repository.GObject.idle_add方法的典型用法代码示例。如果您正苦于以下问题:Python GObject.idle_add方法的具体用法?Python GObject.idle_add怎么用?Python GObject.idle_add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.GObject
的用法示例。
在下文中一共展示了GObject.idle_add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populate
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def populate(self):
def _end_populate():
self.unset_loading()
@queue_cb(callback=_end_populate, gtk=True)
def _do_populate(devices):
if not devices:
logger.info("No devices")
GObject.idle_add(self.set_no_devices_nearby)
for idx, device in enumerate(devices):
logger.info("Adding device {}".format(device))
GObject.idle_add(self.add_device, device, idx)
if not is_bluetooth_available():
logger.info("No adapter")
self.set_no_adapter_available()
return
self.set_loading()
device_scan(_do_populate)
示例2: restore_wallet
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def restore_wallet(self, wallet):
dialog = Gtk.MessageDialog(
parent = None,
flags = Gtk.DialogFlags.MODAL,
buttons = Gtk.ButtonsType.CANCEL,
message_format = "Please wait..." )
dialog.show()
def recover_thread( wallet, dialog ):
wallet.restore(lambda x:x)
GObject.idle_add( dialog.destroy )
thread.start_new_thread( recover_thread, ( wallet, dialog ) )
r = dialog.run()
dialog.destroy()
if r==Gtk.ResponseType.CANCEL: return False
if not wallet.is_found():
show_message("No transactions found for this seed")
return True
示例3: wait_for_click
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def wait_for_click(self, callback, game_location=None):
# wait for click
tools.wait_for_mouse_event('left_down')
# get mouse position & screen size
x, y = tools.get_mouse_position()
width, height = tools.get_screen_size()
# get pixel color
color = tools.get_pixel_color(x, y)
# adjust location to game window
if game_location is not None:
# get game area location
game_x, game_y, game_width, game_height = game_location
#print('x: %d, y: %d, game_x: %d, game_y: %d, game_width: %d, game_height: %d' % (x, y, game_x, game_y, game_width, game_height))
# scale to game area
if tools.position_is_inside_bounds(x, y, game_x, game_y, game_width, game_height):
# position is inside game area, so we fit x & y to it
x = x - game_x
y = y - game_y
width = game_width
height = game_height
# execute callback
GObject.idle_add(callback, (x, y, width, height, color))
示例4: contract_submenu
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def contract_submenu(self, match_item):
match_item['gtk_check'].set_active(False)
match_item['gtk_description'].hide()
match_item['gtk_separator_2'].hide()
match_item['gtk_scorecard'].hide()
match_item['gtk_separator_3'].hide()
match_item['gtk_commentary'].hide()
match_item['gtk_separator_4'].hide()
match_item['last_ball'] = DEFAULT_ICON # set to default
match_item['status'] = ""
match_item['label_scoreline'] = ""
# force update in current cycle
self.update_menu_icon(match_item)
#GObject.idle_add(match_item['gtk_menu'].set_image,Gtk.Image.new_from_icon_name(ICON_PREFIX + match_item['last_ball'], Gtk.IconSize.BUTTON))
if match_item['id'] == self.label_match_id:
self.set_indicator_icon(match_item['last_ball'])
self.set_indicator_label(match_item['gtk_menu'].get_label())
示例5: _do_accept
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def _do_accept(listener, handler, *a):
try:
conn = listener.accept()
args = conn.recv()
logger.debug('Recieved remote call: %r', args)
if args == 'CLOSE':
conn.send('OK')
conn.close()
return False
else:
assert isinstance(args, (list, tuple))
# Throw back into the main thread -- assuming gtk main running
def callback():
handler(*args)
return False # delete signal
GObject.idle_add(callback)
conn.send('OK')
conn.close()
except:
logger.exception('Error while handling incoming connection')
return True
示例6: _check_new_version
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def _check_new_version(journal, current_version, startup):
current_version = StrictVersion(current_version)
new_version = get_new_version_number()
if new_version is not None:
newer_version_available = new_version > current_version
else:
logging.error("New version info could not be read")
new_version = _("unknown")
newer_version_available = None
logging.info(
"Current version: %s, latest version: %s, newer: %s"
% (current_version, new_version, newer_version_available)
)
if newer_version_available or not startup:
GObject.idle_add(
_show_update_dialog, journal, current_version, new_version, startup
)
示例7: on_action_apply_activate
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def on_action_apply_activate(self, widget):
""" Handler for when the "Apply Theme" action is triggered."""
self.builder.get_object("toolbar").set_sensitive(False)
statusbar = self.builder.get_object("statusbar")
self.context_id = statusbar.get_context_id("Apply")
statusbar.push(self.context_id, "Applying theme...")
spinner = self.builder.get_object("spinner")
spinner.show()
spinner.start()
self.set_theme_done = False
GObject.idle_add(self.set_theme_done_cb)
self.set_theme_thread = threading.Thread(target=self.set_theme)
self.set_theme_thread.start()
示例8: queue_cb
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def queue_cb(callback, callback_args=None, callback_kwargs=None, gtk=False):
'''
Run the supplied callback after the function completes
@param callback Function to run upon completion
@param callback_args Arguments to send to the callback
@param callback_kwargs Keyword arguments to send to the callback
@param gtk Should the callback be run for Gtk
'''
callback_args = callback_args or []
callback_kwargs = callback_kwargs or {}
if gtk:
from gi.repository import GObject
callback_args.insert(0, callback)
callback = GObject.idle_add
def cb_decorator(func):
@wraps(func)
def run_cb(*args, **kwargs):
func(*args, **kwargs)
return callback(*callback_args, **callback_kwargs)
return run_cb
return cb_decorator
示例9: quit
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def quit(self):
"""Exit the UI event loop."""
GObject.idle_add(Gtk.main_quit)
示例10: schedule_screen_update
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def schedule_screen_update(self, apply_updates):
"""Schedule screen updates to run in the UI event loop."""
def wrapper():
apply_updates()
self._flush()
self._start_blinking()
self._screen_invalid()
GObject.idle_add(wrapper)
示例11: __init__
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def __init__(self, figure):
if _debug: print 'FigureCanvasGTK3.%s' % fn_name()
FigureCanvasBase.__init__(self, figure)
GObject.GObject.__init__(self)
self._idle_draw_id = 0
self._need_redraw = True
self._lastCursor = None
self.connect('scroll_event', self.scroll_event)
self.connect('button_press_event', self.button_press_event)
self.connect('button_release_event', self.button_release_event)
self.connect('configure_event', self.configure_event)
self.connect('draw', self.on_draw_event)
self.connect('key_press_event', self.key_press_event)
self.connect('key_release_event', self.key_release_event)
self.connect('motion_notify_event', self.motion_notify_event)
self.connect('leave_notify_event', self.leave_notify_event)
self.connect('enter_notify_event', self.enter_notify_event)
self.set_events(self.__class__.event_mask)
self.set_double_buffered(True)
self.set_can_focus(True)
self._renderer_init()
self._idle_event_id = GObject.idle_add(self.idle_event)
示例12: draw_idle
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def draw_idle(self):
def idle_draw(*args):
self.draw()
self._idle_draw_id = 0
return False
if self._idle_draw_id == 0:
self._idle_draw_id = GObject.idle_add(idle_draw)
示例13: _scan_networks
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def _scan_networks(self):
# Perform a network re-scan
network_list = IWList(self._win.wiface).getList(unsecure=False, first=False)
GObject.idle_add(self._go_to_network_screen, network_list)
示例14: _threaded_disconnect
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def _threaded_disconnect(self):
'''
This is needed so we can show a spinner while the user is
disconnecting
'''
disconnect(self._wiface)
def done():
self._disconnect_screen()
self._win.get_window().set_cursor(None)
self._connect_btn.stop_spinner()
self._connect_btn.set_sensitive(True)
GObject.idle_add(done)
示例15: _connect_thread_
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import idle_add [as 别名]
def _connect_thread_(wiface, network_name, passphrase, encryption,
thread_finish_cb):
'''
This function runs in a thread so we can run a spinner alongside.
:param wiface: wifi card id
:param network_name: network id
:param passphrase: password entered by user
:param encryption: type of encryption
:param disable_widget_cb: the callback for any widgets that need to be
disabled
:param thread_finish_cb: the callback to be run when the thread is finished
'''
rc = connect(wiface, network_name, encryption, passphrase)
# save the connection in cache so it reconnects on next system boot
wificache = KwifiCache()
if not rc:
wificache.save(network_name, encryption, passphrase)
else:
wificache.empty()
logger.debug(
"Connecting to {} {} {}. Return code: {}".format(
network_name, encryption, passphrase, rc
)
)
GObject.idle_add(thread_finish_cb, rc)