chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / cura_sf / skeinforge_application / skeinforge_plugins / profile.py
1 """
2 This page is in the table of contents.
3 Profile is a script to set the craft types setting for the skeinforge chain.
4
5 Profile presents the user with a choice of the craft types in the profile_plugins folder.  The chosen craft type is used to determine the craft type profile for the skeinforge chain.  The default craft type is extrusion.
6
7 The setting is the selection.  If you hit 'Save and Close' the selection will be saved, if you hit 'Cancel' the selection will not be saved.
8
9 To change the profile setting, in a shell in the profile folder type:
10 > python profile.py
11
12 """
13
14 from __future__ import absolute_import
15
16 from fabmetheus_utilities import archive
17 from fabmetheus_utilities import euclidean
18 from fabmetheus_utilities import settings
19 from skeinforge_application.skeinforge_utilities import skeinforge_profile
20 import os
21
22
23 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
24 __date__ = '$Date: 2008/21/04 $'
25 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
26
27
28 def addSubmenus( craftTypeName, menu, pluginFileName, pluginPath, profileRadioVar ):
29         "Add a tool plugin menu."
30         submenu = settings.Tkinter.Menu( menu, tearoff = 0 )
31         menu.add_cascade( label = pluginFileName.capitalize(), menu = submenu )
32         settings.ToolDialog().addPluginToMenu( submenu, pluginPath )
33         submenu.add_separator()
34         pluginModule = skeinforge_profile.getCraftTypePluginModule( pluginFileName )
35         profilePluginSettings = settings.getReadRepository( pluginModule.getNewRepository() )
36         isSelected = ( craftTypeName == pluginFileName )
37         for profileName in profilePluginSettings.profileList.value:
38                 value = isSelected and profileName == profilePluginSettings.profileListbox.value
39                 ProfileMenuRadio( pluginFileName, submenu, profileName, profileRadioVar, value )
40
41 def addToMenu( master, menu, repository, window ):
42         "Add a tool plugin menu."
43         ProfileMenuSaveListener( menu, window )
44
45 def addToProfileMenu( menu ):
46         "Add a profile menu."
47         settings.ToolDialog().addPluginToMenu(menu, archive.getUntilDot(archive.getSkeinforgePluginsPath('profile.py')))
48         menu.add_separator()
49         directoryPath = skeinforge_profile.getPluginsDirectoryPath()
50         pluginFileNames = skeinforge_profile.getPluginFileNames()
51         craftTypeName = skeinforge_profile.getCraftTypeName()
52         profileRadioVar = settings.Tkinter.StringVar()
53         for pluginFileName in pluginFileNames:
54                 addSubmenus( craftTypeName, menu, pluginFileName, os.path.join( directoryPath, pluginFileName ), profileRadioVar )
55
56 def getNewRepository():
57         'Get new repository.'
58         return skeinforge_profile.ProfileRepository()
59
60
61 class ProfileMenuRadio(object):
62         "A class to display a profile menu radio button."
63         def __init__( self, profilePluginFileName, menu, name, radioVar, value ):
64                 "Create a profile menu radio."
65                 self.activate = False
66                 self.menu = menu
67                 self.name = name
68                 self.profileJoinName = profilePluginFileName + '.& /' + name
69                 self.profilePluginFileName = profilePluginFileName
70                 self.radioVar = radioVar
71                 menu.add_radiobutton( label = name.replace('_', ' '), command = self.clickRadio, value = self.profileJoinName, variable = self.radioVar )
72                 self.menuLength = menu.index( settings.Tkinter.END )
73                 if value:
74                         self.radioVar.set( self.profileJoinName )
75                         self.menu.invoke( self.menuLength )
76                 self.activate = True
77
78         def clickRadio(self):
79                 "Workaround for Tkinter bug, invoke and set the value when clicked."
80                 if not self.activate:
81                         return
82                 self.radioVar.set( self.profileJoinName )
83                 pluginModule = skeinforge_profile.getCraftTypePluginModule( self.profilePluginFileName )
84                 profilePluginSettings = settings.getReadRepository( pluginModule.getNewRepository() )
85                 profilePluginSettings.profileListbox.value = self.name
86                 settings.writeSettings( profilePluginSettings )
87                 profileSettings = skeinforge_profile.getReadProfileRepository()
88                 plugins = profileSettings.craftRadios
89                 for plugin in plugins:
90                         plugin.value = ( plugin.name == self.profilePluginFileName )
91                 settings.writeSettings( profileSettings )
92                 skeinforge_profile.updateProfileSaveListeners()
93
94
95 class ProfileMenuSaveListener(object):
96         "A class to update a profile menu."
97         def __init__( self, menu, window ):
98                 "Set the menu."
99                 self.menu = menu
100                 addToProfileMenu( menu )
101                 euclidean.addElementToListDictionaryIfNotThere( self, window, settings.globalProfileSaveListenerListTable )
102
103         def save(self):
104                 "Profile has been saved and profile menu should be updated."
105                 settings.deleteMenuItems( self.menu )
106                 addToProfileMenu( self.menu )
107
108
109 def main():
110         "Display the profile dialog."
111         settings.startMainLoopFromConstructor(getNewRepository())
112
113 if __name__ == "__main__":
114         main()