Make a single entry point for the GUI interface, as Cura.gui.app
This commit is contained in:
parent
98ef38eb46
commit
00c2b1ed66
6 changed files with 66 additions and 93 deletions
40
Cura/cura.py
40
Cura/cura.py
|
@ -10,8 +10,6 @@ The slicing code is the same as Skeinforge. But the UI has been revamped to be..
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import sys
|
|
||||||
import warnings
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from Cura.util import profile
|
from Cura.util import profile
|
||||||
|
@ -48,10 +46,6 @@ def main():
|
||||||
parser = OptionParser(usage="usage: %prog [options] <filename>.stl")
|
parser = OptionParser(usage="usage: %prog [options] <filename>.stl")
|
||||||
parser.add_option("-i", "--ini", action="store", type="string", dest="profileini",
|
parser.add_option("-i", "--ini", action="store", type="string", dest="profileini",
|
||||||
help="Load settings from a profile ini file")
|
help="Load settings from a profile ini file")
|
||||||
parser.add_option("-P", "--project", action="store_true", dest="openprojectplanner",
|
|
||||||
help="Open the project planner")
|
|
||||||
parser.add_option("-F", "--flat", action="store_true", dest="openflatslicer",
|
|
||||||
help="Open the 2D SVG slicer (unfinished)")
|
|
||||||
parser.add_option("-r", "--print", action="store", type="string", dest="printfile",
|
parser.add_option("-r", "--print", action="store", type="string", dest="printfile",
|
||||||
help="Open the printing interface, instead of the normal cura interface.")
|
help="Open the printing interface, instead of the normal cura interface.")
|
||||||
parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
|
parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
|
||||||
|
@ -65,45 +59,19 @@ def main():
|
||||||
if options.profileini is not None:
|
if options.profileini is not None:
|
||||||
profile.loadGlobalProfile(options.profileini)
|
profile.loadGlobalProfile(options.profileini)
|
||||||
|
|
||||||
if options.openprojectplanner is not None:
|
if options.printfile is not None:
|
||||||
from Cura.gui import projectPlanner
|
|
||||||
projectPlanner.main()
|
|
||||||
elif options.openflatslicer is not None:
|
|
||||||
from Cura.gui import flatSlicerWindow
|
|
||||||
flatSlicerWindow.main()
|
|
||||||
elif options.printfile is not None:
|
|
||||||
from Cura.gui import printWindow
|
from Cura.gui import printWindow
|
||||||
printWindow.startPrintInterface(options.printfile)
|
printWindow.startPrintInterface(options.printfile)
|
||||||
elif options.slice is not None:
|
elif options.slice is not None:
|
||||||
from Cura.util import sliceRun
|
from Cura.util import sliceRun
|
||||||
sliceRun.runSlice(args)
|
sliceRun.runSlice(args)
|
||||||
else:
|
else:
|
||||||
|
#Place any unused arguments as last file, so Cura starts with opening those files.
|
||||||
if len(args) > 0:
|
if len(args) > 0:
|
||||||
profile.putPreference('lastFile', ';'.join(args))
|
profile.putPreference('lastFile', ';'.join(args))
|
||||||
|
|
||||||
import wx._core
|
from Cura.gui import app
|
||||||
from Cura.gui import splashScreen
|
app.CuraApp().MainLoop()
|
||||||
|
|
||||||
class CuraApp(wx.App):
|
|
||||||
def MacOpenFile(self, path):
|
|
||||||
try:
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
|
||||||
warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
|
|
||||||
|
|
||||||
def mainWindowRunCallback(splash):
|
|
||||||
from Cura.gui import mainWindow
|
|
||||||
if splash is not None:
|
|
||||||
splash.Show(False)
|
|
||||||
mainWindow.main()
|
|
||||||
|
|
||||||
app = CuraApp(False)
|
|
||||||
# Apple discourages usage of splash screens on a mac.
|
|
||||||
if sys.platform.startswith('darwin'):
|
|
||||||
mainWindowRunCallback(None)
|
|
||||||
else:
|
|
||||||
splashScreen.splashScreen(mainWindowRunCallback)
|
|
||||||
app.MainLoop()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
61
Cura/gui/app.py
Normal file
61
Cura/gui/app.py
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import shutil
|
||||||
|
import glob
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
#Only import the _core to save import time
|
||||||
|
import wx._core
|
||||||
|
|
||||||
|
from Cura.gui import splashScreen
|
||||||
|
from Cura.util import profile
|
||||||
|
|
||||||
|
class CuraApp(wx.App):
|
||||||
|
def __init__(self):
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
super(CuraApp, self).__init__(redirect = True, filename = 'output.txt')
|
||||||
|
else:
|
||||||
|
super(CuraApp, self).__init__(redirect = False)
|
||||||
|
|
||||||
|
self.mainWindow = None
|
||||||
|
self.splash = None
|
||||||
|
|
||||||
|
if sys.platform.startswith('darwin'):
|
||||||
|
#Do not show a splashscreen on OSX, as by Apple guidelines
|
||||||
|
self.afterSplashCallback()
|
||||||
|
else:
|
||||||
|
self.splash = splashScreen.splashScreen(self.afterSplashCallback)
|
||||||
|
|
||||||
|
def MacOpenFile(self, path):
|
||||||
|
try:
|
||||||
|
self.mainWindow._loadModels([path])
|
||||||
|
except Exception as e:
|
||||||
|
warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
|
||||||
|
|
||||||
|
def afterSplashCallback(self):
|
||||||
|
#These imports take most of the time and thus should be done after showing the splashscreen
|
||||||
|
from Cura.gui import mainWindow
|
||||||
|
from Cura.gui import configWizard
|
||||||
|
|
||||||
|
#If we haven't run it before, run the configuration wizard.
|
||||||
|
if profile.getPreference('machine_type') == 'unknown':
|
||||||
|
if platform.system() == "Darwin":
|
||||||
|
#Check if we need to copy our examples
|
||||||
|
exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
|
||||||
|
if not os.path.isfile(exampleFile):
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(exampleFile))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
for filename in glob.glob(os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'example', '*.*'))):
|
||||||
|
shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
|
||||||
|
profile.putPreference('lastFile', exampleFile)
|
||||||
|
configWizard.configWizard()
|
||||||
|
|
||||||
|
#Hide the splashscreen before showing the main window.
|
||||||
|
if self.splash is not None:
|
||||||
|
self.splash.Show(False)
|
||||||
|
self.mainWindow = mainWindow.mainWindow()
|
|
@ -186,12 +186,3 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
|
||||||
glEnd()
|
glEnd()
|
||||||
|
|
||||||
glFlush()
|
glFlush()
|
||||||
|
|
||||||
def main():
|
|
||||||
app = wx.App(False)
|
|
||||||
flatSlicerWindow().Show(True)
|
|
||||||
app.MainLoop()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
|
@ -28,22 +28,6 @@ from Cura.util import version
|
||||||
from Cura.util import sliceRun
|
from Cura.util import sliceRun
|
||||||
from Cura.util import meshLoader
|
from Cura.util import meshLoader
|
||||||
|
|
||||||
def main():
|
|
||||||
if profile.getPreference('machine_type') == 'unknown':
|
|
||||||
if platform.system() == "Darwin":
|
|
||||||
#Check if we need to copy our examples
|
|
||||||
exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
|
|
||||||
if not os.path.isfile(exampleFile):
|
|
||||||
try:
|
|
||||||
os.makedirs(os.path.dirname(exampleFile))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
for filename in glob.glob(os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'example', '*.*'))):
|
|
||||||
shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
|
|
||||||
profile.putPreference('lastFile', exampleFile)
|
|
||||||
configWizard.configWizard()
|
|
||||||
mainWindow()
|
|
||||||
|
|
||||||
class mainWindow(wx.Frame):
|
class mainWindow(wx.Frame):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(mainWindow, self).__init__(None, title='Cura - ' + version.getVersion())
|
super(mainWindow, self).__init__(None, title='Cura - ' + version.getVersion())
|
||||||
|
|
|
@ -1150,11 +1150,3 @@ class LogWindow(wx.Frame):
|
||||||
self.SetSize((400,300))
|
self.SetSize((400,300))
|
||||||
self.Centre()
|
self.Centre()
|
||||||
self.Show(True)
|
self.Show(True)
|
||||||
|
|
||||||
def main():
|
|
||||||
app = wx.App(False)
|
|
||||||
projectPlanner().Show(True)
|
|
||||||
app.MainLoop()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import wx._core #We only need the core here, which speeds up the import. As we w
|
||||||
|
|
||||||
from Cura.util.resources import getPathForImage
|
from Cura.util.resources import getPathForImage
|
||||||
|
|
||||||
|
|
||||||
class splashScreen(wx.SplashScreen):
|
class splashScreen(wx.SplashScreen):
|
||||||
def __init__(self, callback):
|
def __init__(self, callback):
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
|
@ -14,27 +13,5 @@ class splashScreen(wx.SplashScreen):
|
||||||
wx.CallAfter(self.DoCallback)
|
wx.CallAfter(self.DoCallback)
|
||||||
|
|
||||||
def DoCallback(self):
|
def DoCallback(self):
|
||||||
self.callback(self)
|
self.callback()
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
|
||||||
|
|
||||||
def showSplash(callback):
|
|
||||||
from Cura.cura import CuraApp
|
|
||||||
app = CuraApp(False)
|
|
||||||
splashScreen(callback)
|
|
||||||
app.MainLoop()
|
|
||||||
|
|
||||||
|
|
||||||
def testCallback(splashscreen):
|
|
||||||
print "Callback!"
|
|
||||||
import time
|
|
||||||
|
|
||||||
time.sleep(2)
|
|
||||||
print "!Callback"
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
showSplash(testCallback)
|
|
||||||
|
|
||||||
if __name__ == u'__main__':
|
|
||||||
main()
|
|
||||||
|
|
Loading…
Reference in a new issue