mirror of
https://github.com/mupen64plus/mupen64plus-ui-python.git
synced 2025-04-02 10:51:53 -04:00
state Load From/Save As
This commit is contained in:
parent
49ef352ea9
commit
b0cb5be057
6 changed files with 93 additions and 9 deletions
|
@ -411,19 +411,21 @@ class Core:
|
|||
log.warn(self.error_message(rval))
|
||||
return value_ptr.contents.value
|
||||
|
||||
def state_load(self):
|
||||
def state_load(self, state_path=None):
|
||||
"""Loads a saved state file from the current slot."""
|
||||
path = C.c_char_p(state_path) if state_path else None
|
||||
rval = self.m64p.CoreDoCommand(
|
||||
M64CMD_STATE_LOAD, C.c_int(1), None)
|
||||
M64CMD_STATE_LOAD, C.c_int(1), path)
|
||||
if rval != M64ERR_SUCCESS:
|
||||
log.debug("state_load()")
|
||||
log.warn(self.error_message(rval))
|
||||
return rval
|
||||
|
||||
def state_save(self):
|
||||
def state_save(self, state_path=None, state_type=1):
|
||||
"""Saves a state file to the current slot."""
|
||||
path = C.c_char_p(state_path) if state_path else None
|
||||
rval = self.m64p.CoreDoCommand(
|
||||
M64CMD_STATE_SAVE, C.c_int(1), None)
|
||||
M64CMD_STATE_SAVE, C.c_int(state_type), path)
|
||||
if rval != M64ERR_SUCCESS:
|
||||
log.debug("state_save()")
|
||||
log.warn(self.error_message(rval))
|
||||
|
|
|
@ -149,6 +149,16 @@ PLUGIN_DEFAULT = {
|
|||
M64PLUGIN_INPUT: "mupen64plus-input-sdl%s" % DLL_EXT
|
||||
}
|
||||
|
||||
M64SAV_M64P = 1
|
||||
M64SAV_PJ64C = 2
|
||||
M64SAV_PJ64 = 3
|
||||
|
||||
M64P_SAVES = {
|
||||
M64SAV_M64P: ("M64P (*.mp)", "mp"),
|
||||
M64SAV_PJ64C: ("PJ64 compressed (*.zip)", "zip"),
|
||||
M64SAV_PJ64: ("PJ64 (*.pj)", "pj")
|
||||
}
|
||||
|
||||
m64p_error = C.c_int
|
||||
m64p_GLattr = C.c_int
|
||||
|
||||
|
|
|
@ -268,6 +268,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
self.menuStateSlot.setEnabled(load)
|
||||
self.actionLoadState.setEnabled(action)
|
||||
self.actionSaveState.setEnabled(action)
|
||||
self.actionLoadFrom.setEnabled(action)
|
||||
self.actionSaveAs.setEnabled(action)
|
||||
self.actionSaveScreenshot.setEnabled(action)
|
||||
self.actionShowROMInfo.setEnabled(action)
|
||||
self.actionMute.setEnabled(action)
|
||||
|
@ -336,6 +338,36 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
"""Saves state."""
|
||||
self.worker.state_save()
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_actionLoadFrom_triggered(self):
|
||||
"""Loads state from file."""
|
||||
dialog = QFileDialog()
|
||||
dialog.setFileMode(QFileDialog.ExistingFile)
|
||||
file_path = dialog.getOpenFileName(
|
||||
self, "Load State From File",
|
||||
os.path.join(self.worker.m64p.config.get_path("UserData"), "save"),
|
||||
"M64P/PJ64 Saves (*.st* *.zip *.pj);;All files (*)")
|
||||
if file_path:
|
||||
self.worker.state_load(file_path)
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_actionSaveAs_triggered(self):
|
||||
"""Saves state to file."""
|
||||
dialog = QFileDialog()
|
||||
file_path, file_filter = dialog.getSaveFileNameAndFilter(
|
||||
self, "Save State To File",
|
||||
os.path.join(self.worker.m64p.config.get_path("UserData"), "save"),
|
||||
";;".join([save_filter for save_filter, save_ext in M64P_SAVES.values()]),
|
||||
M64P_SAVES[M64SAV_M64P][0])
|
||||
if file_path:
|
||||
for save_type, filters in M64P_SAVES.items():
|
||||
save_filter, save_ext = filters
|
||||
if file_filter == save_filter:
|
||||
if not file_path.endswith(save_ext):
|
||||
file_path = "%s.%s" % (file_path, save_ext)
|
||||
self.worker.state_save(file_path, save_type)
|
||||
|
||||
|
||||
@pyqtSignature("")
|
||||
def on_actionSaveScreenshot_triggered(self):
|
||||
"""Saves screenshot."""
|
||||
|
|
|
@ -199,13 +199,13 @@ class Worker(QThread):
|
|||
self.parent.emit(SIGNAL(
|
||||
"save_image(PyQt_PyObject)"), False)
|
||||
|
||||
def state_load(self):
|
||||
def state_load(self, state_path=None):
|
||||
"""Loads state."""
|
||||
self.m64p.state_load()
|
||||
self.m64p.state_load(state_path)
|
||||
|
||||
def state_save(self):
|
||||
def state_save(self, state_path=None, state_type=1):
|
||||
"""Saves state."""
|
||||
self.m64p.state_save()
|
||||
self.m64p.state_save(state_path, state_type)
|
||||
|
||||
def state_set_slot(self, slot):
|
||||
"""Sets save slot."""
|
||||
|
|
|
@ -79,6 +79,9 @@
|
|||
<addaction name="actionSaveState"/>
|
||||
<addaction name="menuStateSlot"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionLoadFrom"/>
|
||||
<addaction name="actionSaveAs"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSaveScreenshot"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionShowROMInfo"/>
|
||||
|
@ -549,6 +552,30 @@ QStatusBar { margin:0px; }</string>
|
|||
</property>
|
||||
</action>
|
||||
<action name="actionCustom"/>
|
||||
<action name="actionLoadFrom">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons.qrc">
|
||||
<normaloff>:/icons/action_state_load.png</normaloff>:/icons/action_state_load.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load From...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveAs">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="icons.qrc">
|
||||
<normaloff>:/icons/action_state_save.png</normaloff>:/icons/action_state_save.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save As...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="images.qrc"/>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Form implementation generated from reading ui file 'mainwindow.ui'
|
||||
#
|
||||
# Created: Wed Jun 5 09:01:17 2013
|
||||
# Created: Fri Jun 7 14:15:00 2013
|
||||
# by: PyQt4 UI code generator 4.10.1
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
@ -240,6 +240,14 @@ class Ui_MainWindow(object):
|
|||
self.actionCheats.setObjectName(_fromUtf8("actionCheats"))
|
||||
self.actionCustom = QtGui.QAction(MainWindow)
|
||||
self.actionCustom.setObjectName(_fromUtf8("actionCustom"))
|
||||
self.actionLoadFrom = QtGui.QAction(MainWindow)
|
||||
self.actionLoadFrom.setEnabled(False)
|
||||
self.actionLoadFrom.setIcon(icon8)
|
||||
self.actionLoadFrom.setObjectName(_fromUtf8("actionLoadFrom"))
|
||||
self.actionSaveAs = QtGui.QAction(MainWindow)
|
||||
self.actionSaveAs.setEnabled(False)
|
||||
self.actionSaveAs.setIcon(icon9)
|
||||
self.actionSaveAs.setObjectName(_fromUtf8("actionSaveAs"))
|
||||
self.menuLoad.addAction(self.actionManually)
|
||||
self.menuLoad.addAction(self.actionFromList)
|
||||
self.menuFile.addAction(self.menuLoad.menuAction())
|
||||
|
@ -249,6 +257,9 @@ class Ui_MainWindow(object):
|
|||
self.menuFile.addAction(self.actionSaveState)
|
||||
self.menuFile.addAction(self.menuStateSlot.menuAction())
|
||||
self.menuFile.addSeparator()
|
||||
self.menuFile.addAction(self.actionLoadFrom)
|
||||
self.menuFile.addAction(self.actionSaveAs)
|
||||
self.menuFile.addSeparator()
|
||||
self.menuFile.addAction(self.actionSaveScreenshot)
|
||||
self.menuFile.addSeparator()
|
||||
self.menuFile.addAction(self.actionShowROMInfo)
|
||||
|
@ -343,6 +354,8 @@ class Ui_MainWindow(object):
|
|||
self.actionSpeedUp.setShortcut(_translate("MainWindow", "F11", None))
|
||||
self.actionCheats.setText(_translate("MainWindow", "Cheats...", None))
|
||||
self.actionCheats.setShortcut(_translate("MainWindow", "F2", None))
|
||||
self.actionLoadFrom.setText(_translate("MainWindow", "Load From...", None))
|
||||
self.actionSaveAs.setText(_translate("MainWindow", "Save As...", None))
|
||||
|
||||
import images_rc
|
||||
import icons_rc
|
||||
|
|
Loading…
Add table
Reference in a new issue