Best Python code snippet using uiautomator
_scrollarea.py
Source:_scrollarea.py  
...308        if not self._scroll:309            super(ScrollArea, self).clear_widgets(children)310        else:311            self._scroll.clear_widgets(children)312    def convert_distance_to_scroll(self, deltax:int, deltay:int):313        """Converts a distance in pixels to a scroll distance.314        This method provides direct access to the interface of the315        ScrollView child widget. For functional details see Kivy's316        documentation.317        """318        return self._scroll.convert_distance_to_scroll(deltax, deltay)319    def scroll_to(self, widget:_Widget, padding:int = 10,320                  animate:bool = True):321        """Scrolls the viewport to the given widget.322        This method provides direct access to the interface of the323        ScrollView child widget. For functional details see Kivy's324        documentation.325        Args:326            widget: The widget to scroll to.327            padding: The padding around the widget to scroll to.328            animate: Set to True for a scroll animation. False329            otherwise.330        """331        return self._scroll.scroll_to(widget, padding, animate)332    def update_from_scroll(self, *largs):333        """Reposition the content according to scroll_x and scroll_y.334        This method provides direct access to the interface of the335        ScrollView child widget. For functional details see Kivy's336        documentation.337        """338        return self._scroll.update_from_scroll(*largs)339    def on_touch_down(self, touch:_MotionEvent):340        """Callback method for touch / click events.341        If the application detects a touch or click, this method is342        called. It passes on the given touch motion event information343        to the ScrollView widget child.344        Args:345            touch: Motion event with details about the touch event.346        """347        return self._scroll.on_touch_down(touch)348    def on_touch_move(self, touch:_MotionEvent):349        """Callback method for touch / cursor motion events.350        If the application detects a cursor or touch motion, this method351        is called. It passes on the given motion event information352        to the ScrollView widget child....pyScroll.py
Source:pyScroll.py  
1#encoding=utf82from PyQt5 import QtGui,QtCore,QtWidgets3from PyQt5.QtGui import *4from PyQt5.QtWidgets import *5from PyQt5.QtWidgets import QHBoxLayout,QVBoxLayout,QFormLayout6from PyQt5.QtCore import *7import sys,os,json8from qtImage import  imageLoader,myPaint9strStyle = '''QScrollBar:horizontal {10    border: 2px solid green;11    background: cyan;12    height: 15px;13    margin: 0px 40px 0 0px;14}15QScrollBar::handle:horizontal {16    background: gray;17    min-width: 20px;18}19QScrollBar::add-line:horizontal {20    background: blue;21    width: 16px;22    subcontrol-position: right;23    subcontrol-origin: margin;24    border: 2px solid black;25}26QScrollBar::sub-line:horizontal {27    background: magenta;28    width: 16px;29    subcontrol-position: top right;30    subcontrol-origin: margin;31    border: 2px solid black;32    position: absolute;33    right: 20px;34}35QScrollBar:left-arrow:horizontal, QScrollBar::right-arrow:horizontal {36    width: 3px;37    height: 3px;38    background: pink;39}40QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {41    background: none;42}43 QScrollBar:vertical {44     border: 2px solid grey;45     background: #32CC99;46     width: 15px;47     margin: 22px 0 22px 0;48 }49 QScrollBar::handle:vertical {50     background: white;51     min-height: 20px;52 }53 QScrollBar::add-line:vertical {54     border: 2px solid grey;55     background: #32CC99;56     height: 20px;57     subcontrol-position: bottom;58     subcontrol-origin: margin;59 }60 QScrollBar::sub-line:vertical {61     border: 2px solid grey;62     background: #32CC99;63     height: 20px;64     subcontrol-position: top;65     subcontrol-origin: margin;66 }67 QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {68     border: 2px solid grey;69     width: 3px;70     height: 3px;71     background: white;72 }73 QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {74     background: none;75 }76'''77class myWindow(QDialog):78    def __init__(self,parent = None):79        super(myWindow,self).__init__()80        self.setWindowFlags(self.windowFlags()|Qt.WindowMinMaxButtonsHint)81        self.resize(600,400)82        self._imagLoader = imageLoader(self)83        self._scroll = QScrollArea(self)84        # self._scroll.setWidgetResizable(True)85        self._scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)86        self._scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)87        self._scroll.setAlignment(Qt.AlignCenter)88        self._scroll.setStyleSheet(strStyle)89        self._widget = myPaint(self)90        self._widget.resize(1000,1000)91        92        self._widget.setFocusPolicy(Qt.WheelFocus)93        hLay  = QHBoxLayout(self._widget)94        self._widget.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed)95        self._scroll.setWidget(self._widget)96        self._scroll.installEventFilter(self)97        self._widget.installEventFilter(self)98        main_lay = QVBoxLayout(self)99        main_lay.addWidget(self._scroll)100        hlay = QHBoxLayout()101        self.btn_about = QPushButton("aboutQt",self)102        self.btn_pause = QPushButton("Pause",self)103        self.btn_cancel = QPushButton("Cancel",self)104        hlay.addStretch()105        hlay.addWidget(self.btn_pause)106        hlay.addWidget(self.btn_about)107        hlay.addWidget(self.btn_cancel)108        main_lay.addLayout(hlay)109        110        menuBar = QMenuBar(self)111        group = QActionGroup(self)112        # group.setExclusive(True)  ## åªå
许ä¸ä¸ª113        menu = menuBar.addMenu("DlgMenu")114        act1 = group.addAction(QAction('111'))115        act2 = group.addAction(QAction('222'))116        act3 = group.addAction(QAction('333'))117        menu.addAction(act1)118        menu.addAction(act2)119        menu.addAction(act3)120        for i in range(1,4):121            str = 'act%d.setCheckable(True)'% i 122            eval(str)123            str = 'act%d.setChecked(True)'% i 124            eval(str)125        # act1.setChecked(True)126        main_lay.setMenuBar(menuBar)127        self.btn_about.clicked.connect(lambda: QApplication.instance().aboutQt())128        self.btn_pause.clicked.connect(self.on_PauseClick)129        self.btn_cancel.clicked.connect(lambda: self.reject())130        self._imagLoader.evt_showImg.connect(self._widget.on_paint)131        self._imagLoader.finished.connect(self._imagLoader.deleteLater)132        QTimer.singleShot(0,lambda:self._imagLoader.start())133    def on_PauseClick(self):134        if self.btn_pause.text() == 'Pause':135            self.btn_pause.setText('Resume')136            self._imagLoader.evt_showImg.disconnect()137        else:138            self.btn_pause.setText('Pause')   139            self._imagLoader.evt_showImg.connect(self._widget.on_paint)140        141    def eventFilter(self,o,e):142        if o == self._scroll:143            if e.type() == QtCore.QEvent.MouseButtonDblClick:144                if self._scroll.isFullScreen():145                    self._scroll.setWindowFlags(Qt.SubWindow)146                    self._scroll.showNormal()147                else:148                    self._scroll.setWindowFlags(Qt.Window)149                    self._scroll.showFullScreen()150                return True151            elif e.type() == QEvent.Wheel:152                event  = QWheelEvent(e)153                # print('\033[31mScrollWheel:',event.globalPos(),event.pos())154                newSize = self._widget.size()155                s = self._scroll.size()156                # print(event.angleDelta(),event.pixelDelta())157                if event.angleDelta().y() > 0:158                    if newSize.width() > s.width()*4:159                        return True160                    newSize*= 1.25161                else:162                    if s.width() == newSize.width():163                        return True164                    newSize*= 0.75165                166                if newSize.width() <= s.width():167                    self._widget.resize(self._scroll.maximumViewportSize())168                    return True169                self._widget.resize(newSize)170                # self._scroll.ensureVisible(event.pos().x(),event.pos().y(),50,50)171                return True172            elif e.type() == QEvent.Resize:173                evt = QResizeEvent(e)174                print('\033[34mScroll resize:',self._scroll.viewport().size(),self._scroll.size(),self._widget.size())175                # print(evt.oldSize(),evt.size(),self._scroll.maximumViewportSize())176                # if evt.oldSize() != evt.size():177                self._scroll.viewport().resize(self._scroll.maximumViewportSize())178                self._widget.resize(self._scroll.maximumViewportSize())179                return True180                181        #   return QDialog.eventFilter(self, o, e)#å°äºä»¶äº¤ç»ä¸å±å¯¹è¯æ¡  182        return False183    def closeEvent(self,evt):184            self._imagLoader.requestInterruption()185            self._imagLoader.wait(1000)186if __name__ == '__main__':187    app = QApplication(sys.argv)188    print(QCoreApplication.libraryPaths())189    print(QtCore.qVersion())190    window = myWindow()191    window.show()...editor_handler.py
Source:editor_handler.py  
1from __future__ import absolute_import2from __future__ import unicode_literals3from __future__ import division4from py23 import *5import sce_core6__all__ = [7		"Handler",8	]9class Handler (sce_core.BasicHandler) :10	11	def __init__ (self) :12		sce_core.BasicHandler.__init__ (self)13	14	def handle_key_backspace (self, _shell) :15		_view = _shell.get_view ()16		_scroll = _view.get_scroll ()17		_cursor = _view.get_cursor ()18		_line = _cursor.get_line ()19		_visual_column = _cursor.get_column ()20		_length = _view.select_visual_length (_line)21		if _visual_column > _length :22			_cursor.set_column (_length)23		elif _visual_column > 0 :24			_real_column = _view.select_real_column (_line, _visual_column - 1)25			_scroll.delete (_line, _real_column, 1)26			_cursor.set_column (_view.select_visual_column (_line, _real_column))27		elif _line > 0 :28			_length = _view.select_visual_length (_line - 1)29			_scroll.unsplit (_line - 1)30			_cursor.increment_line (-1)31			_cursor.set_column (_length)32		elif _length == 0 and _line == 0 and _scroll.get_length () == 1 :33			_scroll.exclude (0)34		else :35			_shell.alert ()36	37	def handle_key_tab (self, _shell) :38		self._insert_character (_shell, "\t")39	40	def handle_key_enter (self, _shell) :41		_view = _shell.get_view ()42		_scroll = _view.get_scroll ()43		_cursor = _view.get_cursor ()44		_line = _cursor.get_line ()45		_column = _cursor.get_column ()46		_scroll.split (_line, _view.select_real_column (_line, _column))47		_string = _scroll.select (_line)48		_prefix = []49		for _char in _string :50			if _char == " " :51				_prefix.append (_char)52			elif _char == "\t" :53				_prefix.append (_char)54			else :55				break56		_prefix = "".join (_prefix)57		_scroll.insert (_line + 1, 0, _prefix)58		_column = _view.compute_visual_length (_prefix)59		_cursor.increment_line (1)60		_cursor.set_column (_column)61	62	def handle_key_delete (self, _shell) :63		_view = _shell.get_view ()64		_scroll = _view.get_scroll ()65		_cursor = _view.get_cursor ()66		_line = _cursor.get_line ()67		_visual_column = _cursor.get_column ()68		_length = _view.select_visual_length (_line)69		if _visual_column > _length :70			_cursor.set_column (_length)71		elif _visual_column < _length :72			_real_column = _view.select_real_column (_line, _visual_column)73			_scroll.delete (_line, _real_column, 1)74			_cursor.set_column (_view.select_visual_column (_line, _real_column))75		elif _line < (_scroll.get_length () - 1) :76			_scroll.unsplit (_line)77			_cursor.set_column (_length)78		elif _length == 0 and _line == 0 and _scroll.get_length () == 1 :79			_scroll.exclude (0)80		else :81			_shell.alert ()82	83	def handle_key_character (self, _shell, _character) :84		self._insert_character (_shell, _character)85	86	def _insert_character (self, _shell, _character) :87		_view = _shell.get_view ()88		_scroll = _view.get_scroll ()89		_cursor = _view.get_cursor ()90		_line = _cursor.get_line ()91		_visual_column = _cursor.get_column ()92		_real_column = _view.select_real_column (_line, _visual_column)93		_scroll.insert (_line, _real_column, _character)...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!!
