Skip to content

Conversation

@kjue25
Copy link
Collaborator

@kjue25 kjue25 commented Feb 5, 2020

Changes made:

  • Implements GTextField constructor, ability to get text, and adding a callback event for return key.
  • Fixes issue with clearing the window erroring when interactors are on the screen.
  • Adds a GWindow method for just clearing the canvas (calls existing backend function).
  • Remove need for GEvents for interactor callbacks since these functions can be associated with a specific interactor in TK (in Java, event needed to distinguish which interactor the event occured on)

Decisions about general conventions/structure:

  • Tell students that interactors in NORTH/SOUTH will get added left to right while WEST/EAST will get added top to bottom. They must add them in order when calling add_to_region().
  • Have campy functions parallel tk as much as possible
  • GInteractors shouldn't need events passed into their callback functions (unnecessary for student functionality with TK)

Currently working for NameSurfer (program not included in PR).

---STILL IN PROGRESS---
Need to fix:

  • GTextField: string passed in doesn't currently do anything
  • Add scrollable text/label object specifically for interactor regions (e.g. for searching name substrings in BabyNames)

Nice to have:

  • Ability to center interactors within a region (maybe specify property align=left/center/right for the region?)

@kjue25 kjue25 requested a review from sredmond February 5, 2020 03:35
Copy link
Owner

@sredmond sredmond left a comment

Choose a reason for hiding this comment

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

Thank you for submitting a PR! Can you comment on the purpose of the new attribute label?

Regarding the other questions:

  • GTextFields show up in Region.NORTH from the lack of lazy (Tk) instantiation throughout all of backend_tk.py (i.e. Tk constructors are called at Python object initialization time, not when the object is added for the first time).
  • There is no GWindow.clear_canvas written yet, although I'd welcome one! For window.clear(), what is the error? I have a feeling it's the ordering between clearing the window and clearing the contents of the top GCompound, but I wouldn't be sure.

"""
super().__init__(self)
self._width = width
self.label = label
Copy link
Owner

Choose a reason for hiding this comment

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

If students shouldn't know about / stumble upon modifying this variable, it can be marked as self._label (indicating that it's intended as a 'private' variable).

return

win = self._windows[-1]
gtextfield._tkin = win
Copy link
Owner

Choose a reason for hiding this comment

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

Small typo?

Suggested change
gtextfield._tkin = win
gtextfield._tkwin = win

return gtextfield._tkobj.get()

def gtextfield_set_enter_event(self, gtextfield, fn):
gtextfield._tkobj.bind("<Return>", lambda event: fn(event))
Copy link
Owner

Choose a reason for hiding this comment

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

This call exposes the Tk event to the student function passed to onenter, and should probably be wrapped up into a GActionEvent eventually, although I'm not sure that the event pipeline is ready for that yet, so this is an acceptable workaround!


def onenter(self, fn):
"""Set event handler for return key"""
_platform.Platform().gtextfield_set_enter_event(self, fn)
Copy link
Owner

Choose a reason for hiding this comment

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

Add this function also to backend_base.py (so that other backends know that they would have to implement it)


def __str__(self):
return "GTextField(text={}, width={})".format(self.text, self.width)
return "GTextField(text={}, label={}, width={})".format(self.text, self.label, self.width)
Copy link
Owner

Choose a reason for hiding this comment

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

What is the difference between text and label on this object? It looks like label is being used as a tk-based string tag for the object in gtextfield_constructor (for eventual events, perhaps?). If they are the same, these attributes should be merged into one.

@kjue25
Copy link
Collaborator Author

kjue25 commented Feb 13, 2020

Here's the window.clear() error:

Traceback (most recent call last):
File "namesurfer.py", line 131, in <module>
    graph = NameSurfer(db)
File "namesurfer.py", line 51, in __init__
    self.draw_fixed_lines()
File "namesurfer.py", line 81, in draw_fixed_lines
    self.window.clear() # FIXME: Breaks with buttons already onscreen
File "/Users/kyliejue/Documents/Stanford_Docs/CS399/campy/campy/graphics/gwindow.py", line 381, in clear
    _platform.Platform().gwindow_clear(self)  # Remove from background layer.
File "/Users/kyliejue/Documents/Stanford_Docs/CS399/campy/campy/private/backends/tk/backend_tk.py", line 223, in gwindow_clear
    gwindow._tkwin.clear()
File "/Users/kyliejue/Documents/Stanford_Docs/CS399/campy/campy/private/backends/tk/backend_tk.py", line 138, in clear
    child.destroy()
AttributeError: 'str' object has no attribute 'destroy'

@kjue25
Copy link
Collaborator Author

kjue25 commented Feb 19, 2020

Resolved window.clear() error above but not sure if maybe there's a cleaner solution

@kjue25 kjue25 requested a review from sredmond February 19, 2020 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants