9
9
Refer to comments in EditorWindow autoindent code for details.
10
10
11
11
"""
12
- from tkinter import (Toplevel , Frame , LabelFrame , Listbox , Label , Button ,
13
- Entry , Text , Scale , Radiobutton , Checkbutton , Canvas ,
12
+ from tkinter import (Toplevel , Listbox , Text , Scale , Canvas ,
14
13
StringVar , BooleanVar , IntVar , TRUE , FALSE ,
15
14
TOP , BOTTOM , RIGHT , LEFT , SOLID , GROOVE , NORMAL , DISABLED ,
16
15
NONE , BOTH , X , Y , W , E , EW , NS , NSEW , NW ,
17
16
HORIZONTAL , VERTICAL , ANCHOR , ACTIVE , END )
18
- from tkinter .ttk import Notebook , Scrollbar
17
+ from tkinter .ttk import (Button , Checkbutton , Entry , Frame , Label , LabelFrame ,
18
+ Notebook , Radiobutton , Scrollbar , Style )
19
19
import tkinter .colorchooser as tkColorChooser
20
20
import tkinter .font as tkFont
21
21
import tkinter .messagebox as tkMessageBox
@@ -137,9 +137,9 @@ def create_action_buttons(self):
137
137
# text in the buttons.
138
138
padding_args = {}
139
139
else :
140
- padding_args = {'padx' : 6 , 'pady' : 3 }
141
- outer = Frame (self , pady = 2 )
142
- buttons = Frame (outer , pady = 2 )
140
+ padding_args = {'padding' : ( 6 , 3 ) }
141
+ outer = Frame (self , padding = 2 )
142
+ buttons = Frame (outer , padding = 2 )
143
143
for txt , cmd in (
144
144
('Ok' , self .ok ),
145
145
('Apply' , self .apply ),
@@ -266,7 +266,7 @@ def create_page_extensions(self):
266
266
self .extension_list .grid (column = 0 , row = 0 , sticky = 'nws' )
267
267
scroll .grid (column = 1 , row = 0 , sticky = 'ns' )
268
268
self .details_frame .grid (column = 2 , row = 0 , sticky = 'nsew' , padx = [10 , 0 ])
269
- frame .configure (padx = 10 , pady = 10 )
269
+ frame .configure (padding = 10 )
270
270
self .config_frame = {}
271
271
self .current_extension = None
272
272
@@ -356,9 +356,8 @@ def create_extension_frame(self, ext_name):
356
356
label .grid (row = row , column = 0 , sticky = NW )
357
357
var = opt ['var' ]
358
358
if opt ['type' ] == 'bool' :
359
- Checkbutton (entry_area , textvariable = var , variable = var ,
360
- onvalue = 'True' , offvalue = 'False' ,
361
- indicatoron = FALSE , selectcolor = '' , width = 8
359
+ Checkbutton (entry_area , variable = var ,
360
+ onvalue = 'True' , offvalue = 'False' , width = 8
362
361
).grid (row = row , column = 1 , sticky = W , padx = 7 )
363
362
elif opt ['type' ] == 'int' :
364
363
Entry (entry_area , textvariable = var , validate = 'key' ,
@@ -635,6 +634,7 @@ class HighPage(Frame):
635
634
def __init__ (self , master ):
636
635
super ().__init__ (master )
637
636
self .cd = master .master
637
+ self .style = Style (master )
638
638
self .create_page_highlight ()
639
639
self .load_theme_cfg ()
640
640
@@ -821,12 +821,14 @@ def tem(event, elem=element):
821
821
self .highlight_target .set (elem )
822
822
text .tag_bind (
823
823
self .theme_elements [element ][0 ], '<ButtonPress-1>' , tem )
824
- text ['state' ] = DISABLED
825
- self .frame_color_set = Frame (frame_custom , relief = SOLID , borderwidth = 1 )
824
+ text ['state' ] = 'disabled'
825
+ self .style .configure ('frame_color_set.TFrame' , borderwidth = 1 ,
826
+ relief = 'solid' )
827
+ self .frame_color_set = Frame (frame_custom , style = 'frame_color_set.TFrame' )
826
828
frame_fg_bg_toggle = Frame (frame_custom )
827
829
self .button_set_color = Button (
828
830
self .frame_color_set , text = 'Choose Color for :' ,
829
- command = self .get_color , highlightthickness = 0 )
831
+ command = self .get_color )
830
832
self .targetlist = DynOptionMenu (
831
833
self .frame_color_set , self .highlight_target , None ,
832
834
highlightthickness = 0 ) #, command=self.set_highlight_targetBinding
@@ -855,7 +857,7 @@ def tem(event, elem=element):
855
857
self .button_delete_custom = Button (
856
858
frame_theme , text = 'Delete Custom Theme' ,
857
859
command = self .delete_custom )
858
- self .theme_message = Label (frame_theme , bd = 2 )
860
+ self .theme_message = Label (frame_theme , borderwidth = 2 )
859
861
860
862
# Pack widgets:
861
863
# body.
@@ -913,7 +915,7 @@ def load_theme_cfg(self):
913
915
item_list = idleConf .GetSectionList ('user' , 'highlight' )
914
916
item_list .sort ()
915
917
if not item_list :
916
- self .custom_theme_on [ ' state' ] = DISABLED
918
+ self .custom_theme_on . state (( 'disabled' ,))
917
919
self .custom_name .set ('- no custom themes -' )
918
920
else :
919
921
self .customlist .SetMenu (item_list , item_list [0 ])
@@ -945,12 +947,10 @@ def var_changed_builtin_name(self, *params):
945
947
changes .add_option ('main' , 'Theme' , 'name' , old_themes [0 ])
946
948
changes .add_option ('main' , 'Theme' , 'name2' , value )
947
949
self .theme_message ['text' ] = 'New theme, see Help'
948
- self .theme_message ['fg' ] = '#500000'
949
950
else :
950
951
changes .add_option ('main' , 'Theme' , 'name' , value )
951
952
changes .add_option ('main' , 'Theme' , 'name2' , '' )
952
953
self .theme_message ['text' ] = ''
953
- self .theme_message ['fg' ] = 'black'
954
954
self .paint_theme_sample ()
955
955
956
956
def var_changed_custom_name (self , * params ):
@@ -1004,14 +1004,14 @@ def set_theme_type(self):
1004
1004
load_theme_cfg
1005
1005
"""
1006
1006
if self .theme_source .get ():
1007
- self .builtinlist ['state' ] = NORMAL
1008
- self .customlist ['state' ] = DISABLED
1009
- self .button_delete_custom [ ' state' ] = DISABLED
1007
+ self .builtinlist ['state' ] = 'normal'
1008
+ self .customlist ['state' ] = 'disabled'
1009
+ self .button_delete_custom . state (( 'disabled' ,))
1010
1010
else :
1011
- self .builtinlist ['state' ] = DISABLED
1012
- self .custom_theme_on [ ' state' ] = NORMAL
1013
- self .customlist ['state' ] = NORMAL
1014
- self .button_delete_custom [ ' state' ] = NORMAL
1011
+ self .builtinlist ['state' ] = 'disabled'
1012
+ self .custom_theme_on . state (( '!disabled' ,))
1013
+ self .customlist ['state' ] = 'normal'
1014
+ self .button_delete_custom . state (( '!disabled' ,))
1015
1015
1016
1016
def get_color (self ):
1017
1017
"""Handle button to select a new color for the target tag.
@@ -1032,7 +1032,8 @@ def get_color(self):
1032
1032
create_new
1033
1033
"""
1034
1034
target = self .highlight_target .get ()
1035
- prev_color = self .frame_color_set .cget ('bg' )
1035
+ prev_color = self .style .lookup (self .frame_color_set ['style' ],
1036
+ 'background' )
1036
1037
rgbTuplet , color_string = tkColorChooser .askcolor (
1037
1038
parent = self , title = 'Pick new color for : ' + target ,
1038
1039
initialcolor = prev_color )
@@ -1053,7 +1054,7 @@ def get_color(self):
1053
1054
def on_new_color_set (self ):
1054
1055
"Display sample of new color selection on the dialog."
1055
1056
new_color = self .color .get ()
1056
- self .frame_color_set [ 'bg' ] = new_color # Set sample.
1057
+ self .style . configure ( ' frame_color_set.TFrame' , background = new_color )
1057
1058
plane = 'foreground' if self .fg_bg_toggle .get () else 'background'
1058
1059
sample_element = self .theme_elements [self .highlight_target .get ()][0 ]
1059
1060
self .highlight_sample .tag_config (sample_element , ** {plane : new_color })
@@ -1139,12 +1140,12 @@ def set_highlight_target(self):
1139
1140
load_theme_cfg
1140
1141
"""
1141
1142
if self .highlight_target .get () == 'Cursor' : # bg not possible
1142
- self .fg_on [ ' state' ] = DISABLED
1143
- self .bg_on [ ' state' ] = DISABLED
1143
+ self .fg_on . state (( 'disabled' ,))
1144
+ self .bg_on . state (( 'disabled' ,))
1144
1145
self .fg_bg_toggle .set (1 )
1145
1146
else : # Both fg and bg can be set.
1146
- self .fg_on [ ' state' ] = NORMAL
1147
- self .bg_on [ ' state' ] = NORMAL
1147
+ self .fg_on . state (( '!disabled' ,))
1148
+ self .bg_on . state (( '!disabled' ,))
1148
1149
self .fg_bg_toggle .set (1 )
1149
1150
self .set_color_sample ()
1150
1151
@@ -1172,7 +1173,7 @@ def set_color_sample(self):
1172
1173
tag = self .theme_elements [self .highlight_target .get ()][0 ]
1173
1174
plane = 'foreground' if self .fg_bg_toggle .get () else 'background'
1174
1175
color = self .highlight_sample .tag_cget (tag , plane )
1175
- self .frame_color_set [ 'bg' ] = color
1176
+ self .style . configure ( ' frame_color_set.TFrame' , background = color )
1176
1177
1177
1178
def paint_theme_sample (self ):
1178
1179
"""Apply the theme colors to each element tag in the sample text.
@@ -1260,7 +1261,7 @@ def delete_custom(self):
1260
1261
item_list = idleConf .GetSectionList ('user' , 'highlight' )
1261
1262
item_list .sort ()
1262
1263
if not item_list :
1263
- self .custom_theme_on [ ' state' ] = DISABLED
1264
+ self .custom_theme_on . state (( 'disabled' ,))
1264
1265
self .customlist .SetMenu (item_list , '- no custom themes -' )
1265
1266
else :
1266
1267
self .customlist .SetMenu (item_list , item_list [0 ])
@@ -1397,7 +1398,7 @@ def create_page_keys(self):
1397
1398
frame_custom , text = 'Get New Keys for Selection' ,
1398
1399
command = self .get_new_keys , state = DISABLED )
1399
1400
# frame_key_sets.
1400
- frames = [Frame (frame_key_sets , padx = 2 , pady = 2 , borderwidth = 0 )
1401
+ frames = [Frame (frame_key_sets , padding = 2 , borderwidth = 0 )
1401
1402
for i in range (2 )]
1402
1403
self .builtin_keyset_on = Radiobutton (
1403
1404
frames [0 ], variable = self .keyset_source , value = 1 ,
@@ -1415,7 +1416,7 @@ def create_page_keys(self):
1415
1416
self .button_save_custom_keys = Button (
1416
1417
frames [1 ], text = 'Save as New Custom Key Set' ,
1417
1418
command = self .save_as_new_key_set )
1418
- self .keys_message = Label (frames [0 ], bd = 2 )
1419
+ self .keys_message = Label (frames [0 ], borderwidth = 2 )
1419
1420
1420
1421
# Pack widgets:
1421
1422
# body.
@@ -1457,7 +1458,7 @@ def load_key_cfg(self):
1457
1458
item_list = idleConf .GetSectionList ('user' , 'keys' )
1458
1459
item_list .sort ()
1459
1460
if not item_list :
1460
- self .custom_keyset_on [ ' state' ] = DISABLED
1461
+ self .custom_keyset_on . state (( 'disabled' ,))
1461
1462
self .custom_name .set ('- no custom keys -' )
1462
1463
else :
1463
1464
self .customlist .SetMenu (item_list , item_list [0 ])
@@ -1487,12 +1488,10 @@ def var_changed_builtin_name(self, *params):
1487
1488
changes .add_option ('main' , 'Keys' , 'name' , old_keys [0 ])
1488
1489
changes .add_option ('main' , 'Keys' , 'name2' , value )
1489
1490
self .keys_message ['text' ] = 'New key set, see Help'
1490
- self .keys_message ['fg' ] = '#500000'
1491
1491
else :
1492
1492
changes .add_option ('main' , 'Keys' , 'name' , value )
1493
1493
changes .add_option ('main' , 'Keys' , 'name2' , '' )
1494
1494
self .keys_message ['text' ] = ''
1495
- self .keys_message ['fg' ] = 'black'
1496
1495
self .load_keys_list (value )
1497
1496
1498
1497
def var_changed_custom_name (self , * params ):
@@ -1526,14 +1525,14 @@ def var_changed_keybinding(self, *params):
1526
1525
def set_keys_type (self ):
1527
1526
"Set available screen options based on builtin or custom key set."
1528
1527
if self .keyset_source .get ():
1529
- self .builtinlist ['state' ] = NORMAL
1530
- self .customlist ['state' ] = DISABLED
1531
- self .button_delete_custom_keys [ ' state' ] = DISABLED
1528
+ self .builtinlist ['state' ] = 'normal'
1529
+ self .customlist ['state' ] = 'disabled'
1530
+ self .button_delete_custom_keys . state (( 'disabled' ,))
1532
1531
else :
1533
- self .builtinlist ['state' ] = DISABLED
1534
- self .custom_keyset_on [ ' state' ] = NORMAL
1535
- self .customlist ['state' ] = NORMAL
1536
- self .button_delete_custom_keys [ ' state' ] = NORMAL
1532
+ self .builtinlist ['state' ] = 'disabled'
1533
+ self .custom_keyset_on . state (( '!disabled' ,))
1534
+ self .customlist ['state' ] = 'normal'
1535
+ self .button_delete_custom_keys . state (( '!disabled' ,))
1537
1536
1538
1537
def get_new_keys (self ):
1539
1538
"""Handle event to change key binding for selected line.
@@ -1595,7 +1594,7 @@ def save_as_new_key_set(self):
1595
1594
1596
1595
def on_bindingslist_select (self , event ):
1597
1596
"Activate button to assign new keys to selected action."
1598
- self .button_new_keys [ ' state' ] = NORMAL
1597
+ self .button_new_keys . state (( '!disabled' ,))
1599
1598
1600
1599
def create_new_key_set (self , new_key_set_name ):
1601
1600
"""Create a new custom key set with the given name.
@@ -1689,7 +1688,7 @@ def delete_custom_keys(self):
1689
1688
item_list = idleConf .GetSectionList ('user' , 'keys' )
1690
1689
item_list .sort ()
1691
1690
if not item_list :
1692
- self .custom_keyset_on [ ' state' ] = DISABLED
1691
+ self .custom_keyset_on . state (( 'disabled' ,))
1693
1692
self .customlist .SetMenu (item_list , '- no custom keys -' )
1694
1693
else :
1695
1694
self .customlist .SetMenu (item_list , item_list [0 ])
@@ -1809,13 +1808,13 @@ def create_page_general(self):
1809
1808
self .helplist ['yscrollcommand' ] = scroll_helplist .set
1810
1809
self .helplist .bind ('<ButtonRelease-1>' , self .help_source_selected )
1811
1810
self .button_helplist_edit = Button (
1812
- frame_helplist_buttons , text = 'Edit' , state = DISABLED ,
1811
+ frame_helplist_buttons , text = 'Edit' , state = 'disabled' ,
1813
1812
width = 8 , command = self .helplist_item_edit )
1814
1813
self .button_helplist_add = Button (
1815
1814
frame_helplist_buttons , text = 'Add' ,
1816
1815
width = 8 , command = self .helplist_item_add )
1817
1816
self .button_helplist_remove = Button (
1818
- frame_helplist_buttons , text = 'Remove' , state = DISABLED ,
1817
+ frame_helplist_buttons , text = 'Remove' , state = 'disabled' ,
1819
1818
width = 8 , command = self .helplist_item_remove )
1820
1819
1821
1820
# Pack widgets:
@@ -1874,15 +1873,15 @@ def help_source_selected(self, event):
1874
1873
def set_add_delete_state (self ):
1875
1874
"Toggle the state for the help list buttons based on list entries."
1876
1875
if self .helplist .size () < 1 : # No entries in list.
1877
- self .button_helplist_edit [ ' state' ] = DISABLED
1878
- self .button_helplist_remove [ ' state' ] = DISABLED
1876
+ self .button_helplist_edit . state (( 'disabled' ,))
1877
+ self .button_helplist_remove . state (( 'disabled' ,))
1879
1878
else : # Some entries.
1880
1879
if self .helplist .curselection (): # There currently is a selection.
1881
- self .button_helplist_edit [ ' state' ] = NORMAL
1882
- self .button_helplist_remove [ ' state' ] = NORMAL
1880
+ self .button_helplist_edit . state (( '!disabled' ,))
1881
+ self .button_helplist_remove . state (( '!disabled' ,))
1883
1882
else : # There currently is not a selection.
1884
- self .button_helplist_edit [ ' state' ] = DISABLED
1885
- self .button_helplist_remove [ ' state' ] = DISABLED
1883
+ self .button_helplist_edit . state (( 'disabled' ,))
1884
+ self .button_helplist_remove . state (( 'disabled' ,))
1886
1885
1887
1886
def helplist_item_add (self ):
1888
1887
"""Handle add button for the help list.
@@ -2062,7 +2061,7 @@ def __init__(self, parent, *args, **kw):
2062
2061
# Create a canvas object and a vertical scrollbar for scrolling it.
2063
2062
vscrollbar = Scrollbar (self , orient = VERTICAL )
2064
2063
vscrollbar .pack (fill = Y , side = RIGHT , expand = FALSE )
2065
- canvas = Canvas (self , bd = 0 , highlightthickness = 0 ,
2064
+ canvas = Canvas (self , borderwidth = 0 , highlightthickness = 0 ,
2066
2065
yscrollcommand = vscrollbar .set , width = 240 )
2067
2066
canvas .pack (side = LEFT , fill = BOTH , expand = TRUE )
2068
2067
vscrollbar .config (command = canvas .yview )
0 commit comments