python类idle_add()的实例源码

uci.py 文件源码 项目:jcchess 作者: johncheetham 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def read_stdout(self): 
        while True:
            try:
                e = ("<-" + self.side + "(" +
                     self.get_running_engine().strip() + "):")
                line= ""
                # python2 line = unicode(self.p.stdout.readline(), errors ='ignore')
                    # or: 'your iso 8859-15 text'.decode('iso8859-15')
                # python3 (doesn't work) lineb = self.p.stdout.readline().encode("utf-8", "ignore")
                #print(lineb)
                #line = str(lineb)
                #print(line, "line")
                line = self.p.stdout.readline()

                if line == "":
                    if gv.verbose:
                        print(e + "eof reached")
                    if gv.verbose:
                        print(e + "stderr:", self.p.stderr.read())
                    break
                #line = line[2:-3]
                #print(line)
                line = line.strip()

                if gv.verbose or gv.verbose_uci:
                    print(e + line)
                GObject.idle_add(self.engine_debug.add_to_log, e+line)
                if line.startswith("info"):
                    GObject.idle_add(
                        self.engine_output.add_to_log, self.side,
                        self.get_running_engine().strip(), line)
                self.op.append(line)
            except Exception as e:
                # line = e + "error"
                print("subprocess error in uci.py read_stdout:", e, "at:", line)
board.py 文件源码 项目:jcchess 作者: johncheetham 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def build_board(self):
        GObject.idle_add(self.update)

    # convert jcchess co-ordinates for square into
    # standard notation (e.g.  (1, 0) -> b1)
board.py 文件源码 项目:jcchess 作者: johncheetham 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def set_square_as_unoccupied(self, x, y):
        self.dnd = (x, y)
        # redraw square
        GLib.idle_add(gv.gui.get_event_box(x, y).queue_draw)

    # called from gui.py when editing the board position to set the piece
    # on a square.
board.py 文件源码 项目:jcchess 作者: johncheetham 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def set_piece_at_square(self, x, y, piece, colour):
        self.chessboard.set_piece_at(chess.square(x, y), chess.Piece(piece, colour))       
        GLib.idle_add(gv.gui.get_event_box(x, y).queue_draw)

    # called from gui.py to remove piece during promotion dialog
board.py 文件源码 项目:jcchess 作者: johncheetham 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def remove_piece_at_square(self, x, y):
        piece=self.chessboard.remove_piece_at(chess.square(x, y))       
        GLib.idle_add(gv.gui.get_event_box(x, y).queue_draw)
        return piece

    # called when user does a "clear board" in board edit
IdleObject.py 文件源码 项目:sbrick-controller 作者: wintersandroid 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def emit(self, *args):
        GObject.idle_add(GObject.GObject.emit, self, *args)
gtk_ui.py 文件源码 项目:python-gui 作者: neovim 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def quit(self):
        """Exit the UI event loop."""
        GObject.idle_add(Gtk.main_quit)
gtk_ui.py 文件源码 项目:python-gui 作者: neovim 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
logic.py 文件源码 项目:btcwidget 作者: rafalh 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _fetch_market_ticker(self, market_id):

        market_config, _ = config.get_market_by_id(market_id)
        exchange, market = market_config['exchange'], market_config['market']
        provider = btcwidget.exchanges.factory.get(exchange)
        try:
            price = provider.ticker(market)
        except Exception as e:
            print('Failed to update ticker data for {}: {}'.format(market_id, e), file=sys.stderr)
            price = None

        if price:
            price_str = btcwidget.currency.service.format_price(price, market[3:])
            print('{} {} ticker: {}'.format(provider.get_name(), market, price_str))
            GObject.idle_add(self._main_win.set_current_price, market_id, price_str)

            self._check_alarms(exchange, market, price)

            self._last_ticer[market_id] = {
                'time': time.time(),
                'open': price,
                'close': price,
            }
            if market_id in self._graph_data_dict:
                graph_data = self._graph_data_dict[market_id]
                graph_data.append(self._last_ticer[market_id])
                self._update_market_graph(market_id)

        self._ticker_threads.pop(market_id, None)
logic.py 文件源码 项目:btcwidget 作者: rafalh 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _update_market_graph(self, market_id):
        now = time.time()
        graph_data = self._graph_data_dict[market_id]
        graph_data = [t for t in graph_data if t['time'] > now - config['graph_period_sec']]
        GObject.idle_add(self._main_win.set_graph_data, market_id, graph_data)
logic.py 文件源码 项目:btcwidget 作者: rafalh 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _trigger_alarm(self, alarm, price):
        if alarm['type'] == 'A':
            GObject.idle_add(btcwidget.alarmmessage.alarm_above_message, alarm, price)
        else:
            GObject.idle_add(btcwidget.alarmmessage.alarm_below_message, alarm, price)
        config['alarms'].remove(alarm)
        config.save()
