def embed(self): self.name_session = uuid.uuid4().hex proc = QtCore.QProcess() started, procId = QtCore.QProcess.startDetached( "xterm", ["-e", "tmux", "new", "-s", self.name_session], ".") if not started: QtWidgets.QMessageBox.critical(self, 'Process not started', "Eh") return attempts = 0 while attempts < 10: screen = Wnck.Screen.get_default() screen.force_update() # do a bit of sleep, else window is not really found time.sleep(0.1) # this is required to ensure that newly mapped window get listed. while Gdk.events_pending(): Gdk.event_get() for w in screen.get_windows(): print(attempts, w.get_pid(), procId, w.get_pid() == procId) if w.get_pid() == procId: self.window = QtGui.QWindow.fromWinId(w.get_xid()) proc.setParent(self) win32w = QtGui.QWindow.fromWinId(w.get_xid()) win32w.setFlags(QtCore.Qt.FramelessWindowHint) widg = QtWidgets.QWidget.createWindowContainer(win32w) self.addTab(widg, 'abc') self.resize(500, 400) # set initial size of window return attempts += 1 QtWidgets.QMessageBox.critical(self, 'Window not found', 'Process started but window not found')
def embed(self, command, *args): proc = QtCore.QProcess() proc.setProgram(command) proc.setArguments(args) started, procId = proc.startDetached() if not started: QtWidgets.QMessageBox.critical(self, 'Command "{}" not started!') return attempts = 0 while attempts < 10: screen = Wnck.Screen.get_default() screen.force_update() # this is required to ensure that newly mapped window get listed. while Gdk.events_pending(): Gdk.event_get() for w in screen.get_windows(): if w.get_pid() == procId: window = QtGui.QWindow.fromWinId(w.get_xid()) container = QtWidgets.QWidget.createWindowContainer( window, self) self.addTab(container, command) return attempts += 1 QtWidgets.QMessageBox.critical(self, 'Window not found', 'Process started but window not found')
def _get_latest_event_of_same_type(event): """Return the latest event in the event queue that is of the same type as <event>, or <event> itself if no such events are in the queue. All events of that type will be removed from the event queue. """ events = [] while Gdk.events_pending(): queued_event = Gdk.event_get() if queued_event is not None: if queued_event.type == event.type: event = queued_event else: events.append(queued_event) for queued_event in events: queued_event.put() return event
def _get_latest_event_of_same_type(event): '''Return the latest event in the event queue that is of the same type as <event>, or <event> itself if no such events are in the queue. All events of that type will be removed from the event queue. ''' return event events = [] while Gdk.events_pending(): queued_event = Gdk.event_get() if queued_event is not None: if queued_event.type == event.type: event = queued_event else: events.append(queued_event) for queued_event in events: queued_event.put() return event
def consume(self, type, state): next = Gdk.event_get() while next and next.type == type and next.state == state: next.free() next = Gdk.event_get() self.statics.consumed.motion += 1