Permalink
Browse files

added mouseover position to explorer

  • Loading branch information...
1 parent 8738fc6 commit 2ce585ebee0de4234292de8abcb59e45a7e6ef97 @phooky committed Aug 23, 2012
Showing with 26 additions and 3 deletions.
  1. +2 −1 tools/mainwindow.py
  2. +5 −1 tools/mainwindow.ui
  3. +19 −1 tools/rom-explorer.py
View
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'mainwindow.ui'
#
-# Created: Mon Aug 13 18:16:52 2012
+# Created: Thu Aug 23 01:07:24 2012
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
@@ -23,6 +23,7 @@ def setupUi(self, MainWindow):
self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.bitmapView = QtGui.QGraphicsView(self.centralwidget)
+ self.bitmapView.setMouseTracking(True)
self.bitmapView.setObjectName(_fromUtf8("bitmapView"))
self.verticalLayout_2.addWidget(self.bitmapView)
self.horizontalLayout = QtGui.QHBoxLayout()
View
@@ -16,7 +16,11 @@
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <widget class="QGraphicsView" name="bitmapView"/>
+ <widget class="QGraphicsView" name="bitmapView">
+ <property name="mouseTracking">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
View
@@ -22,7 +22,10 @@ def __init__(self, path):
self.stride = 1
self.bigendian = 1
self.maxDim = 600
+ self.setAcceptHoverEvents(True)
self.rebuildImage()
+ # Create a wrapped object for emitting events
+ self.qobject = QtCore.QObject()
def rebuildImage(self):
width = self.stride * (8 / self.depth)
@@ -52,6 +55,17 @@ def paint(self, qpainter, qoptions, widget=None):
for strip in range(self.xstrips):
qpainter.drawImage(strip*self.width,0,self.img,0,vh*strip,self.width,vh)
+ def hoverMoveEvent(self,event):
+ strip = int(event.pos().x() / self.width)
+ actualh = min(self.height, self.maxDim)
+ stripoff = strip*self.width*actualh*self.depth
+ yoff = self.width*int(event.pos().y())*self.depth
+ xoff = int(event.pos().x() - strip*self.width)*self.depth
+ totalbitoff = int(xoff+yoff+stripoff)
+ offset = totalbitoff / 8
+ bit = totalbitoff % 8
+ self.qobject.emit(QtCore.SIGNAL("mouseOverLocation"),offset,bit)
+
def boundingRect(self):
return QtCore.QRectF(0,0, self.width * self.xstrips, min(self.height,self.maxDim))
@@ -62,6 +76,9 @@ def __init__(self):
self.ui = mainwindow.Ui_MainWindow()
self.ui.setupUi(self)
+ def updateWithLocation(self,offset,bit):
+ self.ui.statusbar.showMessage('Binary {0} loaded; total size {1} [Offset 0x{2:X} bit {3}]'.format(self.bin.name, self.bin.size, offset, bit))
+
def setBinary(self,bin):
self.bin = bin
self.bin.depth = int(self.ui.bitDepthComboBox.currentText())
@@ -71,6 +88,7 @@ def setBinary(self,bin):
self.scene.addItem(bin)
self.ui.bitmapView.setScene(self.scene)
self.ui.bitmapView.mapToScene(0,0)
+ QtCore.QObject.connect(self.bin.qobject,QtCore.SIGNAL("mouseOverLocation"),self.updateWithLocation)
def updateScene(self):
self.bin.rebuildImage()
@@ -98,4 +116,4 @@ def on_rowStrideBox_valueChanged(self,value):
mw = MainWindow()
mw.setVisible(1)
mw.setBinary(bm)
- app.exec_()
+ app.exec_()

0 comments on commit 2ce585e

Please sign in to comment.