def build(self): screen = MDScreen() self.theme_cls.primary_palette = "Green" # username=MDTextField(text='Enter username', pos_hint={'center_x':0.5,'center_y':0.5},size_hint_x=None,width=300) username = Builder.load_string(username_helper) screen.add_widget(username) return screen
class Test(MDApp): def __init__(self, **kwargs): super().__init__(**kwargs) self.screen = MDScreen() # self.cust = MDRaisedButton(text="I AM A BUTTON") self.cust = MDRaisedButton(text="I AM A BUTTON", on_release=self.custom_func) self.menu_items = [ { "text": f"Item {i}", "viewclass": "OneLineListItem", "on_release": lambda x=f"Item {i}": self.menu_callback(x), } for i in range(5) ] self.menu = MDDropdownMenu( caller=self.cust, items=self.menu_items, width_mult=4, ) # self.cust.on_release=self.custom_func self.screen.add_widget(self.cust) def custom_func(self, *args, **kwargs): self.menu.open() def menu_callback(self, text_item): print(text_item) def build(self): return self.screen
def build(self): screen=MDScreen() # username=MDTextField(text='Enter username', pos_hint={'center_x':0.5,'center_y':0.5},size_hint=(0.5,1)) username=MDTextField(text='Enter username', pos_hint={'center_x':0.5,'center_y':0.5},size_hint_x=None,width=300) screen.add_widget(username) return screen
def build(self): screen = MDScreen() btn = MDRectangleFlatButton(text="Hello World", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) screen.add_widget(btn) return screen
def build(self): self.content = YearContent(size_hint_y=None, height=400).create() self.dialog = MDDialog(title="Choose Year:", type="custom", content_cls=self.content) screen = MDScreen() button = MDFlatButton(text="Click Me", on_release=self.open_dialog) screen.add_widget(button) return screen
def on_enter(self, *args): for name_image in os.listdir(IMAGE_DIR): if name_image != "0.png": path_to_image = os.path.join(IMAGE_DIR, name_image) screen = MDScreen(name=name_image) screen.add_widget(FitImage(source=path_to_image)) MDApp.get_running_app().root.ids.manager.add_widget(screen) self.ids.swiper.add_widget( ItemSwiper( source=path_to_image, name_city=self.cities[name_image], ))
def build(self): screen = MDScreen() self.theme_cls.primary_palette = "Blue" self.username = Builder.load_string(username_helper) button = MDRectangleFlatButton(text='Show', pos_hint={ 'center_x': 0.5, 'center_y': 0.4 }, on_release=self.show_data) screen.add_widget(self.username) screen.add_widget(button) return screen
class Test(MDApp): 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 cust_button_func(self, *args, **kwargs): if self.click_tracker == 0: self.cust_button.remove_widget(self.cust_spinner) self.click_tracker = not self.click_tracker else: self.cust_button.add_widget(self.cust_spinner) self.click_tracker = not self.click_tracker def build(self): return self.main_screen
def build(self): screen = MDScreen() # btn_flat = MDFlatButton(text='Hello World', pos_hint={'center_x': 0.5, 'center_y': 0.5}) btn_flat = MDRectangleFlatButton(text='Hello World', pos_hint={ 'center_x': 0.3, 'center_y': 0.5 }) # btn_icon=MDIconButton(icon='lightbulb',pos_hint={'center_x':0.5,'center_y':0.5}) btn_icon = MDFloatingActionButton(icon='lightbulb', pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) screen.add_widget(btn_icon) screen.add_widget(btn_flat) return screen
def build(self): screen = MDScreen() list_view = MDList() scroll = ScrollView() # item1=OneLineListItem(text='Item 1') # item2 =OneLineListItem(text='Item 2') # list_view.add_widget(item1) # list_view.add_widget(item2) for i in range(20): # items=OneLineListItem(text='Item '+ str(i)) # items = TwoLineListItem(text='Item ' + str(i), secondary_text='Hello World') items = ThreeLineListItem(text='Item ' + str(i), secondary_text='Hello World', tertiary_text='third text') list_view.add_widget(items) scroll.add_widget(list_view) screen.add_widget(scroll) return screen
def build(self): # setting up theme self.theme_cls.theme_style = "Dark" self.theme_cls.primary_palette = "Green" screen = MDScreen() # loading the above code for text field self.url = Builder.load_string(video_url_code) screen.add_widget(self.url) # adding download button download_button = MDRectangleFlatButton(text="Download", pos_hint={ 'center_x': 0.5, 'center_y': 0.4 }, on_press=self.download) screen.add_widget(download_button) return screen
def build(self): self.theme_cls.primary_palette = "Yellow" self.theme_cls.primary_hue = "900" self.theme_cls.theme_style = "Dark" screen = MDScreen() # btn_flat = MDFlatButton(text='Hello World', pos_hint={'center_x': 0.5, 'center_y': 0.5}) btn_flat = MDRectangleFlatButton(text='Hello World', pos_hint={ 'center_x': 0.3, 'center_y': 0.5 }) # btn_icon=MDIconButton(icon='lightbulb',pos_hint={'center_x':0.5,'center_y':0.5}) btn_icon = MDFloatingActionButton(icon='lightbulb', pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }) screen.add_widget(btn_icon) screen.add_widget(btn_flat) return screen
def build(self): screen = MDScreen() list_view = MDList() scroll = ScrollView() # item1=OneLineListItem(text='Item 1') # item2 =OneLineListItem(text='Item 2') # list_view.add_widget(item1) # list_view.add_widget(item2) for i in range(20): # icon=IconLeftWidget(icon='android') # items = ThreeLineIconListItem(text='Item ' + str(i), secondary_text='Hello World',tertiary_text='third text') image = ImageRightWidget(source='my_avatar.png') items = ThreeLineAvatarIconListItem(text='Item ' + str(i), secondary_text='Hello World', tertiary_text='third text') items.add_widget(image) list_view.add_widget(items) scroll.add_widget(list_view) screen.add_widget(scroll) return screen
def build(self): self.theme_cls.primary_palette = "Yellow" self.theme_cls.theme_style = "Dark" screen = MDScreen() self.link = Builder.load_string(yt_download_link) toolbar = Builder.load_string(yt_toolbar) video_btn = Builder.load_string(video_button) sound_btn = Builder.load_string(sound_button) video_btn.bind(on_press=self.download_video) sound_btn.bind(on_press=self.download_sound) screen.add_widget(self.link) screen.add_widget(toolbar) screen.add_widget(video_btn) screen.add_widget(sound_btn) return screen
class Test(MDApp): def __init__(self, **kwargs): super().__init__(**kwargs) self.screen = MDScreen() menu_items = [{ "viewclass": "OneLineListItem", "height": dp(56), "text": f"Item {i}", } for i in range(5)] self.menu = MDDropdownMenu(items=menu_items, width_mult=4) def open_menu(self, caller): self.menu.caller = caller self.menu.open() def on_start(self): pos_hints = [ { "top": 1, "left": 0.1 }, { "top": 1, "center_x": 0.5 }, { "top": 1, "right": 1 }, { "center_y": 0.5, "left": 1 }, { "bottom": 1, "left": 1 }, { "bottom": 1, "center_x": 0.5 }, { "bottom": 1, "right": 1 }, { "center_y": 0.5, "right": 1 }, { "center_y": 0.5, "center_x": 0.5 }, ] for pos_hint in pos_hints: self.screen.add_widget( MDRaisedButton(pos_hint=pos_hint, on_release=self.open_menu)) def build(self): return self.screen
def build(self): screen = MDScreen() label = Builder.load_string(label_helper) self.theme_cls.primary_palette = 'Yellow' self.theme_cls.theme_style = "Dark" self.Pregnancies = Builder.load_string(p_helper) self.Glucose = Builder.load_string(g_helper) self.BloodPressure = Builder.load_string(bp_helper) self.SkinThickness = Builder.load_string(st_helper) self.Insulin = Builder.load_string(i_helper) self.BMI = Builder.load_string(bmi_helper) self.DiabetesPedigreeFunction = Builder.load_string(dp_helper) self.Age = Builder.load_string(age_helper) button = MDRectangleFlatButton(text='Submit', pos_hint={ 'center_x': .5, 'center_y': .04 }, on_release=self.model) screen.add_widget(label) screen.add_widget(self.Pregnancies) screen.add_widget(self.Glucose) screen.add_widget(self.BloodPressure) screen.add_widget(self.SkinThickness) screen.add_widget(self.Insulin) screen.add_widget(self.BMI) screen.add_widget(self.DiabetesPedigreeFunction) screen.add_widget(self.Age) screen.add_widget(button) return screen
class RepeatDialog(MDScreen): def __init__(self, **kw): super().__init__(**kw) self.rv = CustomRecycle() self.sm = ScreenManager() self.custom = False self.repeat_type = None self.date = MDDatePicker() self.date.bind(on_save=self.on_date_save) self.customrepeat = CustomRepeat(name='custom') self.repeatscreen = MDScreen(name='repeat') self.selectgrid = SelectGrid() self.repeatscreen.add_widget(self.rv) self.sm.add_widget(self.repeatscreen) self.sm.add_widget(self.customrepeat) self.items = [ "Doesn't Repeat", 'Repeat Every Day', 'Repeat Every Week', 'Repeat Every Month', 'Repeat Every Year', 'Custom' ] for item in self.items: rv_item = {"viewclass": 'RepeatItem', 'text': item} self.rv.data.append(rv_item) self.customrepeat.ids.fr.active = False self.add_widget(self.sm) def repeat(self, name): if name == 'Custom': self.sm.transition.direction = 'left' self.sm.current = 'custom' self.customrepeat_type = None self.custom_end = None self.custom = True elif name == "Doesn't Repeat": pass else: self.repeat_type = name.split()[2] self.repeat_dict = {"type": self.repeat_type} def get_repeat(self): if not self.custom: return self.repeat_type if self.custom: return self.customdict def on_all_press(self, text): self.customrepeat_type = text if text == 'Week': try: self.customrepeat.ids.float.add_widget(self.selectgrid) self.days = [] except WidgetException: pass else: self.customrepeat.ids.float.remove_widget(self.selectgrid) def set_list(self, day): if day in self.days: self.days.remove(day) else: self.days.append(day) def on_save(self, text): if text == "": toast('Text Missing!') elif not self.customrepeat_type: toast('Type Missing!') elif self.customrepeat_type == 'Week' and not self.days: self.days = None elif not self.custom_end and not self.customrepeat.ids.fr.active: toast('End Date Missing!') else: self.customdict = {'num': text, 'every': self.customrepeat_type} if self.customrepeat_type == 'Week': self.customdict['days'] = self.days self.customdict['end'] = self.custom_end self.parent.parent.parent.dismiss() def on_date_save(self, instance, value, date_range): iso = datetime.date(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day) if not str(value) > str(iso) or not str(value) < "2071-01-01": toast('Invalid Date! Must be in the future!') if str(value) > str(iso) and str(value) < "2071-01-01": self.custom_end = str(value)
def build(self): screen = MDScreen() # Top toolbar: self.toolbar = MDToolbar(title="Ledstrips", elevation=20) self.toolbar.pos_hint = {"top": 1} self.toolbar.right_action_items = [ # Icon list: https://materialdesignicons.com/ ["exit-to-app", lambda x: self.exit()] ] screen.add_widget(self.toolbar) # Version line: screen.add_widget( MDLabel(text=self._version, font_size=12, pos_hint={ "center_x": 0.5, "center_y": 0.95 }, halign="center")) # Log line: self.text_log = MDLabel(font_size=18, pos_hint={ "center_x": 0.5, "center_y": 0.10 }, halign="center", theme_text_color="Error") screen.add_widget(self.text_log) # # Button Loft: # # Get the status of the ledstrip: try: req = urllib.request.urlopen("http://192.168.1.11:8888/light/Loft") res = req.read() contents = json.loads(res.decode("utf-8")) # self.text_log.text = str(contents) print(contents) self._loftStatus = contents["light"]["state"] self._loftBrightness = contents["light"]["brightness"] self._loftRed = contents["light"]["color"]["red"] self._loftGreen = contents["light"]["color"]["green"] self._loftBlue = contents["light"]["color"]["blue"] except Exception as e: self.text_log.text = str(e) _loft_pos = 0.80 screen.add_widget( MDFillRoundFlatButton(text="Loft", font_size=24, pos_hint={ "center_x": 0.5, "center_y": _loft_pos }, on_press=self.loft)) self.sliderRed_loft = MDSlider(min=0, max=255, value=self._loftRed, color='red', hint=True, hint_radius=4, hint_bg_color='red', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _loft_pos - 0.07 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderRed_loft) self.sliderGreen_loft = MDSlider(min=0, max=255, value=self._loftGreen, color='green', hint=True, hint_radius=4, hint_bg_color='green', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _loft_pos - 0.10 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderGreen_loft) self.sliderBlue_loft = MDSlider(min=0, max=255, value=self._loftBlue, color='blue', hint=True, hint_radius=4, hint_bg_color='blue', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _loft_pos - 0.13 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderBlue_loft) self.sliderBrightness_loft = MDSlider(min=1, max=255, value=self._loftBrightness, color='black', hint=True, hint_radius=4, hint_bg_color='black', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _loft_pos - 0.16 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderBrightness_loft) # # Button Bedroom: # # Get the status of the ledstrip: try: req = urllib.request.urlopen( "http://192.168.1.10:8888/light/Bedroom") res = req.read() contents = json.loads(res.decode("utf-8")) # self.text_log.text = str(contents) self._bedroomStatus = contents["light"]["state"] self._bedroomBrightness = contents["light"]["brightness"] self._bedroomRed = contents["light"]["color"]["red"] self._bedroomGreen = contents["light"]["color"]["green"] self._bedroomBlue = contents["light"]["color"]["blue"] except Exception as e: self.text_log.text = str(e) _bedroom_pos = 0.55 screen.add_widget( MDFillRoundFlatButton(text="Bedroom", font_size=24, pos_hint={ "center_x": 0.5, "center_y": _bedroom_pos }, on_press=self.bedroom)) self.sliderRed_bedroom = MDSlider(min=0, max=255, value=self._bedroomRed, color='red', hint=True, hint_radius=4, hint_bg_color='red', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _bedroom_pos - 0.07 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderRed_bedroom) self.sliderGreen_bedroom = MDSlider(min=0, max=255, value=self._bedroomGreen, color='green', hint=True, hint_radius=4, hint_bg_color='green', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _bedroom_pos - 0.10 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderGreen_bedroom) self.sliderBlue_bedroom = MDSlider(min=0, max=255, value=self._bedroomBlue, color='blue', hint=True, hint_radius=4, hint_bg_color='blue', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _bedroom_pos - 0.13 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderBlue_bedroom) self.sliderBrightness_bedroom = MDSlider(min=1, max=255, value=self._bedroomBrightness, color='black', hint=True, hint_radius=4, hint_bg_color='black', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _bedroom_pos - 0.16 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderBrightness_bedroom) # # Button Bureau: # # Get the status of the ledstrip: # { # "self": "http://192.168.1.12:8888/light/Bureau", # "light": { # "name": "Bureau", # "uri": "http://192.168.1.12:8888/light/Bureau", # "state": false, # "color": { # "red": 1, # "green": 1, # "blue": 1 # }, # "brightness": 255 # }, # "switches": [ # { # "name": "Desk", # "uri": "http://192.168.1.12:8888/light/Bureau/switch/Desk", # "state": 1 # } # ] # } try: req = urllib.request.urlopen( "http://192.168.1.12:8888/light/Bureau") res = req.read() contents = json.loads(res.decode("utf-8")) # self.text_log.text = str(contents) self._bureauStatus = contents["light"]["state"] self._bureauBrightness = contents["light"]["brightness"] self._bureauRed = contents["light"]["color"]["red"] self._bureauGreen = contents["light"]["color"]["green"] self._bureauBlue = contents["light"]["color"]["blue"] except Exception as e: self.text_log.text = str(e) _bureau_pos = 0.30 screen.add_widget( MDFillRoundFlatButton(text="Bureau", font_size=24, pos_hint={ "center_x": 0.5, "center_y": _bureau_pos }, on_press=self.bureau)) self.sliderRed_bureau = MDSlider(min=0, max=255, value=self._bureauRed, color='red', hint=True, hint_radius=4, hint_bg_color='red', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _bureau_pos - 0.07 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderRed_bureau) self.sliderGreen_bureau = MDSlider(min=0, max=255, value=self._bureauGreen, color='green', hint=True, hint_radius=4, hint_bg_color='green', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _bureau_pos - 0.10 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderGreen_bureau) self.sliderBlue_bureau = MDSlider(min=0, max=255, value=self._bureauBlue, color='blue', hint=True, hint_radius=4, hint_bg_color='blue', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _bureau_pos - 0.13 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderBlue_bureau) self.sliderBrightness_bureau = MDSlider(min=1, max=255, value=self._bureauBrightness, color='black', hint=True, hint_radius=4, hint_bg_color='black', hint_text_color='black', pos_hint={ "center_x": 0.5, "center_y": _bureau_pos - 0.16 }, size_hint_x=0.9, size_hint_y=0.05) screen.add_widget(self.sliderBrightness_bureau) # Setting it in stone: return screen
def build(self): box = MDScreen(md_bg_color=self.theme_cls.bg_darkest) box.add_widget(CircularTimePicker()) return box
class MDCalendar(MDScreen): def build(self): Builder.load_string(KV) def getDay(self, year, month, day): for date in getDict(): list = date.split(',') if year in list[2] and month in list[1] and day in list[1]: return list[0] def __init__(self, **kw): super().__init__(**kw) self.build() self.sm = ScreenManager() self.boxlayout = BoxLayout(orientation='vertical') self.main_screen = MDScreen() self.main_screen.size_hint = 1, .4 year = int(datetime.now().strftime("%Y")) self.current_year = f'{year}/{year - 579}' self.yearchooser = YearChooser() self.yearchooser.size_hint_y = 0.1 self.widget = Widget() self.widget.size_hint_y = 0.02 self.topBar = TopBar() self.topBar.size_hint_y = 0.1 current_month = datetime.now().strftime("%B") self.months = { 'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6, 'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12 } day = datetime.now().strftime("%d") days = ['M', 'T', 'W', 'T', 'F', 'S', 'S'] self.events = EventContent().create(int(year), self.months[current_month], int(day)) self.events.size_hint = 1, .6 for month in self.months: screen = Screen(name=month) grid = MDGridLayout(cols=7) grid.id = month spacer_grid = MDGridLayout(cols=7) spacer_grid.size_hint_y = .2 spacer_grid.size_hint_x = 1 screen.add_widget(grid) for day in days: grid.add_widget(DayLabel(text=day)) daysinmonth = calendar.monthrange(year, self.months[month])[1] + 1 for i in range(1, daysinmonth): if i == 1: day = self.getDay("2021", month, str(i)) daynum = getattr(calendar, day.upper()) for n in range(daynum): grid.add_widget(Spacer()) label = SelectableLabel(text=str(i)) if month == current_month and label.text == str( datetime.now().strftime('%#d')): label.selected = True grid.add_widget(label) self.sm.add_widget(screen) self.main_screen.add_widget(self.sm) self.sm.current = str(current_month) self.boxlayout.add_widget(self.yearchooser) self.boxlayout.add_widget(self.topBar) self.boxlayout.add_widget(self.main_screen) self.boxlayout.add_widget(self.widget) self.boxlayout.add_widget(self.events) self.add_widget(self.boxlayout) def on_year_change(self, year): screens = self.sm.screens self.events.switch_year(year) for screen in screens[:]: spacers = [] day = self.getDay(str(year), screen.name, str(1)) monthnum = self.months[str(screen.name)] daysinmonth = getMonthDays(screen.name, int(year)) + 1 grid = screen.children[0] for widget in grid.children: if "Spacer" in str(widget): spacers.append(widget) spacers_amount = len(spacers) amount_needed = getattr(calendar, day.upper()) + 1 label = SelectableLabel(text="29") if screen.name == "February" and isLeap(int(year)) is True: grid.add_widget(label) elif screen.name == "February" and isLeap(int(year)) is False: for widget in grid.children: try: if "29" in widget.text: grid.remove_widget(widget) break except AttributeError: pass if amount_needed > spacers_amount: add = amount_needed - spacers_amount - 1 index = len(grid.children) - 7 for x in range(add): grid.add_widget(Spacer(), index) elif spacers_amount > amount_needed: remove = spacers_amount - amount_needed + 1 for y in range(remove): for widget in grid.children: if "Spacer" in str(widget): grid.remove_widget(widget) break self.yearchooser.text = f"{year}/{int(year) - 579}" self.sm.current = "January" self.topBar.ids.topLabel.text = self.sm.current