How to use _getScreenSize method in fMBT

Best Python code snippet using fMBT_python

window.py

Source:window.py Github

copy

Full Screen

...38 else:39 self.font = font40 # Render startup message41 self.showFullscreenMessage("Waiting for data...")42 def _getScreenSize(self) -> Tuple[int, int]:43 return self.screen.get_size()44 def _generateBackgroundTexture(self) -> pygame.Surface:45 # Create a new black surface46 bg = pygame.Surface(self._getScreenSize())47 bg = bg.convert()48 bg.fill((0, 0, 0))49 return bg50 def showFullscreenMessage(self, message: str) -> None:51 # Create a background52 bg = self._generateBackgroundTexture()53 # Create a text object54 text: pygame.Surface = self.font.render(message, 1, (255, 255, 255))55 # Translate the text to the center of the screen56 text_bounds = text.get_rect()57 bg_bounds = bg.get_rect()58 text_bounds.centerx = bg_bounds.centerx59 text_bounds.centery = bg_bounds.centery60 # Render everything61 bg.blit(text, text_bounds)62 self.screen.blit(bg, (0, 0))63 pygame.display.flip()64 def loadServerConfig(self, model: DynmapConfigurationModel) -> None:65 self.config = model66 def isConnectedToServer(self) -> bool:67 return self.config != None68 def getTimeUntilNextFrame(self) -> float:69 # If there is no connection, default on a large timeout70 if not self.isConnectedToServer():71 return 072 else:73 return ((self.config.updaterate / 2) / 1000) - (time.time() - self.last_render_time)74 def updatePlayerList(self, players: List[DynmapPlayerModel]):75 self.online_players = players76 # Get the equal box sizing77 c, r, w, h = self._getEqualBoxSize()78 # Update tiles79 for player in self.online_players:80 # If the player is in a valid world81 if not player.isInHiddenWorld():82 self.loadPlayerTiles(player, (w, h))83 def shouldQuit(self) -> bool:84 for event in pygame.event.get():85 if event.type == pygame.QUIT:86 return True87 else:88 return False89 def _getEqualBoxSize(self) -> Tuple[int, int]:90 # Get the screen aspect ratio91 screen_size = self._getScreenSize()92 aspect_ratio = screen_size[0] / screen_size[1]93 player_count = len([player for player in self.online_players if not player.isInHiddenWorld()])94 # Determine the number of cols and rows95 row_count = math.ceil(player_count / aspect_ratio)96 col_count = math.ceil(player_count / row_count)97 # Determine box sizing98 box_width = screen_size[0] / col_count99 box_height = screen_size[1] / row_count100 return (col_count, row_count, box_width, box_height)101 def loadPlayerTiles(self, player: DynmapPlayerModel, size: Tuple[int, int]):102 # Determine the number of chunks needed for the size103 chunks_needed = (104 math.ceil(size[0] / 128) + 1, math.ceil(size[1] / 128) + 1)105 # Track the size...

Full Screen

Full Screen

instagramBot.py

Source:instagramBot.py Github

copy

Full Screen

...34 self.width = w3536#OS-ONLY FUNCTIONS _______________________________________________________________________3738def _getScreenSize():39 os.system("adb shell wm size")40 res = os.popen('adb shell wm size').read()[15:].strip().split('x')41 return [int(res[0]), int(res[1])]424344def _getScreen(d: Device):45 os.system("adb exec-out screencap -p > screen.png")46 _mySleep(SHORTSLEEP)47 im = Image.open('screen.png')48 left = 049 top = 050 right = d.width51 bottom = d.height - 2052 im1 = im.crop((left, top, right, bottom))53 im1.save('screen.png', 'png')5455def _getCoordinates(ref: str, d: Device):56 _getScreen(d)57 image = imread('screen.png')58 template = imread(ref)59 image_gray = rgb2gray(image)60 template_gray = rgb2gray(template)61 result = match_template(image_gray, template_gray)62 ij = np.unravel_index(np.argmax(result), result.shape)63 x, y = ij[::-1]64 #Here I can handle some offsets65 x = x + 066 y = y + 067 return [x,y]6869def _mySleep(sec:float):70 rnd = random.uniform(-0.5, 0.5)71 if(DEBUG):72 print('sleep: ', sec + rnd)73 sleep(sec + rnd)7475def _tap(x:int, y:int):76 if(DEBUG):77 print('tap | x:',x,' | y:',y)78 os.system("adb shell input tap " + str(x) + " " + str(y))7980def _swipeVertical(l:int):81 if(DEBUG):82 print('vertical swipe: ',l)83 os.system("adb shell input swipe 540 " + str(l) + " 540 10 500")8485def _clickOn(ref: str, d: Device):86 [x,y] = _getCoordinates(ref, d)87 _tap(x,y)888990def _textInput(text: str):91 if(DEBUG):92 print('text input: ', text)93 os.system("adb shell input keyboard text " + "\"" + text + "\"")94 _mySleep(SHORTSLEEP)9596def _osHome():97 os.system("adb shell input keyevent 3")9899def _osSquare():100 os.system("adb shell input keyevent 187")101102def _osBack():103 os.system("adb shell input keyevent 4")104105def _clearConsole():106 os.system("clear")107108#INSTAGRAM-BASIC FUNCTIONS _______________________________________________________________________109110class InstagramBot:111 def __init__(self):112 size = _getScreenSize()113 self.device = Device(h=size[1], w=size[0])114 _clearConsole()115 print('Bot initiated')116 print('Screen size:', self.device.height, 'x', self.device.width)117118 def openInstagram(self):119 if(DEBUG):120 print('open instagram')121 os.system("adb shell monkey -p com.instagram.android 1 -")122 _mySleep(LONGSLEEP)123124 def closeInstagram(self):125 if(DEBUG):126 print('close instagram') ...

