Best Python code snippet using localstack_python
ui.py
Source:ui.py
...46 debug_timer = datetime.now()47 self.set_scroller_func()48 self.ids.image_scroll_view.clear_widgets()49 gc.collect(generation=2)50 self.provider_manager.get_active_provider().clear_tags()51 if self.ids.tags.text != "":52 self.provider_manager.get_active_provider().add_tags_from_string(self.ids.tags.text)53 composition = self.provider_manager.get_active_provider().compose()54 urls = self.provider_manager.get_active_provider().search()55 # Adding GridLayout to ScrollView56 self.ids.image_scroll_view.add_widget(self.generate_image_pane(urls))57 def get_next_page(self, caller=None):58 debug_timer = datetime.now()59 results = self.provider_manager.get_active_provider().more()60 print("get_next_page done with more in " + str(datetime.now() - debug_timer))61 if not results:62 print("No results found!")63 self.generate_image_pane(results, self.ids.image_scroll_view.children[0])64 print("get_next_page done in " + str(datetime.now() - debug_timer))65 def generate_image_pane(self, entries: list, existing_pane=None) -> GridLayout:66 image_pane = GridLayout(cols=3, spacing=0, size_hint=(1, None), pos=(0, 0))67 image_pane.bind(minimum_height=image_pane.setter('height'))68 image_pane.col_default_width = 50069 image_pane.row_default_height = 50070 if existing_pane:71 image_pane = existing_pane72 for entry in entries:73 if entry is None or entry.image_small is None:74 continue75 img = None76 if entry.image_small[-3:] == "mp4":77 print(entry.image_small)78 img = Video(source=entry.image_small)79 pass80 else:81 if entry.image_path and entry.image_path != "":82 img = MetaDataImage(source=entry.image_path, keep_ratio=True, allow_stretch=True,83 extra_headers=self.provider_manager.get_active_provider().get_headers(),84 meta_data=entry)85 else:86 img = MetaDataImage(source=entry.image_small, keep_ratio=True, allow_stretch=True,87 extra_headers=self.provider_manager.get_active_provider().get_headers(),88 meta_data=entry)89 img.size_hint = (1, 1)90 meta_data = copy.deepcopy(img.meta_data)91 img.func = self.launch_big_viewer92 image_pane.add_widget(img)93 return image_pane94 def set_scroller_func(self, _=None):95 debug_timer = datetime.now()96 if self.ids.image_scroll_view.effect_cls != ImageOverscroll:97 self.ids.image_scroll_view.effect_cls = ImageOverscroll98 self.ids.image_scroll_view.effect_cls.func = self.get_next_page99 print("set_scroller_func done in " + str(datetime.now() - debug_timer))100 def launch_big_viewer(self, meta_data: Entry):101 print("Launching big view")102 print(meta_data.as_dict())103 left_button_size_hint = (1, None)104 outer_holder = None105 def toggle_tag_visibility(inner_caller=None):106 print("toggling")107 if labels.parent:108 labels.parent.remove_widget(labels)109 else:110 outer_holder.add_widget(labels)111 # Build the left menu112 saucenao_search_button = FuncImageButton(size_hint=left_button_size_hint,113 source="./assets/images/circle_search.png",114 keep_ratio=True, allow_stretch=True)115 saucenao_search_button.cg_tap = lambda a, b, c: utils.choose_saucenao_result(meta_data.image_full)116 open_in_browser_button = FuncImageButton(size_hint=left_button_size_hint,117 source="./assets/images/circle_open-in-browser.png",118 keep_ratio=True, allow_stretch=True) # handle browser button119 open_in_browser_button.cg_tap = lambda a, b, c: open_link_in_browser(meta_data.image_full)120 open_source_in_browser_button = FuncImageButton(size_hint=left_button_size_hint,121 source="./assets/images/circle_source-code.png",122 keep_ratio=True,123 allow_stretch=True) # handle source button124 open_source_in_browser_button.cg_tap = lambda a, b, c: open_link_in_browser(meta_data.source)125 save_to_disk_button = FuncImageButton(size_hint=left_button_size_hint,126 source="./assets/images/circle_download.png",127 keep_ratio=True, allow_stretch=True) # handle save-image button128 save_to_disk_button.cg_tap = lambda a, b, c: main.async_downloader.submit_url(meta_data.image_full)129 expand_tags_button = FuncImageButton(size_hint=left_button_size_hint,130 source="./assets/images/circle_expand_tags.png",131 keep_ratio=True, allow_stretch=True)132 expand_tags_button.cg_tap = lambda a, b, c: toggle_tag_visibility()133 go_to_src_button = focus_window.build_focus_window_button(meta_data.source)134 left_menu = BoxLayout(orientation='vertical', size_hint=(0.05, 1)) # handle layout135 left_menu.add_widget(saucenao_search_button)136 left_menu.add_widget(open_in_browser_button)137 left_menu.add_widget(open_source_in_browser_button)138 left_menu.add_widget(save_to_disk_button)139 left_menu.add_widget(expand_tags_button)140 if go_to_src_button:141 left_menu.add_widget(go_to_src_button)142 # Set up big image143 if 'twitter_video' in meta_data.tags: # Check if the image is a twitter video144 big_image = ClickableAsyncImage(source=meta_data.image_small)145 elif meta_data.image_path and meta_data.image_path != "": # Check if the image is located on disk146 big_image = ClickableAsyncImage(source=meta_data.image_path)147 else: # Otherwise, load normally148 big_image = ClickableAsyncImage(source=meta_data.image_full,149 extra_headers=self.provider_manager.get_active_provider().get_headers())150 big_image.meta_data = meta_data151 image_container = BoxLayout(size_hint=(1, 1))152 image_container.add_widget(big_image)153 # Build tag container154 labels = GridLayout(cols=3, size_hint=(0.33, 1))155 labels.bind(minimum_height=labels.setter('height'))156 for tag in meta_data.tags:157 button = Button(text=tag)158 button.bind(on_press=self.add_clicked_tag)159 labels.add_widget(button)160 # Set up outer holder161 outer_holder = BoxLayout(size_hint=(1, 1), spacing=10)162 outer_holder.add_widget(left_menu)163 outer_holder.add_widget(image_container)164 # outer_holder.add_widget(labels)165 # Setup popup and launch166 viewer = Popup()167 if meta_data.title and meta_data.title != "":168 viewer.title = meta_data.title + " @ " + str(meta_data.source)169 else:170 viewer.title = str(meta_data.source)171 viewer.content = outer_holder172 viewer.bind(on_dismiss=self.set_scroller_func)173 viewer.open()174 pass175 def add_clicked_tag(self, caller):176 tag = caller.text177 App.get_running_app().root.ids.tags.insert_text(" " + tag)178 self.provider_manager.get_active_provider().add_tag(tag)179 def launch_settings(self):180 viewer = Popup()181 viewer.title = "Settings"182 outer_layout = GridLayout(cols=1)183 provider_check_array = CheckBoxArray(labels=assets.strings.ALL_PROVIDERS,184 title="Provider",185 on_select=self.set_provider)186 provider_check_array.set_active(provider_util.translate(self.provider_manager.get_active_provider()))187 flows_check_array = CheckBoxArray(labels=main.flow_manager.all_flow_names(),188 title="Flows", exclusive=False,189 on_select=main.flow_manager.submit_activation_request)190 for flow in main.flow_manager.get_enabled():191 flows_check_array.set_active(flow)192 outer_layout.add_widget(flows_check_array)193 outer_layout.add_widget(provider_check_array)194 viewer.content = outer_layout195 viewer.open()196 def update_save_dir(self, caller):197 self.save_path = caller.text198 def set_provider(self, provs: list[str]):199 self.provider_manager.set_provider(provs[0])200 def open_flows_menu(self, caller=None):201 Logger.warning("Opening flows menu")202 def sorting_mode_setup(self):203 for sort_mode in self.provider_manager.get_active_provider().sorting_modes:204 btn = Button(text=sort_mode, size_hint_y=None, height=44)205 # for each button, attach a callback that will call the select() method206 # on the dropdown. We'll pass the text of the button as the data of the207 # selection.208 btn.bind(on_release=lambda btn: self.ids.sort_by_dropdown.select(btn.text))209 # then add the button inside the dropdown210 self.ids.sort_by_dropdown.add_widget(btn)211 self.ids.sort_by_dropdown.func = self.provider_manager.get_active_provider().sort_by212# Take care of setup before launching the window213class BooruViuApp(App):214 print("Starting app")215 Loader.loading_image = "./assets/images/loading.gif"216 Loader.num_workers = 3...
home_screen.py
Source:home_screen.py
...31 self.ids.image_scroll_view.clear_widgets()32 gc.collect(generation=2)33 self.set_scroller_func()34 providers['home screen'].read_user_rules()35 composition = providers['home screen'].get_active_provider().compose()36 urls = providers['home screen'].get_active_provider().search()37 pane = self.generate_image_pane(urls)38 # Adding GridLayout to ScrollView39 self.ids.image_scroll_view.add_widget(pane)40 if len(pane.children) > 0:41 self.ids.image_scroll_view.scroll_to(pane.children[-1])42 def get_next_page(self, caller=None):43 debug_timer = datetime.now()44 results = providers['home screen'].get_active_provider().more()45 print("get_next_page done with more in " + str(datetime.now() - debug_timer))46 if not results:47 print("No results found!")48 self.generate_image_pane(results, self.ids.image_scroll_view.children[0])49 print("get_next_page done in " + str(datetime.now() - debug_timer))50 def generate_image_pane(self, entries: list, existing_pane=None) -> GridLayout:51 image_pane = GridLayout(cols=3, spacing=0, size_hint=(1, None), pos=(0, 0))52 image_pane.bind(minimum_height=image_pane.setter('height'))53 image_pane.col_default_width = 50054 image_pane.row_default_height = 50055 if existing_pane:56 image_pane = existing_pane57 for entry in entries:58 if entry is None or entry.image_small is None:59 continue60 img = None61 if entry.image_small[-3:] == "mp4":62 print(entry.image_small)63 img = Video(source=entry.image_small)64 pass65 else:66 if entry.image_path and entry.image_path != "":67 img = MetaDataImage(source=entry.image_path, keep_ratio=True, allow_stretch=True,68 extra_headers=providers[69 'home screen'].get_active_provider().get_headers(),70 meta_data=entry)71 else:72 img = MetaDataImage(source=entry.image_small, keep_ratio=True, allow_stretch=True,73 extra_headers=providers[74 'home screen'].get_active_provider().get_headers(),75 meta_data=entry)76 img.size_hint = (1, 1)77 meta_data = copy.deepcopy(img.meta_data)78 img.func = lambda a=None: set_big_screen_metadata(self, a,79 lambda: set_screen('big view screen'))80 image_pane.add_widget(img)81 return image_pane82 def add_tag(self, tag: Union[str, OneLineListItem]):83 text = None84 if type(tag) == str:85 for part in tag.split(" "):86 text = part87 chip = MDChip(text=part)88 chip.icon_right = "close-circle-outline"89 chip.pos_hint = {'center_y': 0.5}90 chip.bind(on_press=self.remove_tag_chip)91 self.ids.tag_container.add_widget(chip)92 providers['home screen'].get_active_provider().add_tag(part)93 elif type(tag) == OneLineListItem:94 text = tag.text95 chip = MDChip(text=text)96 chip.icon_right = "close-circle-outline"97 chip.pos_hint = {'center_y': 0.5}98 chip.bind(on_press=self.remove_tag_chip)99 self.ids.tag_container.add_widget(chip)100 providers['home screen'].get_active_provider().add_tag(text)101 def remove_tag_chip(self, chip: Union[str, MDChip]):102 if type(chip) == MDChip:103 self.ids.tag_container.remove_widget(chip)104 providers['home screen'].get_active_provider().remove_tag(chip.text)105 elif type(chip) == str:106 for child in self.ids.tag_container.children:107 if child.text == chip:108 self.ids.tag_container.remove_widget(child)109 providers['home screen'].get_active_provider().remove_tag(chip)110 def clear_chips(self):111 while len(self.ids.tag_container.children) > 0:112 self.remove_tag_chip(self.ids.tag_container.children[0])113 def set_scroller_func(self, _=None):114 if self.ids.image_scroll_view.effect_cls != ImageOverscroll:115 self.ids.image_scroll_view.effect_cls = ImageOverscroll116 self.ids.image_scroll_view.effect_cls.func = self.get_next_page117 def set_text_field(self, text: str = ""):118 self.ids.tags.text = text119 def set_title(self, title):120 if type(title) == str:121 self.ids.tool_bar.title = title122 elif isinstance(title, ImageProvider):123 self.ids.tool_bar.title = provider_util.translate(title)...
repository.py
Source:repository.py
...10 ExchangeCurrencyError11)12class CurrencyExchangeRepository:13 @abc.abstractmethod14 def get_active_provider(self):15 pass16 @abc.abstractmethod17 def get_all_currencies(self):18 pass19 @abc.abstractmethod20 def get(self, source_currency, exchanged_currency, valuation_date):21 pass22 @abc.abstractmethod23 def save(24 self,25 source_currency: str,26 exchange_currency: str,27 rate_value: Decimal,28 valuation_date: date29 ):30 pass31class CurrencyExchangeRateSerializer(serializers.ModelSerializer):32 class Meta:33 model = CurrencyExchangeRate34 fields = '__all__'35class CurrencyExchangeRepositoryDB(CurrencyExchangeRepository):36 def get_all_currencies(self):37 return Currency.objects.all().values_list('code', flat=True)38 def get_active_provider(self):39 try:40 provider = Provider.objects.get(default=True)41 except (Provider.DoesNotExist, Provider.MultipleObjectsReturned):42 raise ExchangeProviderError("No Provider created.")43 return provider.provider44 def get(45 self,46 source_currency: str,47 exchanged_currency: str,48 valuation_date: date49 ) -> Decimal:50 try:51 exchange = CurrencyExchangeRate.objects.get(52 source_currency__code=source_currency,...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!