Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
Added support for file open on drop and from argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Jun 16, 2016
1 parent ede87f1 commit d4398b0
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 39 deletions.
40 changes: 28 additions & 12 deletions fgmk
Original file line number Diff line number Diff line change
@@ -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_())
72 changes: 45 additions & 27 deletions src/fgmk/Editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)), "../../"))
Expand All @@ -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)
Expand All @@ -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_())

0 comments on commit d4398b0

Please sign in to comment.