changeset 343:11c5a8a70c02 devel

Fix ide
author Windel Bouwman
date Sat, 01 Mar 2014 16:27:52 +0100
parents 86b02c98a717
children 1378c4b027a0 742588fb8cd6
files python/ide/hexedit.py python/ide/ide.py python/ide/qtwrapper.py test/gui/testhexedit.py test/runtests.sh test/testhexedit.py
diffstat 6 files changed, 79 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/python/ide/hexedit.py	Sat Mar 01 15:40:31 2014 +0100
+++ b/python/ide/hexedit.py	Sat Mar 01 16:27:52 2014 +0100
@@ -1,20 +1,19 @@
 #!/usr/bin/python
 
 import sys
-import os
-from qtwrapper import QtGui, QtCore, QtWidgets, Qt
+from qtwrapper import QtGui, QtCore, QtWidgets, Qt, abspath, uic
 
 
 BYTES_PER_LINE, GAP = 8, 12
 
 def clamp(minimum, x, maximum):
-   return max(minimum, min(x, maximum))
+    return max(minimum, min(x, maximum))
 
 def asciiChar(v):
-   if v < 0x20 or v > 0x7e:
-      return '.'
-   else:
-      return chr(v)
+    if v < 0x20 or v > 0x7e:
+        return '.'
+    else:
+        return chr(v)
 
 class BinViewer(QtWidgets.QWidget):
    """ The view has an address, hex byte and ascii column """
@@ -99,18 +98,18 @@
          painter.fillRect(self.cursorX, self.cursorY + chh - 2, chw, 2, Qt.black)
 
    def keyPressEvent(self, event):
-      if event.matches(QKeySequence.MoveToNextChar):
+      if event.matches(QtGui.QKeySequence.MoveToNextChar):
          self.CursorPosition += 1
-      if event.matches(QKeySequence.MoveToPreviousChar):
+      if event.matches(QtGui.QKeySequence.MoveToPreviousChar):
          self.CursorPosition -= 1
-      if event.matches(QKeySequence.MoveToNextLine):
+      if event.matches(QtGui.QKeySequence.MoveToNextLine):
          self.CursorPosition += 2 * BYTES_PER_LINE
-      if event.matches(QKeySequence.MoveToPreviousLine):
+      if event.matches(QtGui.QKeySequence.MoveToPreviousLine):
          self.CursorPosition -= 2 * BYTES_PER_LINE
-      if event.matches(QKeySequence.MoveToNextPage):
+      if event.matches(QtGui.QKeySequence.MoveToNextPage):
          rows = int(self.scrollArea.viewport().height() / self.charHeight)
          self.CursorPosition += (rows - 1) * 2 * BYTES_PER_LINE
-      if event.matches(QKeySequence.MoveToPreviousPage):
+      if event.matches(QtGui.QKeySequence.MoveToPreviousPage):
          rows = int(self.scrollArea.viewport().height() / self.charHeight)
          self.CursorPosition -= (rows - 1) * 2 * BYTES_PER_LINE
       char = event.text().lower()
@@ -177,10 +176,9 @@
 
 
 class HexEditor(QtWidgets.QMainWindow):
-   def __init__(self):
+    def __init__(self):
       super().__init__()
-      basedir = os.path.dirname(__file__)
-      uic.loadUi(os.path.join(basedir, 'hexeditor.ui'), baseinstance=self)
+      uic.loadUi(abspath('hexeditor.ui'), baseinstance=self)
       self.he = HexEdit()
       self.setCentralWidget(self.he)
       self.actionOpen.triggered.connect(self.doOpen)
@@ -188,20 +186,24 @@
       self.actionSaveAs.triggered.connect(self.doSaveAs)
       self.fileName = None
       self.updateControls()
-   def updateControls(self):
+
+    def updateControls(self):
       s = True if self.fileName else False
       self.actionSave.setEnabled(s)
       self.actionSaveAs.setEnabled(s)
-   def doOpen(self):
-      filename = QFileDialog.getOpenFileName(self)
+
+    def doOpen(self):
+      filename = QtWidgets.QFileDialog.getOpenFileName(self)
       if filename:
          with open(filename, 'rb') as f:
             self.he.bv.Data = f.read()
          self.fileName = filename
       self.updateControls()
-   def doSave(self):
+
+    def doSave(self):
       self.updateControls()
-   def doSaveAs(self):
+
+    def doSaveAs(self):
       filename = QFileDialog.getSaveFileName(self)
       if filename:
          with open(filename, 'wb') as f:
@@ -211,8 +213,8 @@
 
 
 if __name__ == '__main__':
-   app = QApplication(sys.argv)
-   he = HexEditor()
-   he.show()
-   #he.bv.Data = bytearray(range(100)) * 8 + b'x'
-   app.exec()
+    app = QtWidgets.QApplication(sys.argv)
+    he = HexEditor()
+    he.show()
+    #he.bv.Data = bytearray(range(100)) * 8 + b'x'
+    app.exec()
--- a/python/ide/ide.py	Sat Mar 01 15:40:31 2014 +0100
+++ b/python/ide/ide.py	Sat Mar 01 16:27:52 2014 +0100
@@ -6,12 +6,14 @@
 import traceback
 import io
 
