class MainLayout(AnchorLayout): def __init__(self): super().__init__(anchor_x='center', anchor_y='bottom') self.layout = AnchorLayout(anchor_x='center', anchor_y='center', size_hint=(1.0, 0.9)) self.add_widget(self.layout) self.menu_panel = MenuPanel(self) self.add_widget(self.menu_panel) self.new_page(StartPage(self)) def new_page(self, new_page): self.layout.clear_widgets() self.layout.add_widget(new_page)
class StimGen(App): modes = ['Spiral', 'Text'] currmode = 0 def LoadGlobset(self): self.g_lay = BoxLayout(orientation='vertical', padding=5, spacing=5) self.b_lay = BoxLayout(spacing=10) self.globset_lay = BoxLayout(orientation='vertical') s1 = Parameter( label='Name of file:', startval='G:/Main/AnacondaWF/NeuroLab/EyeTracker/generated_video') s2 = Parameter(label='Duration:', startval=10) s3 = Parameter(label='Framerate:', startval=60) s4 = Parameter(label='Width:', startval=1366) s5 = Parameter(label='Heigth:', startval=768) self.bmode = Changer(label='Mode:', startval='Spiral') self.bmode.ids['b_val'].on_press = self.ChangeMode self.globset_lay.add_widget(s1) self.globset_lay.add_widget(s2) self.globset_lay.add_widget(s3) self.globset_lay.add_widget(s4) self.globset_lay.add_widget(s5) self.globset_lay.add_widget(self.bmode) def LoadControlPanel(self): self.control_lay = BoxLayout(orientation='vertical') b1 = Button(text='Generate video', on_press=self.GenVideo) b2 = Button(text='Play video', on_press=self.PlayVideo) b3 = Button(text='Quit') self.control_lay.add_widget(b1) self.control_lay.add_widget(b2) self.control_lay.add_widget(b3) def LoadVideosetSpiral(self): self.videoset_lay.clear_widgets() self.video_lay.clear_widgets() s2 = Parameter(label='Start radius:', startval=100) s3 = Parameter(label='dR:', startval=0) s4 = Parameter(label='dphi:', startval=5) self.videoset_lay.add_widget(s2) self.videoset_lay.add_widget(s3) self.videoset_lay.add_widget(s4) def LoadVideoText(self): self.videoset_lay.clear_widgets() self.video_lay.clear_widgets() p = TextEditor() self.video_lay.add_widget(p) #TextEditor = TextInput() #self.video_lay.add_widget(TextEditor) #self.video_lay.add_widget(Label(text = TextEditor.text)) def build(self): self.videoset_lay = BoxLayout(orientation='vertical') self.video_lay = AnchorLayout() self.LoadGlobset() self.LoadControlPanel() self.LoadVideosetSpiral() self.b_lay.add_widget(self.globset_lay) self.b_lay.add_widget(self.videoset_lay) self.b_lay.add_widget(self.control_lay) self.g_lay.add_widget(self.video_lay) self.g_lay.add_widget(self.b_lay) return self.g_lay def GenVideo(self, instance): name = VideoGen_params['Name of file:'] time = int(VideoGen_params['Duration:']) fps = int(VideoGen_params['Framerate:']) width = int(VideoGen_params['Width:']) heigth = int(VideoGen_params['Heigth:']) sR = int(VideoGen_params['Start radius:']) dR = int(VideoGen_params['dR:']) dPh = int(VideoGen_params['dphi:']) for k in VideoGen_params: print(k, VideoGen_params[k]) GenerateVideo(name, time, width, heigth, fps, sR, dR, dPh) def PlayVideo(self, instance): self.video_lay.clear_widgets() self.video_lay.add_widget(video) video.state = 'stop' video.source = VideoGen_params['Name of file:'] + '.mp4' video.state = 'play' def ChangeMode(self): self.currmode = self.currmode = self.currmode + 1 if self.currmode < len( self.modes) - 1 else 0 self.bmode.ids['b_val'].text = self.modes[self.currmode] if self.currmode == 0: self.LoadVideosetSpiral() else: self.LoadVideoText()
class mainApp(App): def build(self): Window.clearcolor = (228. / 255., 228. / 255., 228. / 255., 1) self.title = "GrunwaldCalc" Window.minimum_width = 300 Window.minimum_height = 200 self.config = ConfigParser() self.config.read("config.ini") self.config.adddefaultsection("Settings") self.config.setdefault("Settings", "Language", locale.getdefaultlocale()[0]) self.language = self.config.getdefault("Settings", "Language", locale.getdefaultlocale()[0]) self.settings = Settings() self.day_calc = DayCalc.Calculate() self.date_finder = DateFinder.WikiScrape() self.day_calc.changeLanguage(self.language) self.date_finder.changeLanguage(self.language) self.container = BoxLayout(orientation="vertical") self.search_layout = BoxLayout(orientation="horizontal", size_hint=(1, 0.25), height=100) self.results_layout = AnchorLayout(anchor_y="top") self.container.add_widget(self.search_layout) self.container.add_widget(self.results_layout) try: with open("./languages/" + self.language + ".lang", encoding="UTF-8") as language_file: self.language_file = json.load(language_file) except FileNotFoundError: self.language = "en_US" with open("./languages/" + self.language + ".lang", encoding="UTF-8") as language_file: self.language_file = json.load(language_file) self.search_box = TextInput(hint_text=(self.language_file["hint"]), size_hint=(0.7, None), height=50, multiline=False) self.search_button = Button(text=self.language_file["button-text"], size_hint=(0.3, None), height=50) self.search_layout.add_widget(self.search_box) self.search_layout.add_widget(self.search_button) self.search_box.bind(on_text_validate=self.start_main) self.search_button.bind(on_press=self.start_main) return self.container def start_main(self, instance): text_value = ''.join(char for char in self.search_box.text if char.isnumeric()) if 4 < len(text_value) < 9: self.results_layout.clear_widgets() self.date = self.day_calc.findWeekday(text_value) self.result_label = Label( text=self.language_file["single-date"].format(self.date), markup=True) self.results_layout.add_widget(self.result_label) else: self.results_layout.clear_widgets() try: self.event_dates = (self.date_finder.findEventDate( self.search_box.text)) self.event_weekdays = [] for date in self.event_dates: self.event_weekdays.append( self.day_calc.findWeekday(self.event_dates[date])) if len(self.event_dates) == 2: self.result_label = Label( text=self.language_file["from-to-date"].format( self.event_dates['from'], self.event_weekdays[0], self.event_dates['to'], self.event_weekdays[1]), markup=True, size_hint=(1, None)) self.result_label.text_size = (self.results_layout.width - 40, self.results_layout.height) self.results_layout.add_widget(self.result_label) else: self.result_label = Label( text=self.language_file["from-to-date"].format( self.event_dates['date'], self.event_weekdays[0]), markup=True, size_hint=(1, None)) self.result_label.text_size = (self.results_layout.width - 40, self.results_layout.height) self.results_layout.add_widget(self.result_label) except LookupError: self.result_label = Label( text=self.language_file["lookup-error"], markup=True) self.results_layout.add_widget(self.result_label)
class ImageApp(App): def __init__(self): super().__init__() self.outer_layout = BoxLayout(padding=10, orientation='vertical') self.first_in_layout = BoxLayout(padding=10, orientation='horizontal', size_hint=(1, 0.5)) self.second_in_layout = BoxLayout(padding=10, orientation='horizontal', size_hint=(1, 0.5)) self.third_in_layout = BoxLayout(padding=10, orientation='horizontal', size_hint=(1, 2)) self.svd_rank_layout = AnchorLayout(anchor_x="right", anchor_y="top") self.svd_number_layout = AnchorLayout(anchor_x="left", anchor_y="top") self.hw_ratio_layout = AnchorLayout(anchor_x="right", anchor_y="top") self.hw_number_layout = AnchorLayout(anchor_x="left", anchor_y="top") self.hw_normalization_layout = AnchorLayout(anchor_x="center", anchor_y="top") self.rgb_layout_1 = AnchorLayout(anchor_x="center", anchor_y="top") self.rgb_layout_2 = AnchorLayout(anchor_x="center", anchor_y="top") self.conv_choice_layout = BoxLayout(padding=0, orientation='vertical') self.conv_dd_layout = AnchorLayout(anchor_x="center", anchor_y="top") self.image_layout = AnchorLayout(anchor_x="center", anchor_y="center") self.reset_layout = AnchorLayout(anchor_x="right", anchor_y="center", size_hint=(0.1, 1)) self.normalization_dropdown = DropDown() self.rgb_dropdown_1 = DropDown() self.rgb_dropdown_2 = DropDown() self.blur_dropdown = DropDown() self.e_det_dropdown = DropDown() self.svd_button = Button(text="SVD", on_press=self.on_svd) self.haar_wavelet_button = Button(text="Haar Wavelet", on_press=self.on_hw) self.convolution_button = Button(text="Image Convolution", on_press=self.on_conv) self.reset_button = Button(text="Reset", on_press=self.reset, size_hint_y=None, height=40) self.normalization_button = Button(text="Normalization", size_hint=(0.6, 0.6)) self.rgb_button_1 = Button(text="RGB", size_hint=(0.6, 0.6)) self.rgb_button_2 = Button(text="RGB", size_hint=(0.6, 0.6)) self.blur_button = Button(text="Blur", on_press=self.on_blur) self.sharpen_button = Button(text="Sharpen", on_press=self.on_sharpen) self.e_det_button = Button(text="Edge Detection", on_press=self.on_e_det) self.type_button_1 = Button(text="Type", size_hint=(0.6, 0.6)) self.type_button_2 = Button(text="Type", size_hint=(0.6, 0.6)) self.yes_button_1 = Button(text="Yes", size_hint_y=None, height=25, on_press=self.normalization_true) self.yes_button_1.bind(on_release=lambda btn: self. normalization_dropdown.select(btn.text)) self.normalization_dropdown.add_widget(self.yes_button_1) self.no_button_1 = Button(text="No", size_hint_y=None, height=25, on_press=self.normalization_false) self.no_button_1.bind(on_release=lambda btn: self. normalization_dropdown.select(btn.text)) self.normalization_dropdown.add_widget(self.no_button_1) self.yes_button_2 = Button(text="Yes", size_hint_y=None, height=25, on_press=self.svd_rgb_true) self.yes_button_2.bind( on_release=lambda btn: self.rgb_dropdown_1.select(btn.text)) self.rgb_dropdown_1.add_widget(self.yes_button_2) self.no_button_2 = Button(text="No", size_hint_y=None, height=25, on_press=self.svd_rgb_false) self.no_button_2.bind( on_release=lambda btn: self.rgb_dropdown_1.select(btn.text)) self.rgb_dropdown_1.add_widget(self.no_button_2) self.yes_button_3 = Button(text="Yes", size_hint_y=None, height=25, on_press=self.hw_rgb_true) self.yes_button_3.bind( on_release=lambda btn: self.rgb_dropdown_2.select(btn.text)) self.rgb_dropdown_2.add_widget(self.yes_button_3) self.no_button_3 = Button(text="No", size_hint_y=None, height=25, on_press=self.hw_rgb_false) self.no_button_3.bind( on_release=lambda btn: self.rgb_dropdown_2.select(btn.text)) self.rgb_dropdown_2.add_widget(self.no_button_3) self.regular_button = Button(text="Regular Blur", size_hint_y=None, height=25, on_press=self.blur_true) self.regular_button.bind( on_release=lambda btn: self.blur_dropdown.select(btn.text)) self.blur_dropdown.add_widget(self.regular_button) self.gaussian_button = Button(text="Gaussian Blur", size_hint_y=None, height=25, on_press=self.blur_false) self.gaussian_button.bind( on_release=lambda btn: self.blur_dropdown.select(btn.text)) self.blur_dropdown.add_widget(self.gaussian_button) self.normalization_button.bind( on_release=self.normalization_dropdown.open) self.normalization_dropdown.bind(on_select=lambda ins, x: setattr( self.normalization_button, 'text', x)) self.rgb_button_1.bind(on_release=self.rgb_dropdown_1.open) self.rgb_dropdown_1.bind( on_select=lambda ins, x: setattr(self.rgb_button_1, 'text', x)) self.rgb_button_2.bind(on_release=self.rgb_dropdown_2.open) self.rgb_dropdown_2.bind( on_select=lambda ins, x: setattr(self.rgb_button_2, 'text', x)) self.vertical_e_button = Button(text="Vertical Edges", size_hint_y=None, height=25, on_press=self.e_det_true) self.vertical_e_button.bind( on_release=lambda btn: self.e_det_dropdown.select(btn.text)) self.e_det_dropdown.add_widget(self.vertical_e_button) self.horizontal_e_button = Button(text="Horizontal Edges", size_hint_y=None, height=25, on_press=self.e_det_false) self.horizontal_e_button.bind( on_release=lambda btn: self.e_det_dropdown.select(btn.text)) self.e_det_dropdown.add_widget(self.horizontal_e_button) self.type_button_1.bind(on_release=self.blur_dropdown.open) self.blur_dropdown.bind( on_select=lambda ins, x: setattr(self.type_button_1, 'text', x)) self.type_button_2.bind(on_release=self.e_det_dropdown.open) self.e_det_dropdown.bind( on_select=lambda ins, x: setattr(self.type_button_2, 'text', x)) self.rank_label = Label(text="Enter rank:", size_hint=(0.5, 0.5)) self.ratio_label = Label(text="Enter ratio:", size_hint=(0.5, 0.5)) self.rank_input = TextInput(multiline=False, size_hint=(0.4, 0.4)) self.rank_input.bind(text=self.rank_input_f) self.ratio_input = TextInput(multiline=False, size_hint=(0.4, 0.4)) self.ratio_input.bind(text=self.ratio_input_f) self.file_chooser = FileChooserIconView(on_submit=self.submit_file) self.mode = None self.svd_rank = None self.svd_rgb = None self.hw_rgb = None self.hw_normalization = None self.hw_ratio = None self.conv_mode = None self.blur_mode = None self.e_det_mode = None self.num = 0 def on_svd(self, ins): self.second_in_layout.clear_widgets() self.second_in_layout.add_widget(self.svd_rank_layout) self.second_in_layout.add_widget(self.svd_number_layout) self.second_in_layout.add_widget(self.rgb_layout_1) self.mode = 0 def on_hw(self, ins): self.second_in_layout.clear_widgets() self.second_in_layout.add_widget(self.hw_ratio_layout) self.second_in_layout.add_widget(self.hw_number_layout) self.second_in_layout.add_widget(self.hw_normalization_layout) self.second_in_layout.add_widget(self.rgb_layout_2) self.mode = 1 def on_conv(self, ins): self.second_in_layout.clear_widgets() self.second_in_layout.add_widget(self.conv_choice_layout) self.second_in_layout.add_widget(self.conv_dd_layout) self.mode = 2 def on_blur(self, ins): self.conv_dd_layout.clear_widgets() self.conv_dd_layout.add_widget(self.type_button_1) self.conv_mode = 0 def on_sharpen(self, ins): self.conv_dd_layout.clear_widgets() self.conv_mode = 1 def on_e_det(self, ins): self.conv_dd_layout.clear_widgets() self.conv_dd_layout.add_widget(self.type_button_2) self.conv_mode = 2 def reset(self, ins): self.third_in_layout.clear_widgets() self.third_in_layout.add_widget(self.file_chooser) def normalization_true(self, ins): self.hw_normalization = True def normalization_false(self, ins): self.hw_normalization = False def hw_rgb_true(self, ins): self.hw_rgb = True def hw_rgb_false(self, ins): self.hw_rgb = False def svd_rgb_true(self, ins): self.svd_rgb = True def svd_rgb_false(self, ins): self.svd_rgb = False def blur_true(self, ins): self.blur_mode = True def blur_false(self, ins): self.blur_mode = False def e_det_true(self, ins): self.e_det_mode = True def e_det_false(self, ins): self.e_det_mode = False def rank_input_f(self, ins, text): try: self.svd_rank = int(text) except ValueError: self.svd_rank = None def ratio_input_f(self, ins, text): try: self.hw_ratio = float(text) except ValueError: self.hw_ratio = None def submit_file(self, ins, filepath, touch): try: filepath = filepath[0] except IndexError(): return None if filepath.endswith(".png") or filepath.endswith(".jpg"): if self.mode == 0: if None in (self.svd_rank, self.svd_rgb): return None elif self.mode == 1: if None in (self.hw_ratio, self.hw_rgb, self.hw_normalization): return None elif self.mode == 2: if self.conv_mode is None: return None elif self.conv_mode == 0: if self.blur_mode is None: return None elif self.conv_mode == 2: if self.e_det_mode is None: return None else: return None if self.mode == 0: try: self.num += 1 rank_approx.approx(filepath, f"output{self.num}.png", self.svd_rank, rgb=self.svd_rgb) image = Image(source=f"output{self.num}.png") self.image_layout.clear_widgets() self.third_in_layout.clear_widgets() self.image_layout.add_widget(image) self.third_in_layout.add_widget(self.image_layout) self.third_in_layout.add_widget(self.reset_layout) except Exception(): self.third_in_layout.clear_widgets() self.third_in_layout.add_widget(self.file_chooser) elif self.mode == 1: try: self.num += 1 haar_wavelet.compress(filepath, f"output{self.num}.png", ratio=self.hw_ratio, rgb=self.hw_rgb, normalization=self.hw_normalization) image = Image(source=f"output{self.num}.png") self.image_layout.clear_widgets() self.third_in_layout.clear_widgets() self.image_layout.add_widget(image) self.third_in_layout.add_widget(self.image_layout) self.third_in_layout.add_widget(self.reset_layout) except Exception(): self.third_in_layout.clear_widgets() self.third_in_layout.add_widget(self.file_chooser) elif self.mode == 2: try: self.num += 1 if self.conv_mode == 0: image_convolution.blur(filepath, self.blur_mode, f"output{self.num}.png") elif self.conv_mode == 1: image_convolution.sharpen(filepath, f"output{self.num}.png") elif self.conv_mode == 2: image_convolution.edge_detection( filepath, self.e_det_mode, f"output{self.num}.png") image = Image(source=f"output{self.num}.png") self.image_layout.clear_widgets() self.third_in_layout.clear_widgets() self.image_layout.add_widget(image) self.third_in_layout.add_widget(self.image_layout) self.third_in_layout.add_widget(self.reset_layout) except Exception(): self.third_in_layout.clear_widgets() self.third_in_layout.add_widget(self.file_chooser) def build(self): self.first_in_layout.add_widget(self.svd_button) self.first_in_layout.add_widget(self.haar_wavelet_button) self.first_in_layout.add_widget(self.convolution_button) self.third_in_layout.add_widget(self.file_chooser) self.outer_layout.add_widget(self.first_in_layout) self.outer_layout.add_widget(self.second_in_layout) self.outer_layout.add_widget(self.third_in_layout) self.svd_rank_layout.add_widget(self.rank_label) self.svd_number_layout.add_widget(self.rank_input) self.hw_ratio_layout.add_widget(self.ratio_label) self.hw_number_layout.add_widget(self.ratio_input) self.hw_normalization_layout.add_widget(self.normalization_button) self.rgb_layout_1.add_widget(self.rgb_button_1) self.rgb_layout_2.add_widget(self.rgb_button_2) self.conv_choice_layout.add_widget(self.blur_button) self.conv_choice_layout.add_widget(self.sharpen_button) self.conv_choice_layout.add_widget(self.e_det_button) self.reset_layout.add_widget(self.reset_button) return self.outer_layout
class ParameterMenu(): def __init__(self, pars_dict, toolbox, widget): self.pars_dict = pars_dict self.toolbox = toolbox self.input_pars = GridLayout(cols=2, size=(300, 50)) self.option_pars = GridLayout(cols=2, size=(300, 50)) self.list_input_pars = [] self.widget = widget self.pic = AnchorLayout(anchor_x='right', anchor_y='top') def create_pars_layout(self): #self.input_pars.add_widget(Label(text = 'Parameter1')) #self.input_pars.add_widget(TextInput()) self.input_pars = GridLayout(cols=2, size=(300, 50 * len(self.pars_dict))) for par in self.pars_dict: self.input_pars = GridLayout(cols=2, size=(300, 50)) self.input_pars.add_widget(Label(text=par['name'])) ti = InputForm(text=str(par['value']), toolbox=self.toolbox) self.input_pars.add_widget(ti) self.list_input_pars.append(self.input_pars) #self.toolbox.add_widget(self.input_pars) for par in self.list_input_pars: self.toolbox.add_widget(par) def save_pars(instance): par_name = '' par_value = '' for par in self.list_input_pars: for child in par.children: #if type(child) is TextInput: if type(child) is InputForm: par_value = child.text elif type(child) is Label: par_name = child.text for parr in self.pars_dict: '''if parr['name'] == par_name and par_value != '': parr['value'] = par_value elif parr['name'] == par_name and par_value == '': parr['value'] = ''' '' if parr['name'] == par_name: parr['value'] = par_value self.toolbox.remove_widget(par) self.list_input_pars.clear() self.input_pars.clear_widgets() self.option_pars.clear_widgets() self.pic.clear_widgets() self.toolbox.remove_widget(self.option_pars) self.toolbox.parent.remove_widget(self.pic) self.toolbox.height = 200 if self.widget.selected_par: self.widget.canvas.remove(self.widget.selected_par) self.widget.selected_par = None def cancel_pars(instance): #print('cancel parameter') self.input_pars.clear_widgets() self.option_pars.clear_widgets() #self.toolbox.remove_widget(self.input_pars) for par in self.list_input_pars: self.toolbox.remove_widget(par) self.list_input_pars.clear() self.pic.clear_widgets() self.toolbox.remove_widget(self.option_pars) self.toolbox.parent.remove_widget(self.pic) self.toolbox.height = 200 if self.widget.selected_par: self.widget.canvas.remove(self.widget.selected_par) self.widget.selected_par = None btn_save = Button(text='Save') btn_save.bind(on_press=save_pars) btn_cancel = Button(text='Cancel') btn_cancel.bind(on_press=cancel_pars) self.option_pars.add_widget(btn_save) self.option_pars.add_widget(btn_cancel) if os.path.exists('/tmp/images/' + self.widget.id + '.jpg'): img = Image(source='/tmp/images/' + self.widget.id + '.jpg', size_hint=(0, 0), size=(200, Window.size[1]), pos_hint=(0, 1)) img.reload() self.pic.add_widget(img) self.toolbox.parent.add_widget(self.pic) self.toolbox.height = 250 + len(self.pars_dict) * 50 #self.toolbox.add_widget(self.input_pars) self.toolbox.add_widget(self.option_pars)