kxgames / glooey

An object-oriented GUI library for pyglet.
MIT License
91 stars 6 forks source link

Label unfocus not working correctly #42

Open PSMusicalRoc opened 4 years ago

PSMusicalRoc commented 4 years ago

Another strange occurrence with the Form widget, but in my GUI I have 9 different cells (pictured below), and whenever I click on the form in either Form near the grid of image renders (henceforth called Character Selectors), it won't let me unfocus the Form unless I press Enter. If I double-click anywhere on the window when this occurs, it will highlight whatever's in the Form for some reason.

window

The code for this Form is as follows:

class Form(TextInput):
  class Label(glooey.EditableLabel):
    custom_font_name = "Segoe UI"
    custom_font_size = 10
    custom_color = "#000000"
    custom_selection_color = "#ffffff"
    custom_selection_background_color = "#3390ff"
    custom_padding = 2
    # SIDE_MODE is a global for how large the window is
    if Globals.SIZE_MODE == "1920x1080":
      custom_size_hint = (160, 20)
    else:
      custom_size_hint = (80, 20)

    def on_insert_text(self, start, text):
      self._text = self._layout.document.text
      # Gets a list of buttons from a parent widget
      buttons = self.parent.parent.parent._buttons
      if text != "":
        i = 0
        length = len(self.parent.parent.parent.character_list)
        character_list = self.parent.parent.parent.character_list
        for button in buttons:
          while True:
            if i >= length:
              button.hide()
              break
            character_name = character_list[i]
            if self._text.lower() in character_name.lower():
              button._foreground.set_text(character_name)
              button.unhide()
              i += 1
              break
            i += 1
      else:
        for button in buttons:
          button.hide()

      self.dispatch_event('on_edit_text', self)

    def on_delete_text(self, start, text):
      self.on_insert_text(start, text)

  def on_unfocus(self, w):
    # Goes to a parent widget and calls a function based on the form's text
    self.parent.parent.parent.changeCharacter(self._label._text)

...where TextInput is the default custom Form class I created. Any ideas as to what could be causing this?

kalekundert commented 4 years ago

Sorry for the slow reply. I'll try to look at this over the weekend. I might have introduced this bug when I tried to fix the last one, we'll see...

kalekundert commented 4 years ago

I haven't gotten to this yet, but I haven't forgot about it. I'll try to keep you updated...

PSMusicalRoc commented 4 years ago

That's alright! School starts for me in a few days, so I'll be a little bit busy too! But thank you!

kalekundert commented 3 years ago

Ok, I finally got around to this today, but unfortunately I wasn't able to reproduce the behavior you described. Can you make a minimal working example that exhibits the bug?