Add Import/Export menu and commands, start to get them working (finally)
This commit is contained in:
parent
3ce14fd504
commit
d9236e697c
@ -13,6 +13,7 @@ from mcedit2.editorcommands.find_replace import FindReplaceDialog
|
|||||||
from mcedit2.editortools.select import SelectCommand
|
from mcedit2.editortools.select import SelectCommand
|
||||||
from mcedit2.panels.player import PlayerPanel
|
from mcedit2.panels.player import PlayerPanel
|
||||||
from mcedit2.util.dialogs import NotImplementedYet
|
from mcedit2.util.dialogs import NotImplementedYet
|
||||||
|
from mcedit2.util.directories import getUserSchematicsDirectory
|
||||||
from mcedit2.util.lazyprop import weakrefprop
|
from mcedit2.util.lazyprop import weakrefprop
|
||||||
from mcedit2.util.raycast import rayCastInBounds
|
from mcedit2.util.raycast import rayCastInBounds
|
||||||
from mcedit2.util.resources import resourcePath
|
from mcedit2.util.resources import resourcePath
|
||||||
@ -123,6 +124,8 @@ class EditorSession(QtCore.QObject):
|
|||||||
|
|
||||||
self.menus = []
|
self.menus = []
|
||||||
|
|
||||||
|
# - Edit -
|
||||||
|
|
||||||
self.menuEdit = QtGui.QMenu(self.tr("Edit"))
|
self.menuEdit = QtGui.QMenu(self.tr("Edit"))
|
||||||
self.menuEdit.setObjectName("menuEdit")
|
self.menuEdit.setObjectName("menuEdit")
|
||||||
|
|
||||||
@ -190,6 +193,8 @@ class EditorSession(QtCore.QObject):
|
|||||||
|
|
||||||
self.menus.append(self.menuEdit)
|
self.menus.append(self.menuEdit)
|
||||||
|
|
||||||
|
# - Select -
|
||||||
|
|
||||||
self.menuSelect = QtGui.QMenu(self.tr("Select"))
|
self.menuSelect = QtGui.QMenu(self.tr("Select"))
|
||||||
|
|
||||||
self.actionSelectAll = QtGui.QAction(self.tr("Select All"), self, triggered=self.selectAll)
|
self.actionSelectAll = QtGui.QAction(self.tr("Select All"), self, triggered=self.selectAll)
|
||||||
@ -202,6 +207,26 @@ class EditorSession(QtCore.QObject):
|
|||||||
|
|
||||||
self.menus.append(self.menuSelect)
|
self.menus.append(self.menuSelect)
|
||||||
|
|
||||||
|
# - Import/Export -
|
||||||
|
|
||||||
|
self.menuImportExport = QtGui.QMenu(self.tr("Import/Export"))
|
||||||
|
|
||||||
|
self.actionExport = QtGui.QAction(self.tr("Export"), self, triggered=self.export)
|
||||||
|
self.actionExport.setShortcut(QtGui.QKeySequence("Ctrl+Shift+E"))
|
||||||
|
self.menuImportExport.addAction(self.actionExport)
|
||||||
|
|
||||||
|
self.actionImport = QtGui.QAction(self.tr("Import"), self, triggered=self.import_)
|
||||||
|
self.actionImport.setShortcut(QtGui.QKeySequence("Ctrl+Shift+D"))
|
||||||
|
self.menuImportExport.addAction(self.actionImport)
|
||||||
|
|
||||||
|
self.actionImport = QtGui.QAction(self.tr("Show Exports Library"), self,
|
||||||
|
triggered=QtGui.qApp.libraryDockWidget.toggleViewAction().trigger)
|
||||||
|
|
||||||
|
self.actionImport.setShortcut(QtGui.QKeySequence("Ctrl+Shift+L"))
|
||||||
|
self.menuImportExport.addAction(self.actionImport)
|
||||||
|
|
||||||
|
self.menus.append(self.menuImportExport)
|
||||||
|
|
||||||
# --- Resources ---
|
# --- Resources ---
|
||||||
|
|
||||||
i, v, p = self.versionInfo
|
i, v, p = self.versionInfo
|
||||||
@ -299,6 +324,7 @@ class EditorSession(QtCore.QObject):
|
|||||||
self.actionDeleteBlocks.setEnabled(enable)
|
self.actionDeleteBlocks.setEnabled(enable)
|
||||||
self.actionDeleteEntities.setEnabled(enable)
|
self.actionDeleteEntities.setEnabled(enable)
|
||||||
self.actionFill.setEnabled(enable)
|
self.actionFill.setEnabled(enable)
|
||||||
|
self.actionExport.setEnabled(enable)
|
||||||
|
|
||||||
# --- Menu commands ---
|
# --- Menu commands ---
|
||||||
|
|
||||||
@ -378,6 +404,34 @@ class EditorSession(QtCore.QObject):
|
|||||||
command.setText(self.tr("Deselect"))
|
command.setText(self.tr("Deselect"))
|
||||||
self.pushCommand(command)
|
self.pushCommand(command)
|
||||||
|
|
||||||
|
# - Import/export -
|
||||||
|
|
||||||
|
def import_(self):
|
||||||
|
# prompt for a file to import
|
||||||
|
startingDir = Settings().value("import_dialog/starting_dir", getUserSchematicsDirectory())
|
||||||
|
result = QtGui.QFileDialog.getOpenFileName(self.mainWindow, self.tr("Import"),
|
||||||
|
startingDir,
|
||||||
|
"All files (*.*)")
|
||||||
|
if result:
|
||||||
|
filename = result[0]
|
||||||
|
if filename:
|
||||||
|
self.importSchematic(filename)
|
||||||
|
|
||||||
|
def export(self):
|
||||||
|
# prompt for filename and format. maybe use custom browser to save to export library??
|
||||||
|
startingDir = Settings().value("import_dialog/starting_dir", getUserSchematicsDirectory())
|
||||||
|
result = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.mainWindow,
|
||||||
|
self.tr("Export Schematic"),
|
||||||
|
startingDir,
|
||||||
|
"All files (*.*)")
|
||||||
|
|
||||||
|
if result:
|
||||||
|
filename = result[0]
|
||||||
|
if filename:
|
||||||
|
task = self.currentDimension.exportSchematicIter(self.currentSelection)
|
||||||
|
schematic = showProgress("Copying...", task)
|
||||||
|
schematic.saveToFile(filename)
|
||||||
|
|
||||||
# --- Library support ---
|
# --- Library support ---
|
||||||
|
|
||||||
def importSchematic(self, filename):
|
def importSchematic(self, filename):
|
||||||
|
@ -75,7 +75,7 @@ class MoveFinishCommand(SimpleRevisionCommand):
|
|||||||
def redo(self):
|
def redo(self):
|
||||||
super(MoveFinishCommand, self).redo()
|
super(MoveFinishCommand, self).redo()
|
||||||
self.previousSelection = self.editorSession.currentSelection
|
self.previousSelection = self.editorSession.currentSelection
|
||||||
self.editorSession.currentSelection = BoundingBox(self.pendingImport.pos, self.previousSelection.size)
|
self.editorSession.currentSelection = BoundingBox(self.pendingImport.pos, self.pendingImport.bounds.size)
|
||||||
self.moveTool.removePendingImport(self.pendingImport)
|
self.moveTool.removePendingImport(self.pendingImport)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from __future__ import absolute_import, division, print_function
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from PySide import QtGui, QtCore
|
from PySide import QtGui, QtCore
|
||||||
from mcedit2.util.directories import getUserFilesDirectory
|
from mcedit2.util.directories import getUserSchematicsDirectory
|
||||||
from mcedit2.widgets.layout import Column
|
from mcedit2.widgets.layout import Column
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -18,7 +18,7 @@ class LibraryWidget(QtGui.QWidget):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(LibraryWidget, self).__init__()
|
super(LibraryWidget, self).__init__()
|
||||||
|
|
||||||
self.folderPath = os.path.join(getUserFilesDirectory(), "schematics")
|
self.folderPath = getUserSchematicsDirectory()
|
||||||
if not os.path.exists(self.folderPath):
|
if not os.path.exists(self.folderPath):
|
||||||
os.makedirs(self.folderPath)
|
os.makedirs(self.folderPath)
|
||||||
|
|
||||||
|
@ -18,4 +18,5 @@ def getUserFilesDirectory():
|
|||||||
os.makedirs(dataDir)
|
os.makedirs(dataDir)
|
||||||
return dataDir
|
return dataDir
|
||||||
|
|
||||||
|
def getUserSchematicsDirectory():
|
||||||
|
return os.path.join(getUserFilesDirectory(), "schematics")
|
||||||
|
@ -301,6 +301,10 @@ class WorldEditor(object):
|
|||||||
self.playerCache.clear()
|
self.playerCache.clear()
|
||||||
self.adapter.saveChanges()
|
self.adapter.saveChanges()
|
||||||
|
|
||||||
|
def saveToFile(self, filename):
|
||||||
|
# XXXX only works with .schematics!!!
|
||||||
|
self.adapter.saveToFile(filename)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
Unload all chunks and close all open filehandles.
|
Unload all chunks and close all open filehandles.
|
||||||
|
Reference in New Issue
Block a user