Python gobject.idle_add() Examples

The following are 30 code examples of gobject.idle_add(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gobject , or try the search function .
Example #1
Source File: paned.py    From NINJA-PingU with GNU General Public License v3.0 6 votes vote down vote up
def do_redistribute(self, recurse_up=False, recurse_down=False):
        """Evenly divide available space between sibling panes"""
        #1 Find highest ancestor of the same type => ha
        highest_ancestor = self
        while type(highest_ancestor.get_parent()) == type(highest_ancestor):
            highest_ancestor = highest_ancestor.get_parent()
        
        # (1b) If Super modifier, redistribute higher sections too
        if recurse_up:
            grandfather=highest_ancestor.get_parent()
            if grandfather != self.get_toplevel():
                grandfather.do_redistribute(recurse_up, recurse_down)
        
        gobject.idle_add(highest_ancestor._do_redistribute, recurse_up, recurse_down)
        while gtk.events_pending():
            gtk.main_iteration_do(False)
        gobject.idle_add(highest_ancestor._do_redistribute, recurse_up, recurse_down) 
Example #2
Source File: gtkbase.py    From gui-o-matic with GNU Lesser General Public License v3.0 6 votes vote down vote up
def run(self):
        self._font_setup()
        self._menu_setup()
        if self.config.get('indicator') and self._HAVE_INDICATOR:
            self._indicator_setup()
        if self.config.get('main_window'):
            self._main_window_setup()

        def ready(s):
            s.ready = True
        gobject.idle_add(ready, self)

        try:
            gtk.main()
        except:
            traceback.print_exc() 
Example #3
Source File: gtkbase.py    From gui-o-matic with GNU Lesser General Public License v3.0 6 votes vote down vote up
def set_status(self, status=None, badge=None, _now=False):
        # FIXME: Can we support badges?
        if status is None:
            return

        if _now:
            do = lambda o, a: o(a)
        else:
            do = gobject.idle_add
        images = self.config.get('images')
        if images:
            icon = images.get(status)
            if not icon:
                icon = images.get('normal')
            if icon:
                self._indicator_set_icon(icon, do=do)
        self._indicator_set_status(status, do=do) 
Example #4
Source File: main.py    From nightmare with GNU General Public License v2.0 6 votes vote down vote up
def idlethread(func):
    '''
    A decorator which causes the function to be called by the gtk
    main iteration loop rather than synchronously...

    NOTE: This makes the call async handled by the gtk main
    loop code.  you can NOT return anything.
    '''
    def dowork(arginfo):
        args,kwargs = arginfo
        return func(*args, **kwargs)

    def idleadd(*args, **kwargs):
        if currentThread().getName() == 'GtkThread':
            return func(*args, **kwargs)
        gtk.gdk.threads_enter()
        gobject.idle_add(dowork, (args,kwargs))
        gtk.gdk.threads_leave()

    return idleadd 
Example #5
Source File: render.py    From tree with MIT License 6 votes vote down vote up
def __init__(self, n, front, back, trunk, trunk_stroke, grains,
               steps_itt, step):

    Render.__init__(self, n, front, back, trunk, trunk_stroke, grains)

    window = gtk.Window()
    window.resize(self.n, self.n)

    self.steps_itt = steps_itt
    self.step = step

    window.connect("destroy", self.__destroy)
    darea = gtk.DrawingArea()
    darea.connect("expose-event", self.expose)
    window.add(darea)
    window.show_all()

    self.darea = darea

    self.steps = 0
    gobject.idle_add(self.step_wrap) 
Example #6
Source File: ipython_view.py    From ns3-ecn-sharp with GNU General Public License v2.0 5 votes vote down vote up
def showPrompt(self, prompt):
    gobject.idle_add(self._showPrompt, prompt) 
Example #7
Source File: GTKstrip.py    From rpi_wordclock with GNU General Public License v3.0 5 votes vote down vote up
def show(self):
        gobject.idle_add(self.update) 
Example #8
Source File: ipython_view.py    From ns3-ecn-sharp with GNU General Public License v2.0 5 votes vote down vote up
def changeLine(self, text):
    gobject.idle_add(self._changeLine, text) 
Example #9
Source File: glcanon.py    From hazzy with GNU General Public License v2.0 5 votes vote down vote up
def load_preview(self, f, canon, *args):
        self.set_canon(canon)
        result, seq = gcode.parse(f, canon, *args)

        self.label.set_text("Generating Preview. Please wait ...")
        gobject.idle_add(self.loading_finished, self, result, seq)

        if result <= gcode.MIN_ERROR:
            self.canon.progress.nextphase(1)
            canon.calc_extents()
            self.stale_dlist('program_rapids')
            self.stale_dlist('program_norapids')
            self.stale_dlist('select_rapids')
            self.stale_dlist('select_norapids') 
Example #10
Source File: core.py    From ns3-802.11ad with GNU General Public License v2.0 5 votes vote down vote up
def run(self):
        """!
        Initializer function.

        @param self: class object.
        @return none
        """
        while not self.quit:
            #print "sim: Wait for go"
            self.go.wait() # wait until the main (view) thread gives us the go signal
            self.go.clear()
            if self.quit:
                break
            #self.go.clear()
            #print "sim: Acquire lock"
            self.lock.acquire()
            try:
                if 0:
                    if ns3.core.Simulator.IsFinished():
                        self.viz.play_button.set_sensitive(False)
                        break
                #print "sim: Current time is %f; Run until: %f" % (ns3.Simulator.Now ().GetSeconds (), self.target_time)
                #if ns3.Simulator.Now ().GetSeconds () > self.target_time:
                #    print "skipping, model is ahead of view!"
                self.sim_helper.SimulatorRunUntil(ns.core.Seconds(self.target_time))
                #print "sim: Run until ended at current time: ", ns3.Simulator.Now ().GetSeconds ()
                self.pause_messages.extend(self.sim_helper.GetPauseMessages())
                gobject.idle_add(self.viz.update_model, priority=PRIORITY_UPDATE_MODEL)
                #print "sim: Run until: ", self.target_time, ": finished."
            finally:
                self.lock.release()
            #print "sim: Release lock, loop."

## ShowTransmissionsMode 
Example #11
Source File: gtkbase.py    From gui-o-matic with GNU Lesser General Public License v3.0 5 votes vote down vote up
def show_main_window(self):
        def show(self):
            if self.main_window:
                self.main_window['window'].show_all()
        gobject.idle_add(show, self) 
Example #12
Source File: unity.py    From gui-o-matic with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _indicator_set_icon(self, icon, do=gobject.idle_add):
        do(self.ind.set_icon, self._theme_image(icon)) 
Example #13
Source File: unity.py    From gui-o-matic with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _indicator_set_status(self, status, do=gobject.idle_add):
        do(self.ind.set_status,
           self._STATUS_MODES.get(status, appindicator.STATUS_ATTENTION)) 
Example #14
Source File: gtkbase.py    From gui-o-matic with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _main_window_setup(self, _now=False):
        def create(self):
            wcfg = self.config['main_window']

            window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            self.main_window = {'window': window}

            if wcfg.get('style', 'default') == 'default':
                self._main_window_default_style()
            else:
                raise NotImplementedError('We only have one style atm.')

            if wcfg.get('close_quits'):
                window.connect('delete-event', lambda w, e: gtk.main_quit())
            else:
                window.connect('delete-event', lambda w, e: w.hide() or True)
            window.connect("destroy", lambda wid: gtk.main_quit())

            window.set_title(self.config.get('app_name', 'gui-o-matic'))
            window.set_decorated(True)
            if wcfg.get('center', False):
                window.set_position(gtk.WIN_POS_CENTER)
            window.set_size_request(
                wcfg.get('width', 360), wcfg.get('height',360))
            if wcfg.get('show'):
                window.show_all()

        if _now:
            create(self)
        else:
            gobject.idle_add(create, self) 
Example #15
Source File: gtkbase.py    From gui-o-matic with GNU Lesser General Public License v3.0 5 votes vote down vote up
def quit(self):
        def q(self):
            gtk.main_quit()
        gobject.idle_add(q, self) 
Example #16
Source File: gtkbase.py    From gui-o-matic with GNU Lesser General Public License v3.0 5 votes vote down vote up
def hide_splash_screen(self, _now=False):
        wait_lock = threading.Lock()
        def hide(self):
            for k in self.splash or []:
                if hasattr(self.splash[k], 'destroy'):
                    self.splash[k].destroy()
            self.splash = None
            wait_lock.release()
        with wait_lock:
            if _now:
                hide(self)
            else:
                gobject.idle_add(hide, self)
            wait_lock.acquire() 
Example #17
Source File: window.py    From NINJA-PingU with GNU General Public License v3.0 5 votes vote down vote up
def deferred_set_rough_geometry_hints(self):
        # no parameters are used in set_rough_geometry_hints, so we can
        # use the set_rough_geometry_hints
        if self.pending_set_rough_geometry_hint == True:
            return
        self.pending_set_rough_geometry_hint = True
        gobject.idle_add(self.do_deferred_set_rough_geometry_hints) 
Example #18
Source File: core.py    From ns-3-dev-git with GNU General Public License v2.0 5 votes vote down vote up
def start():
    assert Visualizer.INSTANCE is None
    if _import_error is not None:
        import sys
        print >> sys.stderr, "No visualization support (%s)." % (str(_import_error),)
        ns.core.Simulator.Run()
        return
    load_plugins()
    viz = Visualizer()
    for hook, args in initialization_hooks:
        gobject.idle_add(hook, viz, *args)
    ns.network.Packet.EnablePrinting()
    viz.start() 
Example #19
Source File: ipython_view.py    From ns3-ecn-sharp with GNU General Public License v2.0 5 votes vote down vote up
def write(self, text, editable=False):
    gobject.idle_add(self._write, text, editable) 
Example #20
Source File: core.py    From ns3-ecn-sharp with GNU General Public License v2.0 5 votes vote down vote up
def start():
    assert Visualizer.INSTANCE is None
    if _import_error is not None:
        import sys
        print >> sys.stderr, "No visualization support (%s)." % (str(_import_error),)
        ns.core.Simulator.Run()
        return
    load_plugins()
    viz = Visualizer()
    for hook, args in initialization_hooks:
        gobject.idle_add(hook, viz, *args)
    ns.network.Packet.EnablePrinting()
    viz.start() 
Example #21
Source File: core.py    From ns3-ecn-sharp with GNU General Public License v2.0 5 votes vote down vote up
def run(self):
        while not self.quit:
            #print "sim: Wait for go"
            self.go.wait() # wait until the main (view) thread gives us the go signal
            self.go.clear()
            if self.quit:
                break
            #self.go.clear()
            #print "sim: Acquire lock"
            self.lock.acquire()
            try:
                if 0:
                    if ns3.core.Simulator.IsFinished():
                        self.viz.play_button.set_sensitive(False)
                        break
                #print "sim: Current time is %f; Run until: %f" % (ns3.Simulator.Now ().GetSeconds (), self.target_time)
                #if ns3.Simulator.Now ().GetSeconds () > self.target_time:
                #    print "skipping, model is ahead of view!"
                self.sim_helper.SimulatorRunUntil(ns.core.Seconds(self.target_time))
                #print "sim: Run until ended at current time: ", ns3.Simulator.Now ().GetSeconds ()
                self.pause_messages.extend(self.sim_helper.GetPauseMessages())
                gobject.idle_add(self.viz.update_model, priority=PRIORITY_UPDATE_MODEL)
                #print "sim: Run until: ", self.target_time, ": finished."
            finally:
                self.lock.release()
            #print "sim: Release lock, loop."

# enumeration 
Example #22
Source File: core.py    From CRE-NS3 with GNU General Public License v2.0 5 votes vote down vote up
def start():
    assert Visualizer.INSTANCE is None
    if _import_error is not None:
        import sys
        print >> sys.stderr, "No visualization support (%s)." % (str(_import_error),)
        ns.core.Simulator.Run()
        return
    load_plugins()
    viz = Visualizer()
    for hook, args in initialization_hooks:
        gobject.idle_add(hook, viz, *args)
    ns.network.Packet.EnablePrinting()
    viz.start() 
Example #23
Source File: core.py    From CRE-NS3 with GNU General Public License v2.0 5 votes vote down vote up
def run(self):
        while not self.quit:
            #print "sim: Wait for go"
            self.go.wait() # wait until the main (view) thread gives us the go signal
            self.go.clear()
            if self.quit:
                break
            #self.go.clear()
            #print "sim: Acquire lock"
            self.lock.acquire()
            try:
                if 0:
                    if ns3.core.Simulator.IsFinished():
                        self.viz.play_button.set_sensitive(False)
                        break
                #print "sim: Current time is %f; Run until: %f" % (ns3.Simulator.Now ().GetSeconds (), self.target_time)
                #if ns3.Simulator.Now ().GetSeconds () > self.target_time:
                #    print "skipping, model is ahead of view!"
                self.sim_helper.SimulatorRunUntil(ns.core.Seconds(self.target_time))
                #print "sim: Run until ended at current time: ", ns3.Simulator.Now ().GetSeconds ()
                self.pause_messages.extend(self.sim_helper.GetPauseMessages())
                gobject.idle_add(self.viz.update_model, priority=PRIORITY_UPDATE_MODEL)
                #print "sim: Run until: ", self.target_time, ": finished."
            finally:
                self.lock.release()
            #print "sim: Release lock, loop."

# enumeration 
Example #24
Source File: oxcSERVER_menuitem.py    From openxenmanager with GNU General Public License v2.0 5 votes vote down vote up
def repair_storage(self, list, ref):
        error = False
        for pbd_ref in self.all['SR'][ref]['PBDs']:
            value = self.connection.Async.PBD.plug(
                self.session_uuid, pbd_ref)["Value"]
            task = self.connection.task.get_record(
                self.session_uuid, value)['Value']
            while task["status"] == "pending":
                task = self.connection.task.get_record(
                    self.session_uuid, value)['Value']

            if len(task["error_info"]):
                print task["error_info"]
                error = True
                gobject.idle_add(lambda: self.wine.builder.get_object(
                    "lblrepairerror").set_markup("<span foreground='red'><b>"
                                                 "Host could not be contacted"
                                                 "</b></span>") and False)
            for i in range(0, list.__len__()):
                if list.get_value(list.get_iter((i,)), 0) == pbd_ref:
                    if error:
                        gobject.idle_add(lambda: list.set_value(list.get_iter((i,)), 3, "<span foreground='red'><b>Unplugged</b></span>") and False)
                    else:
                        gobject.idle_add(lambda: list.set_value(list.get_iter((i,)), 3, "<span foreground='green'><b>Connected</b></span>") and False)
        if not error:
            gobject.idle_add(lambda: self.wine.builder.get_object("lblrepairerror").set_markup("<span foreground='green'><b>All repaired.</b></span>") and False)
        gobject.idle_add(lambda: self.wine.builder.get_object("acceptrepairstorage").set_sensitive(True) and False)
        gobject.idle_add(lambda: self.wine.builder.get_object("cancelrepairstorage").set_label("Close") and False) 
Example #25
Source File: backend_gtk.py    From ImageFusion with MIT License 5 votes vote down vote up
def draw_idle(self):
        def idle_draw(*args):
            try:
                self.draw()
            finally:
                self._idle_draw_id = 0
            return False
        if self._idle_draw_id == 0:
            self._idle_draw_id = gobject.idle_add(idle_draw) 
Example #26
Source File: backend_gtk.py    From ImageFusion with MIT License 5 votes vote down vote up
def __init__(self, figure):
        if _debug: print('FigureCanvasGTK.%s' % fn_name())
        FigureCanvasBase.__init__(self, figure)
        gtk.DrawingArea.__init__(self)

        self._idle_draw_id  = 0
        self._need_redraw   = True
        self._pixmap_width  = -1
        self._pixmap_height = -1
        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('expose_event',         self.expose_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(False)
        self.set_flags(gtk.CAN_FOCUS)
        self._renderer_init()

        self._idle_event_id = gobject.idle_add(self.idle_event)

        self.last_downclick = {} 
Example #27
Source File: ipython_view.py    From ns-3-dev-git with GNU General Public License v2.0 5 votes vote down vote up
def changeLine(self, text):
    gobject.idle_add(self._changeLine, text) 
Example #28
Source File: ipython_view.py    From ns-3-dev-git with GNU General Public License v2.0 5 votes vote down vote up
def showPrompt(self, prompt):
    gobject.idle_add(self._showPrompt, prompt) 
Example #29
Source File: ipython_view.py    From ns-3-dev-git with GNU General Public License v2.0 5 votes vote down vote up
def write(self, text, editable=False):
    gobject.idle_add(self._write, text, editable) 
Example #30
Source File: backend_gtk.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def draw_idle(self):
        if self._idle_draw_id != 0:
            return
        def idle_draw(*args):
            try:
                self.draw()
            finally:
                self._idle_draw_id = 0
            return False
        self._idle_draw_id = gobject.idle_add(idle_draw)