class FileSelector(BoxLayout): def selectfile(self, *args): self.file_label.text = args[1][0]
class NewStatusScreen(Screen): def back_to_status(self): App.get_running_app().root.current='status_screen' App.get_running_app().root.transition.direction='right'
def load_timezones(self): App.get_running_app().root.get_screen('newstatus_screen').ids.dropdown4.clear_widgets() f=open("tz-list","r") for x in f: App.get_running_app().root.get_screen('newstatus_screen').ids.dropdown4.add_widget(ImageLabelButtonTZ(source="images/globe-96.png",text=x)) f.close()
def launch_fileselector(self): print("File selector launched.") popup_selector=Popup(title='Select file',content=FileSelector(),size_hint=(0.9,0.9),auto_dismiss=False) popup_selector.open()
def dismiss_fileselector(self): print("File selector dismissed.")
<FileSelector>: orientation: 'vertical' FileChooserListView: on_selection: root.selectfile(*args) print("args: ", *args) size_hint_y: 0.7 Label: id: file_label size_hint_y: 0.15 text: 'No file selected.' BoxLayout: size_hint_y: 0.15 orientation: 'horizontal' Button: text: 'Cancel' # on_release: root.dismiss_fileselector() Label: id: fileselect_spacer Button: text: 'Done'
<NewStatusScreen>: dropdown4: dropdown4.__self__ name: 'newstatus_screen' canvas.before: Color: rgba: 255/255, 255/255, 255/255, 1 Rectangle: pos: self.pos size: self.size AnchorLayout: id: newstatus_backbtn_layout anchor_x: 'left' anchor_y: 'top' ImageButton: id: newstatus_back_button size_hint: 0.1, 0.1 source: {'normal': 'images/back-96.png', 'down': 'images/back-96.png'} [self.state] on_release: root.back_to_status() BoxLayout: id: newstatus_layout orientation: 'vertical' size_hint: 0.8, 0.9 pos_hint: {'center_x':0.5, 'center_y':0.5} spacing: 2 BoxLayout: id: btns_layout_row1 orientation: 'vertical' CustomTextInput: id: status_text size_hint_y: 0.8 multiline: True focus: True hint_text: 'Enter your new status message' font_size: '20sp' max_characters: 280 Label: id: chars_left size_hint_y: 0.2 markup: True text: str(len(status_text.text))+"/280" color: 0/255, 0/255, 0/255, 1 text_size: self.size halign: 'right' valign: 'top' BoxLayout: id: id: btns_layout_row2 ImageLabelButtonTop: id: parent_button4 source: 'images/globe-96.png' text: 'UTC' on_release: root.load_timezones() dropdown4.open(self) on_parent: dropdown4.dismiss() size_hint_y: None height: '96dp' DropDown: id: dropdown4 on_select: parent_button4.text = args[1][0] parent_button4.source = args[1][1] BoxLayout: id: btns_layout_row3 orientation: 'horizontal' spacing: 5 DatePicker: pHint: 0.9, 0.8 BoxLayout: spacing: 5 orientation: 'vertical' canvas.after: Color: rgba: 128/255, 128/255, 128/255, 1 Line: width: dp(1) rectangle: (*self.pos, self.width, self.height) Label: id: time_label text: 'TIME' font_size: '11sp' font_name: 'roboto/Roboto-Medium.ttf' markup: True halign: 'center' valign: 'middle' color: 0, 0, 0, 1 Slider: id: hrs_slider min: 0 max: 23 step: 1 cursor_size: 25, 25 value: 18 value_track: True value_track_color: 254/255, 107/255, 100/255, 1 orientation: 'horizontal' Label: id: hrs_label text:'HH: '+str(int(hrs_slider.value)) markup: True font_size: '11sp' font_name: 'roboto/Roboto-Medium.ttf' color: 0, 0, 0, 1 halign: 'center' valign: 'middle' Slider: id: mins_slider min: 0 max: 59 step: 1 cursor_size: 25, 25 value: 30 value_track: True value_track_color: 254/255, 107/255, 100/255, 1 orientation: 'horizontal' Label: id: mins_label text:'MM: '+str(int(mins_slider.value)) markup: True font_size: '11sp' font_name: 'roboto/Roboto-Medium.ttf' color: 0, 0, 0, 1 halign: 'center' valign: 'middle' BoxLayout: id: btns_layout_row4 orientation: 'horizontal' ImageButton: id: gallery_button source: {'normal': 'images/picture-96.png', 'down': 'images/picture-green-96.png'} [self.state] on_release: root.launch_fileselector() ImageButton: id: savestatus_button source: {'normal': 'images/save-96.png', 'down': 'images/save-close-96.png'} [self.state]
Make your FileSelector class a PopUp. This way the cancel button can call root.dismiss()
See: https://github.com/ElliotGarbus/KivyFileAndDrive
Look at fctest.kv and classdefs.py
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/64240c59-39bb-4adc-ad72-dadea0f8dad0o%40googlegroups.com.
class FileSelector(Popup): selected_path=StringProperty('') def select_file(self, *args): self.ids.file_label.text = args[1][0] selected_path=args[1][0] print("Selected path:",selected_path) print("self:",self,"args:",args[1][0]) # self- FileSelector object, args - file path
class NewStatusScreen(Screen): def back_to_status(self): App.get_running_app().root.current='status_screen' App.get_running_app().root.transition.direction='right'
def load_timezones(self): App.get_running_app().root.get_screen('newstatus_screen').ids.dropdown4.clear_widgets() f=open("tz-list","r") for x in f: App.get_running_app().root.get_screen('newstatus_screen').ids.dropdown4.add_widget(ImageLabelButtonTZ(source="images/globe-96.png",text=x)) f.close()
def launch_fileselector(self):
print("File selector launched.", self) popup_selector=FileSelector(title='Select file') popup_selector.open()
<FileSelector>: auto_dismiss: True size_hint: 0.9, 0.9 BoxLayout: orientation: 'vertical' FileChooserListView: size_hint_y: 0.7 on_selection: root.select_file(*args) # print("args: ", *args) Label: size_hint_y: 0.15 id: file_label
text: 'No file selected.' BoxLayout: size_hint_y: 0.15 orientation: 'horizontal' Button: text: 'Cancel'
on_release: selected_path: '' # print(selected_path) - Not defined error. 'root.selected_path' returns a null string. # print(root, self, *args) # root - FileSelector object, self - Button object, args - Button object root.dismiss()
Label: id: fileselect_spacer Button: text: 'Done'
on_release: print("KV Selected path:", root.selected_path) # returns a null string. #app.root.get_screen('newstatus_screen').ids.gallery_button.source=root.selected_path # print("Args:",args[0]) # args - Button object root.dismiss()
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
It is hard to know if this is the only issue. But here is one problem:
BoxLayout:
size_hint_y: 0.15
orientation: 'horizontal'
Button:
text: 'Cancel'
on_release:
selected_path: ''
# print(selected_path) - Not defined error. 'root.selected_path' returns a null string.
# print(root, self, *args) # root - FileSelector object, self - Button object, args - Button
You are in the /on_release:’ expression. I’m surprised this did not throw a parsing error. It looks like you are creating a new kivy property ‘selected_path’ Perhaps you wanted:
BoxLayout:
size_hint_y: 0.15
orientation: 'horizontal'
Button:
text: 'Cancel'
on_release:
root.selected_path = ''
# print(selected_path) - Not defined error. 'root.selected_path' returns a null string.
# print(root, self, *args) # root - FileSelector object, self - Button object, args - Button
If you need more help, please share a runnable example.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8c5ca952-ce91-4f33-8b91-97692a9861a5o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8c5ca952-ce91-4f33-8b91-97692a9861a5o%40googlegroups.com.
There were a number of minor issues – the major source of the problems was you were not using self to put data in the property, creating a new local variable. I made changes to the python file and the kv files attached. I’ve tried to put comments where I made changes.
class FileSelector(Popup):
selected_path = StringProperty('')
def select_file(self, *args):
self.ids.file_label.text = args[1][0]
self.selected_path=args[1][0] # need to access self.selected path
print("Selected path:",self.selected_path)
print("self:",self,"args:",args[1][0]) # self- FileSelector object, args - file path
The 'Cancel' button works fine. If I click on the 'Done' button, this is what I get:
Thanks in advance
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/fb8d14c8-ac04-47f7-8512-b3c7fe5347f3o%40googlegroups.com.
class FileSelector(Popup): selected_path = StringProperty('images/picture-96.png')
def select_file(self, *args): if args[1]: # Check to see if args[1] is null. When changing directories, args does not contain any value. Returns null. Hence, the below variable assignments shall fail without the check to verify that args[1] actually holds a path value.
self.ids.file_label.text = args[1][0] self.selected_path=args[1][0] # need to access self.selected path print("Selected path:",self.selected_path)
# print("self:",self,"args:",args[1][0]) # self- FileSelector object, args - file path. When changing directories, args[1] is null. Hence, the print statement returns an 'IndexError: list index out of range' error.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/fb8d14c8-ac04-47f7-8512-b3c7fe5347f3o%40googlegroups.com.
On Jul 18, 2020, at 11:32 AM, Shoumik Das <shoum...@gmail.com> wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/9bf0b805-90ef-4272-897e-0b6a0d41493eo%40googlegroups.com.