99from dynOptionMenuWidget import DynOptionMenu
1010from tabpage import TabPageSet
1111from keybindingDialog import GetKeysDialog
12-
12+ from configSectionNameDialog import GetCfgSectionNameDialog
1313class ConfigDialog (Toplevel ):
1414 """
1515 configuration dialog for idle
@@ -222,7 +222,7 @@ def CreatePageHighlight(self):
222222 value = 0 ,text = 'Background' ,command = self .SetColourSampleBinding )
223223 self .fgHilite .set (1 )
224224 buttonSaveCustomTheme = Button (frameCustom ,
225- text = 'Save as a Custom Theme' )
225+ text = 'Save as New Custom Theme' )
226226 #frameTheme
227227 labelThemeTitle = Label (frameTheme ,text = 'Select a Highlighting Theme' )
228228 labelTypeTitle = Label (frameTheme ,text = 'Select : ' )
@@ -287,7 +287,7 @@ def CreatePageKeys(self):
287287 self .listBindings .config (xscrollcommand = scrollTargetX .set )
288288 self .buttonNewKeys = Button (frameCustom ,text = 'Get New Keys for Selection' ,
289289 command = self .GetNewKeys ,state = DISABLED )
290- buttonSaveCustomKeys = Button (frameCustom ,text = 'Save as a Custom Key Set' )
290+ buttonSaveCustomKeys = Button (frameCustom ,text = 'Save as New Custom Key Set' )
291291 #frameKeySets
292292 labelKeysTitle = Label (frameKeySets ,text = 'Select a Key Set' )
293293 labelTypeTitle = Label (frameKeySets ,text = 'Select : ' )
@@ -496,6 +496,7 @@ def SetThemeType(self):
496496 self .buttonDeleteCustomTheme .config (state = DISABLED )
497497 else :
498498 self .optMenuThemeBuiltin .config (state = DISABLED )
499+ self .radioThemeCustom .config (state = NORMAL )
499500 self .optMenuThemeCustom .config (state = NORMAL )
500501 self .buttonDeleteCustomTheme .config (state = NORMAL )
501502
@@ -506,22 +507,107 @@ def SetKeysType(self):
506507 self .buttonDeleteCustomKeys .config (state = DISABLED )
507508 else :
508509 self .optMenuKeysBuiltin .config (state = DISABLED )
510+ self .radioKeysCustom .config (state = NORMAL )
509511 self .optMenuKeysCustom .config (state = NORMAL )
510512 self .buttonDeleteCustomKeys .config (state = NORMAL )
511513
514+ def GetNewKeys (self ):
515+ listIndex = self .listBindings .index (ANCHOR )
516+ binding = self .listBindings .get (listIndex )
517+ bindName = binding .split ()[0 ] #first part, up to first space
518+ currentKeySequences = idleConf .GetCurrentKeySet ().values ()
519+ newKeys = GetKeysDialog (self ,'Get New Keys' ,bindName ,currentKeySequences )
520+ if newKeys .result : #new keys were specified
521+ if self .keysAreDefault .get (): #current key set is a built-in
522+ message = ('Your changes will be saved as a new Custom Key Set. ' +
523+ 'Enter a name for your new Custom Key Set below.' )
524+ usedNames = idleConf .GetSectionList ('user' ,'keys' )
525+ newKeySet = GetCfgSectionNameDialog (self ,'New Custom Key Set' ,
526+ message ,usedNames )
527+ if not newKeySet .result : #user cancelled custom key set creation
528+ self .listBindings .select_set (listIndex )
529+ self .listBindings .select_anchor (listIndex )
530+ return
531+ else : #create new custom key set based on previously active key set
532+ self .CreateNewKeySet (newKeySet .result )
533+ self .listBindings .delete (listIndex )
534+ self .listBindings .insert (listIndex ,bindName + ' - ' + newKeys .result )
535+ self .listBindings .select_set (listIndex )
536+ self .listBindings .select_anchor (listIndex )
537+ self .keyBinding .set (newKeys .result )
538+ else :
539+ self .listBindings .select_set (listIndex )
540+ self .listBindings .select_anchor (listIndex )
541+
542+ def KeyBindingSelected (self ,event ):
543+ self .buttonNewKeys .config (state = NORMAL )
544+
545+ def CreateNewKeySet (self ,newKeySetName ):
546+ #creates new custom key set based on the previously active key set,
547+ #and makes the new key set active
548+ if self .keysAreDefault .get ():
549+ keySetName = self .builtinKeys .get ()
550+ else :
551+ keySetName = self .customKeys .get ()
552+ prevKeySet = idleConf .GetKeySet (keySetName )
553+ #add the new key set to changedItems
554+ for event in prevKeySet .keys ():
555+ eventName = event [2 :- 2 ] #trim off the angle brackets
556+ self .AddChangedItem ('keys' ,newKeySetName ,eventName ,
557+ prevKeySet [event ])
558+ #change gui over to the new key set
559+ customKeyList = idleConf .GetSectionList ('user' ,'keys' )
560+ customKeyList .append (newKeySetName )
561+ customKeyList .sort ()
562+ print newKeySetName ,customKeyList ,self .changedItems ['keys' ][newKeySetName ]
563+ self .optMenuKeysCustom .SetMenu (customKeyList ,newKeySetName )
564+ self .keysAreDefault .set (0 )
565+ self .SetKeysType ()
566+
512567 def GetColour (self ):
513568 target = self .highlightTarget .get ()
514569 rgbTuplet , colourString = tkColorChooser .askcolor (parent = self ,
515570 title = 'Pick new colour for : ' + target ,
516571 initialcolor = self .frameColourSet .cget ('bg' ))
517572 if colourString : #user didn't cancel
573+ if self .themeIsBuiltin .get (): #current theme is a built-in
574+ message = ('Your changes will be saved as a new Custom Theme. ' +
575+ 'Enter a name for your new Custom Theme below.' )
576+ usedNames = idleConf .GetSectionList ('user' ,'highlight' )
577+ newTheme = GetCfgSectionNameDialog (self ,'New Custom Theme' ,
578+ message ,usedNames )
579+ if not newTheme .result : #user cancelled custom theme creation
580+ return
581+ else : #create new custom theme based on previously active theme
582+ self .CreateNewTheme (newTheme .result )
518583 self .colour .set (colourString )
519584 self .frameColourSet .config (bg = colourString )#set sample
520585 if self .fgHilite .get (): plane = 'foreground'
521586 else : plane = 'background'
522587 apply (self .textHighlightSample .tag_config ,
523588 (self .themeElements [target ][0 ],),{plane :colourString })
524589
590+ def CreateNewTheme (self ,newThemeName ):
591+ #creates new custom theme based on the previously active theme,
592+ #and makes the new theme active
593+ if self .themeIsBuiltin .get ():
594+ themeType = 'default'
595+ themeName = self .builtinTheme .get ()
596+ else :
597+ themeType = 'user'
598+ themeName = self .customTheme .get ()
599+ newTheme = idleConf .GetThemeDict (themeType ,themeName )
600+ #add the new theme to changedItems
601+ self .changedItems ['highlight' ][newThemeName ]= newTheme
602+ #change gui over to the new theme
603+ customThemeList = idleConf .GetSectionList ('user' ,'highlight' )
604+ customThemeList .append (newThemeName )
605+ customThemeList .sort ()
606+ print newThemeName ,customThemeList ,newTheme
607+ self .optMenuThemeCustom .SetMenu (customThemeList ,newThemeName )
608+ self .themeIsBuiltin .set (0 )
609+ self .SetThemeType ()
610+
525611 def OnListFontButtonRelease (self ,event ):
526612 self .fontName .set (self .listFontName .get (ANCHOR ))
527613 self .SetFontSample ()
@@ -620,17 +706,21 @@ def LoadThemeCfg(self):
620706 ##load available theme option menus
621707 if self .themeIsBuiltin .get (): #default theme selected
622708 itemList = idleConf .GetSectionList ('default' ,'highlight' )
709+ itemList .sort ()
623710 self .optMenuThemeBuiltin .SetMenu (itemList ,currentOption )
624711 itemList = idleConf .GetSectionList ('user' ,'highlight' )
712+ itemList .sort ()
625713 if not itemList :
626714 self .radioThemeCustom .config (state = DISABLED )
627715 self .customTheme .set ('- no custom themes -' )
628716 else :
629717 self .optMenuThemeCustom .SetMenu (itemList ,itemList [0 ])
630718 else : #user theme selected
631719 itemList = idleConf .GetSectionList ('user' ,'highlight' )
720+ itemList .sort ()
632721 self .optMenuThemeCustom .SetMenu (itemList ,currentOption )
633722 itemList = idleConf .GetSectionList ('default' ,'highlight' )
723+ itemList .sort ()
634724 self .optMenuThemeBuiltin .SetMenu (itemList ,itemList [0 ])
635725 self .SetThemeType ()
636726 ##load theme element option menu
@@ -654,17 +744,21 @@ def LoadKeyCfg(self):
654744 ##load available keyset option menus
655745 if self .keysAreDefault .get (): #default theme selected
656746 itemList = idleConf .GetSectionList ('default' ,'keys' )
747+ itemList .sort ()
657748 self .optMenuKeysBuiltin .SetMenu (itemList ,currentOption )
658749 itemList = idleConf .GetSectionList ('user' ,'keys' )
750+ itemList .sort ()
659751 if not itemList :
660752 self .radioKeysCustom .config (state = DISABLED )
661753 self .customKeys .set ('- no custom keys -' )
662754 else :
663755 self .optMenuKeysCustom .SetMenu (itemList ,itemList [0 ])
664756 else : #user theme selected
665757 itemList = idleConf .GetSectionList ('user' ,'keys' )
758+ itemList .sort ()
666759 self .optMenuKeysCustom .SetMenu (itemList ,currentOption )
667760 itemList = idleConf .GetSectionList ('default' ,'keys' )
761+ itemList .sort ()
668762 self .optMenuKeysBuiltin .SetMenu (itemList ,itemList [0 ])
669763 self .SetKeysType ()
670764 ##load keyset element list
@@ -676,25 +770,6 @@ def LoadKeyCfg(self):
676770 bindName = bindName [2 :- 2 ] #trim off the angle brackets
677771 self .listBindings .insert (END , bindName + ' - ' + key )
678772
679- def GetNewKeys (self ):
680- listIndex = self .listBindings .index (ANCHOR )
681- binding = self .listBindings .get (listIndex )
682- bindName = binding .split ()[0 ] #first part, up to first space
683- currentKeySequences = idleConf .GetCurrentKeySet ().values ()
684- newKeys = GetKeysDialog (self ,'Get New Keys' ,bindName ,currentKeySequences )
685- if newKeys .result : #new keys were specified
686- self .listBindings .delete (listIndex )
687- self .listBindings .insert (listIndex ,bindName + ' - ' + newKeys .result )
688- self .listBindings .select_set (listIndex )
689- self .listBindings .select_anchor (listIndex )
690- self .keyBinding .set (newKeys .result )
691- else :
692- self .listBindings .select_set (listIndex )
693- self .listBindings .select_anchor (listIndex )
694-
695- def KeyBindingSelected (self ,event ):
696- self .buttonNewKeys .config (state = NORMAL )
697-
698773 def LoadGeneralCfg (self ):
699774 #startup state
700775 self .startupEdit .set (idleConf .GetOption ('main' ,'General' ,
0 commit comments