Esempio n. 1
0
    def __buffer(self):
        """
			Returns the current buffer ready for run/import, checking if it is
			a python buffer and whether has been saved
		"""
        from javax.swing import JOptionPane
        buf = self.view.editPane.buffer
        if buf.mode.name != "python":
            if buf.getProperty("jython.originator"):
                buf = buf.getProperty("jython.originator")

        if buf.mode.name == "python":
            if buf.dirty:
                if not jEdit.getBooleanProperty("options.jython.autosave"):
                    if jEdit.getBooleanProperty("options.jython.saveask"):
                        result = JOptionPane.showConfirmDialog(
                            self.panel, "Do you want to save before running",
                            "Confirm", JOptionPane.YES_NO_CANCEL_OPTION)
                        if result == JOptionPane.CANCEL_OPTION:
                            return None
                        if result == JOptionPane.YES_OPTION:
                            buf.save(self.view, None)
                else:
                    buf.save(self.view, None)
            return buf

        return None
Esempio n. 2
0
 def __ok(self, event):
     self.sys.path[0:len(self.sys.path)] = []
     [
         self.sys.path.append(self.model.get(i))
         for i in xrange(0, self.model.size())
     ]
     if jEdit.getBooleanProperty("options.jython.saveJythonPath"):
         self.export()
     self.visible = 0
Esempio n. 3
0
 def addOutput(self, color, msg):
     style = SimpleAttributeSet()
     if color:
         style.addAttribute(StyleConstants.Foreground, color)
     try:
         self.target.insertString(self.target.length, msg, style)
     except BadLocationException:
         Log.log(Log.ERROR, self, "")
     if jEdit.getBooleanProperty("options.jython.cleanDirtyFlag"):
         self.target.dirty = 0
Esempio n. 4
0
 def runBufferToWindow(self, event):
     """ Runs the current buffer to and exports the result to another window """
     from exportconsole import ConsoleToBuffer
     buffer = self.__buffer()
     if buffer:
         if jEdit.getBooleanProperty("options.jython.reuseOutputBuffer"):
             if not self.exporterConsole:
                 self.exporterConsole = ConsoleToBuffer(self.view, buffer)
             self.exporterConsole.clear()
         else:
             self.exporterConsole = ConsoleToBuffer(self.view, buffer)
         JythonExecutor.getExecutor().execBuffer(self.view, buffer,
                                                 self.exporterConsole)
Esempio n. 5
0
 def __init__(self, view, sys):
     JDialog.__init__(self, view,
                      jEdit.getProperty("jython.pathhandler.title"))
     self.sys = sys
     content = self.contentPane
     content.layout = BorderLayout()
     upperPanel = JPanel(BorderLayout())
     leftPanel = JPanel(BorderLayout(), border = \
      BorderFactory.createTitledBorder(jEdit.getProperty("jython.pathhandler.pathborder")))
     self.model = DefaultListModel()
     for s in sys.path:
         self.model.addElement(s)
     self.pathlist = JList(
         self.model, selectionMode=ListSelectionModel.SINGLE_SELECTION)
     leftPanel.add(JScrollPane(self.pathlist))
     rightPanel = JPanel(GridBagLayout())
     constraints = GridBagConstraints()
     constraints.insets = Insets(5, 5, 5, 5)
     constraints.gridy = GridBagConstraints.RELATIVE
     constraints.gridx = 0
     buttons = [("Plus.png", "New...", self.new), \
      ("ButtonProperties.png", "Edit...", self.edit),
      ("Minus.png", "Remove", self.remove), \
      ("ArrowU.png", "Move Up", self.up), \
      ("ArrowD.png", "Move down", self.down)]
     for (i, t, a) in buttons:
         rightPanel.add(JButton(icon = GUIUtilities.loadIcon(i), \
          toolTipText=t, actionPerformed=a), constraints)
     upperPanel.add(leftPanel, BorderLayout.CENTER)
     upperPanel.add(rightPanel, BorderLayout.EAST)
     content.add(upperPanel, BorderLayout.CENTER)
     lowerPanel = JPanel(FlowLayout(FlowLayout.RIGHT))
     self.saveAsk = JCheckBox(jEdit.getProperty("options.jython.saveJythonPathTitle"), \
      selected = jEdit.getBooleanProperty("options.jython.saveJythonPath"), actionPerformed = self.saveAsk)
     ok = JButton("Ok", actionPerformed=self.__ok)
     lowerPanel.add(self.saveAsk)
     lowerPanel.add(ok)
     self.rootPane.defaultButton = ok
     lowerPanel.add(JButton("Cancel", actionPerformed=self.__cancel))
     content.add(lowerPanel, BorderLayout.SOUTH)
Esempio n. 6
0
    def __init__(self, view):
        """ Constructor, initialized all the main variables and layout """
        # Initializes variables
        self.view = view
        self.history = History(self)
        self.bs = 0
        self.indenter = TabIndenter()
        self.exporterConsole = None
        self.executor = JythonExecutor.getExecutor()

        # Creates toolbar
        actions = [ ("Run.png", "jython.tooltip-run", self.runBuffer), \
         ("RunToBuffer.png", "jython.tooltip-run-another", self.runBufferToWindow), \
         ("RunAgain.png", "jython.tooltip-import", self.importBuffer), \
         ("MultipleResults.png", "jython.tooltip-path", self.path), \
         ("Open.png", "jython.tooltip-browse-path", self.browse), \
         ("CopyToBuffer.png", "jython.tooltip-save-session", self.savesession), \
         ("separator", None, None), \
         ("Clear.png", "jython.tooltip-restart", self.restart),
         ("separator", None, None),
         ("Parse.png", "jython.tooltip-tabnanny", self.tabnanny),
         ("separator", None, None),
         ("Help.png", "jython.tooltip-about", self.about)]
        self.panel = JPanel(BorderLayout())
        self.panel.add(BorderLayout.NORTH,
                       ToolbarHandler(actions).createToolbar())

        # Creates text pane and make keybindings
        # self.output = JTextPane(keyTyped = self.keyTyped, keyPressed = self.keyPressed, keyReleased = self.keyReleased)
        self.output = JTextPane(keyTyped=self.keyTyped,
                                keyPressed=self.keyPressed)
        if jEdit.getBooleanProperty("options.jython.upDownFlag"):
            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_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)))
            ]
        else:
            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, InputEvent.CTRL_MASK, "jython.historyup", \
              self.history.historyUp),
             (KeyEvent.VK_DOWN, InputEvent.CTRL_MASK, "jython.historydown", \
              self.history.historyDown)
            ]
        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)