def handleBetPot(self, hotkey, template, inputEvent): data = self.readData() if not data: return if not data['hwndBetBox']: return if not data['betBoxIsVisible']: return pointTopLeft = template.points['PotTopLeft'] pointBottomRight = template.points['PotBottomRight'] if pointTopLeft == Tc2Config.PointNone: Tc2Config.globalObject.feedbackMessage.emit('%s: -- Point Pot Top Left Not Set -' % template.name() ) return if pointBottomRight == Tc2Config.PointNone: Tc2Config.globalObject.feedbackMessage.emit('%s: -- Point Pot Bottom Right Not Set -' % template.name() ) return # grab pot rect pixmap = QtGui.QPixmap.grabWindow(self.hwnd, pointTopLeft.x(), pointTopLeft.y(), pointBottomRight.x() - pointTopLeft.x(), pointBottomRight.y() - pointTopLeft.y(), ) pgmImage = gocr.ImagePGM.fromQPixmap(pixmap) # scan pot num, err = gocr.scanImage( pgmImage=pgmImage, chars='0-9,.', dustSize=0, outputType=gocr.OutputTypeFloat, outputPattern=self.PatPot, ) if num is None: # try again with inverted image num, err = gocr.scanImage( pgmImage=pgmImage, flagInvertImage=True, chars='0-9,.', dustSize=0, outputType=gocr.OutputTypeFloat, outputPattern=self.PatPot, ) if num is None: try: raise ValueError('Could not scan pot\n<image>%s</image>' % base64.b64encode(pgmImage.toString())) except: Tc2Config.handleException() Tc2Config.globalObject.feedbackMessage.emit('%s: Error - Could not scan pot' % hotkey.action() ) return newBet = hotkey.applyAction(inputEvent, blinds=(data['smallBlind'], data['bigBlind']), bet=num) if newBet is None: return Tc2Win32.windowSetText(data['hwndBetBox'], text=newBet, isUnicode=False) Tc2Config.globalObject.feedbackMessage.emit('%s - %s -- %s' % (template.name() , hotkey.action(), newBet) )
def onActionScanImageTriggered(self): pixmap = self.labelInputImage.pixmap() if pixmap.isNull(): raise ValueError('invalid or no pixmap') pgmImage = gocr.ImagePGM.fromQPixmap(pixmap) params = self.gocrParams() params['pgmImage'] = pgmImage params['outputFormat'] = gocr.OutputFormatUTF8 try: timeElapsed = time.time() out, err = gocr.scanImage(**params) timeElapsed = time.time() - timeElapsed except Exception, d: #TODO: how do we handle exceptions here? err = traceback.format_exc() out = '' timeElapsed = None
def handleBetPot(self, hotkey, template, inputEvent): data = self.readData() if not data: return if not data['hwndBetBox']: return if not data['betBoxIsVisible']: return pointTopLeft = template.points['PotTopLeft'] pointBottomRight = template.points['PotBottomRight'] if pointTopLeft == Tc2Config.PointNone: Tc2Config.globalObject.feedbackMessage.emit( '%s: -- Point Pot Top Left Not Set -' % template.name()) return if pointBottomRight == Tc2Config.PointNone: Tc2Config.globalObject.feedbackMessage.emit( '%s: -- Point Pot Bottom Right Not Set -' % template.name()) return # grab pot rect pixmap = QtGui.QPixmap.grabWindow( self.hwnd, pointTopLeft.x(), pointTopLeft.y(), pointBottomRight.x() - pointTopLeft.x(), pointBottomRight.y() - pointTopLeft.y(), ) pgmImage = gocr.ImagePGM.fromQPixmap(pixmap) # scan pot num, err = gocr.scanImage( pgmImage=pgmImage, chars='0-9,.', dustSize=0, outputType=gocr.OutputTypeFloat, outputPattern=self.PatPot, ) if num is None: # try again with inverted image num, err = gocr.scanImage( pgmImage=pgmImage, flagInvertImage=True, chars='0-9,.', dustSize=0, outputType=gocr.OutputTypeFloat, outputPattern=self.PatPot, ) if num is None: try: raise ValueError('Could not scan pot\n<image>%s</image>' % base64.b64encode(pgmImage.toString())) except: Tc2Config.handleException() Tc2Config.globalObject.feedbackMessage.emit( '%s: Error - Could not scan pot' % hotkey.action()) return newBet = hotkey.applyAction(inputEvent, blinds=(data['smallBlind'], data['bigBlind']), bet=num) if newBet is None: return Tc2Win32.windowSetText(data['hwndBetBox'], text=newBet, isUnicode=False) Tc2Config.globalObject.feedbackMessage.emit( '%s - %s -- %s' % (template.name(), hotkey.action(), newBet))