8000 Fix radio button bug by BruceSherwood · Pull Request #207 · vpython/vpython-jupyter · GitHub
[go: up one dir, main page]

Skip to content

Fix radio button bug #207

New issue
< 8000 div class="mt-3 mb-2 text-center">

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion vpython/vpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
from ._vector_import_helper import (vector, mag, norm, cross, dot, adjust_up,
adjust_axis, object_rotate)

def Exit():
zero = 0.
print('exit')
a = 1.0/zero

import atexit
atexit.register(Exit)

# List of names that will be imported from this file with import *
__all__ = ['Camera', 'GlowWidget', 'version', 'GSversion', 'Mouse', 'arrow', 'attach_arrow',
'attach_light', 'attach_trail', 'baseObj', 'box', 'bumpmaps', 'button',
Expand Down Expand Up @@ -389,7 +397,7 @@ def handle_msg(self, msg):
elif evt['widget'] == 'checkbox':
obj._checked = evt['value']
elif evt['widget'] == 'radio':
obj._checked = evt['value']
obj.checked = evt['value']
elif evt['widget'] == 'winput':
obj._text = evt['text']
obj._number = evt['value']
Expand Down Expand Up @@ -3591,6 +3599,7 @@ def __init__(self, **args):
args['_objName'] = 'checkbox'
self._checked = False
self._text = ''
self._name = ''
super(checkbox, self).setup(args)

@property
Expand All @@ -3611,12 +3620,22 @@ def checked(self, value):
if not self._constructing:
self.addattr('checked')

_radio_groups = {} # radio buttons grouped by name

class radio(controls):
def __init__(self, **args):
args['_objName'] = 'radio'
self._checked = False
self._text = ''
self._name = ''
super(radio, self).setup(args)
if type(self._name) != str:
raise AttributeError("A radio group name must be a string.")
if self._name != '':
if self._name in _radio_groups:
_radio_groups[self._name].append(self)
else:
_radio_groups[self._name] = [self]

@property
def text(self):
Expand All @@ -3632,6 +3651,10 @@ def checked(self):
return self._checked
@checked.setter
def checked(self, value):
if self._checked == value: return
if len(self._name) > 0:
for r in _radio_groups[self.name]:
r._checked = False
self._checked = value
if not self._constructing:
self.addattr('checked')
Expand Down
0