budgie-keyboard-autoswitch.py 文件源码 项目:budgie-extras 作者: UbuntuBudgie 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def watch_yourlanguage(self):
        # fill exceptions (gui) list with data
        self.update_exceptions_gui()
        # fetch set initial data
        wmclass1 = self.get_activeclass()
        activelang1 = self.get_currlangname()
        while True:
            time.sleep(1)
            # if language is changed during lockstate, revert afterwards
            if self.lockscreen_check():
                self.lock_state(activelang1)
            wmclass2 = self.get_activeclass()
            activelang2 = self.get_currlangname()
            # first set a few conditions to act *at all*
            if all(
                [wmclass2, wmclass2 != "raven",
                 wmclass2 != "Wprviews_window",
                 activelang2]):
                classchange = wmclass2 != wmclass1
                langchange = activelang2 != activelang1
                if classchange:
                    self.set_lang_onclasschange(wmclass2, activelang2)
                    activelang2 = self.get_currlangname()
                elif langchange:
                    self.set_exception(activelang2, wmclass2)
                    GObject.idle_add(
                        self.update_exceptions_gui,
                        priority=GObject.PRIORITY_DEFAULT,
                    )
                    open(lang_datafile, "wt").write(str(self.langdata))
                wmclass1 = wmclass2
                activelang1 = activelang2
budgie-countdown.py 文件源码 项目:budgie-extras 作者: UbuntuBudgie 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def set_label(self, newlabel):
        GObject.idle_add(
            self.timer.set_text, newlabel,
            priority=GObject.PRIORITY_DEFAULT
        )
budgie-countdown.py 文件源码 项目:budgie-extras 作者: UbuntuBudgie 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def set_newicon(self, newicon):
        GObject.idle_add(
            self.seticon.set_from_pixbuf, newicon,
            priority=GObject.PRIORITY_DEFAULT
        )
budgie-countdown.py 文件源码 项目:budgie-extras 作者: UbuntuBudgie 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def set_state(self, state, *args):
        for widget in [
            self.hoursbutton, self.minsbutton, self.secsbutton,
            self.sleep, self.nf_bell, self.runcomm,
            self.nf_icon, self.nf_message, self.command_entry,
            self.hrs_label, self.secs_label, self.mins_label,
        ]:
            widget.set_sensitive(state)
        if state is True:
            self.context_start.remove_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION)
            self.context_start.add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
            self.applybutton.set_label("Run")
            GObject.idle_add(
                self.panelgrid.remove, self.timer,
                priority=GObject.PRIORITY_DEFAULT,
            )
            GObject.idle_add(
                self.panelgrid.set_row_spacing, 10,
                priority=GObject.PRIORITY_DEFAULT,
            )
        else:
            self.applybutton.set_label("Stop")
            self.context_start.remove_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
            self.context_start.add_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION)
            GObject.idle_add(
                self.panelgrid.attach, self.timer, 1, 1, 1, 1,
                priority=GObject.PRIORITY_DEFAULT,
            )
            GObject.idle_add(
                self.panelgrid.set_row_spacing, 6,
                priority=GObject.PRIORITY_DEFAULT,
            )
        active = self.runcomm.get_active()
        active = False if not all([active, state]) else True
        GObject.idle_add(
            self.command_entry.set_sensitive, active,
            priority=GObject.PRIORITY_DEFAULT,
        )
widgets.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def on_mcg_error(self, error):
        GObject.idle_add(self._show_error, str(error))


    # Settings callbacks
widgets.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, builder):
        GObject.GObject.__init__(self)

        self._current_album = None
        self._cover_pixbuf = None
        self._timer = None
        self._properties = {}
        self._tracklist_size = TracklistSize.LARGE
        self._icon_theme = Gtk.IconTheme.get_default()

        # Widgets
        self._appwindow = builder.get_object('appwindow')
        self._panel = builder.get_object('cover-panel')
        self._toolbar = builder.get_object('cover-toolbar')
        # Toolbar menu
        self._toolbar_tracklist = builder.get_object('cover-toolbar-tracklist')
        self._toolbar_tracklist_buttons = {
            TracklistSize.LARGE: builder.get_object('cover-toolbar-tracklist-large'),
            TracklistSize.SMALL: builder.get_object('cover-toolbar-tracklist-small'),
            TracklistSize.HIDDEN: builder.get_object('cover-toolbar-tracklist-hidden')
        }
        # Cover
        self._cover_stack = builder.get_object('cover-stack')
        self._cover_spinner = builder.get_object('cover-spinner')
        self._cover_scroll = builder.get_object('cover-scroll')
        self._cover_box = builder.get_object('cover-box')
        self._cover_image = builder.get_object('cover-image')
        self._cover_stack.set_visible_child(self._cover_scroll)
        self._cover_pixbuf = self._get_default_image()
        # Album Infos
        self._info_revealer = builder.get_object('cover-info-revealer')
        self._info_box = builder.get_object('cover-info-box')
        self._album_title_label = builder.get_object('cover-album')
        self._album_date_label = builder.get_object('cover-date')
        self._album_artist_label = builder.get_object('cover-artist')
        # Songs
        self._songs_scale = builder.get_object('cover-songs')
        self._songs_scale.override_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 1))

        # Initial actions
        GObject.idle_add(self._enable_tracklist)
widgets.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def on_cover_size_allocate(self, widget, allocation):
        GObject.idle_add(self._resize_image)
widgets.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def on_grid_scale_change(self, widget, scroll, value):
        size = round(value)
        range =  self._grid_scale.get_adjustment()
        if size < range.get_lower() or size > range.get_upper():
            return
        self._item_size = size
        GObject.idle_add(self._set_widget_grid_size, self._library_grid, size, True)
        GObject.idle_add(self._library_grid.set_item_padding, size / 100)
widgets.py 文件源码 项目:mcg 作者: coderkun 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def on_filter_entry_changed(self, widget):
        self._filter_string = self._filter_entry.get_text()
        GObject.idle_add(self._library_grid_filter.refilter)


问题


面经


文章

微信
公众号

扫码关注公众号