def on_text(self, instance_field: MDTextField, text: str) -> NoReturn: if text != "" and not text.isspace() and not self._backspace: if len(text) <= 1 and instance_field.focus: instance_field.text = text self._set_pos_cursor() elif len(text) == 3: start = instance_field.text[:-1] end = instance_field.text[-1] instance_field.text = f"{start}/{end}" self._set_pos_cursor() elif len(text) == 5: instance_field.text += "/" self._set_pos_cursor() if not self.owner.min_date and not self.owner.max_date: self.owner.update_text_full_date(self._get_list_date())
def askQuestion(self, question, answer='', cb=None,multiline=False): "As a text box based question, with optional default answer. If user confirm, call cb." t = MDTextField(text='', size_hint=(1,None),multiline=multiline,mode="rectangle") def nonsense(a): pass cb = cb or nonsense def cbr_yes(*a): print("Accept Button") cb(t.text) self.dialog.dismiss() def cbr_no(*a): cb(None) self.dialog.dismiss() self.dialog = MDDialog( type="custom", title=question, content_cls=t, buttons=[ Button( text="Accept", text_color=self.theme_cls.primary_color, on_press=cbr_yes ), Button( text="Cancel", text_color=self.theme_cls.primary_color, on_press=cbr_no ), ], ) #self.dialog.set_normal_height() t.text = answer self.dialog.open()
def show_dialog_add_lineup_entry(self): """ Show a dialog to ask the name of the new lineup_entry. :return: """ creation_time = datetime.now().strftime("%Y%m%d-%H%M%S") text = f"Concert_{creation_time}" content_obj = BoxLayout(orientation='vertical', spacing="12dp", size_hint_y=None) # mdlbl1 = MDLabel(text=str(CU.tfs.dic['EXPLANATION_WORKSPACE_PATH'].value)) mdtf1 = MDTextField() mdtf1.text = text mdtf1.hint_text = f"Name of song" mdtf1.helper_text = f"{CU.tfs.dic['EXPLANATION_PLAYLIST_SONG_NAME'].value}" mdtf1.helper_text_mode = "on_focus" # content_obj.add_widget(mdlbl1) content_obj.add_widget(mdtf1) CU.show_input_dialog( title=f"Enter Name of New Songentry", content_obj=content_obj, size_hint=(.7, .4), text_button_ok="Add", ok_callback_set=lambda text_button, instance, *args, **kwargs: { self.add_lineup_entry(instance.text_field.text), self.refresh_list() })
def show_dialog_rename_playlist(self, playlist_rowview): """ Show a dialog to ask for the new name of the playlist. :param playlist_rowview: :return: """ text = f"{str(playlist_rowview.playlist_obj.file_path.stem)}" content_obj = BoxLayout(orientation='vertical', spacing="12dp", size_hint_y=None) mdtf1 = MDTextField() mdtf1.text = text mdtf1.hint_text = f"Name of playlist" mdtf1.helper_text = f"{CU.tfs.dic['EXPLANATION_PLAYLIST_SONG_NAME'].value}" mdtf1.helper_text_mode = "on_focus" content_obj.add_widget(mdtf1) CU.show_input_dialog(title=f"Enter New Name for Playlist", content_obj=content_obj, size_hint=(.7, .4), text_button_ok="Update", text_button_cancel="Cancel", ok_callback_set=lambda *args, **kwargs: (self.rename_playlist(playlist_rowview, mdtf1.text ), self.refresh_list()))
def show_dialog_add_playlist(self): """ Show a dialog to ask the name of the new playlist. :return: """ creation_time = datetime.now().strftime("%Y%m%d-%H%M%S") text = f"Concert_{creation_time}" content_obj = BoxLayout(orientation='vertical', spacing="12dp", size_hint_y=None) mdtf1 = MDTextField() mdtf1.text = text mdtf1.hint_text = f"Name of playlist" mdtf1.helper_text = f"{CU.tfs.dic['EXPLANATION_PLAYLIST_SONG_NAME'].value}" mdtf1.helper_text_mode = "on_focus" content_obj.add_widget(mdtf1) CU.show_input_dialog( title=f"Enter Name of New Playlist", content_obj=content_obj, size_hint=(.7, .4), text_button_ok="Add", text_button_cancel="Cancel", ok_callback_set=lambda *args, **kwargs: (self.add_playlist(mdtf1.text), self.refresh_list()))
def getRowForGui(self, name): rb = MDBoxLayout(orientation='horizontal') vl = MDTextField() rb.add_widget(vl) #rb.add_widget( Label(text=" {}:".format(name) ) ) #vl = Label(text="- - -") #rb.add_widget(vl) vl.hint_text = "{}:".format(name) vl.text = "- - -" vl.disabled = True return vl, rb
def on_start(self): # As a proposal, the actual (default)value of the tf_workspace_path-param is copied to the clipboard: workspace_path_proposal = CU.tfs.dic['tf_workspace_path'].default_value pyperclip.copy(str(workspace_path_proposal)) # In case the user did configure a customized path, that path will be filled in: text = "" if (CU.tfs.dic['tf_workspace_path'].default_value == CU.tfs.dic['tf_workspace_path'].value ) else f"{CU.tfs.dic['tf_workspace_path'].value}" content_obj = BoxLayout(orientation='vertical', spacing="12dp", size_hint_y=None) # mdlbl1 = MDLabel(text=str(CU.tfs.dic['EXPLANATION_WORKSPACE_PATH'].value)) mdtf1 = MDTextField() mdtf1.text = text mdtf1.hint_text = f"{CU.tfs.dic['tf_workspace_path'].description}" mdtf1.helper_text = str(CU.tfs.dic['EXPLANATION_WORKSPACE_PATH'].value) mdtf1.helper_text_mode = "on_focus" # content_obj.add_widget(mdlbl1) content_obj.add_widget(mdtf1) CU.show_input_dialog( title= f"Enter Path to \"{CU.tfs.dic['WORKSPACE_NAME'].value}\"-Folder or to its Parent Folder", content_obj=content_obj, # hint_text=f"{CU.tfs.dic['tf_workspace_path'].description}", # size_hint=(.8, .4), text_button_ok="Load/Create", text_button_cancel="Cancel", ok_callback_set=lambda *args, **kwargs: (CU.tfs.dic['tf_workspace_path'].set_value(mdtf1.text), toast(str(CU.tfs.dic['tf_workspace_path'].value))), cancel_callback_set=lambda *args, **kwargs: toast( f"{CU.tfs.dic['WORKSPACE_NAME'].value} can still be changed anytime from the settings" ))