def test_copy_named_item(self): service = CopyService() service.init(Application) ef = self.element_factory diagram = ef.create(uml2.Diagram) c = diagram.create(items.ClassItem, subject=ef.create(uml2.Class)) c.subject.name = 'Name' import gobject self.assertEquals(0, gobject.main_depth()) diagram.canvas.update_now() i = list(diagram.canvas.get_all_items()) self.assertEquals(1, len(i), i) self.assertEquals('Name', i[0]._name.text) service.copy([c]) assert diagram.canvas.get_all_items() == [c] service.paste(diagram) i = diagram.canvas.get_all_items() self.assertEquals(2, len(i), i) diagram.canvas.update_now() self.assertEquals('Name', i[0]._name.text) self.assertEquals('Name', i[1]._name.text)
def test_copy_named_item(self): service = CopyService() service.init(Application) ef = self.element_factory diagram = ef.create(UML.Diagram) c = diagram.create(items.ClassItem, subject=ef.create(UML.Class)) c.subject.name = 'Name' import gobject self.assertEquals(0, gobject.main_depth()) diagram.canvas.update_now() i = list(diagram.canvas.get_all_items()) self.assertEquals(1, len(i), i) self.assertEquals('Name', i[0]._name.text) service.copy([c]) assert diagram.canvas.get_all_items() == [ c ] service.paste(diagram) i = diagram.canvas.get_all_items() self.assertEquals(2, len(i), i) diagram.canvas.update_now() self.assertEquals('Name', i[0]._name.text) self.assertEquals('Name', i[1]._name.text)
def wrapper(*args, **kwargs): global getattr, setattr, delattr # execute directly if we're not in the main loop. if gobject.main_depth() == 0: return func(*args, **kwargs) elif not self.single: def async_wrapper(): if DEBUG_ASYNC: print 'async:', func, args, kwargs func(*args, **kwargs) source(async_wrapper).attach() else: # Idle handlers should be registered per instance holder = args[0] try: if getattr(holder, async_id): return except AttributeError, e: def async_wrapper(): if DEBUG_ASYNC: print 'async:', func, args, kwargs try: func(*args, **kwargs) finally: delattr(holder, async_id) return False setattr(holder, async_id, source(async_wrapper).attach())
def _run_in_main_loop(func, *args, **kwargs): if _gobject.main_depth(): # In the main loop already return func(*args, **kwargs) callbackobj = IdleBlockCallback(func, args, kwargs) callbackobj.event.clear() _gobject.idle_add(callbackobj, priority=_gobject.PRIORITY_LOW) callbackobj.event.wait() return callbackobj.result
def _on_window_destroy(self, window): """ Window is destroyed... Quit the application. """ self.window = None if gobject.main_depth() > 0: gtk.main_quit() cr = self.component_registry cr.unregister_handler(self._on_undo_manager_state_changed) cr.unregister_handler(self._on_file_manager_state_changed) cr.unregister_handler(self._new_model_content)
def __on_send_data(self, sock, cond, fd, partial, data, eof): if (cond == gobject.IO_HUP): logging.debug("Client closed connection on FileServer") fd.close() sock.close() self.__remove_client() return False # this helps a bit against starvation of the gtk events due to too much # IO traffic if (gobject.main_depth() < 3): gtk.main_iteration(False) chunk = data[0] if (chunk): length = sock.send(chunk) #print length data[0] = chunk[length:] else: if (eof[0]): sock.close() self.__remove_client() return False d = fd.read(4096) if (not d): # we reached the end of file if (not os.path.exists(partial)): # file was transferred completely; close the connection fd.close() eof[0] = True else: # file is still being transferred... # sleep a little because otherwise the IO callback is # immediately called again resulting in high CPU load # while we cannot send anything to the waiting client time.sleep(0.05) #print "gotta wait" return True #new_chunk = hex(len(d))[2:] #print new_chunk #new_chunk += "\r\n" new_chunk = d #new_chunk += "\r\n" data[0] = new_chunk return True
def handler_wrapper(minor, detail1, detail2, any_data, source_application, sender=None, interface=None, member=None, path=None): # Convert the event type type = signal_spec_to_event_type (interface, member, minor) # Marshal the 'any_data' to correct class / structure if type.is_subtype (EventType ("object:bounds-changed")): any_data = BoundingBox(*any_data) elif (type.is_subtype (EventType ("object:children-changed")) or type.is_subtype (EventType ("object:property-change:accessible-parent")) or type.is_subtype (EventType ("object:active-descendant-changed"))): data_name, data_path = any_data; any_data = factory (data_name, data_path, interfaces.ATSPI_ACCESSIBLE) # Create the source application source_app_name, source_app_path = source_application source_application = factory (source_app_name, source_app_path, interfaces.ATSPI_APPLICATION) # Create the source source_name = sender source_path = path if (path == interfaces.ATSPI_ROOT_PATH): source_itf = interfaces.ATSPI_APPLICATION else: source_itf = interfaces.ATSPI_ACCESSIBLE source = factory (source_name, source_path, source_itf) event = Event (type, detail1, detail2, any_data, source_application, source) depth = gobject.main_depth() r = registry.Registry() if (r.async): r.enqueueEvent(event_handler, event) else: return event_handler(event)