def __init__(self, argv): super(MCEditApp, self).__init__(argv) MCEditApp.app = self minecraftinstall.GetInstalls().ensureValidInstall() self.ensureSingle() self.commandLineWorlds = [] self.parseArgs(argv) log.warn("UserFilesDirectory: %s", getUserFilesDirectory()) # --- Necessities --- translator = QtCore.QTranslator() translator.load(resourcePath('mcedit2/i18n/en_US.ts')) self.installTranslator(translator) log.info("Loaded translator.") self.setOrganizationName("MCEdit") self.setOrganizationDomain("mcedit.net") self.setApplicationName("MCEdit") self.setWindowIcon( QtGui.QIcon(resourcePath("mcedit2/assets/mcedit2/mcediticon.png"))) styleSheet = file(resourcePath("mcedit2/styles/mcedit2.qcss")).read() self.setStyleSheet(styleSheet) log.info("Loaded stylesheet.") # --- Main Window --- self.mainWindow = mainWindow = MCEditMainWindow() self.undoGroup = QtGui.QUndoGroup() self.tabWidget = self.mainWindow.tabWidget self.tabWidget.tabCloseRequested.connect(self.tabCloseRequested) self.tabWidget.currentChanged.connect(self.tabChanged) log.info("Loaded main window.") # --- OpenGL --- setDefaultFormat() # --- Sessions --- self._currentSession = None self.sessions = [] self.sessionDockWidgets = [] self.sessionChanged.connect(self.sessionDidChange) # --- Panel Widgets --- self.undoView = QtGui.QUndoView(self.undoGroup) self.undoDockWidget = QtGui.QDockWidget("History", mainWindow, objectName="HistoryWidget") self.undoDockWidget.setWidget(self.undoView) mainWindow.addDockWidget(Qt.RightDockWidgetArea, self.undoDockWidget) mainWindow.panelsToolBar.addAction( self.undoDockWidget.toggleViewAction()) self.undoDockWidget.close() self.logViewWidget = LogViewFrame(mainWindow) self.logViewDockWidget = QtGui.QDockWidget("Error Log", mainWindow, objectName="ErrorsWidget") self.logViewDockWidget.setWidget(self.logViewWidget) mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self.logViewDockWidget) mainWindow.panelsToolBar.addAction( self.logViewDockWidget.toggleViewAction()) self.logViewDockWidget.close() self.libraryView = LibraryWidget() self.libraryDockWidget = QtGui.QDockWidget("Library", mainWindow, objectName="LibraryWidget") self.libraryDockWidget.setWidget(self.libraryView) mainWindow.addDockWidget(Qt.RightDockWidgetArea, self.libraryDockWidget) mainWindow.panelsToolBar.addAction( self.libraryDockWidget.toggleViewAction()) self.libraryDockWidget.close() self.libraryView.doubleClicked.connect(self.libraryItemDoubleClicked) self.globalPanels = [ self.undoDockWidget, self.logViewDockWidget, self.libraryDockWidget ] log.info("Loaded panels.") # --- Debug Widgets --- self.debugMenu = self.createDebugMenu() self.debugObjectInspector = ObjectInspector(mainWindow) self.inspectorDockWidget = QtGui.QDockWidget( "Inspector", mainWindow, objectName="InspectorWidget") self.inspectorDockWidget.setWidget(self.debugObjectInspector) self.debugMenu.addAction(self.inspectorDockWidget.toggleViewAction()) self.inspectorDockWidget.close() self.profileView = ProfilerWidget() self.profileDockWidget = QtGui.QDockWidget("Profiler", mainWindow, objectName="ProfilerWidget") self.profileDockWidget.setWidget(self.profileView) self.debugMenu.addAction(self.profileDockWidget.toggleViewAction()) self.profileDockWidget.close() self.textureAtlasView = QtGui.QLabel() self.textureAtlasView.setScaledContents(True) self.textureAtlasDockWidget = QtGui.QDockWidget( "Texture Atlas", mainWindow, objectName="TextureAtlasWidget") self.textureAtlasArea = QtGui.QScrollArea() self.textureAtlasArea.setWidget(self.textureAtlasView) self.textureAtlasDockWidget.setWidget(self.textureAtlasArea) self.debugMenu.addAction( self.textureAtlasDockWidget.toggleViewAction()) self.textureAtlasDockWidget.close() infoTabs = QtGui.QTabWidget() self.cursorInfo = WorldCursorInfo() infoTabs.addTab(self.cursorInfo, "Cursor") self.viewInfo = WorldViewInfo() infoTabs.addTab(self.viewInfo, "View") self.loaderInfo = ChunkLoaderInfo() infoTabs.addTab(self.loaderInfo, "Loader") self.infoDockWidget = QtGui.QDockWidget("Debug Info", mainWindow, objectName="DebugInfo") self.infoDockWidget.setWidget(infoTabs) self.infoDockWidget.close() log.info("Loaded debug widgets.") # --- Menu Actions --- # -- MCEdit menu -- mainWindow.actionNew_World.triggered.connect(self.createNewWorld) mainWindow.actionNew_World.setShortcut(QtGui.QKeySequence.New) mainWindow.actionOpen_World.triggered.connect(self.chooseOpenWorld) mainWindow.actionOpen_World.setShortcut(QtGui.QKeySequence.Open) mainWindow.actionShow_World_List.triggered.connect(self.showWorldList) mainWindow.actionShow_World_List.setShortcut( QtGui.QKeySequence("Ctrl+L")) mainWindow.actionSave_World.triggered.connect(self.saveCurrentWorld) mainWindow.actionSave_World.setShortcut(QtGui.QKeySequence.Save) mainWindow.actionSave_World_As.triggered.connect( self.saveCurrentWorldAs) mainWindow.actionSave_World_As.setShortcut(QtGui.QKeySequence.SaveAs) mainWindow.actionClose_World.triggered.connect(self.closeCurrentTab) mainWindow.actionClose_World.setShortcut(QtGui.QKeySequence.Close) mainWindow.actionExit_MCEdit.triggered.connect(self.exitEditor) mainWindow.actionExit_MCEdit.setShortcut(QtGui.QKeySequence.Quit) # -- Help menu -- mainWindow.actionAbout_MCEdit.triggered.connect(self.showAbout) mainWindow.actionAbout_MCEdit.setShortcut(QtGui.QKeySequence.Quit) # -- Window Menu -- mainWindow.menuWindow.addAction(self.undoDockWidget.toggleViewAction()) mainWindow.menuWindow.addAction( self.logViewDockWidget.toggleViewAction()) mainWindow.menuWindow.addAction( self.libraryDockWidget.toggleViewAction()) # -- Options Menu -- mainWindow.actionEnable_Lighting_Updates.setChecked( EnableLightingSetting.value()) mainWindow.actionEnable_Lighting_Updates.toggled.connect( EnableLightingSetting.setValue) EnableLightingSetting.valueChanged.connect(self.enableLightingChanged) self.enableLightingChanged(EnableLightingSetting.value()) mainWindow.actionPreferences.triggered.connect(self.showPrefsDialog) mainWindow.actionConfigure_Blocks_Items.triggered.connect( self.showConfigureBlocksDialog) mainWindow.actionPlugins.triggered.connect(self.showPluginsDialog) mainWindow.actionEnable_Developer_Mode.setChecked( DevModeSetting.value()) mainWindow.actionEnable_Developer_Mode.toggled.connect( DevModeSetting.setValue) DevModeSetting.valueChanged.connect(self.toggleDeveloperMode) self.toggleDeveloperMode(DevModeSetting.value()) log.info("Loaded menus.") # --- World List --- self.worldList = WorldListWidget(mainWindow) self.worldList.editWorldClicked.connect(self.editWorldFromList) self.worldList.viewWorldClicked.connect(self.viewWorldFromList) self.worldList.backupWorldClicked.connect(self.backupWorldFromList) self.worldList.repairWorldClicked.connect(self.repairWorldFromList) log.info("Loaded world list.") # --- Status Bar --- self.positionLabel = QtGui.QLabel("xx, yy, zz", minimumWidth=100) self.biomeLabel = QtGui.QLabel("Nowhere", minimumWidth=100) self.blocktypeLabel = QtGui.QLabel("(-1:-1)minecraft:rocktonium", minimumWidth=250) self.blockNameLabel = QtGui.QLabel("rocktonium", minimumWidth=150) self.cpsLabel = QtGui.QLabel("-1 cps", minimumWidth=65) self.fpsLabel = QtGui.QLabel("-1 fps", minimumWidth=65) statusBar = mainWindow.statusBar() statusBar.addPermanentWidget(self.positionLabel) statusBar.addPermanentWidget(self.biomeLabel) statusBar.addPermanentWidget(self.blocktypeLabel) statusBar.addPermanentWidget(self.blockNameLabel) statusBar.addPermanentWidget(self.cpsLabel) statusBar.addPermanentWidget(self.fpsLabel) log.info("Loaded status bar.") # --- Load settings --- mainWindow.loadSettings() self.updateRecentFilesMenu() log.info("Loaded settings.") # --- App Dialogs --- self.prefsDialog = prefsdialog.PrefsDialog(None) self.configureBlocksDialog = configureblocksdialog.ConfigureBlocksDialog( None) self.configureBlocksDialog.finished.connect( self.configureBlocksFinished) # Qt weirdness - initializing QDialog with parent puts the dialog at 0,0 instead of # centering it on the parent. Have to set the parent explicitly and put the Qt.Dialog flag back on # since changing the parent resets the window flags... self.prefsDialog.setParent(mainWindow) self.prefsDialog.setWindowFlags(Qt.Dialog) self.configureBlocksDialog.setParent(mainWindow) self.configureBlocksDialog.setWindowFlags(Qt.Dialog) self.pluginsDialog = PluginsDialog() self.pluginsDialog.setParent(mainWindow) self.pluginsDialog.setWindowFlags(Qt.Dialog) log.info("Loaded app dialogs.") # --- Loader timer --- self.loadTimer = timer = LoaderTimer(self) timer.setInterval(0) timer.timeout.connect(self.loadTimerFired) timer.start() log.info("Loading timer started") mainWindow.showMaximized() QtCore.QTimer.singleShot(0, self.didFinishLaunching)
def __init__(self, argv): super(MCEditApp, self).__init__(argv) MCEditApp.app = self self.ensureSingle() self.commandLineWorlds = [] self.parseArgs(argv) log.warn("UserFilesDirectory: %s", getUserFilesDirectory()) # --- Translations --- self.transDir = resourcePath('mcedit2/i18n') self.transLangs = [ f[:-3] for f in os.listdir(self.transDir) if f.endswith(".qm") ] lang = LangSetting.value() langFile = self.findLangFile(lang) if langFile is None: systemLocale = QtCore.QLocale.system() lang = systemLocale.name() # "en_US" langFile = self.findLangFile(lang) if langFile is None: lang = "en" langFile = os.path.join(self.transDir, "en.qm") chosenLang = lang self.translator = QtCore.QTranslator() self.translator.load(langFile) self.installTranslator(self.translator) log.info("Loaded translator. Selected language: %s", lang) self.translationsMenu = QtGui.QMenu() self.translationsMenu.setTitle(self.tr("Language")) self.langActions = [] for lang in self.transLangs: locale = QtCore.QLocale(lang) language = locale.nativeLanguageName().title() or lang if lang == "pr": language = "Pirate" langAction = self.translationsMenu.addAction(language) langAction.setData(lang) langAction.setCheckable(True) if lang == chosenLang: langAction.setChecked(True) self.langActions.append(langAction) self.translationsMenu.triggered.connect(self.changeLanguage) # --- Necessities --- self.setOrganizationName("MCEdit") self.setOrganizationDomain("mcedit.net") self.setApplicationName("MCEdit") self.setWindowIcon( QtGui.QIcon(resourcePath("mcedit2/assets/mcedit2/mcediticon.png"))) styleSheet = file(resourcePath("mcedit2/styles/mcedit2.qcss")).read() self.setStyleSheet(styleSheet) log.info("Loaded stylesheet.") # --- Main Window --- self.mainWindow = mainWindow = MCEditMainWindow() self.undoGroup = QtGui.QUndoGroup() self.tabWidget = self.mainWindow.tabWidget self.tabWidget.tabCloseRequested.connect(self.tabCloseRequested) self.tabWidget.currentChanged.connect(self.tabChanged) log.info("Loaded main window.") tttIcon = QtGui.QIcon( resourcePath("mcedit2/assets/mcedit2/icons/toolbar_text.png")) self.toggleToolbarTextAction = QtGui.QAction(tttIcon, "Toolbar Text", self) self.toggleToolbarTextAction.setCheckable(True) self.toggleToolbarTextAction.setChecked(True) self.toggleToolbarTextAction.toggled.connect(self.toggleToolbarText) # --- OpenGL --- setDefaultFormat() # --- Sessions --- self._currentSession = None self.sessions = [] self.sessionDockWidgets = [] self.sessionChanged.connect(self.sessionDidChange) # --- Panel Widgets --- historyIcon = QtGui.QIcon( resourcePath("mcedit2/assets/mcedit2/icons/history.png")) self.undoView = QtGui.QUndoView(self.undoGroup) self.undoDockWidget = MCEDockWidget("History", mainWindow, objectName="HistoryWidget") self.undoDockWidget.setWidget(self.undoView) self.undoDockWidget.setWindowIcon(historyIcon) self.undoDockWidget.setUnfocusedOpacity(0.8) mainWindow.addDockWidget(Qt.RightDockWidgetArea, self.undoDockWidget) undoToggleAction = self.undoDockWidget.toggleViewAction() undoToggleAction.setIcon(historyIcon) mainWindow.panelsToolBar.addAction(undoToggleAction) self.undoDockWidget.close() libraryIcon = QtGui.QIcon( resourcePath("mcedit2/assets/mcedit2/icons/library.png")) self.libraryWidget = LibraryWidget() self.libraryDockWidget = MCEDockWidget("Library", mainWindow, objectName="LibraryWidget") self.libraryDockWidget.setWidget(self.libraryWidget) self.libraryDockWidget.setWindowIcon(libraryIcon) self.libraryDockWidget.setUnfocusedOpacity(0.8) mainWindow.addDockWidget(Qt.RightDockWidgetArea, self.libraryDockWidget) libraryToggleAction = self.libraryDockWidget.toggleViewAction() libraryToggleAction.setIcon(libraryIcon) mainWindow.panelsToolBar.addAction(libraryToggleAction) self.libraryDockWidget.close() self.sessionChanged.connect(self.libraryWidget.sessionDidChange) self.libraryWidget.doubleClicked.connect(self.libraryItemDoubleClicked) self.globalPanels = [self.undoDockWidget, self.libraryDockWidget] log.info("Loaded panels.") # --- Debug Widgets --- self.debugMenu = self.createDebugMenu() self.debugObjectInspector = ObjectInspector(mainWindow) self.inspectorDockWidget = MCEDockWidget("Object Inspector", mainWindow, objectName="InspectorWidget") self.inspectorDockWidget.setWidget(self.debugObjectInspector) self.debugMenu.addAction(self.inspectorDockWidget.toggleViewAction()) self.inspectorDockWidget.close() self.profileView = ProfilerWidget() self.profileDockWidget = MCEDockWidget("Profiler", mainWindow, objectName="ProfilerWidget") self.profileDockWidget.setWidget(self.profileView) self.debugMenu.addAction(self.profileDockWidget.toggleViewAction()) self.profileDockWidget.close() self.textureAtlasView = QtGui.QLabel() self.textureAtlasView.setScaledContents(True) self.textureAtlasDockWidget = MCEDockWidget( "Texture Atlas", mainWindow, objectName="TextureAtlasWidget") self.textureAtlasArea = QtGui.QScrollArea() self.textureAtlasArea.setWidget(self.textureAtlasView) self.textureAtlasDockWidget.setWidget(self.textureAtlasArea) self.debugMenu.addAction( self.textureAtlasDockWidget.toggleViewAction()) self.textureAtlasDockWidget.close() infoTabs = QtGui.QTabWidget() self.cursorInfo = WorldCursorInfo() infoTabs.addTab(self.cursorInfo, "Cursor") self.viewInfo = WorldViewInfo() infoTabs.addTab(self.viewInfo, "View") self.loaderInfo = ChunkLoaderInfo() infoTabs.addTab(self.loaderInfo, "Loader") self.infoDockWidget = MCEDockWidget("Debug Info", mainWindow, objectName="DebugInfo") self.infoDockWidget.setWidget(infoTabs) self.infoDockWidget.close() log.info("Loaded debug widgets.") # --- Menu Actions --- # -- MCEdit menu -- mainWindow.actionNew_World.triggered.connect(self.createNewWorld) mainWindow.actionNew_World.setShortcut(QtGui.QKeySequence.New) mainWindow.actionOpen_World.triggered.connect(self.chooseOpenWorld) mainWindow.actionOpen_World.setShortcut(QtGui.QKeySequence.Open) mainWindow.actionShow_World_List.triggered.connect(self.showWorldList) mainWindow.actionShow_World_List.setShortcut( QtGui.QKeySequence("Ctrl+L")) mainWindow.actionSave_World.triggered.connect(self.saveCurrentWorld) mainWindow.actionSave_World.setShortcut(QtGui.QKeySequence.Save) mainWindow.actionSave_World_As.triggered.connect( self.saveCurrentWorldAs) mainWindow.actionSave_World_As.setShortcut(QtGui.QKeySequence.SaveAs) mainWindow.actionClose_World.triggered.connect(self.closeCurrentTab) mainWindow.actionClose_World.setShortcut(QtGui.QKeySequence.Close) mainWindow.actionExit_MCEdit.triggered.connect(self.exitEditor) mainWindow.actionExit_MCEdit.setShortcut(QtGui.QKeySequence.Quit) # -- Help menu -- mainWindow.actionAbout_MCEdit.triggered.connect(self.showAbout) mainWindow.actionAbout_MCEdit.setShortcut(QtGui.QKeySequence.Quit) # -- Window Menu -- mainWindow.menuWindow.addAction(self.undoDockWidget.toggleViewAction()) mainWindow.menuWindow.addAction( self.libraryDockWidget.toggleViewAction()) # -- Options Menu -- mainWindow.actionEnable_Lighting_Updates.setChecked( EnableLightingSetting.value()) mainWindow.actionEnable_Lighting_Updates.toggled.connect( EnableLightingSetting.setValue) EnableLightingSetting.valueChanged.connect(self.enableLightingChanged) self.enableLightingChanged(EnableLightingSetting.value()) mainWindow.actionPreferences.triggered.connect(self.showPrefsDialog) mainWindow.actionConfigure_Blocks_Items.triggered.connect( self.showConfigureBlocksDialog) mainWindow.actionConfigure_Blocks_Items.setEnabled(False) mainWindow.actionPlugins.triggered.connect(self.showPluginsDialog) mainWindow.actionEnable_Developer_Mode.setChecked( DevModeSetting.value()) mainWindow.actionEnable_Developer_Mode.toggled.connect( DevModeSetting.setValue) DevModeSetting.valueChanged.connect(self.toggleDeveloperMode) self.toggleDeveloperMode(DevModeSetting.value()) mainWindow.menuOptions.addMenu(self.translationsMenu) log.info("Loaded menus.") # --- World List --- self.worldList = WorldListWidget(mainWindow) self.worldList.editWorldClicked.connect(self.editWorldFromList) self.worldList.viewWorldClicked.connect(self.viewWorldFromList) self.worldList.backupWorldClicked.connect(self.backupWorldFromList) self.worldList.repairWorldClicked.connect(self.repairWorldFromList) log.info("Loaded world list.") # --- Status Bar --- self.positionLabel = QtGui.QLabel("xx, yy, zz", minimumWidth=100) self.biomeLabel = QtGui.QLabel("Nowhere", minimumWidth=100) self.blocktypeLabel = QtGui.QLabel("(-1:-1)minecraft:rocktonium", minimumWidth=250) self.blockNameLabel = QtGui.QLabel("rocktonium", minimumWidth=150) self.cpsLabel = QtGui.QLabel("-1 cps", minimumWidth=65) self.fpsLabel = QtGui.QLabel("-1 fps", minimumWidth=65) statusBar = mainWindow.statusBar() statusBar.addPermanentWidget(self.positionLabel) statusBar.addPermanentWidget(self.biomeLabel) statusBar.addPermanentWidget(self.blocktypeLabel) statusBar.addPermanentWidget(self.blockNameLabel) statusBar.addPermanentWidget(self.cpsLabel) statusBar.addPermanentWidget(self.fpsLabel) log.info("Loaded status bar.") # --- Load settings --- mainWindow.loadSettings() self.updateRecentFilesMenu() log.info("Loaded settings.") # --- App Dialogs --- # Qt weirdness - initializing QDialog with parent puts the dialog at 0, # 0 instead of centering it on the parent. Have to set the parent explicitly # and put the Qt.Dialog flag back on since changing the parent resets the # window flags... self.prefsDialog = prefsdialog.PrefsDialog(None) self.prefsDialog.setParent(mainWindow) self.prefsDialog.setWindowFlags(Qt.Dialog) self.configureBlocksDialog = configure_blocks.ConfigureBlocksDialog( None) self.configureBlocksDialog.finished.connect( self.configureBlocksFinished) self.configureBlocksDialog.setParent(mainWindow) self.configureBlocksDialog.setWindowFlags(Qt.Dialog) self.pluginsDialog = PluginsDialog() self.pluginsDialog.setParent(mainWindow) self.pluginsDialog.setWindowFlags(Qt.Dialog) log.info("Loaded app dialogs.") # --- Loader timer --- self.loadTimer = timer = LoaderTimer(self) timer.setInterval(0) timer.timeout.connect(self.loadTimerFired) timer.start() log.info("Loading timer started") mainWindow.showMaximized()