Skip to content
New issue

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

Added Special Character Support #369

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion fury/data/files/test_ui_textbox.json
@@ -1 +1 @@
{"MiddleButtonReleaseEvent": 0, "RightButtonReleaseEvent": 0, "KeyPressEvent": 62, "LeftButtonPressEvent": 1, "MouseMoveEvent": 30, "CharEvent": 61, "LeftButtonReleaseEvent": 1, "RightButtonPressEvent": 0, "KeyReleaseEvent": 61, "MiddleButtonPressEvent": 0}
{"CharEvent": 44, "MouseMoveEvent": 99, "KeyPressEvent": 44, "KeyReleaseEvent": 43, "LeftButtonPressEvent": 1, "LeftButtonReleaseEvent": 1, "RightButtonPressEvent": 0, "RightButtonReleaseEvent": 0, "MiddleButtonPressEvent": 0, "MiddleButtonReleaseEvent": 0}
Binary file modified fury/data/files/test_ui_textbox.log.gz
Binary file not shown.
1 change: 1 addition & 0 deletions fury/interactor.py
Expand Up @@ -28,6 +28,7 @@ def update(self, event_name, interactor):
self.name = event_name
self.position = np.asarray(interactor.GetEventPosition())
self.key = interactor.GetKeySym()
self.key_char = interactor.GetKeyCode()
self.alt_key = bool(interactor.GetAltKey())
self.shift_key = bool(interactor.GetShiftKey())
self.ctrl_key = bool(interactor.GetControlKey())
Expand Down
37 changes: 23 additions & 14 deletions fury/ui.py
@@ -1,6 +1,7 @@
from collections import OrderedDict
from warnings import warn
from numbers import Number
from string import printable

import numpy as np
import vtk
Expand Down Expand Up @@ -1562,6 +1563,7 @@ class TextBox2D(UI):
init : bool
Flag which says whether the textbox has just been initialized.
"""

def __init__(self, width, height, text="Enter Text", position=(100, 10),
color=(0, 0, 0), font_size=18, font_family='Arial',
justification='left', bold=False,
Expand Down Expand Up @@ -1687,7 +1689,7 @@ def width_set_text(self, text):
multi_line_text += "\n"
return multi_line_text.rstrip("\n")

def handle_character(self, character):
def handle_character(self, key, key_char):
""" Main driving function that handles button events.

# TODO: Need to handle all kinds of characters like !, +, etc.
Expand All @@ -1696,17 +1698,19 @@ def handle_character(self, character):
----------
character : str
"""
if character.lower() == "return":
if key_char != '' and key_char in printable:
self.add_character(key_char)

if key.lower() == "return":
self.render_text(False)
return True
if character.lower() == "backspace":
if key.lower() == "backspace":
self.remove_character()
elif character.lower() == "left":
elif key.lower() == "left":
self.move_left()
elif character.lower() == "right":
elif key.lower() == "right":
self.move_right()
else:
self.add_character(character)

self.render_text()
return False

Expand Down Expand Up @@ -1864,7 +1868,8 @@ def key_press(self, i_ren, _obj, _textbox_object):
_textbox_object: :class:`TextBox2D`
"""
key = i_ren.event.key
is_done = self.handle_character(key)
key_char = i_ren.event.key_char
is_done = self.handle_character(key, key_char)
if is_done:
i_ren.remove_active_prop(self.text.actor)

Expand Down Expand Up @@ -1896,6 +1901,7 @@ class LineSlider2D(UI):
active_color : (float, float, float)
Color of the handle when it is pressed.
"""

def __init__(self, center=(0, 0),
initial_value=50, min_value=0, max_value=100,
length=200, line_width=5,
Comment on lines +1904 to 1907
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these extra new lines necessary?

Expand Down Expand Up @@ -2244,6 +2250,7 @@ class LineDoubleSlider2D(UI):
Color of the handles when they are pressed.

"""

def __init__(self, line_width=5, inner_radius=0, outer_radius=10,
handle_side=20, center=(450, 300), length=200,
Comment on lines +2253 to 2255
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above and below few new lines.

initial_values=(0, 100), min_value=0, max_value=100,
Expand Down Expand Up @@ -2779,6 +2786,7 @@ class RingSlider2D(UI):
active_color : (float, float, float)
Color of the handle when it is pressed.
"""

def __init__(self, center=(0, 0),
initial_value=180, min_value=0, max_value=360,
slider_inner_radius=40, slider_outer_radius=44,
Expand Down Expand Up @@ -3038,6 +3046,7 @@ class RangeSlider(UI):
The line slider which sets the value

"""

def __init__(self, line_width=5, inner_radius=0, outer_radius=10,
handle_side=20, range_slider_center=(450, 400),
value_slider_center=(450, 300), length=200, min_value=0,
Expand Down Expand Up @@ -3371,9 +3380,9 @@ def _setup(self):
# Option's button
self.button_icons = []
self.button_icons.append(('unchecked',
read_viz_icons(fname="stop2.png")))
read_viz_icons(fname="stop2.png")))
self.button_icons.append(('checked',
read_viz_icons(fname="checkmark.png")))
read_viz_icons(fname="checkmark.png")))
self.button = Button2D(icon_fnames=self.button_icons,
size=self.button_size)

Expand Down Expand Up @@ -3723,7 +3732,7 @@ def _setup(self):
scroll_bar_height = self.nb_slots * (size[1] - 2 * self.margin) \
/ len(self.values)
self.scroll_bar = Rectangle2D(size=(int(size[0]/20),
scroll_bar_height))
scroll_bar_height))
if len(self.values) <= self.nb_slots:
self.scroll_bar.set_visibility(False)
self.panel.add_element(
Expand Down Expand Up @@ -4849,7 +4858,7 @@ def add_element(self, tab_idx, element, coords, anchor="position"):
self.tabs[tab_idx].add_element(element, coords, anchor)
else:
raise IndexError(
"Tab with index {} does not exist".format(tab_idx))
"Tab with index {} does not exist".format(tab_idx))

def remove_element(self, tab_idx, element):
""" Removes element from content panel after checking its existence.
Expand All @@ -4858,7 +4867,7 @@ def remove_element(self, tab_idx, element):
self.tabs[tab_idx].remove_element(element)
else:
raise IndexError(
"Tab with index {} does not exist".format(tab_idx))
"Tab with index {} does not exist".format(tab_idx))

def update_element(self, tab_idx, element, coords, anchor="position"):
""" Updates element on content panel after checking its existence.
Expand All @@ -4867,7 +4876,7 @@ def update_element(self, tab_idx, element, coords, anchor="position"):
self.tabs[tab_idx].update_element(element, coords, anchor)
else:
raise IndexError(
"Tab with index {} does not exist".format(tab_idx))
"Tab with index {} does not exist".format(tab_idx))

def left_button_pressed(self, i_ren, _obj, _sub_component):
click_pos = np.array(i_ren.event.position)
Expand Down