def get_stock_data(row_text, dt): sym = row_text[9:-7] if not sym.isalpha(): print('%s not a symbol' % sym) return nse = Nse() print('getting nse price for stock ', sym) q = nse.get_quote(sym) popup = Popup() popup.title = 'Live data for ' + sym popup.size_hint = (.7, .6) popup.pos_hint = {'center_x': .5, 'center_y': .5} if q is not None: ltp = q['lastPrice'] low = q['dayLow'] high = q['dayHigh'] high52 = q['high52'] low52 = q['low52'] prevClose = q['previousClose'] pChange = q['pChange'] val = get_ltp_string(sym, ltp, prevClose, pChange) c1 = Label(text='Symbol') c2 = Label(text=sym) c3 = Label(text='PrevClose') c4 = Label(text=str(prevClose)) c5 = Label(text='Last Price') c6 = Label(text=val, markup=True) c7 = Label(text='Day Low') c8 = Label(text=str(low)) c9 = Label(text='Day High') c10 = Label(text=str(high)) c11 = Label(text='52 week Low') c12 = Label(text=str(low52)) c13 = Label(text='52 week High') c14 = Label(text=str(high52)) # add the data gridlayout = GridLayout(cols=2) gridlayout.add_widget(c1) gridlayout.add_widget(c2) gridlayout.add_widget(c3) gridlayout.add_widget(c4) gridlayout.add_widget(c5) gridlayout.add_widget(c6) gridlayout.add_widget(c7) gridlayout.add_widget(c8) gridlayout.add_widget(c9) gridlayout.add_widget(c10) gridlayout.add_widget(c11) gridlayout.add_widget(c12) gridlayout.add_widget(c13) gridlayout.add_widget(c14) content = gridlayout else: content = Label(text='No data available for symbol ' + sym) popup.content = content popup.open() MDApp.get_running_app().stock_fetch = False
def create_settings_button(): # a button to call out settings panel settings_button = Button(text = 'settings') # configure a popup window to display settings and parameters settings_popup = Popup( title='Settings', size_hint=(0.8, 0.2)) settings_popup.pos_hint = {'x':0.5-settings_popup.size_hint[0]/2, 'y':0.9-settings_popup.size_hint[1]/2} # distance from popup.center settings_popup_content = GridLayout(cols=1) # a blank layout to put other widgets in settings_popup.content = settings_popup_content # when popup occurs, rezie the preview screen to prevent blockage? def fullscreen_preview(instance): """when popup get dismissed, revert camera preview window to normal""" mc.camera_library('stop_preview') mc.camera_library('fullscreen_preview') def reduced_size_preview(instance): """when popup get opened, reduce camera preview window size to prevent blocking""" mc.camera_library('stop_preview') reduced_size_window = (int(Window.width*0.2), int(Window.height*0.25), int(Window.width*0.6), int(Window.width*0.6/1.33)) mc.camera_library('reduced_size_preview',reduced_size_window) settings_popup.bind(on_dismiss = fullscreen_preview) settings_popup.bind(on_open = reduced_size_preview) def switch_settings_popup_content(instance): """alter popup content when clicking buttons""" settings_popup_content.clear_widgets() settings_popup.open() if instance == settings_button: settings_popup_content.add_widget(settings_panel) elif instance == contrast_button: settings_popup_content.add_widget(contrast_controller) elif instance == brightness_button: settings_popup_content.add_widget(brightness_controller) elif instance == filepath_button: settings_popup_content.add_widget(filepath_controller) mc.camera_library('stop_preview') # the preview will block the keyboard filepath_input.text = format_filepath() # add buttons to call out popups # settings_panel with 3 buttons on it settings_panel, contrast_button, brightness_button, filepath_button = create_settings_panel() brightness_controller, contrast_controller = create_settings_controllers() filepath_controller = create_filepath_controller() for button in [settings_button, contrast_button, brightness_button, filepath_button]: button.bind(on_release= switch_settings_popup_content) return settings_button
def create_gallery(self): folder_chooser_button = Button(text = 'File viewer \nto choose folder', size_hint_x = 0.2) # a button to popup filechooser self.folder_chooser = FileChooser() self.folder_chooser.path = r'C:\Users\herbz\OneDrive - University Of Cambridge\Documents\GitHub\WaterScope-RPi\motor control' self.folder_chooser.add_widget(FileChooserIconLayout()) # a popup window to choose folder folder_chooser_popup = Popup(title = 'choose folder to save image', size_hint = (0.9, 0.9)) folder_chooser_popup.pos_hint = {'x':0.5-folder_chooser_popup.size_hint[0]/2, 'y':0.5-folder_chooser_popup.size_hint[1]/2} folder_chooser_popup.content = self.folder_chooser image_viewer_popup = Popup(title = 'image viewer', size_hint = (0.8, 0.8)) self.number = 1 def activate_folder_chooser(instance): folder_chooser_popup.open() def choose_image(instance, value): '''Callback function for FileChooser''' # change from "['C:\\abc.jpg']" to "C:\\abc.jpg" filepath = str(value).replace('[','').replace(']','').replace('\'','') print('file:' + filepath) # check the file type filepath_split = filepath.split('.') print('image: '+ filepath) if filepath_split[-1] in ['jpg', 'jpeg', 'png', 'tif', 'tiff']: im = PIL_Image.open(filepath) im.thumbnail((300,300)) os.remove(self.thumbnail_location) self.thumbnail_location = r"C:\Users\herbz\OneDrive - University Of Cambridge\Documents\GitHub\WaterScope-RPi\motor control\exp\resources\thumbnail{}.jpg".format(self.number) im.save(self.thumbnail_location, "JPEG") im.close() self.image_object = Image(source = self.thumbnail_location, size_hint_x = 0.8, size_hint_y = 0.8) self.number = self.number*-1 #self.image_object = Image(source = filepath) image_viewer_popup.content = self.image_object image_viewer_popup.open() os.remove(self.thumbnail_location) self.folder_chooser.bind(selection = choose_image) folder_chooser_button.bind(on_release = activate_folder_chooser) return folder_chooser_button
def create_filepath_controller(): global filepath_input # require to update in another function filepath_controller = BoxLayout(orientation = 'horizontal', size_hint_y = 0.1) folder_chooser_button = Button(text = 'File viewer \nto choose folder', size_hint_x = 0.2) # a button to popup filechooser filepath_input = TextInput(multiline = False, size_hint_x = 1 - folder_chooser_button.size_hint_x) filepath = format_filepath() # use the default value which contains date and start from 001 filepath_input.text = filepath for i in [filepath_input, folder_chooser_button]: filepath_controller.add_widget(i) folder_chooser = FileChooser() folder_chooser.add_widget(FileChooserIconLayout()) # a popup window to choose folder folder_chooser_popup = Popup(title = 'choose folder to save image', size_hint = (0.8, 0.8)) folder_chooser_popup.pos_hint = {'x':0.5-folder_chooser_popup.size_hint[0]/2, 'y':0.5-folder_chooser_popup.size_hint[1]/2} folder_chooser_popup.content = folder_chooser folder_chooser_button.bind(on_release = folder_chooser_popup.open) def choose_folder(instance, value): global folder, folder_sign folder = str(value) + folder_sign filepath = format_filepath() filepath_input.text = filepath folder_chooser.bind(path = choose_folder) def update_filepath_input(instance): global folder, filename, folder_sign, filetype # seperate filepath_input elements filepath = filepath_input.text filepath_split = filepath.split(folder_sign) filename = filepath_split[-1] # last element after the folder sign folder = folder_sign.join(filepath_split[0:-1]) + folder_sign # format filepath and update filepath_input filepath = format_filepath() filepath_input.text = filepath filepath_input.bind(on_text_validate = update_filepath_input) return filepath_controller
def create_settings_button(self): '''setting button will trigger popup with different settings''' # a button to call out settings panel settings_button = Button(text = 'settings', size_hint_y = 0.2) # configure a popup window to display settings and parameters settings_popup = Popup( title='Settings', size_hint=(0.8, 0.2)) settings_popup.pos_hint = {'x':0.5-settings_popup.size_hint[0]/2, 'y':0.9-settings_popup.size_hint[1]/2} # distance from popup.center settings_popup_content = GridLayout(cols=1) # a blank layout to put other widgets in settings_popup.content = settings_popup_content def preview_window_resize(argv, instance): ''' resize the window when popup oppens to prevent camera preview blocks the option Using partial() makes first argument argv rather than intance''' if debug_mode is True: if argv == 'fullscreen': print('full screen preview') if argv == 'resized': print('resized preview') if debug_mode is False: if argv == 'fullscreen': mc.camera_library('stop_preview') mc.camera_library('fullscreen_preview') if argv == 'resized': mc.camera_library('stop_preview') reduced_size_window = ( int(Window.width*0.2), int(Window.height*0.25), int(Window.width*0.6), int(Window.width*0.6/1.33)) mc.camera_library('reduced_size_preview', reduced_size_window) settings_popup.bind(on_dismiss = partial(preview_window_resize, 'fullscreen')) settings_popup.bind(on_open = partial(preview_window_resize, 'resized') ) def switch_settings_popup_content(instance): """ Callback for different options buttons alter popup content when clicking buttons""" settings_popup_content.clear_widgets() settings_popup.open() if instance == settings_button: settings_popup_content.add_widget(settings_panel) elif instance == contrast_button: settings_popup_content.add_widget(contrast_controller) elif instance == brightness_button: settings_popup_content.add_widget(brightness_controller) elif instance == white_balance_button: settings_popup_content.add_widget(white_balance_controller) elif instance == filepath_button: if debug_mode is False: mc.camera_library('stop_preview') # the preview will block the keyboard settings_popup_content.add_widget(filepath_controller) # Update the filepath_input and folder_chooser (after taking images, possibly) self.filepath_input.text = self.format_filepath(update = True) # go to different folder to refresh the folder_chooser self.folder_chooser.path = self.folder # add buttons to call out popups # settings_panel with 3 buttons on it settings_panel, contrast_button, brightness_button, white_balance_button, filepath_button = self.create_settings_panel() brightness_controller, contrast_controller, white_balance_controller = self.create_settings_controllers() filepath_controller = self.create_filepath_controller() for button in [settings_button, contrast_button, brightness_button, white_balance_button, filepath_button]: button.bind(on_release= switch_settings_popup_content) return settings_button