-from qtwrapper import QtGui, QtCore, QtWidgets, pyqtSignal, get_icon, abspath, Qt
+from qtwrapper import QtGui, QtCore, QtWidgets, pyqtSignal, get_icon
+from qtwrapper import abspath, Qt
 
 # Compiler imports:
 p = os.path.join(os.path.dirname(__file__), '..')
 sys.path.insert(0, p)
 sys.path.insert(0, os.path.join(p, 'utils'))
+
 import ppci
 from astviewer import AstViewer
 from codeedit import CodeEdit
@@ -19,8 +21,8 @@
 from disasm import Disassembly
 stutil = __import__('st-util')
 import zcc
-import outstream
-from target import armtarget
+from ppci.outstream import BinaryOutputStream
+from ppci.target.target_list import thumb_target
 
 
 def handle_exception(tp, v, tb):
@@ -279,9 +281,9 @@
             return
         fn = ce.FileName
         self.diag.clear()
-        outs = outstream.TextOutputStream()
+        outs = BinaryOutputStream()
         imps = [open(ce.FileName, 'r') for ce in self.allChildren() if ce.FileName and ce.FileName != fn]
-        if not zcc.zcc([open(fn, 'r')], imps, armtarget, outs, self.diag):
+        if not zcc.zcc([open(fn, 'r')], imps, thumb_target, outs, self.diag):
             # Set errors:
             self.builderrors.setErrorList(self.diag.diags)
             ce.setErrors(self.diag.diags)
--- a/python/ide/qtwrapper.py	Sat Mar 01 15:40:31 2014 +0100
+++ b/python/ide/qtwrapper.py	Sat Mar 01 16:27:52 2014 +0100
@@ -1,5 +1,5 @@
 import os
-from PyQt5 import QtCore, QtGui, QtWidgets
+from PyQt5 import QtCore, QtGui, QtWidgets, uic
 from PyQt5.QtCore import pyqtSignal, Qt
 
 def abspath(filename):
--- a/test/gui/testhexedit.py	Sat Mar 01 15:40:31 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-import unittest
-import hexedit
-from PyQt4.QtGui import QApplication
-from PyQt4.QtTest import QTest
-from PyQt4.QtCore import Qt
-import sys
-
-
-class HexTest(unittest.TestCase):
-    def setUp(self):
-        self.app = QApplication(sys.argv)
-        self.ui = hexedit.HexEditor()
-        self.bv = self.ui.he.bv
-        # Provide some random data:
-        self.bv.Data = bytearray(range(10)) * 8 + b'x'
-
-    def tearDown(self):
-        self.app.processEvents()
-        self.app.quit()
-
-    def testOpenButton(self):
-        self.assertEqual(0, self.bv.CursorPosition)
-        #QTest.mouseClick(self.bv, Qt.LeftButton)
-        self.assertEqual(161, self.bv.CursorPosition)
-        QTest.keyClick(self.bv, Qt.Key_Left)
-        self.assertEqual(160, self.bv.CursorPosition)
-        QTest.keyClick(self.bv, Qt.Key_Up)
-        self.assertEqual(128, self.bv.CursorPosition)
-
-
-if __name__ == '__main__':
-    unittest.main()
--- a/test/runtests.sh	Sat Mar 01 15:40:31 2014 +0100
+++ b/test/runtests.sh	Sat Mar 01 16:27:52 2014 +0100
@@ -1,15 +1,13 @@
 #!/usr/bin/env bash
 
-export PYTHONPATH=$PYTHONPATH:`pwd`/../python
+export PYTHONPATH=$PYTHONPATH:`pwd`/../python:`pwd`/../python/ide
 
 if [ "$1" == "loop" ]
 then
   DIR=..
   while :; do
     python -m unittest
-    cd gui
     #python -m unittest -v
-    cd ..
     echo "Awaiting changes in $DIR"
     inotifywait -r -e modify $DIR
   done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testhexedit.py	Sat Mar 01 16:27:52 2014 +0100
@@ -0,0 +1,42 @@
+import sys
+import unittest
+
+import hexedit
+#import ide
+
+from PyQt5.QtWidgets import QApplication
+from PyQt5.QtTest import QTest
+from PyQt5.QtCore import Qt
+
+
+class HexEditorTest(unittest.TestCase):
+    def setUp(self):
+        self.app = QApplication(sys.argv)
+        self.ui = hexedit.HexEditor()
+        self.bv = self.ui.he.bv
+        # Provide some random data:
+        self.bv.Data = bytearray(range(10)) * 8 + b'x'
+
+    def tearDown(self):
+        self.app.processEvents()
+        self.app.quit()
+
+    def tstOpenFile(self):
+        pass
+        #self.ui.actionOpen.trigger()
+        #w = self.app.activeWindow()
+        #print(w)
+        #QTest.keyClick(self.ui, Qt.Key_Escape)
+
+    def tstDataInView(self):
+        self.assertEqual(0, self.bv.CursorPosition)
+        QTest.mouseClick(self.bv, Qt.LeftButton)
+        self.assertEqual(154, self.bv.CursorPosition)
+        QTest.keyClick(self.bv, Qt.Key_Left)
+        self.assertEqual(153, self.bv.CursorPosition)
+        QTest.keyClick(self.bv, Qt.Key_Up)
+        self.assertEqual(137, self.bv.CursorPosition)
+
+
+if __name__ == '__main__':
+    unittest.main()