How to use list_available method in localstack

Best Python code snippet using localstack_python

listselect.py

Source:listselect.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3listselect.py is part of Coquery.4Copyright (c) 2016-2022 Gero Kunter (gero.kunter@coquery.org)5Coquery is released under the terms of the GNU General Public License (v3).6For details, see the file LICENSE that you should have received along7with Coquery. If not, see <http://www.gnu.org/licenses/>.8"""9from PyQt5 import QtCore, QtWidgets10from PyQt5.QtCore import pyqtSignal11from typing import Tuple12from coquery.unicode import utf813from coquery.gui.pyqt_compat import get_toplevel_window14class CoqListSelect(QtWidgets.QWidget):15 """16 A QWidget that presents two exclusive list (a list of available and a17 list of selected items), with controls to move between the two.18 """19 itemSelectionChanged = pyqtSignal(list)20 currentItemChanged = pyqtSignal(object)21 def __init__(self, *args, **kwargs):22 from .ui import coqListSelectUi23 super(CoqListSelect, self).__init__(*args, **kwargs)24 self.ui = coqListSelectUi.Ui_CoqListSelect()25 self.ui.setupUi(self)26 self.setDefocus(True)27 self.ui.button_add.clicked.connect(self.add_selected)28 self.ui.button_remove.clicked.connect(self.remove_selected)29 self.ui.button_up.clicked.connect(self.selected_up)30 self.ui.button_down.clicked.connect(self.selected_down)31 try:32 icon_getter = get_toplevel_window().get_icon33 for button, icon in (34 (self.ui.button_up, "Circled Chevron Up"),35 (self.ui.button_down, "Circled Chevron Down"),36 (self.ui.button_add, "Circled Chevron Right"),37 (self.ui.button_remove, "Circled Chevron Left")):38 button.setIcon(icon_getter(icon))39 except AttributeError:40 pass41 self.ui.list_selected.itemSelectionChanged.connect(self.check_buttons)42 self.ui.list_selected.itemSelectionChanged.connect(43 lambda: self.currentItemChanged.emit(self.currentItem()))44 self.ui.list_available.itemSelectionChanged.connect(45 self.check_buttons)46 self._minimum = 047 self._move_available = True48 self._track_selected = False49 self._last_selected_row = None50 self._last_available_row = None51 self.setFocusPolicy(QtCore.Qt.StrongFocus)52 @staticmethod53 def _fill_list_widget(w, lst, translate, *args, **kwargs):54 for x in lst:55 if translate is not None:56 if not isinstance(x, QtWidgets.QListWidgetItem):57 item = QtWidgets.QListWidgetItem(58 translate(x, *args, **kwargs))59 item.setData(QtCore.Qt.UserRole, x)60 else:61 item = translate(x, *args, **kwargs)62 else:63 if not isinstance(x, QtWidgets.QListWidgetItem):64 item = QtWidgets.QListWidgetItem(x)65 else:66 item = x67 w.addItem(item)68 def setDefocus(self, b):69 self._defocus = b70 def defocus(self):71 return self._defocus72 def setMoveAvailable(self, b):73 if b:74 self.ui.button_up.show()75 self.ui.button_down.show()76 else:77 self.ui.button_up.hide()78 self.ui.button_down.hide()79 self._move_available = b80 def moveAvailable(self):81 return self._move_available82 def trackSelected(self):83 return self._track_selected84 def setTrackSelected(self, b):85 self._track_selected = b86 def setSelectedLabel(self, s):87 self.ui.label_select_list.setText(s)88 def selectedLabel(self):89 return self.ui.label_select_list.text()90 def setAvailableLabel(self, s):91 self.ui.label_available.setText(s)92 def availableLabel(self):93 return self.ui.label_available.text()94 def minimumItems(self):95 return self._minimum96 def setMinimumItems(self, i):97 self._minimum = i98 def count(self):99 return self.ui.list_selected.count()100 def selectedItems(self):101 return [self.ui.list_selected.item(i) for i102 in range(self.ui.list_selected.count())]103 def availableItems(self):104 return [self.ui.list_available.item(i) for i105 in range(self.ui.list_available.count())]106 def setAvailableList(self, lst, translate=None, *args, **kwargs):107 self._fill_list_widget(self.ui.list_available, lst,108 translate, *args, **kwargs)109 def setSelectedList(self, lst, translate=None, *args, **kwargs):110 self._fill_list_widget(self.ui.list_selected, lst,111 translate, *args, **kwargs)112 def add_selected(self):113 for x in self.ui.list_available.selectedItems():114 row = self.ui.list_available.row(x)115 item = self.ui.list_available.takeItem(row)116 self.ui.list_selected.addItem(item)117 self.ui.list_selected.setCurrentItem(item)118 self.itemSelectionChanged.emit(self.selectedItems())119 if self.trackSelected():120 self.ui.list_selected.setFocus()121 self.ui.list_available.setCurrentItem(None)122 def remove_selected(self):123 for x in self.ui.list_selected.selectedItems():124 if self.ui.list_selected.count() > self.minimumItems():125 row = self.ui.list_selected.row(x)126 item = self.ui.list_selected.takeItem(row)127 self.ui.list_available.addItem(item)128 self.ui.list_available.setCurrentItem(item)129 self.itemSelectionChanged.emit(self.selectedItems())130 if self.trackSelected():131 self.ui.list_available.setFocus()132 self.ui.list_selected.setCurrentItem(None)133 def currentItem(self):134 if self.ui.list_selected.selectedItems():135 return self.ui.list_selected.selectedItems()[0]136 if self.ui.list_available.selectedItems():137 return self.ui.list_available.selectedItems()[0]138 else:139 return None140 def setCurrentItem(self, x):141 """142 Set the current item to the item that has 'x' as its data.143 """144 # look in left list:145 for i in range(self.ui.list_selected.count()):146 item = self.ui.list_selected.item(i)147 if utf8(item.data(QtCore.Qt.UserRole)) == x:148 self.ui.list_selected.setCurrentItem(item)149 return150 # look in right list:151 for i in range(self.ui.list_available.count()):152 item = self.ui.list_available.item(i)153 if utf8(item.data(QtCore.Qt.UserRole)) == x:154 self.ui.list_available.setCurrentItem(item)155 return156 def selection_down(self):157 current_row = self.ui.list_selected.currentRow()158 if current_row < self.ui.list_selected.count() - 1:159 self.ui.list_selected.setCurrentItem(160 self.ui.list_selected.item(current_row + 1))161 def selection_up(self):162 current_row = self.ui.list_selected.currentRow()163 if current_row > 0:164 self.ui.list_selected.setCurrentItem(165 self.ui.list_selected.item(current_row - 1))166 def selected_up(self):167 self.move_selected(up=True)168 def selected_down(self):169 self.move_selected(up=False)170 def move_selected(self, up):171 try:172 pos_first = min([self.ui.list_selected.row(x) for x173 in self.ui.list_selected.selectedItems()])174 except ValueError:175 return176 if up:177 new_pos = pos_first - 1178 else:179 new_pos = pos_first + 1180 selected = [self.ui.list_selected.takeItem(pos_first) for _181 in self.ui.list_selected.selectedItems()]182 for x in selected:183 self.ui.list_selected.insertItem(new_pos, x)184 x.setSelected(True)185 self.ui.list_selected.setCurrentItem(x)186 self.check_buttons()187 def check_buttons(self):188 selected_row = self.ui.list_selected.currentRow()189 selected_count = self.ui.list_selected.count()190 available_count = self.ui.list_available.count()191 self.ui.button_up.setEnabled(selected_row > 0)192 self.ui.button_down.setEnabled(selected_row + 1 < selected_count)193 self.ui.button_remove.setEnabled(194 selected_count > self.minimumItems() and selected_row > -1)195 self.ui.button_add.setEnabled(196 available_count > 0 and self.ui.list_available.currentRow() > -1)197 def keyPressEvent(self, event):198 if event.key() == QtCore.Qt.Key_Right:199 self.add_selected()200 elif event.key() == QtCore.Qt.Key_Left:201 self.remove_selected()202 elif event.key() == QtCore.Qt.Key_Up:203 if event.modifiers() == QtCore.Qt.ShiftModifier:204 self.selected_up()205 else:206 self.selection_up()207 elif event.key() == QtCore.Qt.Key_Down:208 if event.modifiers() == QtCore.Qt.ShiftModifier:209 self.selected_down()210 else:211 self.selection_down()212 else:213 super(CoqListSelect, self).keyPressEvent(event)214 def event(self, ev):215 if ev.type() == ev.FocusIn:216 if self.defocus():217 # restore selection bars if focus is regained:218 self.blockSignals(False)219 if self._last_selected_row is None:220 if self.ui.list_selected.count() > 0:221 self.ui.list_selected.setCurrentItem(222 self.ui.list_selected.item(0))223 else:224 self.ui.list_selected.setCurrentItem(225 self._last_selected_row)226 if self._last_available_row is None:227 if self.ui.list_available.count() > 0:228 self.ui.list_available.setCurrentItem(229 self.ui.list_available.item(0))230 else:231 self.ui.list_available.setCurrentItem(232 self._last_available_row)233 elif ev.type() == ev.FocusOut:234 if self.defocus():235 self.blockSignals(True)236 self._last_selected_row = self.ui.list_selected.currentItem()237 self._last_available_row = self.ui.list_available.currentItem()238 self.ui.list_selected.setCurrentItem(None)239 self.ui.list_available.setCurrentItem(None)240 return super(CoqListSelect, self).event(ev)241class SelectionDialog(QtWidgets.QDialog):242 def __init__(self, title, selected, available, text="", minimum=None,243 translator=None, *args, **kwargs):244 super(SelectionDialog, self).__init__(*args, **kwargs)245 translator = translator or (lambda x: x)246 self.setWindowTitle(title)247 self.main_layout = QtWidgets.QVBoxLayout(self)248 self.list_select = CoqListSelect()249 self.list_select.setMinimumItems(minimum or 0)250 self.list_select.setAvailableList(available, translator)251 self.list_select.setSelectedList(selected, translator)252 self.main_layout.addWidget(self.list_select)253 self.resize(500, 310)254 def exec_(self):255 super(SelectionDialog, self).exec_()256 @staticmethod257 def show(*args, **kwargs) -> Tuple[list, list]:258 dialog = SelectionDialog(*args, **kwargs)259 dialog.exec_()260 selected = [x.data(QtCore.Qt.UserRole)261 for x in dialog.list_select.selectedItems()]262 available = [x.data(QtCore.Qt.UserRole)263 for x in dialog.list_select.availableItems()]...

