def forceFocus(self, cursorToo=True): # only force focus if window is viewable if not wutil.isViewable(self.top.winfo_id()): return # warp cursor # if no previous position, move to center gw = self.gwidget if gw: if gw.lastX is None or \ (gw.lastX == 0 and gw.lastY == 0): swCurObj = gw.getSWCursor() if swCurObj: gw.lastX = int(swCurObj.lastx*gw.winfo_width()) gw.lastY = int((1.-swCurObj.lasty)*gw.winfo_height()) else: gw.lastX = int(gw.winfo_width()/2.) gw.lastY = int(gw.winfo_height()/2.) if cursorToo: wutil.moveCursorTo(gw.winfo_id(), gw.winfo_rootx(), gw.winfo_rooty(), gw.lastX, gw.lastY) # On non-X, "focus_force()" places focus on the gwidget canvas, but # this may not have the global focus; it may only be the widget seen # when the application itself has focus. We may need to force the # app itself to have focus first, so we do that here too. wutil.forceFocusToNewWindow() gw.focus_force()
def forceFocus(self): # only force focus if window is viewable if not wutil.isViewable(self.top.winfo_id()): return # warp cursor # if no previous position, move to center gwidget = self.gwidget if gwidget: if gwidget.lastX is None: gwidget.lastX = gwidget.winfo_width()/2 gwidget.lastY = gwidget.winfo_height()/2 wutil.moveCursorTo(gwidget.winfo_id(),gwidget.lastX,gwidget.lastY) gwidget.focus_force()
def moveCursorRelative(self, event, deltaX, deltaY): gwidget = self.gwidget width = self.gwidget.width height = self.gwidget.height # only move cursor if window is viewable if not wutil.isViewable(self.top.winfo_id()): return # if no previous position, ignore cursorobj = gwidget.getSWCursor() newX = cursorobj.lastx * width + deltaX newY = cursorobj.lasty * height + deltaY if newX < 0: newX = 0 if newY < 0: newY = 0 if newX >= width: newX = width - 1 if newY >= height: newY = height - 1 gwidget.moveCursorTo(newX, newY, SWmove=1) self.x = newX self.y = newY