class Library(Screen): def __init__(self, **kwargs): super(Library, self).__init__(**kwargs) self.deckname = None self.skeleton_frame() def skeleton_frame(self): #Displays all decks on the app self.box = MDBoxLayout(orientation="vertical") self.scrollview = ScrollView() self.list = MDList() self.scrollview.add_widget(self.list) #calls the activate_for_loop method self.display_deck() # Buttons on the bottom of the screen # Buttons are places on bottom of screen self.box.add_widget( MDLabel(size_hint=(0.2, 0.15))) # Push down the list of buttons self.box.add_widget(self.scrollview) self.bottom_bar = MDToolbar() self.delete_deck_button = MDIconButton(icon="trash-can-outline", pos_hint={ 'center_x': .5, 'center_y': .5 }) self.delete_deck_button.bind(on_press=self.delete_deck) self.build_deck_button = MDIconButton(icon="plus-thick", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) self.build_deck_button.bind(on_press=self.build_new_deck) #add method to make a new deck self.bottom_bar.add_widget(self.delete_deck_button) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(self.build_deck_button) self.bottom_bar.add_widget(MDLabel()) self.box.add_widget(self.bottom_bar) self.add_widget(self.box) def skeleton_frame2(self, instance): # method must be used to make the on_press method work self.scrollview.remove_widget(self.list) self.box.remove_widget(self.bottom_bar) self.list = MDList() self.scrollview.add_widget(self.list) #Displays all decks on the app self.box = MDBoxLayout(orientation="vertical") self.scrollview = ScrollView() self.list = MDList() self.scrollview.add_widget(self.list) #calls the activate_for_loop method self.display_deck() # Buttons on the bottom of the screen # Buttons are places on bottom of screen self.box.add_widget( MDLabel(size_hint=(0.2, 0.15))) # Push down the list of buttons self.box.add_widget(self.scrollview) self.bottom_bar = MDToolbar() self.delete_deck_button = MDIconButton(icon="trash-can-outline", pos_hint={ 'center_x': .5, 'center_y': .5 }) self.delete_deck_button.bind(on_press=self.delete_deck) self.build_deck_button = MDIconButton(icon="plus-thick", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) self.build_deck_button.bind(on_press=self.build_new_deck) #add method to make a new deck self.bottom_bar.add_widget(self.delete_deck_button) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(self.build_deck_button) self.bottom_bar.add_widget(MDLabel()) self.box.add_widget(self.bottom_bar) self.add_widget(self.box) # Creates a section that will list out the decks def display_deck(self): conn = sqlite3.connect("flashcard_app.db") cur = conn.cursor() cur.execute(""" SELECT DeckName FROM Decks """) names = cur.fetchall() for name in names: # the nested for loop will remove (),' from the string name = str(name) for char in name: if char == "(" or char == ")" or char == "," or char == "'": name = name.replace(char, "") self.items = OneLineListItem(text=name) self.items.bind(on_press=self.display_cards) self.list.add_widget(self.items) conn.commit() conn.close() # working code to switch screens with python code def display_cards(self, instance): self.scrollview.remove_widget(self.list) self.box.remove_widget(self.bottom_bar) self.list = MDList() self.scrollview.add_widget(self.list) self.deckname = instance.text print(self.deckname) conn = sqlite3.connect("flashcard_app.db") cur = conn.cursor() cur.execute( """ SELECT CardName FROM Cards WHERE DeckName = ? """, (instance.text, )) names = cur.fetchall() for name in names: # the nested for loop will remove (),' from the string name = str(name) for char in name: if char == "(" or char == ")" or char == "," or char == "'": name = name.replace(char, "") self.items = OneLineListItem(text=name) self.items.bind(on_press=self.display_name_def) self.list.add_widget(self.items) conn.commit() conn.close() self.get_bottom_bar() def display_cards2(self): self.scrollview.remove_widget(self.list) self.box.remove_widget(self.bottom_bar) self.list = MDList() self.scrollview.add_widget(self.list) conn = sqlite3.connect("flashcard_app.db") cur = conn.cursor() cur.execute( """ SELECT CardName FROM Cards WHERE DeckName = ? """, (self.deckname, )) names = cur.fetchall() for name in names: # the nested for loop will remove (),' from the string name = str(name) for char in name: if char == "(" or char == ")" or char == "," or char == "'": name = name.replace(char, "") self.items = OneLineListItem(text=name) self.items.bind(on_press=self.display_name_def) self.list.add_widget(self.items) conn.commit() conn.close() self.get_bottom_bar() #displays the bottom nav bar when display_cards is called def get_bottom_bar(self): self.bottom_bar = MDToolbar() self.add_card_button = MDIconButton(icon="plus-thick", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) self.trash_button = MDIconButton(icon="trash-can-outline", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) self.back_button = MDIconButton(icon="arrow-left-bold", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) self.trash_button.bind(on_press=self.delete_card) self.back_button.bind(on_press=self.skeleton_frame2) self.add_card_button.bind(on_press=self.add_cards) #self.build_deck_button.bind(on_press=self.to_build_card) # jargon of code to space out the buttons on bottom nav bar self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(self.back_button) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(self.add_card_button) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(self.trash_button) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(MDLabel()) self.box.add_widget(self.bottom_bar) def add_cards(self, instance): close_button = MDFlatButton(text="Close", on_release=self.close_dialog) enter_button = MDFlatButton(text="Enter", on_release=self.add_cardname_to_db) self.grid = MDGridLayout(rows=4, size_hint_y=None, height=int(Window.height) / 8.9) self.front_input = MDTextField(size_hint=(.9, 1)) self.back_input = MDTextField(size_hint=(.9, 1)) self.dialog = MDDialog(title="Card Creation", pos_hint={ 'center_x': .5, 'center_y': .5 }, type="custom", content_cls=Content(), size_hint=(.9, 1), buttons=[close_button, enter_button]) self.grid.add_widget(MDLabel(text=" Front")) self.grid.add_widget(self.front_input) self.grid.add_widget(MDLabel(text=" Back")) self.grid.add_widget(self.back_input) self.dialog.add_widget(self.grid) self.dialog.open() def add_cardname_to_db(self, instance): front_input = self.front_input.text back_input = self.back_input.text print(self.deckname) print(front_input) print(back_input) con = sqlite3.connect("flashcard_app.db") cur = con.cursor() cur.execute( """ INSERT INTO Cards (CardName, Definition, DeckName) VALUES(?, ?, ?) """, (front_input, back_input, self.deckname)) names = cur.fetchall() for name in names: # the nested for loop will remove (),' from the string name = str(name) for char in name: if char == "(" or char == ")" or char == "," or char == "'": name = name.replace(char, "") self.items = OneLineListItem(text=name) #self.items.bind(on_press=self.display_name_def) self.list.add_widget(self.items) con.commit() con.close() self.display_cards2() # displays the front and back of a single card def display_name_def(self, instance): self.predicate = True self.scrollview.remove_widget(self.list) self.box.remove_widget(self.bottom_bar) print(instance.text) con = sqlite3.connect("flashcard_app.db") cur = con.cursor() cur.execute( """ SELECT CardName, Definition FROM Cards WHERE CardName = ? """, (instance.text, )) row = cur.fetchall() for cardname, definition in row: self.front = cardname self.back = definition print(self.front, self.back) con.commit() con.close() # will display the front-side of selected card self.click_action() # the screen will act as a button to display the front or back after clicking the screen def click_action(self): if self.predicate == True: self.button = Button(text=self.front, color=(1, 0, 1, 1), background_color=(0, 0, 0, 0), font_size='20sp', on_release=self.click_action2) self.predicate = False else: self.button = Button(text=self.back, color=(1, 0, 1, 1), background_color=(0, 0, 0, 0), font_size='20sp', on_release=self.click_action2) self.predicate = True self.scrollview.add_widget(self.button) self.bottom_bar_name_def() def click_action2(self, instance): self.box.remove_widget(self.scrollview) self.remove_widget(self.bottom_bar) self.scrollview = ScrollView() if self.predicate == True: self.button = Button(text=self.front, color=(1, 0, 1, 1), background_color=(0, 0, 0, 0), font_size='20sp', on_release=self.click_action2) self.predicate = False else: self.button = Button(text=self.back, color=(1, 0, 1, 1), background_color=(0, 0, 0, 0), font_size='20sp', on_release=self.click_action2) self.predicate = True self.scrollview.add_widget(self.button) self.box.add_widget(self.scrollview) self.bottom_bar_name_def() # displays bottom bar that will return user to displaying the list of decks def bottom_bar_name_def(self): self.bottom_bar = MDToolbar() #self.box = MDBoxLayout(orientation="horizontal") self.back_button = MDFlatButton(text="Return to Decks", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) self.back_button.bind(on_press=self.back_display_cards) #self.box.add_widget(self.back_button) #self.box.add_widget(MDLabel()) self.bottom_bar.add_widget(self.back_button) self.add_widget(self.bottom_bar) def back_display_cards(self, instance): self.box.remove_widget(self.scrollview) self.remove_widget(self.bottom_bar) self.skeleton_frame() # method to build a new deck using a dialog box def build_new_deck(self, instance): close_button = MDFlatButton(text="Close", on_release=self.close_dialog) # *** This button will put name into db, then refresh the page enter_button = MDFlatButton(text="Enter", on_release=self.add_name_to_db) self.input = MDTextField(pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }, size_hint=(.9, 1)) self.dialog = MDDialog(title="Enter Deck Name", size_hint=(0.7, 1), buttons=[close_button, enter_button]) self.dialog.add_widget(self.input) self.dialog.open() # method to close the dialog box def close_dialog(self, instance): self.dialog.dismiss() #method that inserts the deck name into db def add_name_to_db(self, instance): input = self.input.text # this will have an if else statement if an error was typed in #self.error = MDDialog() #self.error.open() conn = sqlite3.connect("flashcard_app.db") cur = conn.cursor() cur.execute( """ INSERT INTO Decks (deckname) VALUES(?)""", (input, )) conn.commit() conn.close() self.remove_widget(self.box) self.skeleton_frame() print("boo") def delete_deck(self, instance): close_button = MDFlatButton(text="Close", on_release=self.close_dialog) delete_dialog_button = MDFlatButton(text="Delete", on_release=self.delete_deck_input) self.dialog = MDDialog(title="Delete Deck", size_hint=(0.7, 1), buttons=[close_button, delete_dialog_button]) self.input = MDTextField() self.dialog.add_widget(self.input) self.dialog.open() def delete_deck_input(self, instance): input = self.input.text con = sqlite3.connect("flashcard_app.db") cur = con.cursor() cur.execute( """ DELETE FROM Decks WHERE DeckName = ?; """, (input, )) cur.execute( """ DELETE FROM Cards WHERE DeckName = ?; """, (input, )) con.commit() con.close() self.remove_widget(self.box) self.skeleton_frame() def delete_card(self, instance): close_button = MDFlatButton(text="Close", on_release=self.close_dialog) delete_dialog_button = MDFlatButton(text="Delete", on_release=self.delete_card_input) self.dialog = MDDialog(title="Delete Card", size_hint=(0.7, 1), buttons=[close_button, delete_dialog_button]) self.input = MDTextField() self.dialog.add_widget(self.input) self.dialog.open() def delete_card_input(self, instance): input = self.input.text con = sqlite3.connect("flashcard_app.db") cur = con.cursor() cur.execute( """ DELETE FROM Cards WHERE CardName = ? """, (input, )) con.commit() con.close() self.display_cards2()
class MapWidget(MDDialog2): @property def projection(self): # return ccrs.PlateCarree() # return ccrs.EckertI() # return ccrs.EquidistantConic() # return ccrs.LambertConformal(central_longitude=0)#,central_latitude=0) # return ccrs.LambertConformal(central_longitude=0)#,central_latitude=0) return ccrs.AlbersEqualArea() @property def figsize(self): # fig = plt.figure() # dpi=fig.dpi // 2 dpi=40 width,height=Window.size return (width//dpi, height//dpi) # bbox = fig.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) # width, height = bbox.width*fig.dpi, bbox.height*fig.dpi # return (width,height) @property def color_land(self): return rgb(*darksienna3,a=0) #darksienna3) @property def color_water(self): return rgb(*russiangreen) @property def color_label(self): return rgb(*COLOR_ICON) @property def color_marker(self): return rgb(*COLOR_ICON) @property def color_line(self): return rgb(*rufusred) # COLOR_ICON) @property def color_line_dark(self): return rgb(*COLOR_ICON) def __init__(self): self.last_lat = None self.last_long = None self.points = [] self.opened=False self.label=None self.intro_label=None # self.fig = fig = plt.figure(figsize=(20,10)) plt.rcParams["figure.figsize"] = self.figsize self.ax = ax = plt.axes( projection=self.projection, ) # ax.set_extent([-170, 165, -55, 75]) # ax.background_patch.set_facecolor(rgb(*COLOR_CARD)[:3]) # ax.outline_patch.set_facecolor(rgb(*COLOR_CARD)[:3]) # self.ax.stock_img() # self.ax.coastlines(color=rgb(*COLOR_CARD)) ax.add_feature(cartopy.feature.OCEAN, zorder=0, color=self.color_water,edgecolor=self.color_water) ax.add_feature(cartopy.feature.LAND, zorder=0, color=self.color_land, edgecolor=self.color_land) ax.outline_patch.set_visible(False) ax.background_patch.set_visible(False) # ax.set_global() # ax.gridlines() self.layout=MDBoxLayout() self.layout.orientation='vertical' self.layout.cols=1 self.layout.size_hint=(None,None) self.layout.size=(Window.size[0],Window.size[1]) # ('666sp','666sp') self.layout.md_bg_color=rgb(*eerieblack) #rgb(*COLOR_BG,a=1) # self.layout.adaptive_height=True # self.layout.height=self.layout.minimum_height self.layout.spacing='0sp' self.layout.padding='0sp' self.img=None self.label_layout=MDGridLayout() self.label_layout.orientation='vertical' self.label_layout.cols=1 self.label_layout.row_default_height='25sp' self.label_layout.row_force_default='25sp' self.label_layout.rows=10 self.label_layout.pos_hint={'y':1} self.label_layout.size_hint=(None,None) self.label_layout.width=Window.size[0] self.label_layout.height='300sp' # self.label_layout.size=(Window.size[0],'400sp') # self.label_layout.size=Window.size # ('666sp','666sp') # self.layout.add_widget(self.label_layout) # do dialog's intro super().__init__( type='custom', text='', content_cls=self.layout, buttons=[ MDFlatButton( text="disconnect", text_color=rgb(*COLOR_TEXT), md_bg_color = rgb(*eerieblack), #(0,0,0,1), theme_text_color='Custom', on_release=self.dismiss, font_name=FONT_PATH ) ], color_bg = rgb(*eerieblack), #(0,0,0,1), overlay_color=(0,0,0,0), background_color=(0,0,0,0) ) self.ids.text.text_color=rgb(*COLOR_TEXT) self.ids.text.font_name=FONT_PATH self.size=Window.size #('666sp','666sp') # self. # self.adaptive_height=True def draw(self): from matplotlib import transforms from PIL import Image as pImage from PIL import ImageOps # tr = transforms.Affine2D().rotate_deg(90) # buf = io.BytesIO() # plt.ion() from comrad.constants import PATH_MAPS odir=PATH_MAPS if not os.path.exists(odir): os.makedirs(odir) ofn=os.path.join(odir,f't_{len(self.points)}.png') # plt.gca().invert_yaxis() plt.savefig(ofn, format='png',transparent=True,pad_inches=0.1,bbox_inches = 'tight') # flip? # im = pImage.open(ofn) # im = im.rotate(90) # im.save(ofn) if not self.img: self.img= AsyncImage(source=ofn) self.img.background_color=(0,0,0,0) self.img.overlay_color=(0,0,0,0) # self.img.texture.flip_horizontal() self.img.pos_hint={'center_x':0.48,'center_y':0.5} # self.img.size=Window.size # self.img.texture = img self.img.add_widget(self.label_layout,1) self.layout.add_widget(self.img,1) else: self.img.source=ofn # self.img.size_hint=(1,1) # self.img.width=Window.size[0] # self.img.allow_stretch=True def makelabel(self,txt): label=MDLabel(text=txt) label.color=self.color_label #rgb(*color) #self.color_label label.font_name=FONT_PATH label.font_size='20sp' # label.size_hint=(1,1) label.width=Window.size[0] label.height='25sp' label.valign='top' return label def add_point(self,lat,long,desc): logger.info(f'adding point? {desc} {lat}, {long}') # plt.text( # long+3, # lat-12, # desc, # horizontalalignment='left', # transform=self.projection # ) import random from comrad.constants import ALL_COLORS color = random.choice(ALL_COLORS) self.points+=[(lat,long,desc)] # # point plt.plot( long, lat, '.', markersize=25, linewidth=10, color=self.color_marker,#rgb(*color), transform=ccrs.Geodetic(), ) # line if self.last_lat and self.last_long: # if self.ax.lines: self.ax.lines.pop(0) for line in self.ax.lines: line.set_color(self.color_line_dark) plt.plot( [self.last_long, long], [self.last_lat, lat], color=self.color_line,#rgb(*color), #self.color_line, linewidth=4, marker='', transform=ccrs.Geodetic(), ) desc = '\n'.join('--> '+desc for lat,long,desc in self.points[-1:]) #if self.label: # self.img.remove_widget(self.label) self.label=label=self.makelabel(desc) # label.height='400sp' # label.pos_hint = {'center_y':0.1+(0.1 * len(self.points))} # label.pos = (0.5,0) self.label_layout.add_widget(label) self.last_lat,self.last_long = lat,long self.ax.set_global() # wait and show def open(self,maxwait=666,pulse=0.1): self.ax.lines=[] self.draw() if not self.intro_label: self.intro_label = self.makelabel('Comrad @Tor: Routing you through the global maze of the deep web ...') self.label_layout.add_widget(self.intro_label) super().open() self.opened=True # await asyncio.sleep(pulse) # waited=0 # while not self.ok_to_continue: # await asyncio.sleep(pulse) # waited+=pulse # if waited>maxwait: break # # logger.info(f'waiting for {waited} seconds... {self.ok_to_continue} {self.response}') # return self.response def dismiss(self): super().dismiss() self.intro_label=None if hasattr(self.layout,'img'): self.layout.remove_widget(self.img) if self.layout: self.remove_widget(self.layout)
class Review(Screen): def __init__(self, **kwargs): super(Review, self).__init__(**kwargs) self.predicate = True self.skeleton_frame() def skeleton_frame(self): # Displays all decks on the app self.box = MDBoxLayout(orientation="vertical") self.scrollview = ScrollView() self.list = MDList() self.scrollview.add_widget(self.list) # calls the activate_for_loop method self.display_deck() # Buttons on the bottom of the screen # Buttons are places on bottom of screen self.box.add_widget( MDLabel(size_hint=(0.2, 0.15))) # Push down the list of buttons self.box.add_widget(self.scrollview) self.bottom_bar = MDToolbar() self.box.add_widget(self.bottom_bar) self.add_widget(self.box) def skeleton_frame2(self, instance): # Displays all decks on the app #self.box.remove_widget(self.complete_label) self.box.remove_widget(self.count_grid) self.box = MDBoxLayout(orientation="vertical") self.scrollview = ScrollView() self.list = MDList() self.scrollview.add_widget(self.list) # calls the activate_for_loop method self.display_deck() # Buttons on the bottom of the screen # Buttons are places on bottom of screen self.box.add_widget( MDLabel(size_hint=(0.2, 0.15))) # Push down the list of buttons self.box.add_widget(self.scrollview) self.bottom_bar = MDToolbar() self.box.add_widget(self.bottom_bar) self.add_widget(self.box) def display_deck(self): conn = sqlite3.connect("flashcard_app.db") cur = conn.cursor() cur.execute(""" SELECT DeckName FROM Decks """) names = cur.fetchall() for name in names: # the nested for loop will remove (),' from the string name = str(name) for char in name: if char == "(" or char == ")" or char == "," or char == "'": name = name.replace(char, "") self.items = OneLineListItem(text=name) self.items.bind(on_press=self.review_deck) self.list.add_widget(self.items) conn.commit() conn.close() # screen will display the review section def review_deck(self, instance): self.num = 0 self.count = 0 self.review_cardname = ["This deck is empty"] self.review_definition = ["This deck is empty"] self.scrollview.remove_widget(self.list) self.box.remove_widget(self.bottom_bar) con = sqlite3.connect("flashcard_app.db") cur = con.cursor() cur.execute( """ SELECT CardName, Definition FROM Cards WHERE DeckName = ? """, (instance.text, )) row = cur.fetchall() for cardname, definition in row: self.review_cardname.append(cardname) self.review_definition.append(definition) self.front = cardname self.back = definition print(self.front, self.back) print(self.review_cardname) if len(self.review_cardname) != 1 and len(self.review_definition) != 1: self.review_cardname.remove("This deck is empty") self.review_definition.remove("This deck is empty") con.commit() con.close() self.click_action() def click_action(self): if self.predicate == True: self.button = Button(text=self.review_cardname[self.num], color=(1, 0, 1, 1), background_color=(0, 0, 0, 0), font_size='20sp', on_release=self.click_action2) self.predicate = False else: self.button = Button(text=self.review_definition[self.num], color=(1, 0, 1, 1), background_color=(0, 0, 0, 0), font_size='20sp', on_release=self.click_action2) self.predicate = True self.scrollview.add_widget(self.button) self.bottom_bar_name_def() def click_action2(self, instance): self.box.remove_widget(self.scrollview) self.remove_widget(self.bottom_bar) self.scrollview = ScrollView() if self.predicate == True: self.button = Button(text=self.review_cardname[self.num], color=(1, 0, 1, 1), background_color=(0, 0, 0, 0), font_size='20sp', on_release=self.click_action2) self.predicate = False else: self.button = Button(text=self.review_definition[self.num], color=(1, 0, 1, 1), background_color=(0, 0, 0, 0), font_size='20sp', on_release=self.click_action2) self.predicate = True self.scrollview.add_widget(self.button) self.box.add_widget(self.scrollview) self.bottom_bar_name_def() def bottom_bar_name_def(self): self.bottom_bar = MDToolbar() self.pass_button = MDIconButton(icon="check-bold", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }, on_release=self.next_card_pass) self.fail_button = MDIconButton(icon="close-box-outline", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }, on_release=self.next_card_fail) self.tag_button = MDIconButton(icon="star-circle", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) #self.back_button.bind(on_press=self.back_display_cards) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(self.fail_button) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(self.tag_button) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(self.pass_button) self.bottom_bar.add_widget(MDLabel()) self.bottom_bar.add_widget(MDLabel()) self.add_widget(self.bottom_bar) def bottom_bar_complete(self): self.bottom_bar = MDToolbar() self.return_review = MDFlatButton(text="Return to Decks", pos_hint={ 'center_x': .5, 'center_y': .5 }, on_release=self.skeleton_frame2) self.bottom_bar.add_widget(self.return_review) self.add_widget(self.bottom_bar) def back_display_cards(self, instance): self.box.remove_widget(self.scrollview) self.remove_widget(self.bottom_bar) self.skeleton_frame() def next_card_pass(self, instance): self.count += 1 self.num += 1 self.predicate = True if self.num == len(self.review_cardname): self.box.remove_widget(self.scrollview) self.remove_widget(self.bottom_bar) self.get_result() #self.complete_label = MDLabel(text="Complete") #self.box.add_widget(self.complete_label) self.bottom_bar_complete() else: self.click_action2(instance) def next_card_fail(self, instance): self.num += 1 self.predicate = True if self.num == len(self.review_cardname): self.box.remove_widget(self.scrollview) self.remove_widget(self.bottom_bar) self.get_result() #self.complete_label = MDLabel(text="Complete") #self.box.add_widget(self.complete_label) self.bottom_bar_complete() else: self.click_action2(instance) def get_result(self): self.count_grid = MDGridLayout(cols=3) self.count_label = MDLabel(text=str(self.count), size_hint_x=None, width=20) self.divider = MDLabel(text="/", size_hint_x=None, width=20) self.total_num = MDLabel(text=str(len(self.review_cardname)), size_hint_x=None, width=20) self.count_grid.add_widget(self.count_label) self.count_grid.add_widget(self.divider) self.count_grid.add_widget(self.total_num) self.box.add_widget(self.count_grid) self.box.add_widget(MDLabel()) self.box.add_widget(MDLabel())
class BooksListScreen(MDScreen): """Screen, contains the list of books with short information and the search bar. """ 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 spinner_toggle(self): if self.spinner.active == False: self.layout.add_widget(self.spinner) self.spinner.active = True else: self.layout.remove_widget(self.spinner) self.spinner.active = False def load_books_list(self, books): """ Method that loads list of books to the screen. Separate method for loading the list is needed because when the book is deleted from the list, or when the user types something in searchbar, the list should be reloaded """ self.spinner_toggle() # Clear all elements in the scroll view # (this elements are books list items) self.scroll_view.clear_widgets() # List will contain all books mdlist = MDList() # Add books to the list one by one for book in books: list_item_widget = BookListItem(book) mdlist.add_widget(list_item_widget) self.spinner_toggle() # Add list to the scroll view self.scroll_view.add_widget(mdlist) def open_book_adder_screen(self, touch): """Called when the user taps on the button and releases it""" BooksTab.screens["book_adder"].load_content() BooksTab.screen_manager.transition.direction = "left" BooksTab.screen_manager.switch_to(BooksTab.screens["book_adder"])