Full Screen

Full Screen

on_cue.py

Source:on_cue.py Github

copy

Full Screen

...34class OnCue(App):35 def build(self):36 # Okay lets get screensize and this is hacky I know37 self.icon = 'OnCueIcon.png'38 screensize = self._getScreenSize()39 Window.size = (int(screensize[0]*0.15), int(screensize[0]*0.2))40 self.window = GridLayout(cols=1)41 # Calculate fontsize from screensize and define our color scheme42 self.fontsize = int(screensize[0]*0.015)43 self.scheme={'Blue':[0.52,0.72,0.9,1],'Pink':[0.91,0.7,0.97,1],'White':[0.9,0.94,0.99,1],'Pink_2':[0.93,0.79,.97,1],44 'Blue_2':[0.62,0.77,0.9,1],'White_2':[0.81,0.85,0.90,1],'Font':[0.09,0.37,0.64],'Blue_3':[0.35,0.6,0.81,1]}45 # first we need to generate an affirmation duh46 self.greeting = FancyLabel(text= '{}!'.format(self._genAffirmation()),font_size= self.fontsize,size_hint=(1,1),color=self.scheme['Font'],bgcolor=self.scheme['Blue'],bold=True)47 self.window.add_widget(self.greeting)48 # Add Frequency input49 fc,self.freq_control = self._addControl(160,'Hz','Pink')50 self.window.add_widget(fc)51 # Add Interval input52 ic,self.interval_control = self._addControl(20,'Min','White')53 self.window.add_widget(ic)54 # Add Volume slider55 vc,self.volume_control = self._addControl(20,'Vol','Pink',True)56 self.window.add_widget(vc)57 # Add StartStop Button58 button_border = FancyBorder(cols=1,padding=[int((x/x)*self.fontsize*0.05) for x in range(1,5)],bgcolor=self.scheme['Blue_3'])59 self.button = Button(text= "START",bold= True,background_color = self.scheme['Blue'],background_normal = "",font_size=self.fontsize)60 self.button.bind(on_press=self.StartStop)61 button_border.add_widget(self.button)62 self.window.add_widget(button_border)63 self.loop_counter = 064 # Define our variables65 self.running = False66 self.freq = None67 self.vol = None68 self.interval = None69 return self.window70 def _addControl(self,default,label,color,slider=False):71 layout = GridLayout(cols = 2)72 # Create sub layout to add a thicccc border73 sub_layout = FancyBorder(cols=1,padding=[int((x/x)*self.fontsize*0.35) for x in range(1,5)],bgcolor=self.scheme[color])74 if slider:75 inp = Slider(min=0, max=40, value=default)76 else:77 cursor_tmp = self.scheme['White'].copy()78 cursor_tmp[3] = 0.579 inp = TextInput(multiline= False,text=str(default),font_size=self.fontsize,input_filter='float',halign='center',80 padding_y = [int(self.fontsize/2),0],cursor_width='4sp',background_color=self.scheme['White_2'],background_normal="",81 selection_color=cursor_tmp,cursor_color=cursor_tmp)82 sub_layout.add_widget(inp)83 layout.add_widget(sub_layout)84 # add a label to our control too how nice85 label = FancyLabel(text=label,font_size=self.fontsize,color=self.scheme['Font'],bold=True,size_hint=(0.35,1),bgcolor=self.scheme[color])86 layout.add_widget(label)87 return layout,inp88 def _getScreenSize(self):89 root = tk.Tk()90 return (root.winfo_screenwidth(),root.winfo_screenheight())91 def _genAffirmation(self):92 affirms = ['Pitch Perfect','You Rock','Sounding Good','Barb Is Listening','Snazzy as Usual']93 tmp = sample(affirms,1)94 return tmp[0]95 def StartStop(self, instance):96 if self.running:97 self.running = False98 self.button.text = 'START'99 self.clock_int.cancel()100 else:101 self.running = True102 self.button.text = 'STOP'...

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 fMBT 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