def __init__(self, wnd, ctrl, **kwargs): if ctrl is None: ctrl = TestController(wnd, "minimal" if self.isMinimal else "full") self.ctrl = ctrl try: self.isMinimal = True if self.isMinimal else False except Exception: # IGNORE:W0703 self.isMinimal = True self._type_name = kwargs["type_name"] self._name = kwargs.setdefault("name", self.ctrl.Name) kwargs.setdefault("minimized_label", self._name) self._id = self.ctrl.Id kwargs["size"] = self.grid_size = minimal_size super(MinView, self).__init__(**kwargs) story_size = scale_tuple(self.grid_size, 0.2) self.story_view_size = None self._description = self.ctrl.Description self.padding = 8 self.spacing = 8 self.font_height = 13 * 2 self._full_width = int(story_size[0]) self._half_width = int(self._full_width / 2) self.visible_lines = 3 self._button_image = None self.layout = MTGridLayout(size=story_size, rows=3, cols=1, spacing=self.spacing) self.row0 = MTGridLayout(cols=2, rows=2, spacing=self.spacing, uniform_width=False, uniform_height=False) self.row1 = MTGridLayout(cols=1, rows=2, spacing=self.spacing, uniform_width=False, uniform_height=False) text_height = self.font_height * self.visible_lines label_txt = "%s Name: " % self._type_name txt_in_id = "%s_name_id" % self._type_name sz = (self._full_width - int(len(label_txt) * pixels), self.font_height) self.story_name = MyTextInput( label=self.name, id=txt_in_id, group=self._id, size=sz, keyboard_to_root="True", place_keyboard_by_control="True", ) self.description = MyTextArea( label=self._description, id="description_id", group=self._id, size=(self._full_width, text_height), keyboard_to_root="True", place_keyboard_by_control="True", ) # push handlers for each text input fields self.story_name.push_handlers(on_text_change=self._set_name) self.description.push_handlers(on_text_change=self._set_description) self.row0.add_widget(MTLabel(label=label_txt)) self.row0.add_widget(self.story_name) self.row1.add_widget(MTLabel(label="Description:")) self.row1.add_widget(self.description) self.layout.add_widget(self.row0) self.layout.add_widget(self.row1) self.layout.pos = (25, 0) self.scribleWidget = MyScribbleWidget( size=self.grid_size, scribbles=self.ctrl.Scribbles, TextFields=self.ctrl.TextFields ) self.scribleWidget.push_handlers(on_change=self.add_remove_scribble) self.scribleWidget.push_handlers(on_text_change=self.scribble_text_change) self.canvas = self.layout self.canvas = self.scribleWidget self.scribleWidget.center = self.center self.add_widget(self.canvas) self.first_draw = True
class MinView(MyInnerWindowWithSaveAndTrash): # MyInnerWindowWithKeyboard): def __init__(self, wnd, ctrl, **kwargs): if ctrl is None: ctrl = TestController(wnd, "minimal" if self.isMinimal else "full") self.ctrl = ctrl try: self.isMinimal = True if self.isMinimal else False except Exception: # IGNORE:W0703 self.isMinimal = True self._type_name = kwargs["type_name"] self._name = kwargs.setdefault("name", self.ctrl.Name) kwargs.setdefault("minimized_label", self._name) self._id = self.ctrl.Id kwargs["size"] = self.grid_size = minimal_size super(MinView, self).__init__(**kwargs) story_size = scale_tuple(self.grid_size, 0.2) self.story_view_size = None self._description = self.ctrl.Description self.padding = 8 self.spacing = 8 self.font_height = 13 * 2 self._full_width = int(story_size[0]) self._half_width = int(self._full_width / 2) self.visible_lines = 3 self._button_image = None self.layout = MTGridLayout(size=story_size, rows=3, cols=1, spacing=self.spacing) self.row0 = MTGridLayout(cols=2, rows=2, spacing=self.spacing, uniform_width=False, uniform_height=False) self.row1 = MTGridLayout(cols=1, rows=2, spacing=self.spacing, uniform_width=False, uniform_height=False) text_height = self.font_height * self.visible_lines label_txt = "%s Name: " % self._type_name txt_in_id = "%s_name_id" % self._type_name sz = (self._full_width - int(len(label_txt) * pixels), self.font_height) self.story_name = MyTextInput( label=self.name, id=txt_in_id, group=self._id, size=sz, keyboard_to_root="True", place_keyboard_by_control="True", ) self.description = MyTextArea( label=self._description, id="description_id", group=self._id, size=(self._full_width, text_height), keyboard_to_root="True", place_keyboard_by_control="True", ) # push handlers for each text input fields self.story_name.push_handlers(on_text_change=self._set_name) self.description.push_handlers(on_text_change=self._set_description) self.row0.add_widget(MTLabel(label=label_txt)) self.row0.add_widget(self.story_name) self.row1.add_widget(MTLabel(label="Description:")) self.row1.add_widget(self.description) self.layout.add_widget(self.row0) self.layout.add_widget(self.row1) self.layout.pos = (25, 0) self.scribleWidget = MyScribbleWidget( size=self.grid_size, scribbles=self.ctrl.Scribbles, TextFields=self.ctrl.TextFields ) self.scribleWidget.push_handlers(on_change=self.add_remove_scribble) self.scribleWidget.push_handlers(on_text_change=self.scribble_text_change) self.canvas = self.layout self.canvas = self.scribleWidget self.scribleWidget.center = self.center self.add_widget(self.canvas) self.first_draw = True def draw(self): super(MinView, self).draw() if self.first_draw: self.first_draw = False self.set_button_image() def scribble_text_change(self, value): self.ctrl.scribble_text_change(value) return True def add_remove_scribble(self, idu, touches): try: scribble = touches[idu] if not idu in scribble.keys(): scribble["Id"] = idu try: self.ctrl.add_scribble(scribble) except Exception: # IGNORE:W0703 pass except KeyError: self.ctrl.remove_scribble(id) def fullscreen(self, *largs, **kwargs): self.isMinimal = not self.isMinimal self.ctrl.switch_view(self.isMinimal) def _get_name(self): if self._name is None or not len(self._name): return self.ctrl.Name return self._name def _set_name(self, value): self._name = value self.ctrl.Name = value name = property(_get_name, _set_name) @property def Id(self): return self._id def _set_description(self, value): self._description = value self.ctrl.Description = value.value @property def ButtonImage(self): return self._button_image def set_button_image(self): pos = self.to_window(*self.pos) size = self.size glReadBuffer(GL_FRONT) data = glReadPixels(pos[0], pos[1], size[0], size[1], GL_RGB, GL_UNSIGNED_BYTE) texture = Texture.create(size[0], size[1], format=GL_RGB) texture.blit_buffer(data, size) self._button_image = Image(texture) # Update all the buttons referencing this artifact try: blist = Storyapp().artifacts[self.Id][1] for im in blist: blist[im].image = self._button_image except KeyError: pass try: blist = Storyapp().backlog[self.Id][1] for im in blist: blist[im].image = self._button_image except KeyError: pass def save(self, touch=None): self.ctrl.save() def close(self, touch): if self.ctrl.Id is None: if not self.name: self.trash() return self.ctrl.close(self) super(MinView, self).close(touch) def trash(self, touch=None, *largs, **kwargs): self.ctrl.trash() super(MinView, self).close(touch)