def __init__(self, frame, namespace=None): """ Create a Jython Console. namespace is an optional and should be a dictionary or Map """ self.frame = frame self.history = History(self) if namespace != None: self.locals = namespace else: self.locals = {} self.buffer = [] # buffer for multi-line commands self.interp = Interpreter(self, self.locals) sys.stdout = StdOutRedirector(self) self.text_pane = JTextPane(keyTyped = self.keyTyped, keyPressed = self.keyPressed) self.__initKeyMap() self.doc = self.text_pane.document self.__propertiesChanged() self.__inittext() self.initialLocation = self.doc.createPosition(self.doc.length-1) # Don't pass frame to popups. JWindows with null owners are not focusable # this fixes the focus problem on Win32, but make the mouse problem worse self.popup = Popup(None, self.text_pane) self.tip = Tip(None) # get fontmetrics info so we can position the popup metrics = self.text_pane.getFontMetrics(self.text_pane.getFont()) self.dotWidth = metrics.charWidth('.') self.textHeight = metrics.getHeight()
def __init__(self, n_tips): super(Node, self).__init__() assert n_tips > 0 self.tips = [Tip(master=self) for _ in xrange(n_tips)] self.tip = self.tips[0] self.protos = []
def __init__(self, frame): self.frame = frame # TODO do I need a reference to frame after the constructor? self.history = History(self) self.bs = 0 # what is this? # command buffer self.buffer = [] self.locals = {"gvSIG": sys.gvSIG} self.interp = Interpreter(self, self.locals) sys.stdout = StdOutRedirector(self) # create a textpane self.output = JTextPane(keyTyped=self.keyTyped, keyPressed=self.keyPressed) # TODO rename output to textpane # CTRL UP AND DOWN don't work keyBindings = [ (KeyEvent.VK_ENTER, 0, "jython.enter", self.enter), (KeyEvent.VK_DELETE, 0, "jython.delete", self.delete), (KeyEvent.VK_HOME, 0, "jython.home", self.home), (KeyEvent.VK_UP, 0, "jython.up", self.history.historyUp), (KeyEvent.VK_DOWN, 0, "jython.down", self.history.historyDown), (KeyEvent.VK_PERIOD, 0, "jython.showPopup", self.showPopup), (KeyEvent.VK_ESCAPE, 0, "jython.hide", self.hide), ('(', 0, "jython.showTip", self.showTip), (')', 0, "jython.hideTip", self.hideTip), #(KeyEvent.VK_UP, InputEvent.CTRL_MASK, DefaultEditorKit.upAction, self.output.keymap.getAction(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0))), #(KeyEvent.VK_DOWN, InputEvent.CTRL_MASK, DefaultEditorKit.downAction, self.output.keymap.getAction(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0))) ] # TODO rename newmap to keymap newmap = JTextComponent.addKeymap("jython", self.output.keymap) for (key, modifier, name, function) in keyBindings: newmap.addActionForKeyStroke(KeyStroke.getKeyStroke(key, modifier), ActionDelegator(name, function)) self.output.keymap = newmap self.doc = self.output.document #self.panel.add(BorderLayout.CENTER, JScrollPane(self.output)) self.__propertiesChanged() self.__inittext() self.initialLocation = self.doc.createPosition(self.doc.length - 1) # Don't pass frame to popups. JWindows with null owners are not focusable # this fixes the focus problem on Win32, but make the mouse problem worse self.popup = Popup(None, self.output) self.tip = Tip(None) # get fontmetrics info so we can position the popup metrics = self.output.getFontMetrics(self.output.getFont()) self.dotWidth = metrics.charWidth('.') self.textHeight = metrics.getHeight() # add some handles to our objects self.locals['console'] = self self.caret = self.output.getCaret()