def generate(self, *args): # The idea is to just do this, but it seems to cause strange things to happen # internally. So we do it outside SWTBot instead. # self.widget.setFocus() page = self.widget.getViewReference().getPage() view = self.widget.getViewReference().getView(False) swtsimulator.runOnUIThread(page.activate, view)
def connectRecord(self, method): class RecordListener(IPartListener): def partActivated(listenerSelf, part): method(part, self) page = self.widget.getViewReference().getPage() swtsimulator.runOnUIThread(page.addPartListener, RecordListener())
def connectRecord(self, method): class RecordListener(IPartListener): def partClosed(listenerSelf, part): #@NoSelf if part is self.widget.getViewReference().getView(False): storytext.guishared.catchAll(method, part, self) page = self.widget.getViewReference().getPage() swtsimulator.runOnUIThread(page.addPartListener, RecordListener())
def _generate(self, cell): row, col = cell button = self.mouseButton() if button == 3: desc = InstantMenuDescriber(self.widget) simulator.runOnUIThread(desc.addFilter) simulator.runOnUIThread(self.widget.clickOnCell, row, col, self.clickCount(), button)
def connectRecord(self, method): swtsimulator.CTabCloseEvent.connectRecord(self, method) class DisposeFilter(swt.widgets.Listener): def handleEvent(listenerSelf, e): #@NoSelf if isinstance(e.widget, swt.custom.CTabItem): self.disposedTabs[e.widget] = e.widget.getText() if not self.disposeFilter: RCPCTabCloseEvent.disposeFilter = DisposeFilter() swtsimulator.runOnUIThread(self.widget.widget.widget.getDisplay().addFilter, SWT.Dispose, self.disposeFilter)
def drag(self, editPart, toX, toY, keyModifiers=0): widgetCentreX, widgetCentreY = self.getCenter(editPart) displayCentre = swtsimulator.runOnUIThread(self.getFigureCanvas().toDisplayLocation, widgetCentreX, widgetCentreY) centreX = displayCentre.x centreY = displayCentre.y self.logger.debug("Dragging " + repr((centreX, centreY)) + " to " + repr((toX, toY))) self.getFigureCanvas().mouseDrag(centreX, centreY, toX, toY, keyModifiers)
def mouseDrag(self, fromX, fromY, toX, toY, keyModifiers=0): # These values, and the broad algorithm here, are taken from a draft implementation of DnD for SWTBot # The code is attached to the bug at https://bugs.eclipse.org/bugs/show_bug.cgi?id=285271 # When it is integrated into SWTBot we should probably use it directly dragThreshold = 16 dragDelay = 0.3 self.eventPoster.moveMouseAndWait(fromX, fromY) self.eventPoster.checkAndPostKeyPressed(keyModifiers) initialDragTargetX = fromX + dragThreshold initialDragTargetY = fromY swtsimulator.runOnUIThread(storytext.guishared.catchAll, self.startDrag, initialDragTargetX, initialDragTargetY) time.sleep(dragDelay) self.moveDragged(initialDragTargetX, initialDragTargetY, toX, toY) swtsimulator.runOnUIThread(storytext.guishared.catchAll, self.eventPoster.postMouseUp) self.eventPoster.checkAndPostKeyReleased(keyModifiers)
def isPreferred(self): viewWidget = self.getViewWidget() if viewWidget in self.widgetViewIds: viewId = self.widgetViewIds.get(viewWidget) activeViewId = swtsimulator.runOnUIThread(self.getActiveViewId) return viewId == activeViewId else: return False
def updateTableInfo(self): simulator.runOnUIThread(self.setOffsets, self.widget) self.logger.debug("Updated NatTable indexer with row offset " + str(self.rowOffset) + " and column offset " + str(self.colOffset)) simulator.TableIndexer.updateTableInfo(self)
def widgetDisposed(self): control = self.getControl() return control is None or swtsimulator.runOnUIThread(control.isDisposed)
def generate(self, *args): # The idea is to just do this, but it seems to cause strange things to happen #internally. So we do it outside SWTBot instead. #self.widget.setFocus() swtsimulator.runOnUIThread(self.clickMatchingTab, *args)
def connectRecord(self, method): swtsimulator.SelectEvent.connectRecord(self, method) widget = self.widget.widget.widget if hasattr(widget, "getAccelerator"): swtsimulator.runOnUIThread(self.connectRecordKeyBinding, widget, method)
def getViewWidget(self): widget = self.widget.widget if isinstance(widget, swt.widgets.MenuItem): return swtsimulator.runOnUIThread(util.getRootMenu, widget) else: return widget
def generate(self, *args): swtsimulator.runOnUIThread(self.widget.clickOnCenter)
def checkRowInViewport(self, row): clientAreaHeight = simulator.runOnUIThread(self.widget.getClientArea).height bounds = simulator.runOnUIThread(self.widget.getBoundsByPosition, 0, row) y = util.getInt(bounds.y) + util.getInt(bounds.height) / 2 if y > clientAreaHeight: raise UseCaseScriptError, "Could not select row, it is outside the viewport"
def scrollToY(self, layer, offset): yCoord = layer.getOrigin().getY() simulator.runOnUIThread(layer.setOriginY, yCoord + offset)
def mouseMoveLeftClick(self, x, y, keyModifiers=0): displayLoc = swtsimulator.runOnUIThread(self.toDisplayLocation, x, y) self.eventPoster.moveClickAndReturn(displayLoc.x, displayLoc.y, keyModifiers)
def connectRecord(self, method): class RecordListener(ExpansionAdapter): def expansionStateChanged(listenerSelf, e): #@NoSelf storytext.guishared.catchAll(method, e, self) swtsimulator.runOnUIThread(self.widget.widget.widget.addExpansionListener, RecordListener())
def addActivePartListener(self, swtbotView): class RecordListener(IPartListener): def partActivated(listenerSelf, part):#@NoSelf self.monitorMenus(swtbotView) page = swtbotView.getViewReference().getPage() swtsimulator.runOnUIThread(page.addPartListener, RecordListener())
def monitorAllWidgets(self, *args, **kw): self.setWidgetAdapter() swtsimulator.runOnUIThread(self.cacheAndMonitorViews) swtsimulator.WidgetMonitor.monitorAllWidgets(self, *args, **kw)
def clickOnCenter(self, row, col, clickCount, button): bounds = self.widget.getBoundsByPosition(col, row) x = util.getInt(bounds.x) + util.getInt(bounds.width) / 2 y = util.getInt(bounds.y) + util.getInt(bounds.height) / 2 displayLoc = simulator.runOnUIThread(self.display.map, self.widget, None, x, y) self.eventPoster.moveClickAndReturn(displayLoc.x, displayLoc.y, count=clickCount, button=button)