def user_screen(self): self.manager.get_screen( 'main').ids.btn_camera.color = get_color_from_hex('#FFFFFF') self.manager.get_screen( 'main').ids.btn_home.color = get_color_from_hex('#FFFFFF') self.manager.get_screen( 'main').ids.btn_user.color = get_color_from_hex('#2196F3') self.manager.get_screen('main').ids.master.clear_widgets() user_layout = GridLayout() user_layout.id = 'user_layout' user_layout.spacing = (0, 0.5) user_layout.padding = 40, 10, 40, 10 user_layout.cols = 1 user_layout.row_default_height = self.height * 0.25 user_layout.row_force_default = True lbl_user = Label() lbl_user.id = 'lbl_home' lbl_user.color = get_color_from_hex('#212121') lbl_user.text = 'User Layout' self.manager.get_screen('main').ids[user_layout.id] = \ WeakProxy(user_layout) self.manager.get_screen('main').ids[lbl_user.id] = \ WeakProxy(lbl_user) self.manager.get_screen('main').ids.master.\ add_widget(user_layout) self.manager.get_screen('main').ids.user_layout.\ add_widget(lbl_user)
def home_screen(self): self.manager.get_screen( 'main').ids.btn_camera.color = get_color_from_hex('#FFFFFF') self.manager.get_screen( 'main').ids.btn_home.color = get_color_from_hex('#2196F3') self.manager.get_screen( 'main').ids.btn_user.color = get_color_from_hex('#FFFFFF') self.manager.get_screen('main').ids.master.clear_widgets() home_layout = GridLayout() home_layout.id = 'home_layout' home_layout.spacing = (0, 0.5) home_layout.padding = 40, 10, 40, 10 home_layout.cols = 1 home_layout.row_default_height = self.height * 0.25 home_layout.row_force_default = True lbl_home = Label() lbl_home.id = 'lbl_home' lbl_home.color = get_color_from_hex('#212121') lbl_home.text = 'Home Layout' self.manager.get_screen('main').ids[home_layout.id] = \ WeakProxy(home_layout) self.manager.get_screen('main').ids[lbl_home.id] = \ WeakProxy(home_layout) self.manager.get_screen('main').ids.master.\ add_widget(home_layout) self.manager.get_screen('main').ids.lbl_home.\ add_widget(lbl_home)
def camera_screen(self): self.manager.get_screen( 'main').ids.btn_camera.color = get_color_from_hex('#2196F3') self.manager.get_screen( 'main').ids.btn_home.color = get_color_from_hex('#FFFFFF') self.manager.get_screen( 'main').ids.btn_user.color = get_color_from_hex('#FFFFFF') self.manager.get_screen('main').ids.master.clear_widgets() camera_layout = GridLayout() camera_layout.id = 'camera_layout' camera_layout.spacing = (0, 0.5) camera_layout.padding = 40, 10, 40, 10 camera_layout.cols = 1 camera_layout.row_default_height = self.height * 0.25 camera_layout.row_force_default = True lbl_camera = Label() lbl_camera.id = 'lbl_camera' lbl_camera.color = get_color_from_hex('#212121') lbl_camera.text = 'Camera Layout' self.manager.get_screen('main').ids[camera_layout.id] = \ WeakProxy(camera_layout) self.manager.get_screen('main').ids[lbl_camera.id] = \ WeakProxy(lbl_camera) self.manager.get_screen('main').ids.master.\ add_widget(camera_layout) self.manager.get_screen('main').ids.camera_layout.\ add_widget(lbl_camera)
def generate_GUI(menus): app_gui = TabbedPanel() app_gui.clear_tabs() app_gui.orientation = "vertical" app_gui.do_default_tab = False app_gui.tab_width = 150 for menu_key, sub_menu in menus.items(): main_menu = TabbedPanelHeader(text=menu_key) scroll_pane = ScrollView() scroll_pane.scroll_type = ['bars', 'content'] scroll_pane.bar_pos_y = 'left' scroll_pane.bar_width = 6 scroll_pane.do_scroll_y = True scroll_pane.do_scroll_x = False scroll_pane.scroll_y = 1 menu_grid = GridLayout(cols=1, spacing=2, size_hint_y=None) menu_grid.orientation = "vertical" menu_grid.padding = 10 menu_grid.row_default_height = 1 menu_height = 0 print(">>>" + menu_key) for sub_menu_key, items in sub_menu.items(): menu_grid.add_widget( Label(text=" " + sub_menu_key, size_hint=(None, None), font_size=14, halign="left", valign="middle")) print("\t" + sub_menu_key) for option in items: if "Name" in option: print("\t\t" + option["Name"]) btn = Button(text=option["Name"], size_hint=(0.1, None), background_color=(0.2, 1, 1, 0.8)) btn.bind(on_press=lambda x: webbrowser.open(option["URL"])) else: print("\t\t" + "<EMPTY>") btn = Button(text="<EMPTY>", size_hint=(0.1, None), background_color=(0.2, 1, 1, 0.8)) btn.bind(on_press=lambda x: webbrowser.open(option["URL"])) btn.width = 250 btn.height = 50 menu_grid.add_widget(btn) menu_height += 80 menu_height += 51 menu_grid.height = menu_height scroll_pane.add_widget(menu_grid) main_menu.content = scroll_pane main_menu.orientation = "vertical" # Adding headers to main layout app_gui.add_widget(main_menu) return app_gui
def __init__(self): #A second argument '**kwargs' can be added here, but not needed. super(GUIlayout, self).__init__() #The same here. #Two layouts are going to be used. A 'small' one (a GridLayout named 'seclayout') that is going to contain the buttons, #and a 'big' one (a BoxLayout referred by 'self') that is going to contain the canvas and the small layout. self.orientation = 'vertical' self.spacing = (5,5) self.xdat=[] #List with the measured values. #The small layout and its parameters. seclayout = GridLayout() seclayout.rows = 2 seclayout.cols = 3 seclayout.size_hint_y = .2 #The percentage of the big layout in the y direction that this layout covers. #This is for the canvas to be bigger than the buttons. seclayout.row_force_default = True seclayout.row_default_height = 50 #Buttons self.measurebutton = Button(text="Measure!") self.measurebutton.bind(on_press=lambda x: self.measure(canvas,1,wavefun)) #Lambda x: in order to send arguments to the function and avoid seclayout.add_widget(self.measurebutton) #"TypeError: <lambda>() takes 0 positional arguments but 1 was given" self.measure10button = Button(text="Measure x10") self.measure10button.bind(on_press=lambda x: self.measure(canvas,10,wavefun)) seclayout.add_widget(self.measure10button) self.measure100button = Button(text="Measure x100") self.measure100button.bind(on_press=lambda x: self.measure(canvas,100,wavefun)) seclayout.add_widget(self.measure100button) self.PDFbutton = Button(text="Check!") self.PDFbutton.bind(on_press=lambda x:self.showPDF(canvas)) seclayout.add_widget(self.PDFbutton) self.clearbutton = Button(text="Clear") self.clearbutton.bind(on_press=lambda x: self.clearall(canvas)) seclayout.add_widget(self.clearbutton) self.add_widget(seclayout) #The small layout is attached to the big layout as a usual widget. canvas = FigureCanvasKivyAgg(f) self.add_widget(canvas) #self. because it is attached to the big layout. #Setting plot things that are shared by PDF and histogram. a.set_title('Measurements histogram') a.set_xlabel('x') a.set_ylabel('Frequency') a.axis([-L/2., L/2., 0., 1.])
def format_airtable_data(header): # Gridlayout to host menu options and URL buttons formated_data = GridLayout(cols=1, spacing=10, size_hint_y=None) formated_data.orientation = "vertical" formated_data.padding = 10 formated_data.row_default_height = 1 rows = 0 # needed to track the number of items inside the gridlayout # Converting airtable data into usable Kivy GUI labels and Buttons for item in tab_menus: if item["id"] == header: # Creating the Labels if str(item["menu"]) != "N/A": formated_data.add_widget(Label(text=item["menu"],size_hint=(.7,.5))) # Creating a menu option as a Label rows += 1 else: # For menu options that have yet to be given a name formated_data.add_widget(Label(text="Menu name pending",size_hint=(.7,.5))) rows += 1 # Creating the URL Buttons that belong bellow each Label for link in item["link"]: url_name = str(link).split('!')[0] url = str(link).split('!')[1] # Creaing the Button without refrences if url_name != "N/A": button = Button(text=url_name, size_hint=(None, None)) else: # For URL links with no assigned names button = Button(text="Unknown Link", size_hint=(None, None)) button.width = 250 button.height = 50 # Assign each Button a refrence to a created function with their respective URL links # This is equivalent to Kivy script: on_press: root.open_link('www.your_url_link.com') button.bind(on_press=lambda x:Resonance().open_link(url)) formated_data.add_widget(button) rows += 1 formated_data.add_widget(Label()) rows += 1 # Formating the gridlayout to fit the sum of items created # Necessary to indicate to Scrollview if scroll is needed # if grid size > window size allow scroll formated_data.height = rows * 50 return formated_data
def __init__(self, **kwargs): super(LoginScreen, self).__init__(**kwargs) layout = GridLayout() layout.cols = 2 layout.spacing = 50 layout.row_default_height = window_height layout.col_default_width = window_width / 10 layout.add_widget(Label(text='Observer')) layout.observer_field = TextInput(multiline=False) layout.add_widget(layout.observer_field) layout.add_widget(Label(text='Box open')) layout.box_open_field = TextInput(box_open_field=True, multiline=False) layout.add_widget(layout.box_open_field) self.layout = layout self.add_widget(layout)