class MDListBottomSheet(MDBottomSheet): mlist = ObjectProperty() def __init__(self, **kwargs): super(MDListBottomSheet, self).__init__(**kwargs) self.mlist = MDList() self.gl_content.add_widget(self.mlist) Clock.schedule_once(self.resize_content_layout, 0) def resize_content_layout(self, *largs): self.gl_content.height = self.mlist.height def add_item(self, text, callback, icon=None): if icon: item = OneLineIconListItem(text=text, on_release=callback) item.add_widget(ListBSIconLeft(icon=icon)) else: item = OneLineListItem(text=text, on_release=callback) item.bind(on_release=lambda x: self.dismiss()) self.mlist.add_widget(item)
def all_student(self): self.conn = sqlite3.connect('SCHOOL.db') self.c = self.conn.cursor() self.all_students = self.c.execute('SELECT * FROM STUDENTS') gris = GridLayout( rows=2, # row_default_height=(self.width - self.cols * self.spacing[0]) / self.cols, # row_force_default=True, # size_hint_y=None, # height=self.minimum_height, padding=(dp(1), dp(1)), spacing=dp(1)) sv = ScrollView() ml = MDList() for row in self.all_students: ml.add_widget( ThreeLineListItem(text=str(row[1]), secondary_text=row[2] + '\n' + row[3])) sv.do_scroll_y = True sv.do_scroll_x = False sv.add_widget(ml) gris.add_widget( MDTextField(hint_text="Helper text on focus", helper_text="This will disappear when you click off", helper_text_mode="on_focus")) gris.add_widget(sv) self.root.ids.students.add_widget(gris) self.root.ids.screen_manager.current = str(self.root.ids.students.name)
def on_enter(self): # schedules already populated if self.ids.schedule_tabs.ids.tab_manager.screens: return current_date = datetime.datetime.now().strftime('%d_%m_%Y') track_names = [] # populating schedules for i in range(*self.schedule_range): track_name = self.base_tab_name.format(i) track_names.append(track_name) track_day = str(i) tab = MDTab(id=track_day, name=track_name, text='{} Out'.format(track_day)) # tab schedule sv = ScrollView(id='tab_{}'.format(track_name), do_scroll_x=False) l = MDList() for track in self.tracks[track_day]: item = Track(info=track) l.add_widget(item) sv.add_widget(l) tab.add_widget(sv) self.ids.schedule_tabs.add_widget(tab) # not really sure if this is the way to select a tab if current_date in track_names: self.ids.schedule_tabs.current = current_date self.ids.spinner.active = False
def anime_confirmation(self, anime_list): Global.ANIME_CONFIRM_LIST = [] for anime in anime_list: Global.ANIME_CONFIRM_LIST.append(anime.name) ml = MDList() for anime in anime_list: item = OneLineRightIconListItem(text=anime.name) item.on_release = functools.partial(self.show_desc, anime) remove_button = RemoveButton(name=anime.name, icon='server-remove') item.add_widget(remove_button) ml.add_widget(item) self.dialog = MDDialog( title=str(len(anime_list)) + " Results! This is what we found for you. Click to open browser for more info!", content=ml, size_hint=(.8, None), height=dp(650), auto_dismiss=False) self.dialog.add_action_button("Cancel", action=lambda *x: self.dialog.dismiss()) self.dialog.add_action_button( "Confirm and + to watchlist", action=lambda *x: self.add_anime_to_db(self.dialog, anime_list)) self.dialog.open()
def on_enter(self, *args): blayout = MyLayout() resview = ScrollView() mylist = MDList() count = 0 title = authors = 'Not Available' bsrc = 'Image-not-available.jpg' for i in self.parent.result: #print('\n'+i+'\n') try: title = i['volumeInfo']['title'] except: pass try: authors = i['volumeInfo']['authors'] except: pass try: bsrc = i['volumeInfo']['imageLinks']['smallThumbnail'] except: pass item = TwoLineAvatarIconListItem(text=title, secondary_text=str(authors)) item.add_widget(BookPhoto(source=bsrc)) item.bind(on_press=partial(self.change_screen, count)) mylist.add_widget(item) count += 1 resview.add_widget(mylist) blayout.add_widget(resview) self.add_widget(blayout)
def info_dialog(self): content = MDList() label = MDLabel(font_style='Subhead', theme_text_color='Secondary', text="\n" + str(self.audio_file), valign='center', halign="center") label.bind(texture_size=label.setter('size')) image = SmartTile(allow_stretch=True, keep_ratio=True, box_color=[0, 0, 0, 0], size_hint_y=None, height=300) image._img_widget.texture = self.ids.avatar.texture content.add_widget(image) content.add_widget(label) self.dialog = MDDialog(title=self.audio_file.name, content=content, size_hint=(.8, 0.75), auto_dismiss=False) self.dialog.add_action_button("Dismiss", action=lambda *x: self.dialog.dismiss()) self.dialog.open()
def build_screen(self): history = JsonStore(history_path) scrollview = ScrollView(do_scroll_x=False) md_list = MDList() scrollview.add_widget(md_list) for i in history.keys(): item = HistoryItem(text=str(i)) item.add_widget( AvatarSampleWidget(source="./assets/kivy-icon-128.png")) md_list.add_widget(item) print("building screen for history") self.add_widget(scrollview)
class ContactDialog(MDDialog): def __init__(self, screen, **kwargs): super(ContactDialog, self).__init__(**kwargs) self.screen = screen self.content = MDList() self.load_contacts() self.add_action_button(text="Cancelar", action=lambda *x: self.dismiss()) def load_contacts(self, ): for c in db(ContatoModel).select(orderby=ContatoModel.nome): self.content.add_widget(ChooseContactItem(self, c))
class FrequenciaDialog(MDDialog): def __init__(self, screen, **kwargs): super(FrequenciaDialog, self).__init__(**kwargs) self.screen = screen self.content = MDList() self.load_options() self.add_action_button(text="Cancelar", action=lambda *x: self.dismiss()) def load_options(self, ): for item in FREQUENCIA: self.content.add_widget(FrequenciaItem(self, item))
def list_course(self): box = BoxLayout() sv = ScrollView() ml = MDList() self.get_courses = self.c.execute('SELECT * FROM COURSES') for row in sorted(self.get_courses): ml.add_widget(OneLineListItem(text=str(row[1]))) sv.do_scroll_y = True sv.do_scroll_x = False sv.add_widget(ml) self.root.ids.courses.add_widget(sv) self.root.ids.screen_manager.current = str(self.root.ids.courses.name)
def teachers(self): sv = ScrollView() ml = MDList() rows = self.c.execute('SELECT * FROM TEACHERS') for row in sorted(rows): ml.add_widget( ThreeLineListItem(text=str(row[1]), secondary_text="id: " + str(row[0]) + '\n' 'under : ' + row[2])) sv.do_scroll_y = True sv.do_scroll_x = False sv.add_widget(ml) self.root.ids.teachers.add_widget(sv) self.root.ids.screen_manager.current = str(self.root.ids.teachers.name)
def subjects(self): self.conn = sqlite3.connect('SCHOOL.db') self.c = self.conn.cursor() self.all_subjects = self.c.execute('SELECT * FROM STUDENTS') sv = ScrollView() ml = MDList() for row in sorted(self.all_subjects): ml.add_widget( ThreeLineListItem(text=str(row[1]), secondary_text="id: " + str(row[0]) + '\n' 'under : ' + row[2])) sv.do_scroll_y = True sv.do_scroll_x = False sv.add_widget(ml) self.root.ids.subjects.add_widget(sv) self.root.ids.screen_manager.current = str(self.root.ids.subjects.name)
def read(self,*largs): content = FloatLayout() scroll = ScrollView() mdlist = MDList() content.add_widget(scroll) scroll.add_widget(mdlist) title = "Testimonies" pop = Popup(title= title,content= content,) pop.open() try: for message in Testify.select(): time.sleep(0.50) mdlist.add_widget(PopList(text=str(message.name),secondary_text=str(message.message))) print('reading testimonies') except peewee.OperationalError: self.login_failure('Check Network Connection')
def show_files_extensions(self, file_type): ''' Loads the files extension settings from the assets/file_extension.json it is called when either 'Document, Video, Image or Audoi' List items is pressed. After loading, it is shown in a dialog :parameters: file_type --> extension key in the json_file e.g 'document_extensions :return: opens a dialog ''' files_extension = JsonStore('assets/files_extension.json') dialog_content = MDList() self.dialog = None for extension in files_extension.get(file_type): # trim '.' from the file extension e.g. '.pdf', and add doc_ext_ # to itso it becomes 'doc_ext_pdf' and use it as the widget id. icon_right_sample_widget = IconRightSampleWidget(id="doc_ext_" + extension[1:]) if files_extension.get(file_type)[extension]: icon_right_sample_widget.active = True # trim '.'from the file extension e.g. '.pdf', and # convert it to uppercase # so it comes 'PDF' list_item = OneLineAvatarIconListItem(text=extension[1:].upper()) list_item.add_widget(icon_right_sample_widget) dialog_content.add_widget(list_item) self.dialog = MDDialog( title="Select file extensions to include in search", content=dialog_content, size_hint=(.8, None), height=self.root.height - dp((self.root.height / 2) / 8), auto_dismiss=False) self.dialog.add_action_button("DONE", action=lambda *x: self.dialog.dismiss()) # bind the dialog to self.save_extensions method when it is closed self.dialog.bind(on_dismiss=partial(self.save_extensions, file_type)) self.dialog.open()
def _create_popup(self, instance): content = BoxLayout(orientation='vertical', spacing='5dp') list = MDList() content.add_widget(list) # add all the options uid = str(self.uid) for option, text in sorted(self.options.items(), key=lambda t: t[1]): state = 'down' if option == self.value else 'normal' # active = True if option == self.value else False btn = OneLineChekboxListItem(text=text, state=state, group=uid) btn.bind(on_release=lambda instance, option=option: self. _set_option(option)) list.add_widget(btn) self.popup = card_with_buttons( content, title=self.desc, buttons=[[_('Cancel'), self.close_dialog]])
def get_student(self, value): sv = ScrollView() ml = MDList() sv.add_widget(ml) get_student = self.c.execute( 'SELECT * FROM STUDENTS WHERE STUDENT_CLASS_NAME = ?', (value, )) for row in get_student: ml.add_widget(OneLineListItem(text=str(row[1]))) sv.do_scroll_y = True sv.do_scroll_x = False r = GridLayout(cols=1, rows=1) r.add_widget(sv) p = Popup(title='STUDENTS', size_hint=(.7, 0.7), background_color=(0, 0, .9, .5), auto_dismiss=True) p.add_widget(r) p.open()
class MDListBottomSheet(MDBottomSheet): mlist = ObjectProperty() def __init__(self, **kwargs): super().__init__(**kwargs) self.mlist = MDList() self.gl_content.add_widget(self.mlist) Clock.schedule_once(self.resize_content_layout, 0) def resize_content_layout(self, *largs): self.gl_content.height = self.mlist.height def add_item(self, text, callback, icon=None): if icon: item = OneLineIconListItem(text=text, on_release=callback) item.add_widget(ListBSIconLeft(icon=icon)) else: item = OneLineListItem(text=text, on_release=callback) item.bind(on_release=lambda x: self.dismiss()) self.mlist.add_widget(item)
def load_requests(self): content = ScrollView() mdlist = MDList() content.add_widget(mdlist) title = "Prayer Requests" pop = Popup(title=title, content=content) pop.open() try: for prayer in PrayerRequest.select(): mdlist.add_widget( PopList(text=str(prayer.name), secondary_text=str(prayer.prayer_request))) except peewee.OperationalError: mdlist.add_widget( PopList( text=str('Error'), secondary_text=str( 'Please Check The Internet Connection and Try Again'))) else: pass
def __init__(self): super(lis,self).__init__() tot=network.get_firebase('Schedule') day1=tot['Day1'] day2=tot['Day2'] k1={} k2={} for no,i in enumerate(day1): if (no==0): continue k1[no]=i.replace('\\t','\t') for no,i in enumerate(day2): if (no==0): continue k2[no]=i.replace('\\t','\t') self.name='shed' t=Toolbar(title='shedule',md_bg_color= self.theme_cls.primary_color,background_palette='Primary') t.add_widget(MDRaisedButton(text='back',on_press=lambda x:self.cng_scr('vute'))) #b1=BoxLayout(orientation='vertical') b1=GridLayout(rows=12) n=MDList() l1=OneLineListItem(text='Day 1') n.add_widget(l1) k1_key=k1.keys() for i in k1_key: ln=OneLineListItem(text=k1[i]) n.add_widget(ln) l3=OneLineListItem(text='') n.add_widget(l3) l2=OneLineListItem(text='Day 2') n.add_widget(l2) k2_key=k2.keys() for i in k2_key: ln=OneLineListItem(text=k2[i]) n.add_widget(ln) b1.add_widget(t) b1.add_widget(n) self.add_widget(b1)
class newwid(GridLayout, Thread): def __init__(self, **kwargs): GridLayout.__init__(self, **kwargs) Thread.__init__(self) self.cols = 1 self.tool = ntoolbar(title='KivDL') self.add_widget(self.tool) self.body = GridLayout(cols=1, padding=(0, 20)) self.add_widget(self.body) self.tex = MDTextField(pos_hint={'center_y': 0.9}, size_hint_x=0.8) self.tex.hint_text = " Enter URL to download" self.fetch_button = MDRaisedButton(text='Fetch', pos_hint={ 'center_y': 0, 'right': 0.95 }, size_hint_x=0.1) self.fetch_button.bind(on_press=self.addcard) self.urlget = GridLayout(cols=2, size_hint_y=0.2) self.urlget.add_widget(self.tex) self.urlget.add_widget(self.fetch_button) self.body.add_widget(self.urlget) self.cardholder = ScrollView(do_scroll_x=False, size_hint_x=0.8) self.cardlist = MDList(padding=(10, 20)) self.cardlist.spacing = (10, 20) self.cardholder.add_widget(self.cardlist) self.body.add_widget(self.cardholder) self.spacer = MDLabel(size_hint_y=0.2) self.cardlist.add_widget(self.spacer) def addcard(self, instance): if self.tex.text != '': self.cardlist.remove_widget(self.spacer) self.cardlist.add_widget(infocard(self.tex.text)) self.cardlist.add_widget(self.spacer) self.tex.text = ''
class ProductListScreenService(object): def __init__(self): self.connectionManager = None self.productListScreen = None self.productListViewModel = None self.scrollView = None self.mdList = None self.spinner = None def bind_objects(self, productListScreen): self.productListScreen = productListScreen self.connectionManager = productListScreen.connectionManager self.productListViewModel = productListScreen.productListViewModel self.spinner = productListScreen.spinner self.scrollView = ScrollView() self.productListScreen.add_widget(widget=self.scrollView) self.mdList = MDList() self.scrollView.add_widget(widget=self.mdList) def set_mdList(self): if len(self.mdList.children) is 0: for product in self.productListViewModel.get_product_list(): item = TwoLineListItem( id=product.id, text=product.name, secondary_text='Buy price:{0} Sell price:{1}'.format( product.buy, product.sell), on_release=self.productListScreen.on_product_select) self.mdList.add_widget(item) else: for i in range(len(self.mdList.children)): self.mdList.children[ i].id = self.productListViewModel.get_product_list()[i].id self.mdList.children[ i].text = self.productListViewModel.get_product_list( )[i].name self.mdList.children[ i].secondary_text = 'Buy price:{0} Sell price:{1}'.format( self.productListViewModel.get_product_list()[i].buy, self.productListViewModel.get_product_list()[i].sell) self.show_list() def send_request(self): requestDto = ProductListDto.GetRequest( token=self.productListScreen.parent.token) try: response = json.loads( self.connectionManager.send_request(body=requestDto.toJSON(), method='GET')) product_list = response['data']['product_list'] temp_list = [] for product_json in product_list: product = Product( id=str(product_json['product_id']), name=str(product_json['product_name']), description=str(product_json['product_description']), buy=str(format(float(product_json['buy_price']), '.3f')), sell=str(format(float(product_json['sell_price']), '.3f')), quantity=int(product_json['product_quantity']), product_type=str(product_json['type'])) temp_list.append(product) self.productListViewModel.set_product_list(product_list=temp_list) self.set_mdList() except (httplib.HTTPException, socket.error) as ex: print 'products request error {0}'.format(ex) def set_list_data(self): thread.start_new_thread(self.send_request, ()) def hide_list(self): self.mdList.opacity = 0 self.spinner.opacity = 1 self.spinner.active = True def show_list(self): self.mdList.opacity = 1 self.spinner.opacity = 0 self.spinner.active = False def mock_response(self): response = ProductListDto.GetResponse() for i in range(4): p = { 'product_id': '{0}'.format(i), 'product_name': 'test {0}'.format(i), 'product_description': 'djaiodjwaoidjsiajd', 'buy_price': (1 + i) * 100.00, 'sell_price': (1 + i) * 100.00, 'product_quantity': (1 + i) * 100.00, 'product_type': 'type {0}'.format(i) } response.get_data().add_product(product=p) return response.toJSON()
def __init__(self): super(lis, self).__init__() self.k1 = db.get_db('all') self.k2 = self.k1[3:] k1 = self.k1 k2 = self.k2 self.name = 'info' t = Toolbar(title='personal info', md_bg_color=self.theme_cls.primary_color, background_palette='Primary') t.add_widget( MDRaisedButton(text='back', on_press=lambda a: self.cng_scr('vute'))) #b1=BoxLayout(orientation='vertical') b1 = GridLayout(rows=12) n = MDList() l1 = OneLineListItem(text='Details') n.add_widget(l1) name = k1[0].split(' ')[0] n.add_widget(OneLineListItem(text='Name :\t' + name)) n.add_widget(OneLineListItem(text='phone :\t' + k1[1])) n.add_widget(OneLineListItem(text='email :\t' + k1[2])) l3 = OneLineListItem(text='') n.add_widget(l3) l2 = OneLineListItem(text='Registered courses') n.add_widget(l2) cou = 1 for i in range(len(k2)): if k2[i] == '1': ln = OneLineListItem(text=str(cou) + ') ' + proj[i]) cou += 1 n.add_widget(ln) if cou == 1: ln = OneLineListItem(text='no regestered courses') n.add_widget(ln) b1.add_widget(t) b1.add_widget(n) self.add_widget(b1)
class infocard(MDCard, Thread): def __init__(self, url, **kwargs): self.url = url MDCard.__init__(self, **kwargs) Thread.__init__(self) self.size_hint_y = None self.size = (100, 300) self.body = GridLayout(cols=1, padding=(2, 5)) self.desbody = GridLayout(cols=2, size_hint_y=0.5) self.downloadbody = GridLayout(cols=2, size_hint_y=0.1) self.titlebody = GridLayout(cols=2, size_hint_y=0.1) self.title = MDLabel(text='VIDEO TITLE', font_style='Body2', pos_hint={ 'center_x': 0.51, 'top': 1.3 }) #self.title.bind(size=self.title.setter('text_size')) self.thumb = AsyncImage(source='load.jpg', pos_hint={'center_x': 0}, size_hint=(0.2, 1)) self.descriptionscroll = ScrollView() self.description = MDLabel(text='Descriptions', font_style='Caption', size_hint_y=None, pos_hint={ 'center_x': 0.5, 'top': 1.15 }) self.description.bind(texture_size=self.description.setter('size')) self.descriptionscroll.add_widget(self.description) self.downloadbutton = MDFloatingActionButton(icon='download', pos_hint={'right': 1}, disabled=True) self.probar = MDProgressBar(max=100, pos_hint={ 'center_y': 0, 'center_x': 0.4 }) self.titlebody.add_widget(self.thumb) self.titlebody.add_widget(self.title) self.desbody.add_widget(self.descriptionscroll) self.downloadbody.add_widget(self.probar) self.downloadbody.add_widget(self.downloadbutton) kvp = ''' #:import MDSpinner kivymd.spinner.MDSpinner #:import MDCheckbox kivymd.selectioncontrols.MDCheckbox Screen: MDSpinner: id: spinner size_hint: None, None size: dp(46), dp(46) pos_hint: {'center_x': 0.5, 'center_y': 0.5} active: True ''' self.sp = Builder.load_string(kvp) #self.spinner=MDSpinner() self.add_widget(self.sp) #self.add_widget(self.spinner) self.status = 'fetch' self.meta = [] self.start() def createbody(self): self.thumb.source = self.meta['id'] + '.jpg' self.thumb.reload() self.body.add_widget(self.titlebody) self.body.add_widget(self.desbody) self.body.add_widget(self.downloadbody) self.add_widget(self.body) def run(self): try: with youtube_dl.YoutubeDL({}) as ydl: y = [] y.append(self.url) self.meta = ydl.extract_info(self.url, download=False) print self.meta self.title.text = self.meta['title'] try: self.description.text = self.meta['description'] except: self.description.text = "NO VIDEO DESCRIPTION FOUND" try: import urllib urllib.urlretrieve(self.meta['thumbnail'], self.meta['id'] + '.jpg') except: pass self.status = 'fetched' self.downloadbutton.disabled = False self.downloadbutton.bind(on_press=self.download) self.remove_widget(self.sp) self.createbody() self.createmenu() try: for x in self.meta['requested_formats']: print x['format'] except: for x in self.meta['formats']: print x['format'] return 0 except Exception as e: print e.message self.description.text = 'Please check url and reenter' self.title.text = 'INVALID URL' self.status = 'error fetch' self.clear_widgets() self.errorlay = FloatLayout() self.dismiss = MDFloatingActionButton(icon='close-circle', pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) self.errortitle = (MDLabel(align='center', font_style='Title', text='Failed to Fetch', pos_hint={ 'center_x': 0.5, 'center_y': 0.2 })) self.errorlay.add_widget(self.dismiss) self.errorlay.add_widget(self.errortitle) self.add_widget(self.errorlay) self.dismiss.bind(on_press=self.dell) def dell(self, instance): self.parent.remove_widget(self) def downloadthread(self): self.downloadbutton.disabled = True with youtube_dl.YoutubeDL({'progress_hooks': [self.progressbarupdate]}) as ydl: ydl.download([self.url]) return 0 def progressbarupdate(self, d): try: percentage = (float(d['downloaded_bytes']) / d['total_bytes']) * 100 except: for x in d: print x, d[x] percentage = (float(d['downloaded_bytes']) / d['total_bytes_estimate']) * 100 print('updating', percentage) self.probar.max = 100 self.probar.value = percentage if d['status'] == 'finished': import os import shutil self.status = 'completed' print os.listdir('./') x = os.listdir('./') for y in x: if y.find('.mp4') >= 0: print 'moving' shutil.copy('./' + y, defaultlocation + y) os.remove('./' + y) def download(self, instance): self.status = 'download' self.dt = Thread(target=self.downloadthread) self.dt.start() def createmenu(self): items = ['3gp', 'mp4', 'webm', 'mkv'] self.formatbuttons = {} self.list = MDList() for x in items: self.formatbuttons[x] = MDFlatButton(text=x) self.list.add_widget(self.formatbuttons[x]) self.formatbut = dropdownmb(text='mp4') self.formatbut.bind(on_press=self.show_list) self.formatbut.pos_hint = {'center_x': 0.5, 'center_y': 0.6} self.controllay = FloatLayout() self.controllay.add_widget(self.formatbut) #self.desbody.add_widget(self.controllay) def show_list(self, instance): instance.parent.add_widget(self.list) self.list.pos = instance.pos