From: <man...@us...> - 2008-09-21 20:16:06
|
Revision: 8260 http://openmsx.svn.sourceforge.net/openmsx/?rev=8260&view=rev Author: manuelbi Date: 2008-09-21 20:15:59 +0000 (Sun, 21 Sep 2008) Log Message: ----------- Added a basic save state manager Modified Paths: -------------- catapult/trunk/ChangeLog catapult/trunk/src/catapult.py Added Paths: ----------- catapult/trunk/res/savestatemanager.ui catapult/trunk/src/savestatemanager.py Modified: catapult/trunk/ChangeLog =================================================================== --- catapult/trunk/ChangeLog 2008-09-21 18:17:19 UTC (rev 8259) +++ catapult/trunk/ChangeLog 2008-09-21 20:15:59 UTC (rev 8260) @@ -2,7 +2,7 @@ 2008-09-21 Manuel Bilderbeek <ma...@ms...> * Added Quick Load and Quick Save of state in File dialog - * Next up: selection of save states (text only) + * Added basic save state manager (load, save, delete), text only 2008-06-24 David Heremans <dav...@gn...> * softwaredb can now correctly launch the software: Added: catapult/trunk/res/savestatemanager.ui =================================================================== --- catapult/trunk/res/savestatemanager.ui (rev 0) +++ catapult/trunk/res/savestatemanager.ui 2008-09-21 20:15:59 UTC (rev 8260) @@ -0,0 +1,122 @@ +<ui version="4.0" > + <class>saveStateManager</class> + <widget class="QDialog" name="saveStateManager" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>352</width> + <height>303</height> + </rect> + </property> + <property name="windowTitle" > + <string>Save State Manager</string> + </property> + <layout class="QGridLayout" name="gridLayout" > + <item row="1" column="0" > + <widget class="QListWidget" name="saveStateListWidget" > + <property name="editTriggers" > + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="showDropIndicator" stdset="0" > + <bool>false</bool> + </property> + <property name="alternatingRowColors" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="0" > + <widget class="QWidget" native="1" name="newFileWidget" > + <layout class="QHBoxLayout" name="horizontalLayout_2" > + <item> + <widget class="QLabel" name="label" > + <property name="text" > + <string>New file:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="newFileLineEdit" /> + </item> + </layout> + </widget> + </item> + <item row="3" column="0" > + <layout class="QHBoxLayout" name="horizontalLayout" > + <item> + <spacer name="horizontalSpacer" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="deleteStateButton" > + <property name="focusPolicy" > + <enum>Qt::ClickFocus</enum> + </property> + <property name="text" > + <string>Delete</string> + </property> + <property name="autoDefault" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="saveStateButton" > + <property name="enabled" > + <bool>true</bool> + </property> + <property name="text" > + <string>Save</string> + </property> + <property name="autoDefault" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="loadStateButton" > + <property name="text" > + <string>Load</string> + </property> + <property name="autoDefault" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="cancelButton" > + <property name="focusPolicy" > + <enum>Qt::StrongFocus</enum> + </property> + <property name="text" > + <string>Cancel</string> + </property> + <property name="autoExclusive" > + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + <item row="0" column="0" > + <widget class="QLabel" name="label_2" > + <property name="text" > + <string>Select a save state:</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> Modified: catapult/trunk/src/catapult.py =================================================================== --- catapult/trunk/src/catapult.py 2008-09-21 18:17:19 UTC (rev 8259) +++ catapult/trunk/src/catapult.py 2008-09-21 20:15:59 UTC (rev 8260) @@ -46,6 +46,7 @@ from trainerselect import TrainerSelect from softwaredb import SoftwareDB from autorun import Autorun +from savestatemanager import SaveStateManager from openmsx_control import ControlBridge, NotConfiguredException from paletteeditor import PaletteEditor from inputtext import InputText @@ -125,6 +126,7 @@ self.__autorun = Autorun(self, settingsManager, bridge) self.__paletteeditor = PaletteEditor(bridge) self.__inputtext = InputText(bridge) + self.__saveStateManager = SaveStateManager(bridge) self.__connectMenuActions(ui) bridge.logLine.connect(self.logLine) @@ -487,7 +489,9 @@ self.__bridge.command('save_settings', EscapedStr(tclEscape(settingsFile)))( None, - lambda message: self.__generalFailHandler(message, 'Problem Saving Settings') + lambda message: self.__generalFailHandler( + message, 'Problem Saving Settings' + ) ) def __loadSettings(self): @@ -504,7 +508,9 @@ 'set', 'renderer', '$__tmp' )( None, - lambda message: self.__generalFailHandler(message, 'Problem Loading Settings') + lambda message: self.__generalFailHandler( + message, 'Problem Loading Settings' + ) ) def __loadSettingsFailedHandler(self, message): @@ -517,20 +523,24 @@ def __quickLoadState(self): self.__bridge.command('loadstate')( None, - lambda message: self.__generalFailHandler(message, 'Problem Quick-Loading State') + lambda message: self.__generalFailHandler( + message, 'Problem Quick-Loading State' + ) ) def __quickSaveState(self): self.__bridge.command('savestate')( None, - lambda message: self.__generalFailHandler(message, 'Problem Quick-Saving State') + lambda message: self.__generalFailHandler( + message, 'Problem Quick-Saving State' + ) ) def __loadState(self): - pass # nothing yet + self.__saveStateManager.exec_('load') def __saveState(self): - pass # nothing yet + self.__saveStateManager.exec_('save') def __generalFailHandler(self, message, title): messageBox = QtGui.QMessageBox(title, message, Added: catapult/trunk/src/savestatemanager.py =================================================================== --- catapult/trunk/src/savestatemanager.py (rev 0) +++ catapult/trunk/src/savestatemanager.py 2008-09-21 20:15:59 UTC (rev 8260) @@ -0,0 +1,125 @@ +# $Id$ + +from PyQt4 import QtGui +from qt_utils import connect + +class SaveStateManager(object): + + def __init__(self, bridge): + self.__bridge = bridge + + self.__saveStateListWidget = None + self.__newFileLineEdit = None + self.__newFileWidget = None + self.__deleteStateButton = None + self.__saveStateButton = None + self.__loadStateButton = None + self.__cancelButton = None + + self.__saveStateDialog = dialog = QtGui.QDialog( + None # TODO: find a way to get the real parent + ) + + from ui_savestatemanager import Ui_saveStateManager + ui = Ui_saveStateManager() + ui.setupUi(dialog) + + self.__saveStateListWidget = ui.saveStateListWidget + self.__newFileLineEdit = ui.newFileLineEdit + self.__newFileWidget = ui.newFileWidget + self.__deleteStateButton = ui.deleteStateButton + self.__saveStateButton = ui.saveStateButton + self.__loadStateButton = ui.loadStateButton + self.__cancelButton = ui.cancelButton + + connect(self.__cancelButton, 'clicked()', lambda: dialog.reject()) + connect(self.__deleteStateButton, 'clicked()', self.__delete) + connect(self.__loadStateButton, 'clicked()', self.__load) + connect(self.__saveStateButton, 'clicked()', self.__save) + connect(self.__newFileLineEdit, 'returnPressed()', self.__save) + + def exec_(self, mode, parent = None): + dialog = self.__saveStateDialog + if mode == 'save': + self.__loadStateButton.setVisible(False) + self.__saveStateButton.setVisible(True) + self.__newFileWidget.setVisible(True) + self.__newFileWidget.setFocus() + dialog.setWindowTitle('Save State') + elif mode == 'load': + self.__loadStateButton.setVisible(True) + self.__saveStateButton.setVisible(False) + self.__newFileWidget.setVisible(False) + dialog.setWindowTitle('Load State') + else: + assert False, 'Invalid mode for dialog: ' + mode + + self.__newFileLineEdit.clear() + self.__refreshList() + + #dialog.setParent(parent) # why does this hang up the app? + return dialog.exec_() + + def __refreshList(self): + self.__bridge.command('list_savestates')( + lambda *reply: self.__fill(*reply), None + ) + + def __fill(self, *saveStateList): + self.__saveStateListWidget.clear() + for saveState in saveStateList: + self.__saveStateListWidget.addItem(saveState) + + def __delete(self): + currentItem = self.__saveStateListWidget.currentItem() + if currentItem == None: + return + selected = currentItem.text() + if selected == '': + return + self.__bridge.command('delete_savestate', + selected, + )( + lambda: self.__refreshList(), + lambda message: self.__generalFailHandler(message, 'Problem deleting state') + ) + + def __load(self): + self.__bridge.command('loadstate', + self.__saveStateListWidget.currentItem().text() + )( + lambda: self.__saveStateDialog.accept(), + lambda message: self.__generalFailHandler(message, 'Problem loading state') + ) + + def __save(self): + selected = self.__newFileLineEdit.text() + if selected == '': + currentItem = self.__saveStateListWidget.currentItem() + if currentItem == None: + return + selected = currentItem.text() + if selected == '': + return + reply = QtGui.QMessageBox.question( + self.__saveStateDialog, + 'Overwrite \"' + selected + '\"?', + '<p>Overwrite save state \"' + selected + '\".</p><p>Are you sure?</p>', + QtGui.QMessageBox.Yes, + QtGui.QMessageBox.Cancel) + if reply == QtGui.QMessageBox.Cancel: + return + self.__newFileLineEdit.clear() + self.__bridge.command('savestate', + selected + )( + lambda dummy: self.__refreshList(), + lambda message: self.__generalFailHandler(message, 'Problem saving state') + ) + + def __generalFailHandler(self, message, title): + messageBox = QtGui.QMessageBox(title, message, + QtGui.QMessageBox.Warning, 0, 0, 0, + self.__saveStateDialog + ) + messageBox.show() Property changes on: catapult/trunk/src/savestatemanager.py ___________________________________________________________________ Added: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |