2 This page is in the table of contents.
3 Profile is a script to set the craft types setting for the skeinforge chain.
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.
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.
9 To change the profile setting, in a shell in the profile folder type:
14 from __future__ import absolute_import
15 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
18 from fabmetheus_utilities import archive
19 from fabmetheus_utilities import euclidean
20 from fabmetheus_utilities import settings
21 from skeinforge_application.skeinforge_utilities import skeinforge_profile
25 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
26 __date__ = '$Date: 2008/21/04 $'
27 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
30 def addSubmenus( craftTypeName, menu, pluginFileName, pluginPath, profileRadioVar ):
31 "Add a tool plugin menu."
32 submenu = settings.Tkinter.Menu( menu, tearoff = 0 )
33 menu.add_cascade( label = pluginFileName.capitalize(), menu = submenu )
34 settings.ToolDialog().addPluginToMenu( submenu, pluginPath )
35 submenu.add_separator()
36 pluginModule = skeinforge_profile.getCraftTypePluginModule( pluginFileName )
37 profilePluginSettings = settings.getReadRepository( pluginModule.getNewRepository() )
38 isSelected = ( craftTypeName == pluginFileName )
39 for profileName in profilePluginSettings.profileList.value:
40 value = isSelected and profileName == profilePluginSettings.profileListbox.value
41 ProfileMenuRadio( pluginFileName, submenu, profileName, profileRadioVar, value )
43 def addToMenu( master, menu, repository, window ):
44 "Add a tool plugin menu."
45 ProfileMenuSaveListener( menu, window )
47 def addToProfileMenu( menu ):
49 settings.ToolDialog().addPluginToMenu(menu, archive.getUntilDot(archive.getSkeinforgePluginsPath('profile.py')))
51 directoryPath = skeinforge_profile.getPluginsDirectoryPath()
52 pluginFileNames = skeinforge_profile.getPluginFileNames()
53 craftTypeName = skeinforge_profile.getCraftTypeName()
54 profileRadioVar = settings.Tkinter.StringVar()
55 for pluginFileName in pluginFileNames:
56 addSubmenus( craftTypeName, menu, pluginFileName, os.path.join( directoryPath, pluginFileName ), profileRadioVar )
58 def getNewRepository():
60 return skeinforge_profile.ProfileRepository()
63 class ProfileMenuRadio:
64 "A class to display a profile menu radio button."
65 def __init__( self, profilePluginFileName, menu, name, radioVar, value ):
66 "Create a profile menu radio."
70 self.profileJoinName = profilePluginFileName + '.& /' + name
71 self.profilePluginFileName = profilePluginFileName
72 self.radioVar = radioVar
73 menu.add_radiobutton( label = name.replace('_', ' '), command = self.clickRadio, value = self.profileJoinName, variable = self.radioVar )
74 self.menuLength = menu.index( settings.Tkinter.END )
76 self.radioVar.set( self.profileJoinName )
77 self.menu.invoke( self.menuLength )
81 "Workaround for Tkinter bug, invoke and set the value when clicked."
84 self.radioVar.set( self.profileJoinName )
85 pluginModule = skeinforge_profile.getCraftTypePluginModule( self.profilePluginFileName )
86 profilePluginSettings = settings.getReadRepository( pluginModule.getNewRepository() )
87 profilePluginSettings.profileListbox.value = self.name
88 settings.writeSettings( profilePluginSettings )
89 profileSettings = skeinforge_profile.getReadProfileRepository()
90 plugins = profileSettings.craftRadios
91 for plugin in plugins:
92 plugin.value = ( plugin.name == self.profilePluginFileName )
93 settings.writeSettings( profileSettings )
94 skeinforge_profile.updateProfileSaveListeners()
97 class ProfileMenuSaveListener:
98 "A class to update a profile menu."
99 def __init__( self, menu, window ):
102 addToProfileMenu( menu )
103 euclidean.addElementToListDictionaryIfNotThere( self, window, settings.globalProfileSaveListenerListTable )
106 "Profile has been saved and profile menu should be updated."
107 settings.deleteMenuItems( self.menu )
108 addToProfileMenu( self.menu )
112 "Display the profile dialog."
113 settings.startMainLoopFromConstructor(getNewRepository())
115 if __name__ == "__main__":