From d4398b0d38be98bc221d3554c99797942020733b Mon Sep 17 00:00:00 2001 From: ericoporto Date: Wed, 15 Jun 2016 22:58:27 -0300 Subject: [PATCH] Added support for file open on drop and from argument --- fgmk | 40 ++++++++++++++++++-------- src/fgmk/Editor.py | 72 +++++++++++++++++++++++++++++----------------- 2 files changed, 73 insertions(+), 39 deletions(-) diff --git a/fgmk b/fgmk index fe99670..07cc812 100755 --- a/fgmk +++ b/fgmk @@ -1,19 +1,35 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- -import os -import sys +from os import path as ospath +from sys import path as syspath -if os.path.isdir(os.path.join(".","src")) and os.path.isfile( - os.path.join(".","setup.py")): - sys.path.append(os.path.realpath("src")) - sys.path.append(os.path.realpath("src/fgmk")) - sys.path.append(os.path.realpath("src/extras")) +if ospath.isdir(ospath.join(".","src")) and ospath.isfile( + ospath.join(".","setup.py")): + syspath.append(ospath.realpath("src")) + syspath.append(ospath.realpath("src/fgmk")) + syspath.append(ospath.realpath("src/extras")) -from fgmk.Editor import Editor - -def main(): - Editor() if __name__ == "__main__": - main() + from sys import argv, exit + from time import time, sleep + from PyQt5.QtWidgets import QApplication, QSplashScreen + from PyQt5.QtCore import Qt + from fgmk.Editor import MainWindow, Icon + + a = QApplication(argv) + start = time() + splash_pix = Icon() + splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint) + splash.setMask(splash_pix.mask()) + splash.show() + while time() - start < 1: + sleep(0.001) + a.processEvents() + mw = MainWindow(argv) + a.processEvents() + mw.show() + splash.finish(mw) + mw.raise_() + exit(a.exec_()) diff --git a/src/fgmk/Editor.py b/src/fgmk/Editor.py index b29a05b..568f2e3 100644 --- a/src/fgmk/Editor.py +++ b/src/fgmk/Editor.py @@ -752,9 +752,9 @@ def changeTileCurrent(self, changeTo): self.myMapWidget.currentTile = changeTo self.myPaletteWidget.setImageCurrent(changeTo) - def __init__(self, parent=None, **kwargs): + def __init__(self, filelist, **kwargs): global sSettings - super().__init__(parent, **kwargs) + super().__init__(None, **kwargs) self.resize(1024, 768) @@ -781,6 +781,40 @@ def __init__(self, parent=None, **kwargs): self.FancyWindow(self) + self.opemFileIfDropped(filelist) + + self.setAcceptDrops(True) + + def dragEnterEvent(self, event): + if event.mimeData().hasUrls: + event.accept() + else: + event.ignore() + + def dragMoveEvent(self, event): + if event.mimeData().hasUrls: + event.accept() + else: + event.ignore() + + def dropEvent(self, event): + if event.mimeData().hasUrls: + event.accept() + self.opemFileIfDropped(event.mimeData().urls()[0].toLocalFile()) + + else: + event.ignore() + + def opemFileIfDropped(self, filelist): + if (isinstance(filelist,str)): + if (".map.json" in filelist): + self.openFileByName(filelist) + + else: + matching = [s for s in filelist if ".map.json" in s] + if len(matching) > 0: + self.openFileByName(matching[0]) + def selectStartPosition(self): result = gameInit.selectStartingPosition(self, sSettings) @@ -995,12 +1029,8 @@ def exportToJsAs(self): sSettings["workingFile"] = filename self.myMap.exportJS(sSettings["workingFile"]) - def openFile(self): + def openFileByName(self, filename): global sSettings - if(sSettings["gamefolder"] == ""): - sSettings["gamefolder"] = os.path.expanduser("~") - filename = QtWidgets.QFileDialog.getOpenFileName( - self, 'Open File', sSettings["gamefolder"], "JSON Level (*.map.json);;All Files (*)")[0] if os.path.isfile(filename): sSettings["gamefolder"] = os.path.abspath( os.path.join(os.path.dirname(str(filename)), "../../")) @@ -1016,6 +1046,14 @@ def openFile(self): self.myEventsWidget.updateEventsList() self.myCharasPalWidget.reinit() + def openFile(self): + global sSettings + if(sSettings["gamefolder"] == ""): + sSettings["gamefolder"] = os.path.expanduser("~") + filename = QtWidgets.QFileDialog.getOpenFileName( + self, 'Open File', sSettings["gamefolder"], "JSON Level (*.map.json);;All Files (*)")[0] + self.openFileByName(filename) + def helpAbout(self): credits = "Made by Erico\nWith help from the internet.\nHigly based in Tsubasa's Redo, and inspired in Enterbrain's RPG Maker 2000.\nThanks Nintendo for making the SNES." QMessageBox.about(self, "About...", credits) @@ -1035,23 +1073,3 @@ def closeEvent(self, event): def Icon(): return QPixmap('icon.png') - -def Editor(): - from sys import argv, exit - global __mwind__ - - a = QApplication(argv) - start = time() - splash_pix = Icon() - splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint) - splash.setMask(splash_pix.mask()) - splash.show() - while time() - start < 1: - sleep(0.001) - a.processEvents() - __mwind__ = MainWindow() - a.processEvents() - __mwind__.show() - splash.finish(__mwind__) - __mwind__.raise_() - exit(a.exec_())