Full Screen

Full Screen

skates.py

Source:skates.py Github

copy

Full Screen

1"""2 В прокате коньков есть разные размеры. Известно, что желающий покататься3 может надеть коньки любого размера, которые не меньше размера его ноги.4 Напишите функцию, которая принимает список доступных размеров коньков и5 список размеров ног желающих.6 И возвращает наибольшее количество людей,7 которые смогут покататься одновременно.8 Например:9 [in]10 [39, 38, 41, 37] (доступные размеры)11 [40, 39, 41] (размеры ног желающих)12 [out]13 214 [37, 38, 39, 40] , [37, 37, 40, 40] -> 315 [37, 38, 39, 40] , [42] -> 016 [37, 38, 39] , [37, 37, 37, 37] -> 317 Напишите несколько тестов18"""19# Solutions20# 121def skates(available_sizes, foot_sizes):22 res_list = []23 for i in available_sizes:24 for j in foot_sizes:25 if j <= i and len(res_list) < len(available_sizes):26 res_list.append(i)27 foot_sizes.remove(j)28 return len(res_list)29list_available = [37, 38, 39, 40]30list_foot = [37, 37, 40, 40]31assert skates(list_available, list_foot) == 332list_available = [39, 38, 41, 37]33list_foot = [40, 39, 41]34assert skates(list_available, list_foot) == 235print("All tests passed successfully")36# 237def skates(available_sizes, foot_sizes):38 available = sorted(list(map(int, available_sizes.split())))39 desired = sorted(list(map(int, foot_sizes.split())))40 count = 041 while True:42 try:43 available = list(filter(lambda x: x >= min(desired), available))44 available.pop(0)45 desired.pop(0)46 count += 147 except IndexError:48 break49 return count50list_available = "37 38 39 40"51list_foot = "37 37 40 40"52assert skates(list_available, list_foot) == 353list_available = "39 38 41 37"54list_foot = "40 39 41"55assert skates(list_available, list_foot) == 2...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful