def addImage(self, filename): image = Image(source=filename) image.size_hint = None, None image.width = metrics.sp(120) image.height = metrics.sp(120) self.add_widget(image) return
def build(self, func): root = BoxLayout(orientation='vertical', padding='5dp', size_hint=(1, None)) root.size_y = '100dp' with root.canvas: Color(.88, .88, .88) Rectangle(pos=root.pos, size=root.size) b0 = BoxLayout() a1 = AnchorLayout(size_hint=(1, 1)) # короткое имя btn = Button(size_hint=(1, 1), text='Add ' + self.short, on_press=func, id=self.short) a1.add_widget(btn) # содержит картинку a2 = AnchorLayout(anchor_x='right', anchor_y='center') i1 = Image(size_hint=(None, None), source=paths.images + 'flags/{}.png'.format(self.short)) i1.width = '60dp' i1.height = '60dp' a2.add_widget(i1) b0.add_widget(a1) b0.add_widget(a2) root.add_widget(b0) return root
def build(self, convert): root = BoxLayout(orientation='vertical', padding='5dp', size_hint=(1, None), id='root') root.size_y = '100dp' with root.canvas: Color(.88, .88, .88) Rectangle(pos=root.pos, size=root.size) # содержит картинку b0 = BoxLayout(id='box_root', padding='30dp', spacing='10dp') # size_hint=(1, 1), ai = AnchorLayout(size_hint=(.3, 1)) i1 = Image(size_hint=(None, None), source=paths.images + 'flags/{}.png'.format(self.item.short)) i1.width = '60dp' i1.height = '60dp' ai.add_widget(i1) b0.add_widget(ai) # содержит ввод и корткое имя # короткое имя a1 = AnchorLayout(size_hint=(.1, 1)) l1 = Label(color=(0, 0, 0, 1), font_size='20dp', text=self.item.short) a1.add_widget(l1) b0.add_widget(a1) # ввод a_inp = AnchorLayout(size_hint=(1, .8), id='anchor_input') inp = LimInput(size_hint=(1, None), id=self.item.short, write_tab=False, multiline=False) inp.height = '30dp' inp.make_convert = convert a_inp.add_widget(inp) b0.add_widget(a_inp) root.add_widget(b0) a2 = AnchorLayout(anchor_x='center', padding='30dp') l2 = Label(size_hint=(None, None), color=(0, 0, 0, 1), font_size='20dp', text=self.item.name) a2.add_widget(l2) root.add_widget(a2) root.input = inp return root
def build(self): root = BoxLayout(orientation='vertical', padding='5dp', size_hint=(1, None)) root.size_y = '100dp' with root.canvas: Color(.88, .88, .88) Rectangle(pos=root.pos, size=root.size) b = BoxLayout(size_hint=(1, .9)) i1 = Image(size_hint=(None, None), source=paths.images + 'res/{}.svg'.format(self.item.name)) i1.width = '55dp' i1.height = '55dp' b.add_widget(i1) # полное имя и цена a1 = AnchorLayout() l1 = Label(color=(0, 0, 0, 1), font_size='20dp', text=self.item.name) a1.add_widget(l1) # короткое имя a2 = AnchorLayout() l2 = Label(color=(0, 0, 0, 1), font_size='20dp', text='{0:.2f}'.format(self.item.rate) + '$') a2.add_widget(l2) b1 = BoxLayout(spacing='30dp', padding='20dp') b1.add_widget(a1) b1.add_widget(a2) a3 = AnchorLayout() l3 = Label(color=(0, 0, 0, 1), font_size='20dp', text='price for 100 gr') a3.add_widget(l3) a4 = AnchorLayout(size_hint=(1, .19), anchor_x='right') l4 = Label(size_hint=(None, None), text=str(self.item.date), color=(0, 0, 0, 1)) a4.add_widget(l4) b2 = BoxLayout(spacing='30dp', padding='20dp') b2.add_widget(a3) b2.add_widget(a4) g0 = GridLayout(spacing='30dp', padding='20dp', rows=2) g0.add_widget(b1) g0.add_widget(b2) b.add_widget(g0) root.add_widget(b) return root
def build(self): self.title = "Blackjack" self.parent = Widget() sm = ScreenManager() # set up the screens #splashcreen self.ss = Screen(name = 'splash_screen') splashmenu = SplashScreen() splashmenu.buildUp() self.ss.add_widget(splashmenu) #main menu self.mm = Screen(name = 'main_menu') self.mainmenu = MainMenu() self.mainmenu.buildUp() self.mm.add_widget(self.mainmenu) #add the logo to mainmenu and splashscreen logo = Image(source = 'images/logo.png') logo.width = Window.width/2 logo.height = Window.height/2 logo.x = Window.width/2 - (logo.width-logo.width*.05) logo.y = (Window.height/2 - logo.width/2) self.mm.add_widget(logo) #game screen self.gs = Game(name = 'game') #Add screens to screen manager sm.add_widget(self.ss) sm.add_widget(self.mm) sm.add_widget(self.gs) sm.current = 'main_menu' def check_screen_change(obj): if(self.mainmenu.buttonText == 'Play'): sm.current = 'game' self.gs.start_round() self.mainmenu.bind(on_button_release = check_screen_change) return sm
def __init__(self, height: int, **kwargs): super(TopBar, self).__init__(**kwargs) topBack = Image() topBack.color = [0, 0, 0, 1] topBack.width = Window.size[0] topBack.height = height self.add_widget(topBack) self.__grid = GridLayout() self.__grid.cols = 10 self.__grid.rows = 1 self.__grid.width = Window.size[0] self.__grid.height = height self.add_widget(self.__grid)
def __init__(self, height: int, backCallback: callable, homeCallback: callable, **kwargs): super(BottomBar, self).__init__(**kwargs) bottomBack = Image() bottomBack.color = [0, 0, 0, 1] bottomBack.width = Window.size[0] bottomBack.height = height self.add_widget(bottomBack) btnGrid = GridLayout() btnGrid.cols = 5 btnGrid.rows = 1 btnGrid.width = Window.size[0] btnGrid.height = height self.add_widget(btnGrid) btnBack = Button(text="Back") btnBack.bind(on_press=lambda instance: backCallback()) btnGrid.add_widget(btnBack, 0) btnHome = Button(text="Home") btnHome.bind(on_press=lambda instance: homeCallback()) btnGrid.add_widget(btnHome, 1)
def build(self): root = BoxLayout(orientation='vertical', padding='5dp', size_hint=(1, None)) root.size_y = '100dp' with root.canvas: Color(.88, .88, .88) Rectangle(pos=root.pos, size=root.size) b = BoxLayout(size_hint=(1, 1)) ai = BoxLayout() i1 = Image(size_hint=(None, None), source=paths.images + 'flags/{}.png'.format(self.item.short)) ai.add_widget(i1) i1.width = '90dp' i1.height = '90dp' b.add_widget(ai) g = BoxLayout(spacing='30dp', orientation='vertical') a1 = AnchorLayout() l1 = Label(color=(0, 0, 0, 1), font_size='20dp', text=(self.item.short + ' ' + str(self.item.rate[0]) + ' ' + self.item.symbol + ' – ' + '{0:.2f}'.format(self.item.rate[1]) + ' Br')) a1.add_widget(l1) a2 = AnchorLayout() l2 = Label(color=(0, 0, 0, 1), font_size='20dp', text=self.item.name) a2.add_widget(l2) g.add_widget(a1) g.add_widget(a2) b.add_widget(g) root.star = Button(size_hint=(None, None)) root.star.width = '80dp' root.star.height = '80dp' root.star.on_press = self.fav # star.background_down = 'images\\appIcons\\star.png' if self.item.fav_s: s = paths.images + 'appIcons/starT.png' else: s = paths.images + 'appIcons/star.png' root.star.background_normal = s self.star = root.star b.add_widget(root.star) root.add_widget(b) a3 = AnchorLayout(anchor_x='center') l3 = Label(size_hint=(None, .1), text=str(self.item.date), color=(0, 0, 0, 1)) a3.add_widget(l3) g.add_widget(a3) return root
def entered(self): grid = self.children[0].children[0] grid.clear_widgets() self.books = [] self.book_filepaths = [ helper.get_resources_path() + "/books/" + b for b in os.listdir(helper.get_resources_path() + "/books/") ] self.titles = [] if self.book_filepaths == []: grid.add_widget(Label(text="No books found :(")) n = 0 for b in self.book_filepaths: n += 1 if n % 2 == 0: grid.height = 200 + n * 200 n = 0 for b in self.book_filepaths: n += 1 button = Button(on_press=self.goto_read) button.size_hint = (None, None) button.size = (200, 200) self.children[0].children[0].add_widget(button) layout = BoxLayout() button.add_widget(layout) x = ((1 - (n % 2)) * 240) + 70 y = grid.height - ((((n - 1) / 2) - (((n - 1) / 2) % 1)) * 240) - 250 layout.pos = (x, y) layout.size = button.size layout.orientation = "vertical" self.book_filename = b.split("/")[-1].split(".")[0] book = EPUBEE(b) cover = book.get_cover() if cover != "": cover_path = helper.get_app_path( ) + APP_NAME + "/covers/" + self.book_filename + ".jpeg" cover.save(cover_path) self.books.append(book) img = Image(source=cover_path) img.size_hint_x = None img.width = 100 img.height = 100 if len(book.title) > 18: text = book.title[:15] + "..." else: text = book.title self.titles.append(text) lbl = Label(text=text, color=[.5, .5, .5, 1], size_hint=(None, None), pos=(button.pos[0], button.pos[1])) if cover != "": layout.add_widget(img) print("adding") layout.add_widget(lbl)
def build(self): root = BoxLayout(orientation='vertical', padding='5dp', size_hint=(1, None)) root.size_y = '100dp' with root.canvas: Color(.88, .88, .88) Rectangle(pos=root.pos, size=root.size) b = BoxLayout(size_hint=(1, 1)) ai = BoxLayout(size_hint=(.3, 1)) i1 = Image(size_hint=(None, None), source=paths.images + 'crypts/{}.svg'.format(self.item.short)) i1.width = '60dp' i1.height = '60dp' ai.add_widget(i1) b.add_widget(ai) g1 = BoxLayout(spacing='40dp', padding='40dp') # полное имя a1 = AnchorLayout(anchor_x='left', anchor_y='center', padding='10dp') l1 = Label(size_hint=(None, None), color=(0, 0, 0, 1), font_size='20dp', text=self.item.name) l1.valign = 'middle' l1.halign = 'left' a1.add_widget(l1) # цена a3 = AnchorLayout(anchor_x='right', anchor_y='center', padding='10dp') l3 = Label(size_hint=(None, None), color=(0, 0, 0, 1), font_size='20dp', text='{0:.2f}'.format(self.item.rate) + '$') l3.valign = 'middle' l3.halign = 'right' a3.add_widget(l3) g1.add_widget(a1) g1.add_widget(a3) g2 = BoxLayout(spacing='40dp', padding='40dp') # короткое имя a2 = AnchorLayout(anchor_x='left', anchor_y='center', padding='10dp') l2 = Label(size_hint=(None, None), color=(0, 0, 0, 1), font_size='20dp', text=self.item.short) l2.valign = 'middle' l2.halign = 'left' a2.add_widget(l2) g2.add_widget(a2) a4 = AnchorLayout(anchor_x='right', anchor_y='center', padding='10dp') l4 = Label(size_hint=(None, None), text=str(self.item.date), color=(0, 0, 0, 1)) l4.valign = 'middle' l4.halign = 'left' a4.add_widget(l4) g2.add_widget(a4) b0 = BoxLayout(spacing='40dp', orientation='vertical') b0.add_widget(g1) b0.add_widget(g2) b.add_widget(b0) root.add_widget(b) return root