Initial subclass of wx.App and removing splash on Mac OS X.

master
Ilya Kulakov 2012-12-05 23:54:11 +07:00
parent 0a1b1c419a
commit 1d42ce8afc
3 changed files with 64 additions and 51 deletions

View File

@ -10,8 +10,12 @@ 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
import wx._core
from util import profile from util import profile
__author__ = 'Daid' __author__ = 'Daid'
@ -41,6 +45,14 @@ Art of Illusion <http://www.artofillusion.org/>"""
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
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 main(): 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",
@ -56,42 +68,43 @@ def main():
parser.add_option("-s", "--slice", action="store_true", dest="slice", parser.add_option("-s", "--slice", action="store_true", dest="slice",
help="Slice the given files instead of opening them in Cura") help="Slice the given files instead of opening them in Cura")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if options.profile != None:
if options.profile is not None:
profile.loadGlobalProfileFromString(options.profile) profile.loadGlobalProfileFromString(options.profile)
if options.profileini != None: if options.profileini is not None:
profile.loadGlobalProfile(options.profileini) profile.loadGlobalProfile(options.profileini)
if options.openprojectplanner != None:
if options.openprojectplanner is not None:
from gui import projectPlanner from gui import projectPlanner
projectPlanner.main() projectPlanner.main()
return elif options.openflatslicer is not None:
if options.openflatslicer != None:
from gui import flatSlicerWindow from gui import flatSlicerWindow
flatSlicerWindow.main() flatSlicerWindow.main()
return elif options.printfile is not None:
if options.printfile != None:
from gui import printWindow from gui import printWindow
printWindow.startPrintInterface(options.printfile) printWindow.startPrintInterface(options.printfile)
return elif options.slice is not None:
if options.slice != None:
from util import sliceRun from util import sliceRun
sliceRun.runSlice(args) sliceRun.runSlice(args)
else: else:
if len(args) > 0: if len(args) > 0:
profile.putPreference('lastFile', ';'.join(args)) profile.putPreference('lastFile', ';'.join(args))
from gui import splashScreen from gui import splashScreen
splashScreen.showSplash(mainWindowRunCallback) def mainWindowRunCallback(splash):
from gui import mainWindow
if splash is not None:
splash.Show(False)
mainWindow.main()
app = CuraApp(False)
def mainWindowRunCallback(splash): # Apple discurage usage of splash screens on a mac.
from gui import mainWindow if sys.platform.startswith('darwin'):
mainWindowRunCallback(None)
mainWindow.main(splash) else:
splashScreen.splashScreen(mainWindowRunCallback)
app.MainLoop()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -25,7 +25,7 @@ from util import version
from util import sliceRun from util import sliceRun
from util import meshLoader from util import meshLoader
def main(splash): def main():
#app = wx.App(False) #app = wx.App(False)
if profile.getPreference('machine_type') == 'unknown': if profile.getPreference('machine_type') == 'unknown':
if platform.system() == "Darwin": if platform.system() == "Darwin":
@ -39,7 +39,6 @@ def main(splash):
for filename in glob.glob(os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'example', '*.*'))): 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))) shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
profile.putPreference('lastFile', exampleFile) profile.putPreference('lastFile', exampleFile)
splash.Show(False)
configWizard.configWizard() configWizard.configWizard()
if profile.getPreference('startMode') == 'Simple': if profile.getPreference('startMode') == 'Simple':
simpleMode.simpleModeWindow() simpleMode.simpleModeWindow()
@ -53,12 +52,12 @@ class mainWindow(configBase.configWindowBase):
super(mainWindow, self).__init__(title='Cura - ' + version.getVersion()) super(mainWindow, self).__init__(title='Cura - ' + version.getVersion())
extruderCount = int(profile.getPreference('extruder_amount')) extruderCount = int(profile.getPreference('extruder_amount'))
wx.EVT_CLOSE(self, self.OnClose) wx.EVT_CLOSE(self, self.OnClose)
#self.SetIcon(icon.getMainIcon()) #self.SetIcon(icon.getMainIcon())
self.SetDropTarget(dropTarget.FileDropTarget(self.OnDropFiles, meshLoader.supportedExtensions())) self.SetDropTarget(dropTarget.FileDropTarget(self.OnDropFiles, meshLoader.supportedExtensions()))
menubar = wx.MenuBar() menubar = wx.MenuBar()
fileMenu = wx.Menu() fileMenu = wx.Menu()
i = fileMenu.Append(-1, 'Load model file...\tCTRL+L') i = fileMenu.Append(-1, 'Load model file...\tCTRL+L')
@ -97,7 +96,7 @@ class mainWindow(configBase.configWindowBase):
# i = toolsMenu.Append(-1, 'Open SVG (2D) slicer...') # i = toolsMenu.Append(-1, 'Open SVG (2D) slicer...')
# self.Bind(wx.EVT_MENU, self.OnSVGSlicerOpen, i) # self.Bind(wx.EVT_MENU, self.OnSVGSlicerOpen, i)
menubar.Append(toolsMenu, 'Tools') menubar.Append(toolsMenu, 'Tools')
expertMenu = wx.Menu() expertMenu = wx.Menu()
i = expertMenu.Append(-1, 'Open expert settings...') i = expertMenu.Append(-1, 'Open expert settings...')
self.Bind(wx.EVT_MENU, self.OnExpertOpen, i) self.Bind(wx.EVT_MENU, self.OnExpertOpen, i)
@ -111,7 +110,7 @@ class mainWindow(configBase.configWindowBase):
i = expertMenu.Append(-1, 'ReRun first run wizard...') i = expertMenu.Append(-1, 'ReRun first run wizard...')
self.Bind(wx.EVT_MENU, self.OnFirstRunWizard, i) self.Bind(wx.EVT_MENU, self.OnFirstRunWizard, i)
menubar.Append(expertMenu, 'Expert') menubar.Append(expertMenu, 'Expert')
helpMenu = wx.Menu() helpMenu = wx.Menu()
i = helpMenu.Append(-1, 'Online documentation...') i = helpMenu.Append(-1, 'Online documentation...')
self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('https://daid.github.com/Cura'), i) self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('https://daid.github.com/Cura'), i)
@ -119,7 +118,7 @@ class mainWindow(configBase.configWindowBase):
self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('https://github.com/daid/Cura/issues'), i) self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('https://github.com/daid/Cura/issues'), i)
menubar.Append(helpMenu, 'Help') menubar.Append(helpMenu, 'Help')
self.SetMenuBar(menubar) self.SetMenuBar(menubar)
if profile.getPreference('lastFile') != '': if profile.getPreference('lastFile') != '':
self.filelist = profile.getPreference('lastFile').split(';') self.filelist = profile.getPreference('lastFile').split(';')
self.SetTitle('Cura - %s - %s' % (version.getVersion(), self.filelist[-1])) self.SetTitle('Cura - %s - %s' % (version.getVersion(), self.filelist[-1]))
@ -132,9 +131,9 @@ class mainWindow(configBase.configWindowBase):
#Main tabs #Main tabs
nb = wx.Notebook(self) nb = wx.Notebook(self)
(left, right) = self.CreateConfigTab(nb, 'Print config') (left, right) = self.CreateConfigTab(nb, 'Print config')
configBase.TitleRow(left, "Accuracy") configBase.TitleRow(left, "Accuracy")
c = configBase.SettingRow(left, "Layer height (mm)", 'layer_height', '0.2', 'Layer height in millimeters.\n0.2 is a good value for quick prints.\n0.1 gives high quality prints.') c = configBase.SettingRow(left, "Layer height (mm)", 'layer_height', '0.2', 'Layer height in millimeters.\n0.2 is a good value for quick prints.\n0.1 gives high quality prints.')
validators.validFloat(c, 0.0001) validators.validFloat(c, 0.0001)
@ -143,13 +142,13 @@ class mainWindow(configBase.configWindowBase):
validators.validFloat(c, 0.0001) validators.validFloat(c, 0.0001)
validators.wallThicknessValidator(c) validators.wallThicknessValidator(c)
c = configBase.SettingRow(left, "Enable retraction", 'retraction_enable', False, 'Retract the filament when the nozzle is moving over a none-printed area. Details about the retraction can be configured in the advanced tab.') c = configBase.SettingRow(left, "Enable retraction", 'retraction_enable', False, 'Retract the filament when the nozzle is moving over a none-printed area. Details about the retraction can be configured in the advanced tab.')
configBase.TitleRow(left, "Fill") configBase.TitleRow(left, "Fill")
c = configBase.SettingRow(left, "Bottom/Top thickness (mm)", 'solid_layer_thickness', '0.6', 'This controls the thickness of the bottom and top layers, the amount of solid layers put down is calculated by the layer thickness and this value.\nHaving this value a multiply of the layer thickness makes sense. And keep it near your wall thickness to make an evenly strong part.') c = configBase.SettingRow(left, "Bottom/Top thickness (mm)", 'solid_layer_thickness', '0.6', 'This controls the thickness of the bottom and top layers, the amount of solid layers put down is calculated by the layer thickness and this value.\nHaving this value a multiply of the layer thickness makes sense. And keep it near your wall thickness to make an evenly strong part.')
validators.validFloat(c, 0.0) validators.validFloat(c, 0.0)
c = configBase.SettingRow(left, "Fill Density (%)", 'fill_density', '20', 'This controls how densily filled the insides of your print will be. For a solid part use 100%, for an empty part use 0%. A value around 20% is usually enough') c = configBase.SettingRow(left, "Fill Density (%)", 'fill_density', '20', 'This controls how densily filled the insides of your print will be. For a solid part use 100%, for an empty part use 0%. A value around 20% is usually enough')
validators.validFloat(c, 0.0, 100.0) validators.validFloat(c, 0.0, 100.0)
configBase.TitleRow(left, "Skirt") configBase.TitleRow(left, "Skirt")
c = configBase.SettingRow(left, "Line count", 'skirt_line_count', '1', 'The skirt is a line drawn around the object at the first layer. This helps to prime your extruder, and to see if the object fits on your platform.\nSetting this to 0 will disable the skirt. Multiple skirt lines can help priming your extruder better for small objects.') c = configBase.SettingRow(left, "Line count", 'skirt_line_count', '1', 'The skirt is a line drawn around the object at the first layer. This helps to prime your extruder, and to see if the object fits on your platform.\nSetting this to 0 will disable the skirt. Multiple skirt lines can help priming your extruder better for small objects.')
validators.validInt(c, 0, 10) validators.validInt(c, 0, 10)
@ -161,7 +160,7 @@ class mainWindow(configBase.configWindowBase):
validators.validFloat(c, 1.0) validators.validFloat(c, 1.0)
validators.warningAbove(c, 150.0, "It is highly unlikely that your machine can achieve a printing speed above 150mm/s") validators.warningAbove(c, 150.0, "It is highly unlikely that your machine can achieve a printing speed above 150mm/s")
validators.printSpeedValidator(c) validators.printSpeedValidator(c)
#configBase.TitleRow(right, "Temperature") #configBase.TitleRow(right, "Temperature")
c = configBase.SettingRow(right, "Printing temperature", 'print_temperature', '0', 'Temperature used for printing. Set at 0 to pre-heat yourself') c = configBase.SettingRow(right, "Printing temperature", 'print_temperature', '0', 'Temperature used for printing. Set at 0 to pre-heat yourself')
validators.validFloat(c, 0.0, 340.0) validators.validFloat(c, 0.0, 340.0)
@ -169,7 +168,7 @@ class mainWindow(configBase.configWindowBase):
if profile.getPreference('has_heated_bed') == 'True': if profile.getPreference('has_heated_bed') == 'True':
c = configBase.SettingRow(right, "Bed temperature", 'print_bed_temperature', '0', 'Temperature used for the heated printer bed. Set at 0 to pre-heat yourself') c = configBase.SettingRow(right, "Bed temperature", 'print_bed_temperature', '0', 'Temperature used for the heated printer bed. Set at 0 to pre-heat yourself')
validators.validFloat(c, 0.0, 340.0) validators.validFloat(c, 0.0, 340.0)
configBase.TitleRow(right, "Support structure") configBase.TitleRow(right, "Support structure")
c = configBase.SettingRow(right, "Support type", 'support', ['None', 'Exterior Only', 'Everywhere'], 'Type of support structure build.\n"Exterior only" is the most commonly used support setting.\n\nNone does not do any support.\nExterior only only creates support where the support structure will touch the build platform.\nEverywhere creates support even on the insides of the model.') c = configBase.SettingRow(right, "Support type", 'support', ['None', 'Exterior Only', 'Everywhere'], 'Type of support structure build.\n"Exterior only" is the most commonly used support setting.\n\nNone does not do any support.\nExterior only only creates support where the support structure will touch the build platform.\nEverywhere creates support even on the insides of the model.')
c = configBase.SettingRow(right, "Add raft", 'enable_raft', False, 'A raft is a few layers of lines below the bottom of the object. It prevents warping. Full raft settings can be found in the expert settings.\nFor PLA this is usually not required. But if you print with ABS it is almost required.') c = configBase.SettingRow(right, "Add raft", 'enable_raft', False, 'A raft is a few layers of lines below the bottom of the object. It prevents warping. Full raft settings can be found in the expert settings.\nFor PLA this is usually not required. But if you print with ABS it is almost required.')
@ -182,9 +181,9 @@ class mainWindow(configBase.configWindowBase):
validators.warningAbove(c, 3.5, "Are you sure your filament is that thick? Normal filament is around 3mm or 1.75mm.") validators.warningAbove(c, 3.5, "Are you sure your filament is that thick? Normal filament is around 3mm or 1.75mm.")
c = configBase.SettingRow(right, "Packing Density", 'filament_density', '1.00', 'Packing density of your filament. This should be 1.00 for PLA and 0.85 for ABS') c = configBase.SettingRow(right, "Packing Density", 'filament_density', '1.00', 'Packing density of your filament. This should be 1.00 for PLA and 0.85 for ABS')
validators.validFloat(c, 0.5, 1.5) validators.validFloat(c, 0.5, 1.5)
(left, right) = self.CreateConfigTab(nb, 'Advanced config') (left, right) = self.CreateConfigTab(nb, 'Advanced config')
configBase.TitleRow(left, "Machine size") configBase.TitleRow(left, "Machine size")
c = configBase.SettingRow(left, "Nozzle size (mm)", 'nozzle_size', '0.4', 'The nozzle size is very important, this is used to calculate the line width of the infill, and used to calculate the amount of outside wall lines and thickness for the wall thickness you entered in the print settings.') c = configBase.SettingRow(left, "Nozzle size (mm)", 'nozzle_size', '0.4', 'The nozzle size is very important, this is used to calculate the line width of the infill, and used to calculate the amount of outside wall lines and thickness for the wall thickness you entered in the print settings.')
validators.validFloat(c, 0.1, 10.0) validators.validFloat(c, 0.1, 10.0)
@ -281,7 +280,7 @@ class mainWindow(configBase.configWindowBase):
self.updateProfileToControls() self.updateProfileToControls()
self.SetBackgroundColour(nb.GetBackgroundColour()) self.SetBackgroundColour(nb.GetBackgroundColour())
self.Fit() self.Fit()
if wx.Display().GetClientArea().GetWidth() < self.GetSize().GetWidth(): if wx.Display().GetClientArea().GetWidth() < self.GetSize().GetWidth():
f = self.GetSize().GetWidth() - wx.Display().GetClientArea().GetWidth() f = self.GetSize().GetWidth() - wx.Display().GetClientArea().GetWidth()
@ -291,7 +290,7 @@ class mainWindow(configBase.configWindowBase):
self.SetMinSize(self.GetSize()) self.SetMinSize(self.GetSize())
self.Centre() self.Centre()
self.Show(True) self.Show(True)
def OnLoadProfile(self, e): def OnLoadProfile(self, e):
dlg=wx.FileDialog(self, "Select profile file to load", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST) dlg=wx.FileDialog(self, "Select profile file to load", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
dlg.SetWildcard("ini files (*.ini)|*.ini") dlg.SetWildcard("ini files (*.ini)|*.ini")
@ -317,7 +316,7 @@ class mainWindow(configBase.configWindowBase):
else: else:
wx.MessageBox('No profile found in GCode file.\nThis feature only works with GCode files made by Cura 12.07 or newer.', 'Profile load error', wx.OK | wx.ICON_INFORMATION) wx.MessageBox('No profile found in GCode file.\nThis feature only works with GCode files made by Cura 12.07 or newer.', 'Profile load error', wx.OK | wx.ICON_INFORMATION)
dlg.Destroy() dlg.Destroy()
def OnSaveProfile(self, e): def OnSaveProfile(self, e):
dlg=wx.FileDialog(self, "Select profile file to save", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE) dlg=wx.FileDialog(self, "Select profile file to save", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
dlg.SetWildcard("ini files (*.ini)|*.ini") dlg.SetWildcard("ini files (*.ini)|*.ini")
@ -325,7 +324,7 @@ class mainWindow(configBase.configWindowBase):
profileFile = dlg.GetPath() profileFile = dlg.GetPath()
profile.saveGlobalProfile(profileFile) profile.saveGlobalProfile(profileFile)
dlg.Destroy() dlg.Destroy()
def OnResetProfile(self, e): def OnResetProfile(self, e):
dlg = wx.MessageDialog(self, 'This will reset all profile settings to defaults.\nUnless you have saved your current profile, all settings will be lost!\nDo you really want to reset?', 'Profile reset', wx.YES_NO | wx.ICON_QUESTION) dlg = wx.MessageDialog(self, 'This will reset all profile settings to defaults.\nUnless you have saved your current profile, all settings will be lost!\nDo you really want to reset?', 'Profile reset', wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal() == wx.ID_YES result = dlg.ShowModal() == wx.ID_YES
@ -337,22 +336,22 @@ class mainWindow(configBase.configWindowBase):
profile.putProfileSetting('machine_center_x', '40') profile.putProfileSetting('machine_center_x', '40')
profile.putProfileSetting('machine_center_y', '40') profile.putProfileSetting('machine_center_y', '40')
self.updateProfileToControls() self.updateProfileToControls()
def OnBatchRun(self, e): def OnBatchRun(self, e):
br = batchRun.batchRunWindow(self) br = batchRun.batchRunWindow(self)
br.Centre() br.Centre()
br.Show(True) br.Show(True)
def OnPreferences(self, e): def OnPreferences(self, e):
prefDialog = preferencesDialog.preferencesDialog(self) prefDialog = preferencesDialog.preferencesDialog(self)
prefDialog.Centre() prefDialog.Centre()
prefDialog.Show(True) prefDialog.Show(True)
def OnSimpleSwitch(self, e): def OnSimpleSwitch(self, e):
profile.putPreference('startMode', 'Simple') profile.putPreference('startMode', 'Simple')
simpleMode.simpleModeWindow() simpleMode.simpleModeWindow()
self.Close() self.Close()
def OnDefaultMarlinFirmware(self, e): def OnDefaultMarlinFirmware(self, e):
firmwareInstall.InstallFirmware() firmwareInstall.InstallFirmware()
@ -392,7 +391,7 @@ class mainWindow(configBase.configWindowBase):
if filelist[-1] == False: if filelist[-1] == False:
return return
self._loadModels(filelist) self._loadModels(filelist)
def _loadModels(self, filelist): def _loadModels(self, filelist):
self.filelist = filelist self.filelist = filelist
self.SetTitle(filelist[-1] + ' - Cura - ' + version.getVersion()) self.SetTitle(filelist[-1] + ' - Cura - ' + version.getVersion())
@ -405,7 +404,7 @@ class mainWindow(configBase.configWindowBase):
def OnLoadModel(self, e): def OnLoadModel(self, e):
self._showModelLoadDialog(1) self._showModelLoadDialog(1)
def OnLoadModel2(self, e): def OnLoadModel2(self, e):
self._showModelLoadDialog(2) self._showModelLoadDialog(2)
@ -414,7 +413,7 @@ class mainWindow(configBase.configWindowBase):
def OnLoadModel4(self, e): def OnLoadModel4(self, e):
self._showModelLoadDialog(4) self._showModelLoadDialog(4)
def OnSlice(self, e): def OnSlice(self, e):
if len(self.filelist) < 1: if len(self.filelist) < 1:
wx.MessageBox('You need to load a file before you can prepare it.', 'Print error', wx.OK | wx.ICON_INFORMATION) wx.MessageBox('You need to load a file before you can prepare it.', 'Print error', wx.OK | wx.ICON_INFORMATION)
@ -428,7 +427,7 @@ class mainWindow(configBase.configWindowBase):
if newSize.GetWidth() < wx.GetDisplaySize()[0]: if newSize.GetWidth() < wx.GetDisplaySize()[0]:
self.SetSize(newSize) self.SetSize(newSize)
self.progressPanelList.append(spp) self.progressPanelList.append(spp)
def OnPrint(self, e): def OnPrint(self, e):
if len(self.filelist) < 1: if len(self.filelist) < 1:
wx.MessageBox('You need to load a file and prepare it before you can print.', 'Print error', wx.OK | wx.ICON_INFORMATION) wx.MessageBox('You need to load a file and prepare it before you can print.', 'Print error', wx.OK | wx.ICON_INFORMATION)
@ -442,7 +441,7 @@ class mainWindow(configBase.configWindowBase):
ecw = expertConfig.expertConfigWindow() ecw = expertConfig.expertConfigWindow()
ecw.Centre() ecw.Centre()
ecw.Show(True) ecw.Show(True)
def OnProjectPlanner(self, e): def OnProjectPlanner(self, e):
pp = projectPlanner.projectPlanner() pp = projectPlanner.projectPlanner()
pp.Centre() pp.Centre()
@ -471,7 +470,7 @@ class mainWindow(configBase.configWindowBase):
def OnQuit(self, e): def OnQuit(self, e):
self.Close() self.Close()
def OnClose(self, e): def OnClose(self, e):
profile.saveGlobalProfile(profile.getDefaultProfilePath()) profile.saveGlobalProfile(profile.getDefaultProfilePath())
self.Destroy() self.Destroy()

View File

@ -19,7 +19,8 @@ class splashScreen(wx.SplashScreen):
def showSplash(callback): def showSplash(callback):
app = wx.App(False) from Cura.cura import CuraApp
app = CuraApp(False)
splashScreen(callback) splashScreen(callback)
app.MainLoop() app.MainLoop()