summaryrefslogtreecommitdiff
path: root/src/ui.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ui.py106
1 files changed, 56 insertions, 50 deletions
diff --git a/src/ui.py b/src/ui.py
index 96e2ceb..9536206 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -3,8 +3,6 @@ from editorui import *
class KPLayerList(QtGui.QWidget):
-
-
def __init__(self):
QtGui.QWidget.__init__(self)
@@ -23,20 +21,20 @@ class KPLayerList(QtGui.QWidget):
self.setupToolbar(self.toolbar)
self.setLayout(self.layout)
-
+
def setupToolbar(self, tb):
tb.addAction(QtGui.QIcon(), 'Add', self.addLayer)
tb.addAction(QtGui.QIcon(), 'Remove', self.removeLayer)
tb.addAction(QtGui.QIcon(), 'Move Up', self.moveUp)
tb.addAction(QtGui.QIcon(), 'Move Down', self.moveDown)
-
+
def selectedLayerIndex(self):
return self.listView.selectionModel().currentIndex().row()
def selectedLayer(self):
return KP.map.layers[self.listView.selectionModel().currentIndex().row()]
-
+
def addLayer(self):
KP.map.appendLayer(KP.map.createNewLayer())
@@ -58,27 +56,26 @@ class KPLayerList(QtGui.QWidget):
class KPObjectSelector(QtGui.QListView):
-
def __init__(self):
"""Initialises the widget. Remember to call setModel() on it with a KPGroupModel
whenever the layer changes."""
-
+
QtGui.QListView.__init__(self)
self.setFlow(QtGui.QListView.LeftToRight)
self.setLayoutMode(QtGui.QListView.SinglePass)
self.setMovement(QtGui.QListView.Static)
self.setResizeMode(QtGui.QListView.Adjust)
self.setWrapping(True)
-
+
# self.setItemDelegate(KPObjectSelector.ObjectItemDelegate())
# Borrowed the signals and junk from Reggie, figure we'll need em'
- self.clicked.connect(self.HandleObjReplace)
-
-
+ self.clicked.connect(self.handleObjReplace)
+
+
def toggleTopLevel(self, id):
"""Changes the top level group in the list view."""
-
+
# Not quite sure how to implement this yet. Basically, the model is hierarchal,
# and it'll return items from whatever the top level KPGroupItem is. But removing
# and adding stuff isn't possible, since I need to retain my recursive object.
@@ -90,47 +87,47 @@ class KPObjectSelector(QtGui.QListView):
# even though all rows are retained.
#
# It's kind of like a custom QSortFilterProxyModel. Maybe I should subclass that.
-
+
self.setCurrentIndex(self.model().index(sel, 0, QtCore.QModelIndex()))
-
+
@QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex)
def currentChanged(self, current, previous):
"""Throws a signal when the selected object changed"""
- self.ObjChanged.emit(current.row())
-
- def HandleObjReplace(self, index):
+ self.objChanged.emit(current.row())
+
+ def handleObjReplace(self, index):
"""Throws a signal when the selected object is used as a replacement"""
if QtGui.QApplication.keyboardModifiers() == QtCore.Qt.AltModifier:
- self.ObjReplace.emit(index.row())
-
- ObjChanged = QtCore.pyqtSignal(int)
- ObjReplace = QtCore.pyqtSignal(int)
-
-
+ self.objReplaced.emit(index.row())
+
+ objChanged = QtCore.pyqtSignal(int)
+ objReplaced = QtCore.pyqtSignal(int)
+
+
class KPGroupItemDelegate(QtGui.QAbstractItemDelegate):
- """Handles tileset groups, objects and their rendering"""
-
- def __init__(self):
- """Initialises the delegate"""
- QtGui.QAbstractItemDelegate.__init__(self)
-
- def paint(self, painter, option, index):
- """Paints an object"""
- if option.state & QtGui.QStyle.State_Selected:
- painter.fillRect(option.rect, option.palette.highlight())
-
- p = index.model().data(index, QtCore.Qt.DecorationRole)
- painter.drawPixmap(option.rect.x()+2, option.rect.y()+2, p)
- #painter.drawText(option.rect, str(index.row()))
-
- def sizeHint(self, option, index):
- """Returns the size for the object"""
- p = index.model().data(index, QtCore.Qt.UserRole)
- return p
+ """Handles tileset groups, objects and their rendering"""
+
+ def __init__(self):
+ """Initialises the delegate"""
+ QtGui.QAbstractItemDelegate.__init__(self)
+
+ def paint(self, painter, option, index):
+ """Paints an object"""
+ if option.state & QtGui.QStyle.State_Selected:
+ painter.fillRect(option.rect, option.palette.highlight())
+
+ p = index.model().data(index, QtCore.Qt.DecorationRole)
+ painter.drawPixmap(option.rect.x()+2, option.rect.y()+2, p)
+ #painter.drawText(option.rect, str(index.row()))
+
+ def sizeHint(self, option, index):
+ """Returns the size for the object"""
+ p = index.model().data(index, QtCore.Qt.UserRole)
+ return p
+
+
-
-
@@ -147,27 +144,36 @@ class KPMainWindow(QtGui.QMainWindow):
self.setupMenuBar()
self.setupDocks()
-
+
def setupMenuBar(self):
mb = self.menuBar()
m = mb.addMenu('&File')
# ...
-
+
def setupDocks(self):
self.layerList = KPLayerList()
self.layerListDock = QtGui.QDockWidget('Layers')
self.layerListDock.setWidget(self.layerList)
- # self.objectSelector = KPObjectSelector()
- # # self.objectSelector.setModel(SomeTileset.getModel())
- # self.objectSelectorDock = QtGui.QDockWidget('Layers')
- # self.objectSelectorDock.setWidget(self.layerList)
+ self.objectSelector = KPObjectSelector()
+ # TODO: refactor this, this is just a bit of a hack for now
+ from wii.u8archive import WiiArchiveU8
+ arc = WiiArchiveU8(open('/home/me/Dropbox/NEWERsmbw/Test2.arc', 'rb'))
+ img = arc.resolvePath('/BG_tex/Test2_tex.bin').data
+ obj = arc.resolvePath('/BG_unt/Test2.bin').data
+ objm = arc.resolvePath('/BG_unt/Test2_hd.bin').data
+ grp = arc.resolvePath('/BG_grp/Test2_grp.bin').data
+ TestTileset = KPTileset(img, obj, objm, grp)
+ self.objectSelector.setModel(TestTileset.getModel())
+ self.objectSelectorDock = QtGui.QDockWidget('Objects')
+ self.objectSelectorDock.setWidget(self.objectSelector)
self.addDockWidget(Qt.RightDockWidgetArea, self.layerListDock)
+ self.addDockWidget(Qt.RightDockWidgetArea, self.objectSelectorDock)