Commits

Henning Schröder committed 41ea407

merged changes from editor preview

Comments (0)

Files changed (12)

codeaide/editors.py

 
     def __init__(self, parent=None):
         if not codeaide.modes.loaded:
-            codeaide.modes.load_all(verbose=False)
+            codeaide.modes.load_all(verbose=True)
         CodeAide.__init__(self, parent)
         for mod_name in self.require_modules:
             mod = __import__(mod_name, {}, {}, [])
     @classmethod
     def create_window(cls, *args, **kwargs):
         edit = super(BaseConsole, cls).create_window(*args, **kwargs)
-        edit.new_buffer()
         return edit
 
 
         self.busy = Idler(self).busy
         self.update_hooks()
         self.setFocus()
+        
+        self.new_buffer()
+    
 
-        
     @property
     def default_settings(self):
         return dict(
         bottom = top + bbgeom.height()
         ebottom_top = 0 #event.rect().top()
         ebottom_bottom = self.height() #event.rect().bottom()
+        visible_blocks_append = visible_blocks.append
         while block.isValid() and top <= ebottom_bottom:
             if block.isVisible() and bottom >= ebottom_top:
-                visible_blocks.append(
+                visible_blocks_append(
                    VisibleBlock(row, block, (0, top, w, h))
                    )
             block = block.next()

codeaide/modes/language/highlighter.py

 # -*- coding: utf-8  
+from PyQt4.QtCore import SIGNAL
+from codeaide.base import ModeBase
 
-from codeaide.base import ModeBase
 
 class HighlighterBase(ModeBase):
     
     def init(self):
+        self.textedit.connect(
+            self.textedit, SIGNAL("documentChanged()"), self.on_document_changed)
         self.init_highlighter()
-        
-        
+          
+          
+    def on_document_changed(self):
+        self.init_highlighter()
+    
+
     def init_highlighter(self):
         pass
 
-
-
+    
+    
+    

codeaide/modes/python/core.py

+# -*- coding: utf-8 -*-
+from PyQt4.QtCore import SIGNAL
+
 from codeaide.modes.language.highlighter import HighlighterBase
 from .highlighter import PythonHighlighter
 
     
     def init_highlighter(self):
         self.highlighter = PythonHighlighter(self.textedit)
-

codeaide/modes/python/highlighter.py

 # -*- coding: utf-8 -*-
+from PyQt4.QtCore import SIGNAL
 from PyQt4.QtGui import QTextCharFormat, QFont, QTextCursor
 
 from codeaide.modes.language.phighlighter import SyntaxHighlighter, load_syntax
     
     def __init__(self, textedit):
         partition_scanner, scanners, formats = load_syntax(python_syntax, textedit.settings.scheme)
-        SyntaxHighlighter.__init__(self, textedit.document(), 
+        SyntaxHighlighter.__init__(self, textedit.document(),
                                    partition_scanner, scanners, formats, textedit.font())
 

codeaide/modes/visualhelper.py

+# -*- coding: utf-8 -*-
 import re
 
 from codeaide.base import *
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import sys
+try:
+    from PyQt4.QtCore import Qt
+    from PyQt4.QtGui import QApplication, QSplitter, QMainWindow
+except ImportError, e:
+    print e
+    print "You have to install the python-pyqt4 package"
+    sys.exit(255)
+
+import excepthook
+excepthook.install()
+
+from codeaide.editors import PythonEditor, PythonConsole
+
+
+class IDE(QMainWindow):
+    
+    def __init__(self):
+        QMainWindow.__init__(self)
+        self.splitter = QSplitter(Qt.Vertical, self)
+        self.setCentralWidget(self.splitter)
+        self.edit = PythonEditor(self.splitter)
+        self.edit.install("EmacsCore")
+        src = open("demo.py").read()
+        self.edit.setPlainText(src)
+        #self.edit.load_buffer("demo.py")
+        self.console = PythonConsole(self.splitter)
+
+        self.splitter.setStretchFactor(0, 1)
+        self.resize(800, 600)
+    
+
+
+def main():
+    app = QApplication(sys.argv)
+    win = IDE()
+    win.show()
+    return app.exec_()
+
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)

excepthook/Makefile

+PYUIC=pyuic4
+UI_FILES=$(shell ls *.ui 2>/dev/null)
+UI_COMPILED=$(UI_FILES:.ui=_ui.py)
+
+all: $(UI_COMPILED)
+
+%_ui.py:%.ui
+	$(PYUIC) -x -o "$@" "$<"
+
+
+clean:
+	rm -f $(FORMS) *~ *.pyc

excepthook/__init__.py

+"""
+Exception hook
+If some unexpected error occures it can be shown in a nice looking dialog.
+Especially useful is the traceback view.
+
+Things to extend: Clicking on the filename should open an editor.
+Things to consider: Mail exceptions, copy to clipboard or send to bug tracker.
+"""
+import sys
+import cgitb
+import atexit
+
+from PyQt4.QtCore import pyqtSignature, Qt
+from PyQt4.QtGui import QDialog, QApplication
+
+from excepthook_ui import Ui_ExceptHookDialog
+
+import warnings
+warnings.filterwarnings(
+  action='ignore',
+  message='BaseException.message has been deprecated as of Python 2.6',
+  category=DeprecationWarning,
+  module='cgitb')
+                                    
+
+
+def on_error(exc_type, exc_obj, exc_tb):
+    """
+    This is the callback function for sys.excepthook
+    """
+    dlg = ExceptHookDialog(exc_type, exc_obj, exc_tb)
+    dlg.show()
+    dlg.exec_()
+
+
+
+def show_current_error(title=None):
+    """
+    Call this function to show the current error.
+    It can be used inside an except-block.
+    """
+    dlg = ExceptHookDialog(sys.exc_type, sys.exc_value, sys.exc_traceback, title)
+    dlg.show()
+    dlg.exec_()
+
+
+def install():
+    "activates the error handler"
+    sys.excepthook = on_error
+
+
+    
+def uninstall():
+    "removes the error handler"
+    sys.excepthook = sys.__excepthook__
+
+atexit.register(uninstall)
+
+
+class ExceptHookDialog(QDialog):
+
+
+    def __init__(self, exc_type, exc_obj, exc_tb, title=None):
+        QDialog.__init__(self)
+        self.ui = Ui_ExceptHookDialog()
+        self.ui.setupUi(self)
+        if title:
+            self.setWindowTitle(self.windowTitle() + ": " + title)
+        self.ui.detailsButton.setCheckable(True)
+        self.setExtension(self.ui.tracebackBrowser)
+        self.setOrientation(Qt.Vertical)
+        msg = "%s: %s" % (exc_type.__name__, exc_obj)
+        self.ui.exceptionLabel.setText(msg)
+        html = cgitb.html((exc_type, exc_obj, exc_tb))
+        self.ui.tracebackBrowser.setText(html)
+        self.resize(self.sizeHint())
+
+
+    @pyqtSignature("")
+    def on_closeButton_clicked(self):
+        self.close()
+
+
+    @pyqtSignature("")
+    def on_detailsButton_clicked(self):
+        self.showExtension(self.ui.detailsButton.isChecked())
+
+
+
+if __name__ == "__main__":
+    # Some tests:
+    app = QApplication(sys.argv)
+    install()
+    print "Triggering error 1"
+    try:
+        fail = 1 / 0
+    except:
+        show_current_error("Using inside except")
+    print "Triggering error 2"
+    fail2 = 1 / 0
+    print "This will never be reached because excepthook"
+    print "complains about fail2"

excepthook/excepthook.ui

+<ui version="4.0" >
+ <class>ExceptHookDialog</class>
+ <widget class="QDialog" name="ExceptHookDialog" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>542</width>
+    <height>290</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Script error</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout" >
+   <item>
+    <layout class="QGridLayout" name="gridLayout" >
+     <property name="spacing" >
+      <number>10</number>
+     </property>
+     <item row="0" column="0" >
+      <widget class="QLabel" name="label" >
+       <property name="text" >
+        <string>An exception occured while running the script.</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1" >
+      <widget class="QPushButton" name="closeButton" >
+       <property name="text" >
+        <string>&amp;Close</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="0" >
+      <widget class="QLabel" name="exceptionLabel" >
+       <property name="font" >
+        <font>
+         <weight>75</weight>
+         <bold>true</bold>
+        </font>
+       </property>
+       <property name="text" >
+        <string>Exception</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1" >
+      <widget class="QPushButton" name="detailsButton" >
+       <property name="text" >
+        <string>&amp;Details >></string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QTextBrowser" name="tracebackBrowser" >
+     <property name="minimumSize" >
+      <size>
+       <width>0</width>
+       <height>200</height>
+      </size>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

excepthook/excepthook_ui.py

+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'excepthook.ui'
+#
+# Created: Thu Aug 19 20:48:19 2010
+#      by: PyQt4 UI code generator 4.7.2
+#
+# WARNING! All changes made in this file will be lost!
+
+from PyQt4 import QtCore, QtGui
+
+class Ui_ExceptHookDialog(object):
+    def setupUi(self, ExceptHookDialog):
+        ExceptHookDialog.setObjectName("ExceptHookDialog")
+        ExceptHookDialog.resize(542, 290)
+        self.verticalLayout = QtGui.QVBoxLayout(ExceptHookDialog)
+        self.verticalLayout.setObjectName("verticalLayout")
+        self.gridLayout = QtGui.QGridLayout()
+        self.gridLayout.setSpacing(10)
+        self.gridLayout.setObjectName("gridLayout")
+        self.label = QtGui.QLabel(ExceptHookDialog)
+        self.label.setObjectName("label")
+        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
+        self.closeButton = QtGui.QPushButton(ExceptHookDialog)
+        self.closeButton.setObjectName("closeButton")
+        self.gridLayout.addWidget(self.closeButton, 0, 1, 1, 1)
+        self.exceptionLabel = QtGui.QLabel(ExceptHookDialog)
+        font = QtGui.QFont()
+        font.setWeight(75)
+        font.setBold(True)
+        self.exceptionLabel.setFont(font)
+        self.exceptionLabel.setObjectName("exceptionLabel")
+        self.gridLayout.addWidget(self.exceptionLabel, 1, 0, 1, 1)
+        self.detailsButton = QtGui.QPushButton(ExceptHookDialog)
+        self.detailsButton.setObjectName("detailsButton")
+        self.gridLayout.addWidget(self.detailsButton, 1, 1, 1, 1)
+        self.verticalLayout.addLayout(self.gridLayout)
+        self.tracebackBrowser = QtGui.QTextBrowser(ExceptHookDialog)
+        self.tracebackBrowser.setMinimumSize(QtCore.QSize(0, 200))
+        self.tracebackBrowser.setObjectName("tracebackBrowser")
+        self.verticalLayout.addWidget(self.tracebackBrowser)
+
+        self.retranslateUi(ExceptHookDialog)
+        QtCore.QMetaObject.connectSlotsByName(ExceptHookDialog)
+
+    def retranslateUi(self, ExceptHookDialog):
+        ExceptHookDialog.setWindowTitle(QtGui.QApplication.translate("ExceptHookDialog", "Script error", None, QtGui.QApplication.UnicodeUTF8))
+        self.label.setText(QtGui.QApplication.translate("ExceptHookDialog", "An exception occured while running the script.", None, QtGui.QApplication.UnicodeUTF8))
+        self.closeButton.setText(QtGui.QApplication.translate("ExceptHookDialog", "&Close", None, QtGui.QApplication.UnicodeUTF8))
+        self.exceptionLabel.setText(QtGui.QApplication.translate("ExceptHookDialog", "Exception", None, QtGui.QApplication.UnicodeUTF8))
+        self.detailsButton.setText(QtGui.QApplication.translate("ExceptHookDialog", "&Details >>", None, QtGui.QApplication.UnicodeUTF8))
+
+
+if __name__ == "__main__":
+    import sys
+    app = QtGui.QApplication(sys.argv)
+    ExceptHookDialog = QtGui.QDialog()
+    ui = Ui_ExceptHookDialog()
+    ui.setupUi(ExceptHookDialog)
+    ExceptHookDialog.show()
+    sys.exit(app.exec_())
+

test_py_console.py

-#!/usr/bin/env python2.5
+#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 from codeaide import editors