class LeafScreen(Screen): def on_pre_enter(self): self.clear_widgets() self.leafLayout = BoxLayout(orientation = 'vertical') self.readMode() #self.editMode() self.add_widget(self.leafLayout) self.win = Window self.win.bind(on_keyboard=self.keyboardHandler) self.leafLayout.bind( size=self._update_rect, pos=self._update_rect) with self.leafLayout.canvas.before: Color(0.5, 0.8, 1, 0.9) self.rect = Rectangle( size=self.leafLayout.size, pos=self.leafLayout.pos) def _update_rect(self, instance, value): self.rect.pos = instance.pos self.rect.size = instance.size def on_pre_leave(self): self.win.unbind(on_keyboard=self.keyboardHandler) def keyboardHandler(self, window, keycode1, keycode2, text, modifiers): if keycode1 == systemBtnBack: self.back() return True return False def readMode(self, *args): self.leafLayout.clear_widgets() # top btnBack = Button(text='Back', size_hint_x=0.1) capture = Label(text=tree.curItem().name, size_hint_x=0.8, color = color['lblPath']) btnEdit = Button(text='Edit', size_hint_x=0.1) topLayout = BoxLayout(size_hint_y = 0.1) topLayout.add_widget(btnBack) topLayout.add_widget(capture) topLayout.add_widget(btnEdit) self.leafLayout.add_widget(topLayout) btnBack.bind(on_press=self.back) # Content self.textField = TextInputForScroll( size_hint_y=None, text=tree.curItem().read(), background_color = color['readLeaf'], readonly = True, focus = True) self.textField.on_text() textFieldScroll = ScrollView( bar_width = 10) textFieldScroll.add_widget(self.textField) self.leafLayout.add_widget(textFieldScroll) btnEdit.bind(on_release=self.editMode) def editMode(self, *args): self.leafLayout.clear_widgets() # top btnBack = Button(text='Back', size_hint_x=0.1) capture = Label(text=tree.curItem().name, size_hint_x=0.8, color = color['lblPath']) btnSave = Button(text='Save', size_hint_x=0.1) topLayout = BoxLayout(size_hint_y = 0.1) topLayout.add_widget(btnBack) topLayout.add_widget(capture) topLayout.add_widget(btnSave) self.leafLayout.add_widget(topLayout) btnBack.bind(on_press=self.back) # Content self.textField = TextInput( text=tree.curItem().read(), background_color = color['editLeaf'], focus = True) self.leafLayout.add_widget(self.textField) btnSave.bind(on_release=self.readMode, on_press=self.save) def save(self, *args): tree.curItem().write(self.textField.text) def back(self, *args): if sm.current == "leafScreen" : self.save() if not tree.reachRoot(): tree.down() sm.transition = SlideTransition(direction='right') sm.current = 'mainScreen'