Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
aa454c8b
Commit
aa454c8b
authored
11 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Widget states are correctly initialised (i.e. if the initial property value is invalid)
parent
908c3a29
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tkprop/properties.py
+27
-8
27 additions, 8 deletions
tkprop/properties.py
tkprop/widgets.py
+4
-0
4 additions, 0 deletions
tkprop/widgets.py
with
31 additions
and
8 deletions
tkprop/properties.py
+
27
−
8
View file @
aa454c8b
...
...
@@ -216,7 +216,8 @@ class TkVarProxy(object):
listeners are notified of the variable value change.
"""
valid
=
True
valid
=
True
listeners
=
self
.
changeListeners
.
items
()
# This is silly. Tkinter allows Boolean/Int/Double
# variables to be set to invalid values (e.g. it
...
...
@@ -233,8 +234,14 @@ class TkVarProxy(object):
# failing type cast. Ugly.
except
:
newValue
=
self
.
tkVar
.
_tk
.
globalgetvar
(
self
.
name
)
# if the new value is valid, save it as the last
# known good value
# print a log message if the value has changed
if
newValue
!=
self
.
lastValue
:
log
.
debug
(
'
Variable {} changed: {} (valid: {}, {} listeners)
'
.
format
(
self
.
name
,
newValue
,
valid
,
len
(
listeners
)))
# if the new value is valid, save
# it as the last known good value
try
:
self
.
tkProp
.
validate
(
self
.
owner
,
newValue
)
self
.
lastValue
=
newValue
...
...
@@ -242,11 +249,6 @@ class TkVarProxy(object):
except
ValueError
:
valid
=
False
listeners
=
self
.
changeListeners
.
items
()
log
.
debug
(
'
Variable {} changed: {} (valid: {}, {} listeners)
'
.
format
(
self
.
name
,
newValue
,
valid
,
len
(
listeners
)))
# Notify all listeners about the change, ignoring
# any errors - it is up to the listeners to ensure
# that they handle invalid values
...
...
@@ -347,6 +349,23 @@ class PropertyBase(object):
self
.
changeListeners
[
instance
].
pop
(
name
)
def
forceValidation
(
self
,
instance
):
"""
Forces validation of this property value, for the current instance.
This will result in any registered listeners being notified.
"""
varProxies
=
instance
.
getTkVar
(
self
.
label
)
# getTkVar returns either a TkVarProxy object, or a
# list of TkVarProxy objects (it should do, anyway).
if
isinstance
(
varProxies
,
TkVarProxy
):
varProxies
=
[
varProxies
]
for
var
in
varProxies
:
var
.
_traceCb
()
def
_varChanged
(
self
,
value
,
valid
,
instance
,
tkProp
,
name
):
"""
This function is registered with the TkVarProxy object (or
...
...
This diff is collapsed.
Click to expand it.
tkprop/widgets.py
+
4
−
0
View file @
aa454c8b
...
...
@@ -71,6 +71,10 @@ def _setupValidation(widget, propObj, tkProp, tkVar):
listenerName
=
'
ChangeBGOnValidate_{}
'
.
format
(
tkVar
.
name
)
tkVar
.
addListener
(
listenerName
,
_changeBGOnValidate
)
# Validate the initial property value,
# so the background is appropriately set
tkProp
.
forceValidation
(
propObj
)
# The _lastFilePathDir variable is used to retain the
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment