Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4fb791bc
Commit
4fb791bc
authored
Jul 12, 1994
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete redesign for more code sharing.
Added readonly options, used for .class field.
parent
3e2f5746
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
177 additions
and
101 deletions
+177
-101
Demo/tkinter/guido/AttrDialog.py
Demo/tkinter/guido/AttrDialog.py
+177
-101
No files found.
Demo/tkinter/guido/AttrDialog.py
View file @
4fb791bc
...
@@ -17,12 +17,14 @@ from Tkinter import *
...
@@ -17,12 +17,14 @@ from Tkinter import *
class
Option
:
class
Option
:
def
__init__
(
self
,
packdialog
,
option
,
varclass
):
varclass
=
StringVar
# May be overridden
self
.
packdialog
=
packdialog
def
__init__
(
self
,
dialog
,
option
):
self
.
dialog
=
dialog
self
.
option
=
option
self
.
option
=
option
self
.
master
=
pack
dialog
.
top
self
.
master
=
dialog
.
top
self
.
default
,
self
.
klass
=
pack
dialog
.
options
[
option
]
self
.
default
,
self
.
klass
=
dialog
.
options
[
option
]
self
.
var
=
varclass
(
self
.
master
)
self
.
var
=
self
.
varclass
(
self
.
master
)
self
.
frame
=
Frame
(
self
.
master
,
self
.
frame
=
Frame
(
self
.
master
,
{
Pack
:
{
'expand'
:
0
,
'fill'
:
'x'
}})
{
Pack
:
{
'expand'
:
0
,
'fill'
:
'x'
}})
self
.
label
=
Label
(
self
.
frame
,
self
.
label
=
Label
(
self
.
frame
,
...
@@ -30,25 +32,27 @@ class Option:
...
@@ -30,25 +32,27 @@ class Option:
Pack
:
{
'side'
:
'left'
},
Pack
:
{
'side'
:
'left'
},
})
})
self
.
update
()
self
.
update
()
self
.
addoption
()
def
refresh
(
self
):
def
refresh
(
self
):
self
.
pack
dialog
.
refresh
()
self
.
dialog
.
refresh
()
self
.
update
()
self
.
update
()
def
update
(
self
):
def
update
(
self
):
try
:
try
:
self
.
current
=
self
.
pack
dialog
.
current
[
self
.
option
]
self
.
current
=
self
.
dialog
.
current
[
self
.
option
]
except
KeyError
:
except
KeyError
:
self
.
current
=
self
.
default
self
.
current
=
self
.
default
self
.
var
.
set
(
self
.
current
)
self
.
var
.
set
(
self
.
current
)
def
set
(
self
,
e
=
None
):
def
set
(
self
,
e
=
None
):
# Should be overridden
pass
pass
class
BooleanOption
(
Option
):
class
BooleanOption
(
Option
):
def
__init__
(
self
,
packdialog
,
option
):
varclass
=
BooleanVar
Option
.
__init__
(
self
,
packdialog
,
option
,
BooleanVar
)
def
addoption
(
self
):
self
.
button
=
Checkbutton
(
self
.
frame
,
self
.
button
=
Checkbutton
(
self
.
frame
,
{
'text'
:
'on/off'
,
{
'text'
:
'on/off'
,
'onvalue'
:
'1'
,
'onvalue'
:
'1'
,
...
@@ -62,8 +66,7 @@ class BooleanOption(Option):
...
@@ -62,8 +66,7 @@ class BooleanOption(Option):
class
EnumOption
(
Option
):
class
EnumOption
(
Option
):
def
__init__
(
self
,
packdialog
,
option
):
def
addoption
(
self
):
Option
.
__init__
(
self
,
packdialog
,
option
,
StringVar
)
self
.
button
=
Menubutton
(
self
.
frame
,
self
.
button
=
Menubutton
(
self
.
frame
,
{
'textvariable'
:
self
.
var
,
{
'textvariable'
:
self
.
var
,
'relief'
:
'raised'
,
'relief'
:
'raised'
,
...
@@ -72,11 +75,9 @@ class EnumOption(Option):
...
@@ -72,11 +75,9 @@ class EnumOption(Option):
})
})
self
.
menu
=
Menu
(
self
.
button
)
self
.
menu
=
Menu
(
self
.
button
)
self
.
button
[
'menu'
]
=
self
.
menu
self
.
button
[
'menu'
]
=
self
.
menu
for
v
in
self
.
packdialog
.
classes
[
self
.
klass
]:
for
v
in
self
.
dialog
.
classes
[
self
.
klass
]:
label
=
v
if
v
==
self
.
default
:
label
=
label
+
' (default)'
self
.
menu
.
add_radiobutton
(
self
.
menu
.
add_radiobutton
(
{
'label'
:
label
,
{
'label'
:
v
,
'variable'
:
self
.
var
,
'variable'
:
self
.
var
,
'value'
:
v
,
'value'
:
v
,
'command'
:
self
.
set
,
'command'
:
self
.
set
,
...
@@ -84,8 +85,7 @@ class EnumOption(Option):
...
@@ -84,8 +85,7 @@ class EnumOption(Option):
class
StringOption
(
Option
):
class
StringOption
(
Option
):
def
__init__
(
self
,
packdialog
,
option
):
def
addoption
(
self
):
Option
.
__init__
(
self
,
packdialog
,
option
,
StringVar
)
self
.
entry
=
Entry
(
self
.
frame
,
self
.
entry
=
Entry
(
self
.
frame
,
{
'textvariable'
:
self
.
var
,
{
'textvariable'
:
self
.
var
,
'width'
:
10
,
'width'
:
10
,
...
@@ -96,23 +96,75 @@ class StringOption(Option):
...
@@ -96,23 +96,75 @@ class StringOption(Option):
})
})
self
.
entry
.
bind
(
'<Return>'
,
self
.
set
)
self
.
entry
.
bind
(
'<Return>'
,
self
.
set
)
class
PackOption
:
# Mix-in class
class
ReadonlyOption
(
Option
):
def
set
(
self
,
e
=
None
):
def
addoption
(
self
):
self
.
current
=
self
.
var
.
get
()
self
.
label
=
Label
(
self
.
frame
,
try
:
{
'textvariable'
:
self
.
var
,
Pack
.
config
(
self
.
packdialog
.
widget
,
Pack
:
{
'side'
:
'right'
}})
{
self
.
option
:
self
.
current
})
except
TclError
:
class
Dialog
:
self
.
refresh
()
def
__init__
(
self
,
master
):
self
.
master
=
master
self
.
refresh
()
self
.
top
=
Toplevel
(
self
.
master
)
self
.
top
.
title
(
self
.
__class__
.
__name__
)
self
.
top
.
minsize
(
1
,
1
)
self
.
addchoices
()
def
addchoices
(
self
):
self
.
choices
=
{}
list
=
[]
for
k
,
dc
in
self
.
options
.
items
():
list
.
append
(
k
,
dc
)
list
.
sort
()
for
k
,
(
d
,
c
)
in
list
:
try
:
cl
=
self
.
classes
[
c
]
except
KeyError
:
cl
=
'unknown'
if
type
(
cl
)
==
TupleType
:
cl
=
self
.
enumoption
elif
cl
==
'boolean'
:
cl
=
self
.
booleanoption
elif
cl
==
'readonly'
:
cl
=
self
.
readonlyoption
else
:
cl
=
self
.
stringoption
self
.
choices
[
k
]
=
cl
(
self
,
k
)
booleanoption
=
BooleanOption
stringoption
=
StringOption
enumoption
=
EnumOption
readonlyoption
=
ReadonlyOption
class
PackDialog
(
Dialog
):
def
__init__
(
self
,
widget
):
self
.
widget
=
widget
Dialog
.
__init__
(
self
,
widget
)
def
refresh
(
self
):
self
.
current
=
self
.
widget
.
newinfo
()
self
.
current
[
'.class'
]
=
self
.
widget
.
winfo_class
()
class
BooleanPackOption
(
PackOption
,
BooleanOption
):
pass
class
packoption
:
# Mix-in class
class
EnumPackOption
(
PackOption
,
EnumOption
):
pass
def
set
(
self
,
e
=
None
):
class
StringPackOption
(
PackOption
,
StringOption
):
pass
self
.
current
=
self
.
var
.
get
()
try
:
Pack
.
config
(
self
.
dialog
.
widget
,
{
self
.
option
:
self
.
current
})
except
TclError
:
self
.
refresh
()
class
PackDialog
:
class
booleanoption
(
packoption
,
BooleanOption
):
pass
class
enumoption
(
packoption
,
EnumOption
):
pass
class
stringoption
(
packoption
,
StringOption
):
pass
class
readonlyoption
(
packoption
,
ReadonlyOption
):
pass
options
=
{
options
=
{
'.class'
:
(
None
,
'Class'
),
'after'
:
(
None
,
'Widet'
),
'after'
:
(
None
,
'Widet'
),
'anchor'
:
(
'center'
,
'Anchor'
),
'anchor'
:
(
'center'
,
'Anchor'
),
'before'
:
(
None
,
'Widget'
),
'before'
:
(
None
,
'Widget'
),
...
@@ -128,46 +180,101 @@ class PackDialog:
...
@@ -128,46 +180,101 @@ class PackDialog:
classes
=
{
classes
=
{
'Anchor'
:
(
'n'
,
'ne'
,
'e'
,
'se'
,
's'
,
'sw'
,
'w'
,
'nw'
,
'center'
),
'Anchor'
:
(
'n'
,
'ne'
,
'e'
,
'se'
,
's'
,
'sw'
,
'w'
,
'nw'
,
'center'
),
'
Fill'
:
(
'none'
,
'x'
,
'y'
,
'both'
)
,
'
Boolean'
:
'boolean'
,
'
Side'
:
(
'top'
,
'right'
,
'bottom'
,
'left'
)
,
'
Class'
:
'readonly'
,
'Expand'
:
'boolean'
,
'Expand'
:
'boolean'
,
'Fill'
:
(
'none'
,
'x'
,
'y'
,
'both'
),
'Pad'
:
'pixel'
,
'Pad'
:
'pixel'
,
'Widget'
:
'widget'
,
'Side'
:
(
'top'
,
'right'
,
'bottom'
,
'left'
),
'Widget'
:
'readonly'
,
}
}
def
__init__
(
self
,
widget
):
class
RemotePackDialog
(
PackDialog
):
def
__init__
(
self
,
master
,
app
,
widget
):
self
.
master
=
master
self
.
app
=
app
self
.
widget
=
widget
self
.
widget
=
widget
self
.
refresh
()
self
.
refresh
()
self
.
top
=
Toplevel
(
self
.
widget
)
self
.
top
=
Toplevel
(
self
.
master
)
self
.
top
.
title
(
'
Pack: %s'
%
widget
.
widgetName
)
self
.
top
.
title
(
'
Remote %s Pack: %s'
%
(
self
.
app
,
self
.
widget
)
)
self
.
top
.
minsize
(
1
,
1
)
# XXX
self
.
top
.
minsize
(
1
,
1
)
# XXX
self
.
anchor
=
EnumPackOption
(
self
,
'anchor'
)
self
.
addchoices
()
self
.
side
=
EnumPackOption
(
self
,
'side'
)
self
.
fill
=
EnumPackOption
(
self
,
'fill'
)
self
.
expand
=
BooleanPackOption
(
self
,
'expand'
)
self
.
ipadx
=
StringPackOption
(
self
,
'ipadx'
)
self
.
ipady
=
StringPackOption
(
self
,
'ipady'
)
self
.
padx
=
StringPackOption
(
self
,
'padx'
)
self
.
pady
=
StringPackOption
(
self
,
'pady'
)
# XXX after, before, in
def
refresh
(
self
):
def
refresh
(
self
):
self
.
current
=
self
.
widget
.
newinfo
()
try
:
words
=
self
.
master
.
tk
.
splitlist
(
self
.
master
.
send
(
self
.
app
,
'pack'
,
'newinfo'
,
self
.
widget
))
except
TclError
,
msg
:
print
'send pack newinfo'
,
self
.
widget
,
':'
,
msg
return
dict
=
{}
for
i
in
range
(
0
,
len
(
words
),
2
):
key
=
words
[
i
][
1
:]
value
=
words
[
i
+
1
]
dict
[
key
]
=
value
dict
[
'.class'
]
=
self
.
master
.
send
(
self
.
app
,
'winfo'
,
'class'
,
self
.
widget
)
self
.
current
=
dict
class
remotepackoption
:
# Mix-in class
def
set
(
self
,
e
=
None
):
self
.
current
=
self
.
var
.
get
()
try
:
self
.
dialog
.
master
.
send
(
self
.
dialog
.
app
,
'pack'
,
'config'
,
self
.
dialog
.
widget
,
'-'
+
self
.
option
,
self
.
current
)
except
TclError
,
msg
:
print
'send pack config ... :'
,
msg
self
.
refresh
()
class
WidgetOption
:
# Mix-in class
class
booleanoption
(
remotepackoption
,
BooleanOption
):
pass
class
enumoption
(
remotepackoption
,
EnumOption
):
pass
class
stringoption
(
remotepackoption
,
StringOption
):
pass
class
readonlyoption
(
remotepackoption
,
ReadonlyOption
):
pass
def
set
(
self
,
e
=
None
):
class
WidgetDialog
(
Dialog
):
self
.
current
=
self
.
var
.
get
()
try
:
def
__init__
(
self
,
widget
):
self
.
packdialog
.
widget
[
self
.
option
]
=
self
.
current
self
.
widget
=
widget
except
TclError
:
if
self
.
addclasses
.
has_key
(
self
.
widget
.
widgetName
):
self
.
refresh
()
classes
=
{}
for
c
in
(
self
.
classes
,
self
.
addclasses
[
self
.
widget
.
widgetName
]):
for
k
in
c
.
keys
():
classes
[
k
]
=
c
[
k
]
self
.
classes
=
classes
Dialog
.
__init__
(
self
,
widget
)
def
refresh
(
self
):
self
.
configuration
=
self
.
widget
.
config
()
self
.
current
=
{}
self
.
options
=
{}
options
[
'.class'
]
=
(
None
,
'Class'
)
self
.
current
[
'.class'
]
=
self
.
widget
.
winfo_class
()
for
k
,
v
in
self
.
configuration
.
items
():
if
len
(
v
)
>
4
:
self
.
current
[
k
]
=
v
[
4
]
self
.
options
[
k
]
=
v
[
3
],
v
[
2
]
# default, klass
class
BooleanWidgetOption
(
WidgetOption
,
BooleanOption
):
pass
class
widgetoption
:
# Mix-in class
class
EnumWidgetOption
(
WidgetOption
,
EnumOption
):
pass
def
set
(
self
,
e
=
None
):
class
StringWidgetOption
(
WidgetOption
,
StringOption
):
pass
self
.
current
=
self
.
var
.
get
()
try
:
self
.
dialog
.
widget
[
self
.
option
]
=
self
.
current
except
TclError
:
self
.
refresh
()
class
WidgetDialog
:
class
booleanoption
(
widgetoption
,
BooleanOption
):
pass
class
enumoption
(
widgetoption
,
EnumOption
):
pass
class
stringoption
(
widgetoption
,
StringOption
):
pass
class
readonlyoption
(
widgetoption
,
ReadonlyOption
):
pass
# Universal classes
# Universal classes
classes
=
{
classes
=
{
...
@@ -176,6 +283,7 @@ class WidgetDialog:
...
@@ -176,6 +283,7 @@ class WidgetDialog:
'Background'
:
'color'
,
'Background'
:
'color'
,
'Bitmap'
:
'bitmap'
,
'Bitmap'
:
'bitmap'
,
'BorderWidth'
:
'pixel'
,
'BorderWidth'
:
'pixel'
,
'Class'
:
'readonly'
,
'CloseEnough'
:
'double'
,
'CloseEnough'
:
'double'
,
'Command'
:
'command'
,
'Command'
:
'command'
,
'Confine'
:
'boolean'
,
'Confine'
:
'boolean'
,
...
@@ -231,53 +339,21 @@ class WidgetDialog:
...
@@ -231,53 +339,21 @@ class WidgetDialog:
}
}
def
__init__
(
self
,
widget
):
self
.
widget
=
widget
if
self
.
addclasses
.
has_key
(
self
.
widget
.
widgetName
):
classes
=
{}
for
c
in
(
self
.
classes
,
self
.
addclasses
[
self
.
widget
.
widgetName
]):
for
k
in
c
.
keys
():
classes
[
k
]
=
c
[
k
]
self
.
classes
=
classes
self
.
refresh
()
self
.
top
=
Toplevel
(
self
.
widget
)
self
.
top
.
title
(
'Widget: %s'
%
widget
.
widgetName
)
self
.
top
.
minsize
(
1
,
1
)
self
.
choices
=
{}
for
k
,
(
d
,
c
)
in
self
.
options
.
items
():
try
:
cl
=
self
.
classes
[
c
]
except
KeyError
:
cl
=
'unknown'
if
type
(
cl
)
==
TupleType
:
cl
=
EnumWidgetOption
elif
cl
==
'boolean'
:
cl
=
BooleanWidgetOption
else
:
cl
=
StringWidgetOption
self
.
choices
[
k
]
=
cl
(
self
,
k
)
def
refresh
(
self
):
self
.
configuration
=
self
.
widget
.
config
()
self
.
current
=
{}
self
.
options
=
{}
for
k
,
v
in
self
.
configuration
.
items
():
if
len
(
v
)
>
4
:
self
.
current
[
k
]
=
v
[
4
]
self
.
options
[
k
]
=
v
[
3
],
v
[
2
]
# default, klass
def
test
():
def
test
():
import
sys
root
=
Tk
()
root
=
Tk
()
root
.
minsize
(
1
,
1
)
root
.
minsize
(
1
,
1
)
frame
=
Frame
(
root
,
{
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
}})
if
sys
.
argv
[
2
:]:
button
=
Button
(
frame
,
{
'text'
:
'button'
,
pd
=
RemotePackDialog
(
root
,
sys
.
argv
[
1
],
sys
.
argv
[
2
])
Pack
:
{
'expand'
:
1
}})
else
:
canvas
=
Canvas
(
frame
,
{
Pack
:
{}})
frame
=
Frame
(
root
,
{
Pack
:
{
'expand'
:
1
,
'fill'
:
'both'
}})
bpd
=
PackDialog
(
button
)
button
=
Button
(
frame
,
{
'text'
:
'button'
,
bwd
=
WidgetDialog
(
button
)
Pack
:
{
'expand'
:
1
}})
cpd
=
PackDialog
(
canvas
)
canvas
=
Canvas
(
frame
,
{
Pack
:
{}})
cwd
=
WidgetDialog
(
canvas
)
bpd
=
PackDialog
(
button
)
bwd
=
WidgetDialog
(
button
)
cpd
=
PackDialog
(
canvas
)
cwd
=
WidgetDialog
(
canvas
)
root
.
mainloop
()
root
.
mainloop
()
test
()
test
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment