def analyze(self): # "RIFF" #!self.riffTag = util.getBytes(self.data, 0, 4) # riffSize = dataSize - 8 #!self.riffSize = util.getInt(self.data, 4) # "WAVE" #!self.waveTag = util.getBytes(self.data, 8, 4) # "fmt " #!self.fmtChunk = util.getBytes(self.data, 12, 4) # size of the format section self.fmtChunkSize = util.getInt(self.data, 16) # "data" #!self.dataChunk = util.getBytes(self.data, 20+self.fmtChunkSize, 4) # size of the data section self.dataChunkSize = util.getInt(self.data, 24 + self.fmtChunkSize) # "LIST" #!self.listTag = util.getBytes(self.data, 28+self.fmtChunkSize+self.dataChunkSize, 4) # size of list section (includes iname) #!self.listSize = util.getInt(self.data, 32+self.fmtChunkSize+self.dataChunkSize) # "INFO" #!self.infoTag = util.getBytes(self.data, 36+self.fmtChunkSize+self.dataChunkSize, 4) # "INAM" #!self.inamTag = util.getBytes(self.data, 40+self.fmtChunkSize+self.dataChunkSize, 4) # size of iname section self.inamSize = util.getInt( self.data, 44 + self.fmtChunkSize + self.dataChunkSize) # Name of impulse response self.name = util.getBytes(self.data, 48 + self.fmtChunkSize + self.dataChunkSize, self.inamSize) # Remove the trailing null byte when converting to a string self.nameStr = self.name.decode('utf-8')[:-1]
def analyze(self): self.device = util.getInt(self.data, 0) self.deviceVersion = util.getInt(self.data, 1 * util.intSize) # convert int to hex string gives version string without '.' and with trailing zeros: '2810000' verStr = "{:x}".format(int(self.deviceVersion / 0x10000)) self.deviceVersionStr = verStr[:1] + '.' + verStr[1:] self.backupDate = util.getInt(self.data, 4 * util.intSize) self.backupDateStr = time.asctime(time.localtime(self.backupDate))
def makeToolTipEvent(self, cell): event = Event() event.type = SWT.MouseHover event.widget = self.canvas bounds = cell.getBounds() event.x = util.getInt(bounds.x) + util.getInt(bounds.width) / 2 event.y = util.getInt(bounds.y) + util.getInt(bounds.height) / 2 return event
def addColouredRectangle(self, calls, colorText, rect, fontSize): # Find some text to apply it to, if we can for i, (text, x, y) in enumerate(calls): # Adding pixels to "user space units". Is this always allowed? if rect.contains(x, y) or rect.contains(x, y + fontSize): calls[i] = text + colorText, x, y return calls.append((colorText, util.getInt(rect.x), util.getInt(rect.y)))
def getCheckBoxCoordinates(self, row, col, painter, bounds): cell = self.widget.getCellByPosition(col, row) configRegistry = self.widget.getConfigRegistry() image = util.callPrivateMethod(painter, "getImage", [ cell, configRegistry ], [ ILayerCell, IConfigRegistry ]) imageBounds = image.getBounds() imageWidth = util.getInt(imageBounds.width) imageHeight = util.getInt(imageBounds.height) cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry) x = bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageWidth) + imageWidth / 2 y = bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageHeight) + imageHeight / 2 return x, y
def makeToolTipEvent(self, widgetOrItem): event = Event() event.type = SWT.MouseHover if isinstance(widgetOrItem, Item): event.widget = widgetOrItem.getParent() event.item = widgetOrItem bounds = widgetOrItem.getBounds() event.x = util.getInt(bounds.x) + util.getInt(bounds.width) / 2 event.y = util.getInt(bounds.y) + util.getInt(bounds.height) / 2 else: event.widget = widgetOrItem event.item = None event.x = -1 event.y = -1 return event
def setup(self): self.numPlayers = getInt("How many players? [min={}, max={}]".format( self.minPlayers, self.maxPlayers), min=self.minPlayers, max=self.maxPlayers) for i in range(self.numPlayers): self._createPlayer(i + 1)
def _getRemainingPoints(self, cid, cp): IDs = list(self.players.keys()) IDs.remove(cid) points = 0 for pid in IDs: player = self.players[pid] left = getInt("Piece values left for {}".format(player.getName()), zeroable=True) points += left cp.addScore(points + 25)
def analyzeFooter(self): # self.name = util.getBytes(self.footer, 0, util.sectionNameSize) # for i in range(util.sectionNameSize, self.footerSize, util.intSize): self.footerValues.append(util.getInt(self.footer, i)) # self.sectionOffset = self.footerValues[0] self.compressedSize = self.footerValues[2] self.compressed = (self.footerValues[4] > 0) self.uncompressedSize = self.footerValues[5]
def analyzeHXB(self, debug): # Diagnostic (IR lables only exist if loaded, SL00 always exists, rest depend on use) # IR section labeling from b'000I' to b'F70I' # self.footerOffset = util.getInt(self.data, util.footerOffsetLocation) self.footerSize = self.filesize - self.footerOffset if debug: print("footerOffset = {}".format(self.footerOffset)) print("footerSize = {}".format(self.footerSize)) # #!print((self.filesize - self.footerOffset)/util.footerSectionSize) # for footerSectionOffset in range(self.footerOffset, self.filesize, util.footerSectionSize): # Get the section s = section.Section(self.data, footerSectionOffset, util.footerSectionSize) self.sections.append(s) # if debug: print("{} {}".format(s.name, s.footerValues)) # If Section has an IR, append it to a list to simply code in hx-tool.py if s.ir != None: self.IRs.append(s.ir) elif s.setListName != None: self.setListNames.append(s.setListName) elif s.setList != None: self.setLists.append(s.setList) elif s.jsonGlobal != None: self.globalSettings = s.jsonGlobal elif s.deviceInfo != None: self.deviceInfo = s.deviceInfo elif s.description != None: self.description = s.description else: pass
def makeCall(self, desc, child): loc = child.getLocation() # x and y should be public fields, and are sometimes. In our tests, they are methods, for some unknown reason return desc, util.getInt(loc.x), util.getInt(loc.y)
if username and pw: try: sha256_password = sha256(pw.encode()).hexdigest() connection = db.connect('localhost', 'kpp1', 'mah9eiQu', '2021_kpp1') cursor = connection.cursor(db.cursors.DictCursor) cursor.execute( """SELECT * FROM runner WHERE username = %s""", (username)) if cursor.rowcount > 0: result = 'This username is already taken' else: # Take in current status if sent high_score = util.getInt('high_score', 0) curr_balance = util.getInt('curr_balance', 0) armour = util.getInt('armour', 0, 5) health_regen = util.getInt('health_regen', 0, 5) boost = util.getInt('boost', 0, 5) cursor.execute( """ INSERT INTO runner (username, pw, high_score, curr_balance, armour, health_regen, boost) VALUES (%s, %s, %s, %s, %s, %s, %s) """, (username, sha256_password, high_score, curr_balance, armour, health_regen, boost)) connection.commit() cookie = SimpleCookie()
def cellVisible(self, cell): bounds = cell.getBounds() return util.getInt(bounds.width) > 0 and util.getInt(bounds.height) > 0
def getCenterCoordinates(self, bounds): x = util.getInt(bounds.x) + util.getInt(bounds.width) / 2 y = util.getInt(bounds.y) + util.getInt(bounds.height) / 2 return x, y
def nextTurn(self): super().nextTurn() # Stop if a player has reached the end game points and all # players have played their turn. if self._checkWinner(): return newRound = False curPlayer = self.players[self.curid] print("\n=== Turn {}: {} (#{}) ===".format(self.turn, curPlayer.getName(), self.curid)) while True: print( "\n[T]ake (-5), [C]an't (-10), [P]lay, [S]ummary, [E]nd, [?] Help", end=" ") data = input(CONSOLE).lower() if data not in ["t", "c", "p", "s", "e", "?"]: continue if data == "t": curPlayer.addScore(-5) continue elif data == "c": curPlayer.addScore(-10) break elif data == "p": score = getInt("How many points was played?", zeroable=True) while True: print( "[R]ound, [P]ass, [B]ridge (+40), [H]exagon (+50), [?] Help", end=" ") data = input(CONSOLE).lower() if data not in ["b", "h", "r", "p", "?"]: continue if data == "r": self._getRemainingPoints(self.curid, curPlayer) newRound = True elif data == "b": score += 40 continue elif data == "h": score += 50 continue elif data == "?": print("\n[R]ound won\n" "[P]ass turn\n" "Made [B]ridge (+40)\n" "Made [H]exagon (+50)\n") continue break curPlayer.addScore(score) if newRound: self._resetTurns() self._printSummary() break elif data == "b": curPlayer.addScore(40) continue elif data == "k": curPlayer.addScore(50) continue elif data == "s": self._printSummary() elif data == "e": self._setFinished() break elif data == "?": print("\n[T]ake piece (-5)\n" "[C]an't play piece (-10)\n" "[P]lay piece\n" "[S]ummary\n" "[E]nd game") continue self.curid += 1 if self._checkWinner(): return if newRound or self.curid > self.numPlayers: self.curid = 1
def setup(self): super().setup() self.endScore = getInt("How many points to win?", default=400)
def clickOnCenter(self, row, col, clickCount, button): bounds = self.widget.getBoundsByPosition(col, row) x = util.getInt(bounds.x) + util.getInt(bounds.width) / 2 y = util.getInt(bounds.y) + util.getInt(bounds.height) / 2 displayLoc = simulator.runOnUIThread(self.display.map, self.widget, None, x, y) self.eventPoster.moveClickAndReturn(displayLoc.x, displayLoc.y, count=clickCount, button=button)
def checkRowInViewport(self, row): clientAreaHeight = simulator.runOnUIThread(self.widget.getClientArea).height bounds = simulator.runOnUIThread(self.widget.getBoundsByPosition, 0, row) y = util.getInt(bounds.y) + util.getInt(bounds.height) / 2 if y > clientAreaHeight: raise UseCaseScriptError, "Could not select row, it is outside the viewport"