From: Jaime van Kessel Date: Thu, 19 Sep 2013 15:26:59 +0000 (+0200) Subject: Added option to copy profile settings to clipboard and reading settings from clipboar... X-Git-Tag: 13.10~58^2~1 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9632181937a1fdb688cb903a9f9e8d97c6766409;p=cura.git Added option to copy profile settings to clipboard and reading settings from clipboard. Refactored function names that were unclear / inconsistent --- diff --git a/Cura/cura.py b/Cura/cura.py index 7c847c38..2172a4bf 100644 --- a/Cura/cura.py +++ b/Cura/cura.py @@ -30,7 +30,7 @@ def main(): profile.loadPreferences(profile.getPreferencePath()) if options.profile is not None: - profile.loadProfileFromString(options.profile) + profile.setProfileFromString(options.profile) elif options.profileini is not None: profile.loadProfile(options.profileini) else: diff --git a/Cura/gui/alterationPanel.py b/Cura/gui/alterationPanel.py index ec07bc1e..db7350ba 100644 --- a/Cura/gui/alterationPanel.py +++ b/Cura/gui/alterationPanel.py @@ -5,7 +5,7 @@ import wx, wx.stc from Cura.gui.util import gcodeTextArea from Cura.util import profile - +#Panel to change the start & endcode of the gcode. class alterationPanel(wx.Panel): def __init__(self, parent, callback): wx.Panel.__init__(self, parent,-1) diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index df325045..97ea62dc 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -106,22 +106,30 @@ class mainWindow(wx.Frame): self.menubar.Append(self.fileMenu, _("&File")) toolsMenu = wx.Menu() + i = toolsMenu.Append(-1, _("Switch to quickprint...")) self.switchToQuickprintMenuItem = i self.Bind(wx.EVT_MENU, self.OnSimpleSwitch, i) + i = toolsMenu.Append(-1, _("Switch to full settings...")) self.switchToNormalMenuItem = i self.Bind(wx.EVT_MENU, self.OnNormalSwitch, i) + #toolsMenu.AppendSeparator() #i = toolsMenu.Append(-1, 'Batch run...') #self.Bind(wx.EVT_MENU, self.OnBatchRun, i) #self.normalModeOnlyItems.append(i) + if minecraftImport.hasMinecraft(): i = toolsMenu.Append(-1, _("Minecraft import...")) self.Bind(wx.EVT_MENU, self.OnMinecraftImport, i) + if version.isDevVersion(): i = toolsMenu.Append(-1, _("PID Debugger...")) self.Bind(wx.EVT_MENU, self.OnPIDDebugger, i) + + i = toolsMenu.Append(-1, _("Copy profile to clipboard")) + self.Bind(wx.EVT_MENU, self.onCopyProfileClipboard,i) self.menubar.Append(toolsMenu, _("Tools")) expertMenu = wx.Menu() @@ -187,7 +195,7 @@ class mainWindow(wx.Frame): sizer.Layout() self.sizer = sizer - self.updateProfileToControls() + self.updateProfileToAllControls() self.SetBackgroundColour(self.normalSettingsPanel.GetBackgroundColour()) @@ -198,6 +206,12 @@ class mainWindow(wx.Frame): self.SetSize((wx.Display().GetClientArea().GetWidth()/2,wx.Display().GetClientArea().GetHeight()/2)) self.Centre() + #Timer set; used to check if profile is on the clipboard + self.timer = wx.Timer(self) + self.Bind(wx.EVT_TIMER, self.onTimer) + self.timer.Start(1000) + self.lastTriedClipboard = profile.getProfileString() + # Restore the window position, size & state from the preferences file try: if profile.getPreference('window_maximized') == 'True': @@ -231,6 +245,30 @@ class mainWindow(wx.Frame): self.updateSliceMode() + def onTimer(self, e): + #Check if there is something in the clipboard + profileString = "" + try: + if not wx.TheClipboard.IsOpened(): + wx.TheClipboard.Open() + do = wx.TextDataObject() + if wx.TheClipboard.GetData(do): + profileString = do.GetText() + wx.TheClipboard.Close() + + if "CURA_PROFILE_STRING:" in profileString: + #print "Found correct syntax on clipboard" + profileString = profileString.replace("\n","") + profileString = profileString.replace("CURA_PROFILE_STRING:", "") + if profileString != self.lastTriedClipboard: + self.lastTriedClipboard = profileString + profile.setProfileFromString(profileString) + print "changed profile" + self.updateProfileToAllControls() + except: + print "Unable to read from clipboard" + + def updateSliceMode(self): isSimple = profile.getPreference('startMode') == 'Simple' @@ -268,7 +306,7 @@ class mainWindow(wx.Frame): def OnDropFiles(self, files): if len(files) > 0: profile.setPluginConfig([]) - self.updateProfileToControls() + self.updateProfileToAllControls() self.scene.loadScene(files) def OnModelMRU(self, e): @@ -300,7 +338,7 @@ class mainWindow(wx.Frame): self.config.Flush() # Load Profile profile.loadProfile(path) - self.updateProfileToControls() + self.updateProfileToAllControls() def addToProfileMRU(self, file): self.profileFileHistory.AddFileToHistory(file) @@ -308,7 +346,7 @@ class mainWindow(wx.Frame): self.profileFileHistory.Save(self.config) self.config.Flush() - def updateProfileToControls(self): + def updateProfileToAllControls(self): self.scene.updateProfileToControls() self.normalSettingsPanel.updateProfileToControls() self.simpleSettingsPanel.updateProfileToControls() @@ -319,7 +357,7 @@ class mainWindow(wx.Frame): if dlg.ShowModal() == wx.ID_OK: profileFile = dlg.GetPath() profile.loadProfile(profileFile) - self.updateProfileToControls() + self.updateProfileToAllControls() # Update the Profile MRU self.addToProfileMRU(profileFile) @@ -334,10 +372,10 @@ class mainWindow(wx.Frame): hasProfile = False for line in f: if line.startswith(';CURA_PROFILE_STRING:'): - profile.loadProfileFromString(line[line.find(':')+1:].strip()) + profile.setProfileFromString(line[line.find(':')+1:].strip()) hasProfile = True if hasProfile: - self.updateProfileToControls() + self.updateProfileToAllControls() 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) dlg.Destroy() @@ -356,7 +394,7 @@ class mainWindow(wx.Frame): dlg.Destroy() if result: profile.resetProfile() - self.updateProfileToControls() + self.updateProfileToAllControls() def OnSimpleSwitch(self, e): profile.putPreference('startMode', 'Simple') @@ -383,7 +421,7 @@ class mainWindow(wx.Frame): def OnFirstRunWizard(self, e): configWizard.configWizard() - self.updateProfileToControls() + self.updateProfileToAllControls() def OnBedLevelWizard(self, e): configWizard.bedLevelWizard() @@ -406,6 +444,19 @@ class mainWindow(wx.Frame): debugger.Centre() debugger.Show(True) + def onCopyProfileClipboard(self, e): + try: + if not wx.TheClipboard.IsOpened(): + wx.TheClipboard.Open() + clipData = wx.TextDataObject() + self.lastTriedClipboard = profile.getProfileString() + profileString = profile.insertNewlines("CURA_PROFILE_STRING:" + self.lastTriedClipboard) + clipData.SetText(profileString) + wx.TheClipboard.SetData(clipData) + wx.TheClipboard.Close() + except: + print "Could not write to clipboard, unable to get ownership. Another program is using the clipboard." + def OnCheckForUpdate(self, e): newVersion = version.checkForNewerVersion() if newVersion is not None: @@ -447,8 +498,8 @@ class mainWindow(wx.Frame): profile.putPreference('window_pos_y', posy) (width, height) = self.GetSize() profile.putPreference('window_width', width) - profile.putPreference('window_height', height) - + profile.putPreference('window_height', height) + # Save normal sash position. If in normal mode (!simple mode), get last position of sash before saving it... isSimple = profile.getPreference('startMode') == 'Simple' if not isSimple: @@ -477,7 +528,7 @@ class normalSettingsPanel(configBase.configPanelBase): (left, right, self.printPanel) = self.CreateDynamicConfigTab(self.nb, 'Basic') self._addSettingsToPanels('basic', left, right) self.SizeLabelWidths(left, right) - + (left, right, self.advancedPanel) = self.CreateDynamicConfigTab(self.nb, 'Advanced') self._addSettingsToPanels('advanced', left, right) self.SizeLabelWidths(left, right) diff --git a/Cura/gui/preferencesDialog.py b/Cura/gui/preferencesDialog.py index b14a55ba..c70fca07 100644 --- a/Cura/gui/preferencesDialog.py +++ b/Cura/gui/preferencesDialog.py @@ -74,5 +74,5 @@ class preferencesDialog(wx.Dialog): def OnClose(self, e): if self.oldExtruderAmount != int(profile.getMachineSetting('extruder_amount')): wx.MessageBox(_("After changing the amount of extruders you need to restart Cura for full effect."), _("Extruder amount warning."), wx.OK | wx.ICON_INFORMATION) - self.parent.updateProfileToControls() + self.parent.updateProfileToAllControls() self.Destroy() diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 4178fa66..5249237f 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -490,7 +490,7 @@ def resetProfile(): else: putProfileSetting('nozzle_size', '0.5') -def loadProfileFromString(options): +def setProfileFromString(options): options = base64.b64decode(options) options = zlib.decompress(options) (profileOpts, alt) = options.split('\f', 1) @@ -518,7 +518,7 @@ def getProfileString(): p.append(set.getName() + "=" + tempOverride[set.getName()]) else: p.append(set.getName() + "=" + set.getValue()) - if set.isAlteration(): + elif set.isAlteration(): if set.getName() in tempOverride: alt.append(set.getName() + "=" + tempOverride[set.getName()]) else: @@ -527,6 +527,12 @@ def getProfileString(): ret = base64.b64encode(zlib.compress(ret, 9)) return ret +def insertNewlines(string, every=64): #This should be moved to a better place then profile. + lines = [] + for i in xrange(0, len(string), every): + lines.append(string[i:i+every]) + return '\n'.join(lines) + def getPreferencesString(): p = [] global settingsList