class PopUpTarget(WidgetDecoration): # FIXME: this whole class is a terrible hack and must be fixed # when layout and rendering are separated _sizing = set([BOX]) _selectable = True def __init__(self, original_widget): self.__super.__init__(original_widget) self._pop_up = None self._current_widget = self._original_widget def _update_overlay(self, size, focus): canv = self._original_widget.render(size, focus=focus) self._cache_original_canvas = canv # imperfect performance hack pop_up = canv.get_pop_up() if pop_up: left, top, (w, overlay_width, overlay_height) = pop_up if self._pop_up != w: self._pop_up = w self._current_widget = Overlay(w, self._original_widget, ('fixed left', left), overlay_width, ('fixed top', top), overlay_height) else: self._current_widget.set_overlay_parameters( ('fixed left', left), overlay_width, ('fixed top', top), overlay_height) else: self._pop_up = None self._current_widget = self._original_widget def render(self, size, focus=False): self._update_overlay(size, focus) return self._current_widget.render(size, focus=focus) def get_cursor_coords(self, size): self._update_overlay(size, True) return self._current_widget.get_cursor_coords(size) def get_pref_col(self, size): self._update_overlay(size, True) return self._current_widget.get_pref_col(size) def keypress(self, size, key): self._update_overlay(size, True) return self._current_widget.keypress(size, key) def move_cursor_to_coords(self, size, x, y): self._update_overlay(size, True) return self._current_widget.move_cursor_to_coords(size, x, y) def mouse_event(self, size, event, button, x, y, focus): self._update_overlay(size, focus) return self._current_widget.mouse_event(size, event, button, x, y, focus) def pack(self, size=None, focus=False): self._update_overlay(size, focus) return self._current_widget.pack(size)
class PopUpTarget(WidgetDecoration): # FIXME: this whole class is a terrible hack and must be fixed # when layout and rendering are separated _sizing = set([BOX]) _selectable = True def __init__(self, original_widget): self.__super.__init__(original_widget) self._pop_up = None self._current_widget = self._original_widget def _update_overlay(self, size, focus): canv = self._original_widget.render(size, focus=focus) self._cache_original_canvas = canv # imperfect performance hack pop_up = canv.get_pop_up() if pop_up: left, top, (w, overlay_width, overlay_height) = pop_up if self._pop_up != w: self._pop_up = w self._current_widget = Overlay( w, self._original_widget, ('fixed left', left), overlay_width, ('fixed top', top), overlay_height) else: self._current_widget.set_overlay_parameters( ('fixed left', left), overlay_width, ('fixed top', top), overlay_height) else: self._pop_up = None self._current_widget = self._original_widget def render(self, size, focus=False): self._update_overlay(size, focus) return self._current_widget.render(size, focus=focus) def get_cursor_coords(self, size): self._update_overlay(size, True) return self._current_widget.get_cursor_coords(size) def get_pref_col(self, size): self._update_overlay(size, True) return self._current_widget.get_pref_col(size) def keypress(self, size, key): self._update_overlay(size, True) return self._current_widget.keypress(size, key) def move_cursor_to_coords(self, size, x, y): self._update_overlay(size, True) return self._current_widget.move_cursor_to_coords(size, x, y) def mouse_event(self, size, event, button, x, y, focus): self._update_overlay(size, focus) return self._current_widget.mouse_event(size, event, button, x, y, focus) def pack(self, size=None, focus=False): self._update_overlay(size, focus) return self._current_widget.pack(size)
def _update_overlay(self, size, focus): canv = self._original_widget.render(size, focus=focus) self._cache_original_canvas = canv # imperfect performance hack pop_up = canv.get_pop_up() if pop_up: left, top, ( w, overlay_width, overlay_height) = pop_up if self._pop_up != w: self._pop_up = w self._current_widget = Overlay(w, self._original_widget, ('fixed left', left), overlay_width, ('fixed top', top), overlay_height) else: self._current_widget.set_overlay_parameters( ('fixed left', left), overlay_width, ('fixed top', top), overlay_height) else: self._pop_up = None self._current_widget = self._original_widget
def _update_overlay(self, size, focus): canv = self._original_widget.render(size, focus=focus) self._cache_original_canvas = canv # imperfect performance hack pop_up = canv.get_pop_up() if pop_up: left, top, (w, overlay_width, overlay_height) = pop_up if self._pop_up != w: self._pop_up = w self._current_widget = Overlay( w, self._original_widget, ('fixed left', left), overlay_width, ('fixed top', top), overlay_height) else: self._current_widget.set_overlay_parameters( ('fixed left', left), overlay_width, ('fixed top', top), overlay_height) else: self._pop_up = None self._current_widget = self._original_widget
def __init__(self, title, input_title, min_chars=0, dim=False): """ :param title: the string used in the application heading :param input_title: the name of the input string being captured (e.g. Password) :param min_chars: minimum number of characters for a valid string (default: 8) :param dim: optimize for a smaller screen (True/False) """ self._input_title = input_title self._min_chars = min_chars self.small_display = dim self.def_keys = [] self.frame = self.setup_frame(title, input_title) self.pop_up = self.setup_popup("Error") # Create the main view, overlaying the popup widget with the main view view = Overlay(self.pop_up, self.frame, 'center', None, 'middle', None) self.view = view