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
16bitmood
wants to merge
1
commit into
fury-gl:master
from
16bitmood:textbox2d--special-character-support
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
@@ -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, | ||
|
@@ -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. | ||
|
@@ -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 | ||
|
||
|
@@ -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) | ||
|
||
|
@@ -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, | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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) | ||
|
||
|
@@ -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( | ||
|
@@ -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. | ||
|
@@ -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. | ||
|
@@ -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) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?