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
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
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'
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 )
41 def addToMenu( master, menu, repository, window ):
42 "Add a tool plugin menu."
43 ProfileMenuSaveListener( menu, window )
45 def addToProfileMenu( menu ):
47 settings.ToolDialog().addPluginToMenu(menu, archive.getUntilDot(archive.getSkeinforgePluginsPath('profile.py')))
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 )
56 def getNewRepository():
58 return skeinforge_profile.ProfileRepository()
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."
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 )
74 self.radioVar.set( self.profileJoinName )
75 self.menu.invoke( self.menuLength )
79 "Workaround for Tkinter bug, invoke and set the value when clicked."
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()
95 class ProfileMenuSaveListener(object):
96 "A class to update a profile menu."
97 def __init__( self, menu, window ):
100 addToProfileMenu( menu )
101 euclidean.addElementToListDictionaryIfNotThere( self, window, settings.globalProfileSaveListenerListTable )
104 "Profile has been saved and profile menu should be updated."
105 settings.deleteMenuItems( self.menu )
106 addToProfileMenu( self.menu )
110 "Display the profile dialog."
111 settings.startMainLoopFromConstructor(getNewRepository())
113 if __name__ == "__main__":