From: <dav...@us...> - 2007-05-23 06:06:05
|
Revision: 7256 http://armagetronad.svn.sourceforge.net/armagetronad/?rev=7256&view=rev Author: davidfancella Date: 2007-05-22 23:06:05 -0700 (Tue, 22 May 2007) Log Message: ----------- Lots of work to support adding new resource editors easily. Modified Paths: -------------- tools/acme/trunk/libacmegui/editors/genericEditor.py tools/acme/trunk/libacmegui/editors/mapEditor.py tools/acme/trunk/libacmegui/mainqt.py tools/acme/trunk/libacmegui/toolView.py Added Paths: ----------- tools/acme/trunk/libacmegui/editors/editorbase.py Added: tools/acme/trunk/libacmegui/editors/editorbase.py =================================================================== --- tools/acme/trunk/libacmegui/editors/editorbase.py (rev 0) +++ tools/acme/trunk/libacmegui/editors/editorbase.py 2007-05-23 06:06:05 UTC (rev 7256) @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +''' + + @version $Id: __init__.py 7231 2007-05-20 22:53:21Z davidfancella $ + + This file is part of acme. + + acme is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + acme is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with acme; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + acme is copyright 2005, 2007 by David Fancella + +''' + +from PyQt4 import QtGui + +lastid = 0 + +class EditorBase(object): + toolBoxParent = None + __id = None + + def __init__(self, toolBoxParent): + self.toolBoxParent = toolBoxParent + global lastid + lastid += 1 + self.__id = lastid + + def id(self): + return self.__id + + def idstr(self): + return str(self.__id) + + def LoadResource(self, thePath): + print "EditorBase: LoadResource not implemented yet" + + def NewResource(self): + print "EditorBase: NewResource not implemented yet" + + def GetActions(self): + print "EditorBase: GetActions not implemented yet" + return None + + def GetToolBox(self): + print "EditorBase: GetToolBox not implemented yet" + return QtGui.QWidget(self.toolBoxParent) + + Modified: tools/acme/trunk/libacmegui/editors/genericEditor.py =================================================================== --- tools/acme/trunk/libacmegui/editors/genericEditor.py 2007-05-23 04:14:05 UTC (rev 7255) +++ tools/acme/trunk/libacmegui/editors/genericEditor.py 2007-05-23 06:06:05 UTC (rev 7256) @@ -26,9 +26,12 @@ from PyQt4 import QtGui, QtCore -class genericEditor(QtGui.QTextEdit): - def __init__(self, parent): +from libacmegui.editors import editorbase + +class genericEditor(QtGui.QTextEdit, editorbase.EditorBase): + def __init__(self, parent, toolboxparent): QtGui.QTextEdit.__init__(self, parent) + editorbase.EditorBase.__init__(self, toolboxparent) def LoadResource(self, theResource): theText = QtGui.QTextDocument(theResource.theDom.toxml(), self) Modified: tools/acme/trunk/libacmegui/editors/mapEditor.py =================================================================== --- tools/acme/trunk/libacmegui/editors/mapEditor.py 2007-05-23 04:14:05 UTC (rev 7255) +++ tools/acme/trunk/libacmegui/editors/mapEditor.py 2007-05-23 06:06:05 UTC (rev 7256) @@ -27,7 +27,9 @@ from PyQt4 import QtGui, QtCore from libacme import map +from libacme import paths +from libacmegui.editors import editorbase from libacmegui.editors.mapwidgets import wall from libacmegui.editors.mapwidgets import spawn from libacmegui.editors.mapwidgets import zone @@ -64,9 +66,10 @@ #self.snapPointer.update() QtGui.QGraphicsScene.mouseMoveEvent(self, eve) -class mapView(QtGui.QGraphicsView): - def __init__(self, parent): +class mapView(QtGui.QGraphicsView, editorbase.EditorBase): + def __init__(self, parent, toolboxparent): QtGui.QGraphicsView.__init__(self, parent) + editorbase.EditorBase.__init__(self, toolboxparent) self.setCursor(QtCore.Qt.CrossCursor) #self.setViewportMargins(3,3,3,3) @@ -86,10 +89,34 @@ self.scaleFactor = 1 QtCore.QObject.connect(self.mapScene, QtCore.SIGNAL("changed(const QList<QRectF>&)"), self.updateSceneP) + self._createActions() + + def _createActions(self): + self.actionList = { 'name' : 'Map', + 'actions' : QtGui.QActionGroup(self) } + + tmpAction = QtGui.QAction( QtGui.QIcon(QtGui.QPixmap( paths.GetPath('icons', 'walls.png') ) ), "Add Wall", self.actionList['actions']) + QtCore.QObject.connect(tmpAction, QtCore.SIGNAL("triggered(bool)"), self.notImpl) + self.actionList['actions'].addAction(tmpAction) + + tmpAction = QtGui.QAction( QtGui.QIcon(QtGui.QPixmap( paths.GetIcon('spawn.png') ) ), "Add Spawn", self.actionList['actions']) + QtCore.QObject.connect(tmpAction, QtCore.SIGNAL("triggered(bool)"), self.notImpl) + self.actionList['actions'].addAction(tmpAction) + + tmpAction = QtGui.QAction( QtGui.QIcon(QtGui.QPixmap( paths.GetIcon('editcut.png') ) ), "Slash", self.actionList['actions']) + QtCore.QObject.connect(tmpAction, QtCore.SIGNAL("triggered(bool)"), self.notImpl) + self.actionList['actions'].addAction(tmpAction) + + def GetActions(self): + return self.actionList + + def notImpl(self): + print "This feature not yet implemented, whatever it is" + def updateSceneP(self, theRect): self.updateScene(theRect) - def LoadMap(self, theMap): + def LoadResource(self, theMap): self.theMap = map.aaMap(theMap) QtCore.QObject.disconnect(self.mapScene, QtCore.SIGNAL("changed(const QList<QRectF>&)"), self.updateSceneP) Modified: tools/acme/trunk/libacmegui/mainqt.py =================================================================== --- tools/acme/trunk/libacmegui/mainqt.py 2007-05-23 04:14:05 UTC (rev 7255) +++ tools/acme/trunk/libacmegui/mainqt.py 2007-05-23 06:06:05 UTC (rev 7256) @@ -53,6 +53,8 @@ self.panel = panel class mainView(QtGui.QWidget): + editorList = None + def __init__(self, args): QtGui.QWidget.__init__(self, args) @@ -63,27 +65,54 @@ self.splitter1.setContentsMargins(0,0,0,0) self.mainEditor = toolView.ToolBook(self.splitter1) - self.toolBox = QtGui.QWidget(self.splitter1) + self.toolBox = QtGui.QStackedWidget(self.splitter1) editorLayout.addWidget(self.splitter1) self.splitter1.setStretchFactor(0, 2) self.splitter1.setStretchFactor(1, 1) + + self.editorList = {} + self.NewEditor(genericEditor.genericEditor) + + self._connectSlots() + + def _connectSlots(self): + QtCore.QObject.connect( self.mainEditor, QtCore.SIGNAL("editorSelected"), self.SelectEditor) + + def SelectEditor(self, theEditor): + self.toolBox.setCurrentWidget( self.editorList[theEditor.idstr()]['toolbox'] ) + self.parent().SetEditorActions( self.editorList[theEditor.idstr()]['actions'] ) + + def NewEditor(self, editorType): + anEditor = editorType(self, self.toolBox) + anEditor.NewResource() + self.mainEditor.addTab(anEditor, "<unnamed>" ) + + theToolBox = anEditor.GetToolBox() + self.toolBox.addWidget(theToolBox) + + theActionList = anEditor.GetActions() + + self.editorList[anEditor.idstr()] = { 'editor' : anEditor, + 'toolbox' : theToolBox, + 'actions' : theActionList } + + self.mainEditor.setCurrentWidget(anEditor) + + QtCore.QObject.connect( anEditor, QtCore.SIGNAL("mouseHover"), self.mouseHover) + + return anEditor + def LoadResource(self, theResourcePath): theResource = resource_parser.LoadResource(theResourcePath) if theResource.GetType() == "aamap": - aMapEditor = mapEditor.mapView(self) - aMapEditor.LoadMap(theResource) - self.mainEditor.addTab(aMapEditor, theResource.GetName() ) - self.mainEditor.setCurrentWidget(aMapEditor) - QtCore.QObject.connect( aMapEditor, QtCore.SIGNAL("mouseHover"), self.mouseHover) + anEditor = self.NewEditor(mapEditor.mapView) else: - anEditor = genericEditor.genericEditor(self) - anEditor.LoadResource(theResource) - self.mainEditor.addTab(anEditor, theResource.GetName() ) - self.mainEditor.setCurrentWidget(anEditor) - QtCore.QObject.connect( anEditor, QtCore.SIGNAL("mouseHover"), self.mouseHover) + anEditor = self.NewEditor(genericEditor.genericEditor) + anEditor.LoadResource(theResource) + self.mainEditor.setTabText(self.mainEditor.indexOf(anEditor), theResource.GetName() ) def mouseHover(self, eve): self.emit(QtCore.SIGNAL("mouseHover"), eve) @@ -104,6 +133,7 @@ self._connectSlots() self._createFileActions() self._createMenus() + self._createToolbars() self._createStatusBar() self.setWindowIcon( QtGui.QIcon( paths.GetPath('icons', "armagetronad.png") ) ) @@ -137,21 +167,15 @@ # for stuff Qt Designer doesn't handle def _createToolbars(self): - '''self.theFileToolbar = QtGui.QToolBar() + self.theFileToolbar = QtGui.QToolBar() self.theFileToolbar.setIconSize( QtCore.QSize(32,32) ) self.theFileToolbar.addActions(self.fileActions.actions() ) self.addToolBar(self.theFileToolbar) - self.templateToolbar = QtGui.QToolBar() - self.templateToolbar.setIconSize( QtCore.QSize(32,32) ) - self.templateBox = QtGui.QComboBox(self.templateToolbar) - self.templateModel = templatemodel.TemplateModel(self.templateBox, "./") - self.templateBox.setModel(self.templateModel) - self.templateToolbar.addWidget(self.templateBox) - QtCore.QObject.connect(self.templateBox, QtCore.SIGNAL("activated(const QString&)"), self.templateSelected) - self.addToolBar(self.templateToolbar) - ''' - pass + self.editorToolbar = QtGui.QToolBar() + self.editorToolbar.setIconSize( QtCore.QSize(32,32) ) + self.addToolBar(self.editorToolbar) + self.editorToolbar.hide() def _createMenus(self): self.theFileMenu = QtGui.QMenu("&File") @@ -169,6 +193,14 @@ def quit(self): QtGui.QApplication.quit() + def SetEditorActions(self, theActions): + if theActions is not None: + self.editorToolbar.clear() + self.editorToolbar.addActions(theActions['actions'].actions() ) + self.editorToolbar.show() + else: + self.editorToolbar.hide() + def fileNew(self): pass Modified: tools/acme/trunk/libacmegui/toolView.py =================================================================== --- tools/acme/trunk/libacmegui/toolView.py 2007-05-23 04:14:05 UTC (rev 7255) +++ tools/acme/trunk/libacmegui/toolView.py 2007-05-23 06:06:05 UTC (rev 7256) @@ -43,8 +43,14 @@ self._connectSlots() def _connectSlots(self): - pass + QtCore.QObject.connect(self.closeTab, QtCore.SIGNAL("clicked(bool)"), self.closeTabClick) + QtCore.QObject.connect(self, QtCore.SIGNAL("currentChanged(int)"), self.editorChanged) + def closeTabClick(self, status): + print "Close tab button clicked" + + def editorChanged(self, index): + self.emit( QtCore.SIGNAL("editorSelected"), self.widget(index) ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |