def on_busy(self, *_): """Set up :attr:`busy_modal` if necessary. Then open or close it depending on state of :attr:`busy`.""" if not self.busy_modal: self.busy_modal = ModalView( auto_dismiss=False, size_hint=(1.2, 1.2), opacity=0.5, ) spinner = MDSpinner(active=False, size_hint=(0.5, 0.5)) self.busy_modal.add_widget(spinner) self.bind(busy=spinner.setter("active")) if self.busy: self.busy_modal.open() else: self.busy_modal.dismiss()
def on_pre_enter(self, *args): global img_gal, img_link, imggalData self.spinner = MDSpinner( size_hint=(None, None), size=(46, 46), pos_hint={'center_x': 1, 'center_y': .5}, active=True, ) self.ids.scroll_grid.add_widget(self.spinner) if img_gal == 'apod': #self.data = imggalData #data = {'media_type' : 'video'} print(imggalData) self.ids.title.text = imggalData['title'] self.ids.explanation.text = imggalData['explanation'] self.link = imggalData['url'] if imggalData['media_type'] == 'image': #self.ids.img.source = self.link #import requests self.ids.button.text = 'View Image' self.ids.button.on_press = self.changeScr elif imggalData['media_type'] == 'video': self.ids.button.text = 'Watch Video'
def spin(self): btn = self.ids['submit'] btn.add_widget( MDSpinner( active=True, pos_hint="'center_x': .5, 'center_y': .5", ))
def __init__(self): super(Test, self).__init__() self.click_tracker = 0 self.main_screen = MDScreen() self.cust_button = MDFillRoundFlatIconButton( text="MDRAISEDBUTTON", md_bg_color=(1, 0, 1, 1), #size_hint=(None, None), #size=(300, 300), pos_hint={'center_x':0.5, 'center_y':0.5}, font_size=dp(16), on_press=self.cust_button_func ) self.cust_spinner = MDSpinner( size_hint=(None, None), size=(dp(28), dp(28)), #pos_hint={'center_x':0.1, 'center_y':0.1}, active=True, line_width=3, palette=[ [0.28627450980392155, 0.8431372549019608, 0.596078431372549, 1], [0.3568627450980392, 0.3215686274509804, 0.8666666666666667, 1], [0.8862745098039215, 0.36470588235294116, 0.592156862745098, 1], [0.8784313725490196, 0.9058823529411765, 0.40784313725490196, 1], ] ) self.cust_button.add_widget(self.cust_spinner) self.main_screen.add_widget(self.cust_button)
def clear_projects(self): """Remove all project list items and add a spinner to signify loading""" self.content.projects_list.clear_widgets() self.content.spinner_container.add_widget( MDSpinner(size_hint=(None, None), pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }, size=(dp(48), dp(48))))
def display_spinner(self): self.spinner_widget = MDSpinner() self.spinner_widget.size_hint = None, None # .25, .5 self.spinner_widget.size = (dp(250), dp(250)) self.spinner_widget.pos_hint = {'center_x': .5, 'center_y': .5} self.spinner_widget.active = True #self.spinner_widget.opacity = 1 self.spinner_widget.color = [0, 0, 0, 1] self.add_widget(self.spinner_widget) self.padding = "45dp"
def remove(self, val): self.spinner3 = MDSpinner(size_hint=(None, None), pos_hint={ 'center_x': .5, 'center_y': .5 }, active=True) self.root.ids.remove_screen.add_widget(self.spinner3) st = threading.Thread(target=self._remove, args=(val, ), daemon=True) toast(f"Removing page {val}.\nPlease wait.") st.start()
def update(self): self.spinner = MDSpinner(size_hint=(None, None), pos_hint={ 'center_x': .5, 'center_y': .5 }, active=True) self.add_widget(self.spinner) update_thread = threading.Thread(target=self.Update) toast("uploading files this may take some time.") update_thread.start()
def remove_all(self): self.spinner2 = MDSpinner(size_hint=(None, None), pos_hint={ 'center_x': .5, 'center_y': .5 }, active=True) self.root.ids.remove_screen.add_widget(self.spinner2) st = threading.Thread(target=self._remove_all, daemon=True) toast("Removing all Files.\nPlease wait.") st.start()
def changePin(self, previous, new, cnew): self.spinner = MDSpinner(size_hint=(None, None), pos_hint={ 'center_x': .5, 'center_y': .5 }, active=True) self.add_widget(self.spinner) cpin_thread = threading.Thread(target=self.change_pin, args=(previous, new, cnew), daemon=True) toast("Updating Current Pin.\nPlease Wait.") cpin_thread.start()
def loading_spinner(pos_hint, active=False): from kivymd.uix.spinner import MDSpinner loading = MDSpinner( size_hint=(None, None), size=('30dp', '30dp'), pos_hint=pos_hint, size_hint_y=None, ) def deactivate_loading(*args): loading.active = False if not active: Clock.schedule_once(deactivate_loading) return loading
def on_request(self, instance, value): """Adds a ``MDSpinner`` to the dialog.""" for widget in self.content_cls.children: if isinstance(widget, MDBoxLayout): widget.clear_widgets() self.content_cls.spacing = "12dp" self.content_cls.add_widget( MDSpinner( size_hint=(None, None), size=("48dp", "48dp"), pos_hint={"center_x": 0.5}, )) break
def _remove_book(self, book=None, func=None): modal_spinner = ModalView(size_hint=(None, None), size=(100, 100), auto_dismiss=False, background='', background_color=(1, 1, 1, 0)) modal_spinner.add_widget(MDSpinner(size_hint=(0.7, 0.7), active=True)) self.modal_spinner = modal_spinner modal_spinner.open() def thread_func(): book.epub_remove() clear_func() @mainthread def clear_func(): func() modal_spinner.dismiss() Thread(target=thread_func).start()
def __init__(self, **kwargs): super().__init__(**kwargs) # In this small block, books are generated from the json file. # (from the task) self.books = [] add_book_button = MDFloatingActionButton( icon="plus", on_release=self.open_book_adder_screen ) # Creating layout where all inner parts will be placed # (such as the foundation of the house) self.layout = MDBoxLayout(orientation="vertical") self.search_field = SearchField() self.spinner = MDSpinner( pos_hint={'center_x': .5, 'center_y': .5}, size_hint=(0.03, 0.03) ) self.spinner.active = False # ScrollView allows to scroll list that was put inside of whis view. # If there is no ScrollView, the user will not be able to see list # items that are outside of the screen. self.scroll_view = ScrollView() # Books are put in the books_list # (the book_list is put in the scroll_view, this is realized in the # `load_books_list` method) # Search field and scroll view are put into the layout self.layout.add_widget(self.search_field) self.layout.add_widget(self.scroll_view) # And the layout is put into this screen self.add_widget(self.layout) self.add_widget(add_book_button)
def _get_books(self): search_box = self.ids.search_box books_list = self.ids.books_list terms = search_box.ids.input.text.strip() if not terms: search_box.ids.input.text = '' return modal_spinner = ModalView(size_hint=(None, None), size=(100, 100), auto_dismiss=False, background='', background_color=(1, 1, 1, 0)) modal_spinner.add_widget(MDSpinner(size_hint=(0.7, 0.7), active=True)) self.modal_spinner = modal_spinner def thread_func(): books = search_books(terms) self._update_books(books) modal_spinner.open() Thread(target=thread_func).start()
def song_details(self, i): self.s_manager = self.root.ids.screen_manager self.change_screen('SongDetailsScreen') self.details_screen = self.root.ids.SongDetailsScreen self.details_screen.clear_widgets() self.song_name = self.search_data[i]['title'].replace( """, "'").replace("&", "&").replace("'", "'") self.song_id = self.search_data[i]['id'] try: self.artist_name = self.search_data[i]['more_info'][ 'primary_artists'].replace(""", "'").replace( "&", "&").replace("'", "'") self.album = self.search_data[i]['album'].replace( """, "'").replace("&", "&").replace("'", "'") except: self.artist_name = self.search_data[i]['subtitle'] self.image_url = self.search_data[i]['image'].replace( '50x50', '500x500').replace('150x150', '500x500') self.image_path = os.path.join(self.data_path, self.song_id + '.jpg') self.fetch_thread = threading.Thread(target=self.fetch_details) self.fetch_thread.start() self.details_screen.add_widget( MDIconButton(icon='chevron-left', pos_hint={ "center_x": 0.05, "center_y": 0.95 }, on_press=lambda x: self.back_screen())) song_image = AsyncImage(source=self.image_url, pos_hint={ "center_x": 0.5, "center_y": 0.5 }, allow_stretch=True) card = MDCard(orientation='vertical', pos_hint={ "center_x": 0.5, "center_y": 0.65 }, size_hint=(None, None), size=(self.win_size * 0.9, self.win_size * 0.9)) card.add_widget(song_image) self.details_screen.add_widget(card) self.details_screen.add_widget( MDLabel(text=self.song_name, halign='center', theme_text_color='Custom', text_color=self.theme_cls.primary_color, font_style='H4', bold=True, pos_hint={"top": 0.84})) self.details_screen.add_widget( MDLabel(text=self.artist_name, halign='center', theme_text_color='Secondary', font_style='H6', pos_hint={"top": 0.8})) self.spinner = MDSpinner(size_hint=(None, None), size=("50", "50"), pos_hint={ 'center_x': 0.5, "center_y": 0.15 }, active=True) #self.details_screen.add_widget(MDLabel(text=self.album, halign='center', theme_text_color='Hint', font_style='H6', pos_hint={"top":0.9})) self.heart_icon = MDIconButton(icon='heart-outline', user_font_size="30sp", theme_text_color='Secondary', pos_hint={ "center_x": 0.1, "center_y": 0.15 }, on_press=lambda x: self.add_fav()) self.details_screen.add_widget(self.heart_icon) self.play_progress = MDProgressBar(pos_hint={ 'center_x': 0.5, 'center_y': 0.25 }, size_hint_x=0.9, value=0, color=self.theme_cls.primary_color) self.details_screen.add_widget(self.play_progress) self.tap_target_view = MDTapTargetView( widget=self.heart_icon, title_text="Add to Favorites", description_text="Feature currently under development", widget_position="left_bottom", ) self.details_screen.add_widget( MDIconButton(icon="chevron-double-left", pos_hint={ "center_x": .3, "center_y": .15 }, user_font_size="50sp", on_release=lambda x: self.rewind())) self.details_screen.add_widget( MDIconButton(icon="chevron-double-right", pos_hint={ "center_x": .7, "center_y": .15 }, user_font_size="50sp", on_release=lambda x: self.forward())) self.play_btn = MDFloatingActionButton( icon='play', pos_hint={ 'center_x': 0.5, "center_y": 0.15 }, user_font_size="50sp", md_bg_color=(1, 1, 1, 1), elevation_normal=10, on_press=lambda x: self.play_song_online()) self.details_screen.add_widget(self.play_btn) self.details_screen.add_widget( MDIconButton(icon='arrow-collapse-down', user_font_size="30sp", theme_text_color='Secondary', pos_hint={ 'center_x': 0.9, "center_y": 0.15 }, on_press=lambda x: self.download_bar())) try: self.dia.dismiss() except: pass
def fetchData(self, *args): global lat, lon spinner = MDSpinner(size_hint=(None, None), size=(46, 46), pos_hint={ 'center_x': .5, 'center_y': .2 }, active=True, id=spin) self.add_widget(spinner) label = MDLabel(pos_hint={'center_y': 0.1}, text="This may take a while", halign="center", id=splabel) self.add_widget(label) def graphPlot(category, parameter): cat = '' para = '' if category == 'Interannual': cat = "INTERANNUAL" else: cat = "DAILY" if parameter == 'T2M_RANGE': para = 'Temperature (C)' elif parameter == 'RH2M': para = 'Moisture(%)' else: para = 'Wind Speed (m/s)' url = "https://power.larc.nasa.gov/cgi-bin/v1/DataAccess.py?&request=execute&identifier=SinglePoint¶meters=" + parameter + "&startDate=" + self.ids.fromd.text[: 4] + "&endDate=" + self.ids.to.text[: 4] + "&userCommunity=AG&tempAverage=" + cat + "&outputList=JSON&lat=" + lat + "&" + "lon=" + lon try: response = requests.get(url) print(response) data = response.json() data = data['features'][0]['properties']['parameter'][ 'T2M_RANGE'] dates = [] values = [] for key, value in data.items(): if key[-2:] != '13' and value >= 0: dates.append(key) values.append(value) print(key + " " + str(value)) import matplotlib.pyplot as plt plt.figure(figsize=(40, 20)) plt.plot(dates, values) plt.title(para + ' Vs Year') plt.xlabel('Year') plt.ylabel(para) plt.savefig('graph.png', bbox_inches='tight') self.remove_widget(self.ids.spinner) self.remove_widget(self.ids.splabel) self.manager.current = 'ndata' except: print("Error") self.manager.current = "nasa" Snackbar(text="Can't get data from Nasa!").show() if self.ids.ele_drop_item.text == 'Temperature': graphPlot(self.ids.per_drop_item.text, 'T2M_RANGE') elif self.ids.ele_drop_item.text == 'Moisture': graphPlot(self.ids.per_drop_item.text, 'RH2M') elif self.ids.ele_drop_item.text == 'Wind': graphPlot(self.ids.per_drop_item.text, 'WS2M') else: Snackbar(text="Select Search Topic and Period first!").show()
def fetchData(self, *args): global lat, lon spinner = MDSpinner( size_hint=(None, None), size=(46, 46), pos_hint={'center_x': .5, 'center_y': .2}, active=True, ) self.add_widget(spinner) label = MDLabel( pos_hint={'center_y': 0.1}, text="This may take a while", halign="center", ) self.add_widget(label) def graphPlot(category, parameter, *args): def snk(*args): Snackbar(text = "Getting Data...").open() Clock.schedule_once(snk, 0.1) cat = '' para = '' if category == 'Interannual': cat = "INTERANNUAL" url = "https://power.larc.nasa.gov/cgi-bin/v1/DataAccess.py?&request=execute&identifier=SinglePoint¶meters=" + parameter + "&startDate=" + self.ids.fromd.text[:4].replace('-','') + "&endDate=" + self.ids.to.text[:4].replace('-','') +"&userCommunity=AG&tempAverage=" + cat + "&outputList=JSON&lat=" + str(lat) + "&" + "lon=" + str(lon) else: cat = "DAILY" url = "https://power.larc.nasa.gov/cgi-bin/v1/DataAccess.py?&request=execute&identifier=SinglePoint¶meters=" + parameter + "&startDate=" + self.ids.fromd.text.replace('-','') + "&endDate=" + self.ids.to.text.replace('-','') +"&userCommunity=AG&tempAverage=" + cat + "&outputList=JSON&lat=" + str(lat) + "&" + "lon=" + str(lon) if parameter == 'T2M_RANGE': para = 'Temperature (C)' elif parameter == 'RH2M': para = 'Moisture (%)' else: para = 'Wind Speed (m/s)' print(url) try: response = requests.get(url) print(response) data = response.json() data = data['features'][0]['properties']['parameter'][parameter] dates = [] values = [] for key, value in data.items(): if category == 'Interannual': if key[-2:] != '13' and value >= 0: dates.append(key) values.append(value) print(key + " " + str(value)) else: dates.append(key) values.append(value) print(key + " " + str(value)) import matplotlib.pyplot as plt plt.figure(figsize=(17,10)) plt.plot(dates, values) plt.title(para + ' Vs Year') plt.xlabel('Year') plt.ylabel(para) plt.xticks(rotation=90) #my_path = os.path.dirname(os.path.realpath(__file__)) global graphName graphName = 'graphs/graph_' + str(int(time.time())) + '.png' print(graphName) plt.savefig(graphName, bbox_inches='tight') #self.manager.current = 'graph' def changeScreen(*args): self.manager.current = 'ndata' Clock.schedule_once(changeScreen, 1) except Exception as e: try: self.remove_widget(spinner) self.remove_widget(label) except: pass print("Error") print(e) self.manager.current = "nasa" Snackbar(text="Can't get data from Nasa!").open() print(self.ids.ele_drop_item.text) print(self.ids.per_drop_item.text) if self.ids.ele_drop_item.text == 'Temperature': graphPlot(self.ids.per_drop_item.text, 'T2M_RANGE') elif self.ids.ele_drop_item.text == 'Moisture': graphPlot(self.ids.per_drop_item.text, 'RH2M') elif self.ids.ele_drop_item.text == 'Wind': graphPlot(self.ids.per_drop_item.text, 'WS2M') else: Snackbar(text="Select Search Topic and Period first!").open()