Skip to content
Browse files

initial commit of rom explorer gui

  • Loading branch information...
1 parent 4cd50d9 commit 084020c51e37524e8d4984ef844525c57d439f3a @phooky committed Aug 10, 2012
Showing with 265 additions and 0 deletions.
  1. +73 −0 tools/mainwindow.py
  2. +99 −0 tools/mainwindow.ui
  3. +93 −0 tools/rom-explorer.py
View
73 tools/mainwindow.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'mainwindow.ui'
+#
+# Created: Wed Aug 8 09:44:45 2012
+# by: PyQt4 UI code generator 4.9.1
+#
+# WARNING! All changes made in this file will be lost!
+
+from PyQt4 import QtCore, QtGui
+
+try:
+ _fromUtf8 = QtCore.QString.fromUtf8
+except AttributeError:
+ _fromUtf8 = lambda s: s
+
+class Ui_MainWindow(object):
+ def setupUi(self, MainWindow):
+ MainWindow.setObjectName(_fromUtf8("MainWindow"))
+ MainWindow.resize(800, 600)
+ self.centralwidget = QtGui.QWidget(MainWindow)
+ self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
+ self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget)
+ self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
+ self.bitmapView = QtGui.QGraphicsView(self.centralwidget)
+ self.bitmapView.setObjectName(_fromUtf8("bitmapView"))
+ self.verticalLayout_2.addWidget(self.bitmapView)
+ self.horizontalLayout = QtGui.QHBoxLayout()
+ self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
+ self.label_2 = QtGui.QLabel(self.centralwidget)
+ self.label_2.setObjectName(_fromUtf8("label_2"))
+ self.horizontalLayout.addWidget(self.label_2)
+ self.bitDepthComboBox = QtGui.QComboBox(self.centralwidget)
+ self.bitDepthComboBox.setObjectName(_fromUtf8("bitDepthComboBox"))
+ self.bitDepthComboBox.addItem(_fromUtf8(""))
+ self.bitDepthComboBox.addItem(_fromUtf8(""))
+ self.bitDepthComboBox.addItem(_fromUtf8(""))
+ self.bitDepthComboBox.addItem(_fromUtf8(""))
+ self.bitDepthComboBox.addItem(_fromUtf8(""))
+ self.bitDepthComboBox.addItem(_fromUtf8(""))
+ self.horizontalLayout.addWidget(self.bitDepthComboBox)
+ self.label = QtGui.QLabel(self.centralwidget)
+ self.label.setObjectName(_fromUtf8("label"))
+ self.horizontalLayout.addWidget(self.label)
+ self.rowStrideBox = QtGui.QSpinBox(self.centralwidget)
+ self.rowStrideBox.setMinimum(1)
+ self.rowStrideBox.setMaximum(2096)
+ self.rowStrideBox.setObjectName(_fromUtf8("rowStrideBox"))
+ self.horizontalLayout.addWidget(self.rowStrideBox)
+ self.verticalLayout_2.addLayout(self.horizontalLayout)
+ MainWindow.setCentralWidget(self.centralwidget)
+ self.menubar = QtGui.QMenuBar(MainWindow)
+ self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 25))
+ self.menubar.setObjectName(_fromUtf8("menubar"))
+ MainWindow.setMenuBar(self.menubar)
+ self.statusbar = QtGui.QStatusBar(MainWindow)
+ self.statusbar.setObjectName(_fromUtf8("statusbar"))
+ MainWindow.setStatusBar(self.statusbar)
+
+ self.retranslateUi(MainWindow)
+ QtCore.QMetaObject.connectSlotsByName(MainWindow)
+
+ def retranslateUi(self, MainWindow):
+ MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "ROM Bitmap Explorer", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Bit Depth", None, QtGui.QApplication.UnicodeUTF8))
+ self.bitDepthComboBox.setItemText(0, QtGui.QApplication.translate("MainWindow", "1", None, QtGui.QApplication.UnicodeUTF8))
+ self.bitDepthComboBox.setItemText(1, QtGui.QApplication.translate("MainWindow", "2", None, QtGui.QApplication.UnicodeUTF8))
+ self.bitDepthComboBox.setItemText(2, QtGui.QApplication.translate("MainWindow", "4", None, QtGui.QApplication.UnicodeUTF8))
+ self.bitDepthComboBox.setItemText(3, QtGui.QApplication.translate("MainWindow", "8", None, QtGui.QApplication.UnicodeUTF8))
+ self.bitDepthComboBox.setItemText(4, QtGui.QApplication.translate("MainWindow", "16", None, QtGui.QApplication.UnicodeUTF8))
+ self.bitDepthComboBox.setItemText(5, QtGui.QApplication.translate("MainWindow", "24", None, QtGui.QApplication.UnicodeUTF8))
+ self.label.setText(QtGui.QApplication.translate("MainWindow", "Row Stride (bytes)", None, QtGui.QApplication.UnicodeUTF8))
+
View
99 tools/mainwindow.ui
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>ROM Bitmap Explorer</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QGraphicsView" name="bitmapView"/>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Bit Depth</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="bitDepthComboBox">
+ <item>
+ <property name="text">
+ <string>1</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>2</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>4</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>8</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>16</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>24</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Row Stride (bytes)</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="rowStrideBox">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>2096</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>25</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
View
93 tools/rom-explorer.py
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+
+from PyQt4 import QtCore, QtGui
+import sys
+import math
+import mainwindow
+import os.path
+
+# Depth: depth in bits
+# Width: width in bytes
+# Height: computed
+
+# Strips: # of strips (auto?)
+class BinMapper(QtGui.QGraphicsItem):
+ def __init__(self, path):
+ super(BinMapper,self).__init__()
+ f = open(path)
+ self.name = os.path.basename(path)
+ self.data = f.read()
+ self.size = len(self.data)
+ self.depth = 1
+ self.stride = 1
+ self.bigendian = 1
+ self.rebuildImage()
+
+ def rebuildImage(self):
+ width = self.stride * (8 / self.depth)
+ height = int(math.ceil(self.size / float(self.stride)))
+ self.img = QtGui.QImage(width,height,QtGui.QImage.Format_Mono)
+ byteidx = 0
+ try:
+ for y in range(height):
+ line = self.img.scanLine(y)
+ line.setsize(self.stride)
+ for x in range(self.stride):
+ line[x] = self.data[byteidx]
+ byteidx = byteidx + 1
+ except IndexError:
+ # zero out the rest of the image
+ pass
+
+ def paint(self, qpainter, qoptions, widget=None):
+ qpainter.drawImage(0,0,self.img)
+
+ def boundingRect(self):
+ width = self.stride * (8 / self.depth)
+ height = int(math.ceil(self.size / float(self.stride)))
+ return QtCore.QRectF(0,0,width, height)
+
+
+class MainWindow(QtGui.QMainWindow):
+ def __init__(self):
+ super(MainWindow, self).__init__()
+ self.ui = mainwindow.Ui_MainWindow()
+ self.ui.setupUi(self)
+
+ def setBinary(self,bin):
+ self.bin = bin
+ self.bin.depth = int(self.ui.bitDepthComboBox.currentText())
+ self.bin.stride = self.ui.rowStrideBox.value()
+ self.ui.statusbar.showMessage('Binary {0} loaded; total size {1}.'.format(bin.name, bin.size))
+ self.scene = QtGui.QGraphicsScene()
+ self.scene.addItem(bin)
+ self.ui.bitmapView.setScene(self.scene)
+ self.ui.bitmapView.mapToScene(0,0)
+
+ def updateScene(self):
+ self.bin.rebuildImage()
+ self.ui.bitmapView.scene().setSceneRect(self.bin.boundingRect())
+ self.ui.bitmapView.viewport().update()
+
+ #QtCore.pyqtSlot()
+ def on_bitDepthComboBox_currentIndexChanged(self,index):
+ self.bin.rebuildImage()
+ self.bin.depth = int(self.ui.bitDepthComboBox.currentText())
+ self.updateScene()
+
+ #QtCore.pyqtSlot()
+ def on_rowStrideBox_valueChanged(self,value):
+ self.bin.stride = self.ui.rowStrideBox.value()
+ self.updateScene()
+
+# Strategies for iterating through cut-up formats
+
+import cProfile
+
+if __name__ == '__main__':
+ app = QtGui.QApplication(sys.argv)
+ bm = BinMapper(sys.argv[1])
+ mw = MainWindow()
+ mw.setVisible(1)
+ mw.setBinary(bm)
+ app.exec_()

0 comments on commit 084020c

Please sign in to comment.
Something went wrong with that request. Please try again.