Best Python code snippet using uiautomator
xkb.py
Source:xkb.py
1# -*- python -*-2'''3xpybar â xmobar replacement written in python4Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Mattias Andrée (maandree@kth.se)5This program is free software: you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation, either version 3 of the License, or8(at your option) any later version.9This program is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.13You should have received a copy of the GNU General Public License14along with this program. If not, see <http://www.gnu.org/licenses/>.15'''16import Xlib.XK17from x import *18class XKB:19 '''20 X keyboard monitor21 '''22 23 24 NUM = 125 '''26 :int The bit in `get_locks` representing Num Lock27 '''28 29 CAPS = 230 '''31 :int The bit in `get_locks` representing Royal Canterlot Voice32 '''33 34 SCROLL = 435 '''36 :int The bit in `get_locks` representing Scroll Lock37 '''38 39 40 def __init__(self):41 '''42 Constructor43 '''44 self.__root = get_screen().root45 46 lockkey = lambda lock : get_display().keysym_to_keycode(Xlib.XK.string_to_keysym(lock + '_Lock'))47 find = lambda array, item : (1 << array.index(item)) if item in array else -148 mods = [x[0] for x in get_display().get_modifier_mapping()]49 50 self.__num = find(mods, lockkey('Num'))51 self.__caps = find(mods, lockkey('Caps'))52 self.__scroll = find(mods, lockkey('Scroll'))53 54 55 # TODO add update listener56 def get_locks(self):57 '''58 Get the currently active lock keys (num lock, caps lock and scroll lock, but not compose)59 60 @return :int The bitwise OR of the active lock keys (XKB.NUM, XKB.CAPS, XKB.SCROLL)61 '''62 mask = self.__root.query_pointer().mask63 rc = 064 rc |= XKB.NUM if (mask & self.__num) == self.__num else 065 rc |= XKB.CAPS if (mask & self.__caps) == self.__caps else 066 rc |= XKB.SCROLL if (mask & self.__scroll) == self.__scroll else 067 return rc68 69 70 def get_locks_str(self):71 '''72 Get the currently active lock keys (num lock, caps lock and scroll lock, but not compose)73 74 @return :list<str> A list of locks in title case ('Num', 'Caps', 'Scroll')75 '''76 mask = self.__root.query_pointer().mask77 rc = []78 if (mask & self.__num) == self.__num: rc.append('Num')79 if (mask & self.__caps) == self.__caps: rc.append('Caps')80 if (mask & self.__scroll) == self.__scroll: rc.append('Scroll')...
scrollableFrame.py
Source:scrollableFrame.py
1import tkinter as tk23class ScrollableFrame(tk.Frame):45 def __init__(self, parent, config, **args):6 super().__init__(parent, args)78 self.__active_scroll = False910 self.__config = config11 self.__canvas = tk.Canvas(self, args)12 self.__frame = tk.Frame(self.__canvas, args)13 self.__scroll = tk.Scrollbar(self, command = self.__canvas.yview)14 self.__canvas.configure(yscrollcommand = self.__scroll_set)1516 self.__canvas.pack(fill = tk.BOTH, expand = True)17 self.__canvas.create_window((0, 0), window = self.__frame, anchor = tk.NW)1819 self.bind("<Configure>", self.__on_configure)20 self.bind('<Enter>', self.__bind_scroll)21 self.bind('<Leave>', self.__unbind_scroll)22 self.__frame.bind("<Configure>", self.on_frame_configure)2324 def __scroll_set(self, lo, hi):25 self.__active_scroll = float(lo) > 0.0 or float(hi) < 1.026 if self.__active_scroll:27 self.__scroll.place(28 x = self.winfo_width() - self.__scroll.winfo_width(),29 relheight = 1)30 else:31 self.__scroll.place_forget()32 self.__on_configure(None)33 self.__scroll.set(lo, hi)3435 def __on_configure(self, _event):36 width = self.winfo_width()37 if self.__active_scroll:38 width -= self.__scroll.winfo_width()39 self.__config(width)4041 def on_frame_configure(self, _event):42 self.__canvas.configure(scrollregion = self.__canvas.bbox(tk.ALL))4344 def __bind_scroll(self, _event):45 self.__canvas.bind_all("<MouseWheel>", self.__mouse_scroll)46 self.__canvas.bind_all("<Button-4>", self.__mouse_scroll)47 self.__canvas.bind_all("<Button-5>", self.__mouse_scroll)4849 def __unbind_scroll(self, _event):50 self.__canvas.unbind_all("<MouseWheel>")51 self.__canvas.unbind_all("<Button-4>")52 self.__canvas.unbind_all("<Button-5>")5354 def __mouse_scroll(self, event):55 if not self.__active_scroll:56 return57 self.__canvas.yview_scroll(1 if event.num == 5 or event.delta < 0 else -1, tk.UNITS)5859 def get_inner_frame(self):60 return self.__frame6162 def get_canvas(self):
...
Derecha.py
Source:Derecha.py
1# -*- coding: utf-8 -*-2import gi3gi.require_version("Gtk", "3.0")4from gi.repository import Gtk5from JAMediaPlayer.derecha.BalanceWidget import BalanceWidget6#from JAMediaPlayer.derecha.EqualizerWidget import EqualizerWidget7from JAMediaPlayer.derecha.JAMediaPlayerList import PlayerList8from JAMediaPlayer.derecha.PlayerControls import PlayerControls9from JAMediaPlayer.Globales import ocultar10from JAMediaPlayer.Globales import mostrar11class Derecha(Gtk.VBox):12 13 def __init__(self):14 Gtk.VBox.__init__(self)15 self.balance = BalanceWidget()16 #self.equalizer = EqualizerWidget()17 self.lista = PlayerList()18 self.playercontrols = PlayerControls()19 balanceFrame = Gtk.Frame()20 balanceFrame.set_label(" Balance: ")21 balanceFrame.get_label_widget().get_style_context().add_class('equalizerlabelframe')22 balanceFrame.add(self.balance)23 #equalizerFrame = Gtk.Frame()24 #equalizerFrame.set_label(" Ecualizador: ")25 #equalizerFrame.get_label_widget().get_style_context().add_class('equalizerlabelframe')26 #equalizerFrame.add(self.equalizer)27 confbox = Gtk.VBox()28 confbox.get_style_context().add_class("equalizerbox")29 confbox.pack_start(balanceFrame, False, False, 0)30 #confbox.pack_start(equalizerFrame, False, False, 10)31 self.__scroll = Gtk.ScrolledWindow()32 self.__scroll.get_style_context().add_class('scrolllist')33 self.__scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)34 self.__scroll.add_with_viewport(confbox)35 self.pack_start(self.__scroll, True, True, 0)36 self.pack_start(self.lista, True, True, 0)37 self.pack_end(self.playercontrols, False, False, 0)38 self.show_all()39 self.lista.lista.connect("len_items", self.__len_items)40 def __len_items(self, widget, items):41 self.playercontrols.activar(items)42 def show_config(self, val):43 if val:44 mostrar([self.__scroll])45 ocultar([self.lista, self.playercontrols])46 else:47 ocultar([self.__scroll])48 mostrar([self.lista, self.playercontrols])49 50 def setup_init(self):51 ocultar([self.__scroll])...
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!!