How to use buttons method in pyatom

Best Python code snippet using pyatom_python

model.py

Source:model.py Github

copy

Full Screen

...99 """100 self.turn_count += 1101 self.change_marker(button)102 if self.winner() == self.current_player:103 self.disable_buttons()104 if self.game_type == 1:105 self.status_label.config(text='You lose')106 else:107 self.status_label.config(text=f'Congratulations '108 f'{self.players[self.current_player]}, you won!')109 self.score[self.current_player] += 1110 logging.info('%s wins.', self.players[self.current_player])111 logging.info('Score: %s/%s.', self.score[1], self.score[2])112 return 0113 elif self.turn_count == 9:114 self.status_label.config(text='That is a tie')115 logging.info('A tie.')116 return 1117 self.swap_turn()118 if self.game_type == 1 and self.current_player == 1:119 self.disable_buttons()120 button_number = self.minimax(self.get_board(), self.current_player)[0]121 if self.button_clicked(self.buttons_frame.winfo_children()[button_number]) != 0:122 self.enable_buttons()123 return 2124 def minimax(self, new_board, new_player):125 """126 minimax(new_board: list, new_player: int) -> tuple127 Recursive function to control computer moves.128 """129 f_spots = self.free_spots(new_board)130 if self.minimax_winner(new_board) == 1:131 return 10132 if self.minimax_winner(new_board) == 2:133 return -10134 if not f_spots:135 return 0136 results = {}137 buffer = tuple(new_board)138 for i in f_spots:139 new_board[i] = self.markers[new_player]140 result = self.minimax(new_board, 1 if new_player == 2 else 2)141 results[i] = result[1] if isinstance(result, tuple) else result142 new_board = list(buffer)143 if new_player == 1:144 return max(results, key=results.get), max(list(results.values()))145 return min(results, key=results.get), min(list(results.values()))146 def get_board(self):147 """148 get_board() -> list149 Returns the game board state as a list with nine items.150 """151 board = []152 for button in self.buttons_frame.winfo_children():153 board.append(button['text'])154 return board155 def disable_buttons(self):156 """157 disable_buttons()158 Disables all not pressed buttons on the game board159 """160 for i in self.free_spots(self.get_board()):161 self.buttons_frame.winfo_children()[i]['state'] = 'disable'162 def enable_buttons(self):163 """164 enable_buttons()165 Enables all not pressed buttons on the game board166 """167 for i in self.free_spots(self.get_board()):168 self.buttons_frame.winfo_children()[i]['state'] = 'normal'169 @staticmethod170 def minimax_winner(brd):171 """172 minimax_winner(brd: list) -> int173 Returns winner id if the game is end or 0 otherwise.174 Used only by minimax method.175 """176 i = j = 0177 for _ in range(3):178 if brd[i] == brd[i + 1] == brd[i + 2] and brd[i]:...

Full Screen

Full Screen

CatalogGUI.py

Source:CatalogGUI.py Github

copy

Full Screen

1from pandac.PandaModules import NodePath, Vec42from direct.showbase.DirectObject import DirectObject3from direct.gui.DirectButton import DirectButton4from toontown.catalog.CatalogTabButton import CatalogTabButton5from toontown.catalog.CatalogArrowButton import CatalogArrowButton6from toontown.catalog.CatalogRadioButton import CatalogRadioButton7from toontown.catalog import CatalogGlobals8from toontown.toonbase import ToontownGlobals9from toontown.toonbase import TTLocalizer10class CatalogGUI(NodePath, DirectObject):11 def __init__(self, phone, doneEvent=None):12 NodePath.__init__(self, aspect2d.attachNewNode('CatalogGUI'))13 DirectObject.__init__(self)14 CatalogGlobals.CatalogNodePath.find('**/CATALOG_GUI_BKGD').copyTo(self)15 self.setScale(CatalogGlobals.CatalogBKGDScale)16 self.phone = phone17 self.doneEvent = doneEvent18 self.arrowButtons = {}19 self.createArrowButtons()20 self.currentTab = None21 self.tabButtons = {}22 self.createTabButtons()23 self.radioButtons = []24 # self.createRadioButtons()25 self.activePage = 026 self.gifting = -127 guiItems = loader.loadModel('phase_5.5/models/gui/catalog_gui')28 hangupGui = guiItems.find('**/hangup')29 hangupRolloverGui = guiItems.find('**/hangup_rollover')30 self.hangup = DirectButton(self, relief=None, pos=(2.28, 0, -1.3),31 image=[hangupGui, hangupRolloverGui, hangupRolloverGui, hangupGui],32 text=['', TTLocalizer.CatalogHangUp, TTLocalizer.CatalogHangUp],33 text_fg=Vec4(1), text_scale=0.07, text_pos=(0.0, 0.14),34 command=self.hangUp)35 guiItems.removeNode()36 def setCurrentTab(self, tab):37 self.currentTab = tab38 def getCurrentTab(self):39 return self.currentTab40 def setActivePage(self, activePage):41 self.activePage = activePage42 def getActivePage(self):43 return self.activePage44 def createTabButtons(self):45 # We need to create the tabs in reverse order...46 self.tabButtons['SPECIAL_TAB'] = CatalogTabButton(self, 'BTN7',47 self.specialTabClicked)48 self.tabButtons['NAMETAG_TAB'] = CatalogTabButton(self, 'BTN6',49 self.nametagTabClicked)50 self.tabButtons['CLOTHING_TAB'] = CatalogTabButton(self, 'BTN5',51 self.clothingTabClicked)52 self.tabButtons['PHRASES_TAB'] = CatalogTabButton(self, 'BTN4',53 self.phrasesTabClicked)54 self.tabButtons['EMOTE_TAB'] = CatalogTabButton(self, 'BTN3',55 self.emoteTabClicked)56 self.tabButtons['FURNITURE_TAB'] = CatalogTabButton(self, 'BTN2',57 self.furnitureTabClicked)58 self.tabButtons['POPULAR_TAB'] = CatalogTabButton(self, 'BTN1',59 self.popularTabClicked)60 tabList = []61 for tab in self.tabButtons:62 tabList.append(self.tabButtons[tab])63 for tab in self.tabButtons:64 self.tabButtons[tab].setOtherTabs(tabList)65 def popularTabClicked(self):66 messenger.send('wakeup')67 def furnitureTabClicked(self):68 messenger.send('wakeup')69 def emoteTabClicked(self):70 messenger.send('wakeup')71 def phrasesTabClicked(self):72 messenger.send('wakeup')73 def clothingTabClicked(self):74 messenger.send('wakeup')75 def nametagTabClicked(self):76 messenger.send('wakeup')77 def specialTabClicked(self):78 messenger.send('wakeup')79 def createArrowButtons(self):80 self.arrowButtons['LEFT_ARROW'] = CatalogArrowButton(self, 'LT',81 self.leftArrowClicked)82 self.arrowButtons['RIGHT_ARROW'] = CatalogArrowButton(self, 'RT',83 self.rightArrowClicked)84 def leftArrowClicked(self):85 messenger.send('wakeup')86 if self.currentTab:87 self.currentTab.moveLeft()88 def rightArrowClicked(self):89 messenger.send('wakeup')90 if self.currentTab:91 self.currentTab.moveRight()92 def createRadioButtons(self):93 byNameRadioButton = CatalogRadioButton(self, 'ByName',94 self.byNameRadioButtonClicked)95 byCostRadioButton = CatalogRadioButton(self, 'ByCost',96 self.byCostRadioButtonClicked)97 self.radioButtons.append(byNameRadioButton)98 self.radioButtons.append(byCostRadioButton)99 for radioButton in self.radioButtons:100 radioButton.setOthers(self.radioButtons)101 byNameRadioButton.enable()102 def byNameRadioButtonClicked(self):103 pass104 def byCostRadioButtonClicked(self):105 pass106 def enableBothArrows(self):107 for arrow in self.arrowButtons:108 self.arrowButtons[arrow].show()109 def disableBothArrows(self):110 for arrow in self.arrowButtons:111 self.arrowButtons[arrow].hide()112 def disableLeftArrow(self):113 self.arrowButtons['LEFT_ARROW'].hide()114 def disableRightArrow(self):115 self.arrowButtons['RIGHT_ARROW'].hide()116 def show(self):117 self.accept('CatalogItemPurchaseRequest', self.__handlePurchaseRequest)118 base.setBackgroundColor(Vec4(0.570312, 0.449219, 0.164062, 1.0))119 NodePath.show(self)120 render.hide()121 def hide(self):122 self.ignore('CatalogItemPurchaseRequest')123 base.setBackgroundColor(ToontownGlobals.DefaultBackgroundColor)124 NodePath.hide(self)125 render.show()126 def unload(self):127 self.hide()128 for arrow in self.arrowButtons:129 self.arrowButtons[arrow].cleanup()130 for tab in self.tabButtons:131 self.tabButtons[tab].cleanup()132 for radio in self.radioButtons:133 radio.cleanup()134 self.hangup.destroy()135 self.destroy()136 def destroy(self):137 NodePath.removeNode(self)138 def hangUp(self):139 self.unload()140 print self.doneEvent141 messenger.send(self.doneEvent)142 def __handlePurchaseRequest(self, item):143 item.requestPurchase(self.phone, self.__handlePurchaseResponse)144 def __handlePurchaseResponse(self, retCode, item):145 self.lockItems()146 def lockItems(self):147 for tab in self.tabButtons:148 self.tabButtons[tab].lockItems()149 def updateItems(self):150 for tab in self.tabButtons:...

Full Screen

Full Screen

OTPDialog.py

Source:OTPDialog.py Github

copy

Full Screen

1from direct.gui.DirectGui import *2from direct.directnotify import DirectNotifyGlobal3import string4from otp.otpbase import OTPGlobals5from otp.otpbase import OTPLocalizer6NoButtons = 07Acknowledge = 18CancelOnly = 29TwoChoice = 310YesNo = 411TwoChoiceCustom = 512class OTPDialog(DirectDialog):13 def __init__(self, parent = None, style = NoButtons, **kw):14 if parent == None:15 parent = aspect2d16 self.style = style17 buttons = None18 if self.style != NoButtons:19 buttons = loader.loadModel(self.path)20 if self.style == TwoChoiceCustom:21 okImageList = (buttons.find('**/ChtBx_OKBtn_UP'), buttons.find('**/ChtBx_OKBtn_DN'), buttons.find('**/ChtBx_OKBtn_Rllvr'))22 cancelImageList = (buttons.find('**/CloseBtn_UP'), buttons.find('**/CloseBtn_DN'), buttons.find('**/CloseBtn_Rllvr'))23 buttonImage = [okImageList, cancelImageList]24 buttonValue = [DGG.DIALOG_OK, DGG.DIALOG_CANCEL]25 if 'buttonText' in kw:26 buttonText = kw['buttonText']27 del kw['buttonText']28 else:29 buttonText = [OTPLocalizer.DialogOK, OTPLocalizer.DialogCancel]30 elif self.style == TwoChoice:31 okImageList = (buttons.find('**/ChtBx_OKBtn_UP'), buttons.find('**/ChtBx_OKBtn_DN'), buttons.find('**/ChtBx_OKBtn_Rllvr'))32 cancelImageList = (buttons.find('**/CloseBtn_UP'), buttons.find('**/CloseBtn_DN'), buttons.find('**/CloseBtn_Rllvr'))33 buttonImage = [okImageList, cancelImageList]34 buttonText = [OTPLocalizer.DialogOK, OTPLocalizer.DialogCancel]35 buttonValue = [DGG.DIALOG_OK, DGG.DIALOG_CANCEL]36 elif self.style == YesNo:37 okImageList = (buttons.find('**/ChtBx_OKBtn_UP'), buttons.find('**/ChtBx_OKBtn_DN'), buttons.find('**/ChtBx_OKBtn_Rllvr'))38 cancelImageList = (buttons.find('**/CloseBtn_UP'), buttons.find('**/CloseBtn_DN'), buttons.find('**/CloseBtn_Rllvr'))39 buttonImage = [okImageList, cancelImageList]40 buttonText = [OTPLocalizer.DialogYes, OTPLocalizer.DialogNo]41 buttonValue = [DGG.DIALOG_OK, DGG.DIALOG_CANCEL]42 elif self.style == Acknowledge:43 okImageList = (buttons.find('**/ChtBx_OKBtn_UP'), buttons.find('**/ChtBx_OKBtn_DN'), buttons.find('**/ChtBx_OKBtn_Rllvr'))44 buttonImage = [okImageList]45 buttonText = [OTPLocalizer.DialogOK]46 buttonValue = [DGG.DIALOG_OK]47 elif self.style == CancelOnly:48 cancelImageList = (buttons.find('**/CloseBtn_UP'), buttons.find('**/CloseBtn_DN'), buttons.find('**/CloseBtn_Rllvr'))49 buttonImage = [cancelImageList]50 buttonText = [OTPLocalizer.DialogCancel]51 buttonValue = [DGG.DIALOG_CANCEL]52 elif self.style == NoButtons:53 buttonImage = []54 buttonText = []55 buttonValue = []56 else:57 self.notify.error('No such style as: ' + str(self.style))58 optiondefs = (('buttonImageList', buttonImage, DGG.INITOPT),59 ('buttonTextList', buttonText, DGG.INITOPT),60 ('buttonValueList', buttonValue, DGG.INITOPT),61 ('buttonPadSF', 2.2, DGG.INITOPT),62 ('text_font', DGG.getDefaultFont(), None),63 ('text_wordwrap', 12, None),64 ('text_scale', 0.07, None),65 ('buttonSize', (-.05, 0.05, -.05, 0.05), None),66 ('button_pad', (0, 0), None),67 ('button_relief', None, None),68 ('button_text_pos', (0, -0.1), None),69 ('fadeScreen', 0.5, None),70 ('image_color', OTPGlobals.GlobalDialogColor, None))71 self.defineoptions(kw, optiondefs)72 DirectDialog.__init__(self, parent)73 self.initialiseoptions(OTPDialog)74 if buttons != None:75 buttons.removeNode()76 return77class GlobalDialog(OTPDialog):78 notify = DirectNotifyGlobal.directNotify.newCategory('GlobalDialog')79 def __init__(self, message = '', doneEvent = None, style = NoButtons, okButtonText = OTPLocalizer.DialogOK, cancelButtonText = OTPLocalizer.DialogCancel, **kw):80 if not hasattr(self, 'path'):81 self.path = 'phase_3/models/gui/dialog_box_buttons_gui'82 if doneEvent == None and style != NoButtons:83 self.notify.error('Boxes with buttons must specify a doneEvent.')84 self.__doneEvent = doneEvent85 if style == NoButtons:86 buttonText = []87 elif style == Acknowledge:88 buttonText = [okButtonText]89 elif style == CancelOnly:90 buttonText = [cancelButtonText]91 else:92 buttonText = [okButtonText, cancelButtonText]93 optiondefs = (('dialogName', 'globalDialog', DGG.INITOPT),94 ('buttonTextList', buttonText, DGG.INITOPT),95 ('text', message, None),96 ('command', self.handleButton, None))97 self.defineoptions(kw, optiondefs)98 OTPDialog.__init__(self, style=style)99 self.initialiseoptions(GlobalDialog)100 return101 def handleButton(self, value):102 if value == DGG.DIALOG_OK:103 self.doneStatus = 'ok'104 messenger.send(self.__doneEvent)105 elif value == DGG.DIALOG_CANCEL:106 self.doneStatus = 'cancel'...

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