def saveCursorPos(self): if (not self.windowID) or (self.windowID != getFocalWindowID()): return if _has_aqutil: scrnPosDict = aqutil.getPointerGlobalPosition() self.lastScreenX = scrnPosDict['x'] self.lastScreenY = scrnPosDict['y'] return if not WUTIL_USING_X: return # some of the following xutil methods are undefined # This also won't work on a Mac if running from the Terminal app # but it WILL work on a Mac from an X11 xterm window if WUTIL_USING_X and WUTIL_ON_MAC and self.windowID < 2: return posdict = getPointerPosition(self.windowID) if posdict: x = posdict['win_x'] y = posdict['win_y'] else: return windict = getWindowAttributes(self.windowID) if windict and windict['width'] > 0: maxX = windict['width'] maxY = windict['height'] else: return # do nothing if position out of window if x < 0 or y < 0 or x >= maxX or y >= maxY: return self.lastX = x self.lastY = y
def saveCursorPos(self): if (not self.windowID) or (self.windowID != getFocalWindowID()): return if _has_aqutil: scrnPosDict = aqutil.getPointerGlobalPosition() self.lastScreenX = scrnPosDict['x'] self.lastScreenY = scrnPosDict['y'] return if not WUTIL_USING_X: return # some of the following xutil methods are undefined # This also won't work on a Mac if running from the Terminal app # but it WILL work on a Mac from an X11 xterm window if WUTIL_USING_X and WUTIL_ON_MAC and self.windowID < 2: return posdict = getPointerPosition(self.windowID) if posdict: x = posdict['win_x'] y = posdict['win_y'] else: return windict = getWindowAttributes(self.windowID) if windict and windict['width'] > 0: maxX = windict['width'] maxY = windict['height'] else: return # do nothing if position out of window if x < 0 or y < 0 or x >= maxX or y >= maxY: return self.lastX = x self.lastY = y
def restoreLast(self): if not self.hasGraphics: return if len(self.focusStack) > 1: # update current position if we're in the correct window current = self.focusStack.pop() if current.getWindowID() == getFocalWindowID(): current.saveCursorPos() if self.focusInFamily(): self.focusStack[-1].forceFocus()
def restoreLast(self): if not self.hasGraphics: return if len(self.focusStack) > 1: # update current position if we're in the correct window current = self.focusStack.pop() if current.getWindowID() == getFocalWindowID(): current.saveCursorPos() if self.focusInFamily(): self.focusStack[-1].forceFocus()
def getCurrentFocusEntity(self): """Return the focus entity that currently has focus. Return None if focus is not in the focus family""" if not self.hasGraphics: return None, None currentFocusWinID = getFocalWindowID() currentTopID = getTopID(currentFocusWinID) for name, focusEntity in self.focusEntities.items(): if getTopID(focusEntity.getWindowID()) == currentTopID: return name, focusEntity else: return None, None
def getCurrentFocusEntity(self): """Return the focus entity that currently has focus. Return None if focus is not in the focus family""" if not self.hasGraphics: return None, None currentFocusWinID = getFocalWindowID() currentTopID = getTopID(currentFocusWinID) for name,focusEntity in self.focusEntities.items(): if getTopID(focusEntity.getWindowID()) == currentTopID: return name, focusEntity else: return None, None
def focusInFamily(self): """Determine if current focus is within the pyraf family (as defined by self.focusEntities)""" if not self.hasGraphics: return 0 currentFocusWinID = getFocalWindowID() currentTopID = getTopID(currentFocusWinID) for focusEntity in self.focusEntities.values(): fwid = focusEntity.getWindowID() if fwid: if getTopID(fwid) == currentTopID: return 1 return 0 # not in family
def focusInFamily(self): """Determine if current focus is within the pyraf family (as defined by self.focusEntities)""" if not self.hasGraphics: return 0 currentFocusWinID = getFocalWindowID() currentTopID = getTopID(currentFocusWinID) for focusEntity in self.focusEntities.values(): fwid = focusEntity.getWindowID() if fwid: if getTopID(fwid) == currentTopID: return 1 return 0 # not in family
def __init__(self): """IMPORTANT: This class must be instantiated while focus is in the terminal window""" self.lastScreenX = None self.lastScreenY = None try: self.windowID = getFocalWindowID() if self.windowID == -1: self.windowID = None if _has_aqutil: scrnPosDict = aqutil.getPointerGlobalPosition() self.lastScreenX = scrnPosDict['x'] self.lastScreenY = scrnPosDict['y'] except EnvironmentError, e: self.windowID = None
def __init__(self): """IMPORTANT: This class must be instantiated while focus is in the terminal window""" self.lastScreenX = None self.lastScreenY = None try: self.windowID = getFocalWindowID() if self.windowID == -1: self.windowID = None if _has_aqutil: scrnPosDict = aqutil.getPointerGlobalPosition() self.lastScreenX = scrnPosDict['x'] self.lastScreenY = scrnPosDict['y'] except EnvironmentError, e: self.windowID = None
def forceFocus(self, cursorToo=True): if WUTIL_ON_MAC and WUTIL_USING_X: return # X ver. under dev. on OSX... (was broken anyway) if not (self.windowID and isViewable(self.windowID)): # no window or not viewable return if self.windowID == getFocalWindowID(): # focus is already here return if _has_aqutil: if self.lastScreenX is not None and cursorToo: moveCursorTo(self.windowID, self.lastScreenX, self.lastScreenY, 0, 0) else: # WUTIL_USING_X if self.lastX is not None and cursorToo: moveCursorTo(self.windowID, 0, 0, self.lastX, self.lastY) if not GRAPHICS_ALWAYS_ON_TOP: setFocusTo(self.windowID)
def forceFocus(self, cursorToo=True): if WUTIL_ON_MAC and WUTIL_USING_X: return # X ver. under dev. on OSX... (was broken anyway) if not (self.windowID and isViewable(self.windowID)): # no window or not viewable return if self.windowID == getFocalWindowID(): # focus is already here return if _has_aqutil: if self.lastScreenX is not None and cursorToo: moveCursorTo(self.windowID, self.lastScreenX, self.lastScreenY, 0, 0) else: # WUTIL_USING_X if self.lastX is not None and cursorToo: moveCursorTo(self.windowID, 0, 0, self.lastX, self.lastY) if not GRAPHICS_ALWAYS_ON_TOP: setFocusTo(self.windowID)
def updateWindowID(self, id=None): """Update terminal window ID (to current window if id is not given)""" if id is None: id = getFocalWindowID() self.windowID = id
def updateWindowID(self, id=None): """Update terminal window ID (to current window if id is not given)""" if id is None: id = getFocalWindowID() self.windowID = id