def onGlobalObjectInitSettingsFinished(self, globalObject): self.layout() self._splitter.restoreState( Tc2Config.settingsValue(self.SettingsKeySplitterState, QtCore.QByteArray()).toByteArray() ) self._listWidget.setCurrentRow( Tc2Config.settingsValue(self.SettingsKeyCurrentSettingIndex, 0).toInt()[0] ) self._listWidget.setAlternatingRowColors(globalObject.settingsGlobal.alternatingRowColors()) globalObject.settingsGlobal.alternatingRowColorsChanged.connect(self._listWidget.setAlternatingRowColors)
def main(argv=None, run=True): argv = [] if argv is None else argv if '--config' in argv: i = argv.index('--config') del argv[i] try: fileName = argv[i] except IndexError: raise ValueError( 'Option --config present but no config file specified') else: del argv[i] if os.path.isfile(fileName) or os.path.islink(fileName): Tc2Config.setSettings( QtCore.QSettings(fileName, QtCore.QSettings.IniFormat)) else: raise ValueError('No such config file: %s' % fileName) application = QtGui.QApplication(argv) gui = Gui() gui.show() if run: application.exec_() else: return gui
def onInitSettings(self): self.layout() value = QtCore.Qt.Checked if Tc2Config.settingsValue(self.SettingsKeyAutoClosePopupNews, False).toBool() else QtCore.Qt.Unchecked self.checkAutoClosePopupNews.setCheckState(value) self.checkAutoClosePopupNews.stateChanged.connect( lambda value, self=self: self.setAutoClosePopupNews(self.checkAutoClosePopupNews.checkState() == QtCore.Qt.Checked) ) value = QtCore.Qt.Checked if Tc2Config.settingsValue(self.SettingsKeyAutoCloseTourneyRegistrationBoxes, False).toBool() else QtCore.Qt.Unchecked self.checkAutoCloseTourneyRegistrationBoxes.setCheckState(value) self.checkAutoCloseTourneyRegistrationBoxes.stateChanged.connect( lambda value, self=self: self.setAutoCloseTourneyRegistrationBoxes(self.checkAutoCloseTourneyRegistrationBoxes.checkState() == QtCore.Qt.Checked) ) value = QtCore.Qt.Checked if Tc2Config.settingsValue(self.SettingsKeyAutoCloseTableMessageBoxes, False).toBool() else QtCore.Qt.Unchecked self.checkAutoCloseTableMessageBoxes.setCheckState(value) self.checkAutoCloseTableMessageBoxes.stateChanged.connect( lambda value, self=self: self.setAutoCloseTableMessageBoxes(self.checkAutoCloseTableMessageBoxes.checkState() == QtCore.Qt.Checked) ) value = QtCore.Qt.Checked if Tc2Config.settingsValue(self.SettingsKeyAutoCloseLogin, False).toBool() else QtCore.Qt.Unchecked self.checkAutoCloselogin.setCheckState(value) self.checkAutoCloselogin.stateChanged.connect( lambda value, self=self: self.setAutoCloseLogin(self.checkAutoCloselogin.checkState() == QtCore.Qt.Checked) ) value = QtCore.Qt.Checked if Tc2Config.settingsValue(self.SettingsKeyMoveMouseToActiveTable, False).toBool() else QtCore.Qt.Unchecked self.checkMoveMouseToActiveTable.setCheckState(value) self.checkMoveMouseToActiveTable.stateChanged.connect( lambda value, self=self: self.setMoveMouseToActiveTable(self.checkMoveMouseToActiveTable.checkState() == QtCore.Qt.Checked) ) Tc2Config.globalObject.objectCreatedSettingsPokerStars.emit(self)
def onButtonBackupClicked(self, checked): dlg = QtGui.QFileDialog(self) dlg.setWindowTitle('Backup tableCrab To Config File..') dlg.setFileMode(dlg.AnyFile) dlg.setAcceptMode(dlg.AcceptSave) dlg.setConfirmOverwrite(True) filters = QtCore.QStringList() filters << 'Config Files (*.ini *.cfg)' filters << 'All Files (*)' dlg.setNameFilters(filters) dlg.restoreState( Tc2Config.settingsValue(self.SettingsKeyDialogBackupState, QtCore.QByteArray()).toByteArray() ) result = dlg.exec_() Tc2Config.settingsSetValue(self.SettingsKeyDialogBackupState, dlg.saveState() ) if result != dlg.Accepted: return fileName = dlg.selectedFiles()[0] fileInfo = QtCore.QFileInfo(fileName) format = fileInfo.suffix().toLower() # default save format to to ".ini" if not format: fileName = fileName + '.ini' #NOTE: looks like Qt is only checking for write protect anything else may or may not pass ..and we don't get any IO errors # so we try in advance. obv there are still loopholes fp = None try: fp = open(fileName, 'w').close() except Exception, d: Tc2Config.msgWarning(self, 'Could Not Open Config File\n\n%s' % d) return
def onGlobalObjectInitSettingsFinished(self, globalObject): self._browser.setUrl(QtCore.QUrl('')) self._spinBox.valueChanged.connect(self.onSpinBoxValueChanged) self.setSideBarPosition( globalObject.settingsHandViewer.sideBarPosition()) globalObject.settingsHandViewer.sideBarPositionChanged.connect( self.setSideBarPosition) self.adjustActions() self._browserFrame.layout(globalObject.settingsGlobal.toolBarPosition( ) == Tc2Config.ToolBarPositionTop) self.layout() self._splitter.restoreState( Tc2Config.settingsValue(self.SettingsKeySplitterState, QtCore.QByteArray()).toByteArray()) globalObject.settingsGlobal.toolBarPositionChanged.connect( lambda position, frame=self._browserFrame: frame.layout( toolBarTop=position == Tc2Config.ToolBarPositionTop)) self._toolBar.setZoomSteps( globalObject.settingsGlobal.webViewZoomSteps()) globalObject.settingsGlobal.webViewZoomStepsChanged.connect( self._toolBar.setZoomSteps) value, ok = Tc2Config.settingsValue( self.SettingsKeyZoomFactor, Browser.BrowserToolBar.ZoomFactorDefault).toDouble() if ok: self._toolBar.setZoomFactor(value) value, ok = Tc2Config.settingsValue(self.SettingsKeySideBarCurrent, 0).toInt() if ok: self.sideBarContainer.setCurrentIndex(value)
def setFixedFont(self, value): Tc2Config.settingsSetValue(self.SettingsKeyFontFixed, value.toString()) # adjust WeKit fixed font settings = QtWebKit.QWebSettings.globalSettings() settings.setFontFamily(settings.FixedFont, value.family()) settings.setFontSize(settings.DefaultFixedFontSize, value.pointSize()) self.fixedFontChanged.emit(value)
def onLabelFeedbackDoubleClicked(self): lastError = self._feedbackMessages[None] if lastError: dlg = Tc2DialogException.DialogException(lastError, parent=self) dlg.restoreGeometry( Tc2Config.settingsValue(self.SettingsKeyDialogExceptionGeometry, QtCore.QByteArray()).toByteArray()) dlg.exec_() Tc2Config.settingsSetValue(self.SettingsKeyDialogExceptionGeometry, dlg.saveGeometry() )
def fromConfig(klass, settingsKey): id = None key = '' hotkeyName = '' baseValue = None multiplier = None id = Tc2Config.settingsValue( (settingsKey, 'ID'), '').toString() if id != klass.id(): return None #TODO: rename to "Key" key = Tc2Config.settingsValue( (settingsKey, 'Hotkey'), Tc2Config.KeyNone).toString() if key == Tc2Config.KeyNone: return None hotkeyName = Tc2Config.settingsValue( (settingsKey, 'HotkeyName'), '').toString() if klass.HasMultiplier: multiplier, ok = Tc2Config.settingsValue( (settingsKey, 'Multiplier'), -1.0).toDouble() if not ok: return None if multiplier > klass.MultiplierMax or multiplier < klass.MultiplierMin: return None if klass.HasBaseValue: baseValue = Tc2Config.settingsValue( (settingsKey, 'BaseValue'), '').toString() if baseValue not in klass.BaseValues: return None return klass(key=key, hotkeyName=hotkeyName, baseValue=baseValue, multiplier=multiplier)
def layout(self): grid = Tc2Config.GridBox(self) grid.col(self.buttonBox) grid.row() grid.col(Tc2Config.HLine(self)) grid.row() grid.col(self.edit)
def onInitSettings(self): self.layout() value = Tc2Config.settingsValue(self.SettingsKeyProxyHostName, '').toString() self.editProxyHostName.setText(value) self.editProxyHostName.textChanged.connect(self.setProxyHostName) value, ok = Tc2Config.settingsValue(self.SettingsKeyProxyPort, '').toInt() if not ok or value > Tc2Config.MaxProxyPort or value < Tc2Config.MinProxyPort: value = Tc2Config.DefaultProxyPort self.spinProxyPort.setValue(value) self.spinProxyPort.valueChanged.connect(self.setProxyPort) value = Tc2Config.settingsValue(self.SettingsKeyProxyUserName, '').toString() self.editProxyUserName.setText(value) self.editProxyUserName.textChanged.connect(self.setProxyUserName) self.editProxyPassword.textChanged.connect(self.setProxyPassword) value, ok = Tc2Config.settingsValue(self.SettingsKeyFetchTimeout, '').toDouble() if not ok or value > Tc2Config.MaxFetchTimeout or value < Tc2Config.MinFetchTimeout: value = Tc2Config.DefaultFetchTimeout self.spinFetchTimeout.setValue(value) self.spinFetchTimeout.valueChanged.connect(self.setFetchTimeout) Tc2Config.globalObject.objectCreatedSettingsNetwork.emit(self)
def layout(self): grid = Tc2Config.GridBox(self) grid.col(self.labelAction).col(self.editAction) grid.row() grid.col(self.labelHotkey).col(self.hotkeyBox) grid.row() grid.col(self.labelHotkeyName).col(self.editHotkeyName) grid.row() grid.col(self.labelBaseValue).col(self.comboBaseValue) grid.row() grid.col(self.labelMultiplier).col(self.spinMultiplier) grid.row() grid.col(Tc2Config.VStretch()) grid.row() grid.col(Tc2Config.HLine(self), colspan=2) grid.row() grid.col(self.buttonBox, colspan=2) # adjust tab order Tc2Config.setTabOrder( self, self.buttonBox, self.hotkeyBox, self.editHotkeyName, self.comboBaseValue, self.spinMultiplier, )
def layout(self): grid = Tc2Config.GridBox(self) grid.col(self.flopsterWidget) grid.row() grid.col(Tc2Config.HLine(self), colspan=3) grid.row() grid.col(self.buttonBox, colspan=3)
def onGlobalObjectInitSettingsFinished(self, globalObject): self.layout() vipStatus = Tc2Config.settingsValue(self.SettingsKeyVIPStatus, '').toString() index = self.comboVIPStatus.findText(vipStatus, QtCore.Qt.MatchExactly) if index >= 0: self.comboVIPStatus.setCurrentIndex(index) self.comboVIPStatus.currentIndexChanged.connect(self.onComboVIPStatusCurrentIndexChanged) gameType = Tc2Config.settingsValue(self.SettingsKeyGameType, '').toString() index = self.comboGameType.findText(gameType, QtCore.Qt.MatchExactly) if index >= 0: self.comboGameType.setCurrentIndex(index) self.comboGameType.currentIndexChanged.connect(self.onComboGameTypeCurrentIndexChanged) currency = Tc2Config.settingsValue(self.SettingsKeyCurrency, '').toString() index = self.comboCurrency.findText(currency, QtCore.Qt.MatchExactly) if index >= 0: self.comboCurrency.setCurrentIndex(index) self.comboCurrency.currentIndexChanged.connect(self.onComboCurrencyCurrentIndexChanged) conversion = Tc2Config.settingsValue(self.SettingsKeyConversion, '').toString() if conversion == 'FPPs': self.radioFPPs.setChecked(True) else: self.radioCash.setChecked(True)
def grabHand(self): #NOTE: we could be faced with an arbitrary windowat this point or an inavlid handle if Tc2Win32.windowGetTextLength( self._hwndEdit) > Tc2Config.MaxHandHistoryText: #TODO: have to find a better way to give feedback on what hapens on hand grabbing Tc2Config.globalObject.feedbackMessage.emit( self.parent(), 'Hand text too long') return data = Tc2Win32.windowGetText(self._hwndEdit, maxSize=Tc2Config.MaxHandHistoryText) if data and data != self._data: self._data = data handData = '' hand = Tc2HandTypes.PokerHand() #TODO: very sloppy test to minimize risk we are grabbing 'show summary only' in instant hand history if not ('*** HOLE CARDS ***' in data or '*** 3rd STREET ***' in data or '*** DEALING HANDS ***' in data): pass else: #NOTE: we are let Tc2Config handle errors because we are maybe working with arbitrary data # from an unknown window try: hand = self._handParser.parse(data) except: Tc2Config.handleException('\n' + data) else: handData = self._handFormatter.dump(hand) self.siteHandler.handGrabbed.emit(hand, handData)
def setFixedFont(self, value): Tc2Config.settingsSetValue(self.SettingsKeyFontFixed, value.toString()) # adjust WeKit fixed font settings = QtWebKit.QWebSettings.globalSettings() settings.setFontFamily(settings.FixedFont, value.family() ) settings.setFontSize(settings.DefaultFixedFontSize, value.pointSize() ) self.fixedFontChanged.emit(value)
def fromConfig(klass, settingsKey): id = None key = '' hotkeyName = '' baseValue = None multiplier = None id = Tc2Config.settingsValue((settingsKey, 'ID'), '').toString() if id != klass.id(): return None #TODO: rename to "Key" key = Tc2Config.settingsValue((settingsKey, 'Hotkey'), Tc2Config.KeyNone).toString() if key == Tc2Config.KeyNone: return None hotkeyName = Tc2Config.settingsValue((settingsKey, 'HotkeyName'), '').toString() if klass.HasMultiplier: multiplier, ok = Tc2Config.settingsValue( (settingsKey, 'Multiplier'), -1.0).toDouble() if not ok: return None if multiplier > klass.MultiplierMax or multiplier < klass.MultiplierMin: return None if klass.HasBaseValue: baseValue = Tc2Config.settingsValue((settingsKey, 'BaseValue'), '').toString() if baseValue not in klass.BaseValues: return None return klass(key=key, hotkeyName=hotkeyName, baseValue=baseValue, multiplier=multiplier)
def onButtonBackupClicked(self, checked): dlg = QtGui.QFileDialog(self) dlg.setWindowTitle('Backup tableCrab To Config File..') dlg.setFileMode(dlg.AnyFile) dlg.setAcceptMode(dlg.AcceptSave) dlg.setConfirmOverwrite(True) filters = QtCore.QStringList() filters << 'Config Files (*.ini *.cfg)' filters << 'All Files (*)' dlg.setNameFilters(filters) dlg.restoreState( Tc2Config.settingsValue(self.SettingsKeyDialogBackupState, QtCore.QByteArray()).toByteArray()) result = dlg.exec_() Tc2Config.settingsSetValue(self.SettingsKeyDialogBackupState, dlg.saveState()) if result != dlg.Accepted: return fileName = dlg.selectedFiles()[0] fileInfo = QtCore.QFileInfo(fileName) format = fileInfo.suffix().toLower() # default save format to to ".ini" if not format: fileName = fileName + '.ini' #NOTE: looks like Qt is only checking for write protect anything else may or may not pass ..and we don't get any IO errors # so we try in advance. obv there are still loopholes fp = None try: fp = open(fileName, 'w').close() except Exception, d: Tc2Config.msgWarning(self, 'Could Not Open Config File\n\n%s' % d) return
def setStyleSheet(self, value): if Tc2Config.MaxHandStyleSheet >= 0: if value.length() > Tc2Config.MaxHandStyleSheet: Tc2Config.globalObject.feedback.emit(self, 'Style sheet too big -- maximum Is %s chars' % Tc2Config.MaxHandStyleSheet) return Tc2Config.globalObject.feedback.emit(self, '') Tc2Config.settingsSetValue(self.SettingsKeyStyleSheet, value) self.styleSheetChanged.emit(value)
def toConfig(self, key): Tc2Config.settingsSetValue( (key, 'ID'), self.id() ) Tc2Config.settingsSetValue( (key, 'Name'), self.name() ) Tc2Config.settingsSetValue( (key, 'Size'), self.size) Tc2Config.settingsSetValue( (key, 'ItemIsExpanded'), self.itemIsExpanded) for pointName, point in self.points.items(): Tc2Config.settingsSetValue( (key, pointName), point) return True
def layout(self): #TODO: how to adjust tool bar position acc to SettingsGlobal? grid = Tc2Config.GridBox(self) grid.col(self.frameHelp) grid.row() grid.col(Tc2Config.HLine(self)) grid.row() grid.col(self.buttonBox)
def onEditTextChanged(self): text = self.edit.toPlainText() if Tc2Config.MaxHandStyleSheet >= 0: if text.length() > Tc2Config.MaxHandStyleSheet: Tc2Config.globalObject.feedback.emit(self, 'Style sheet too big -- maximum Is %s chars' % Tc2Config.MaxHandStyleSheet) return Tc2Config.globalObject.feedback.emit(self, '') Tc2Config.settingsSetValue(self.SettingsKeyStyleSheet, text)
def onCloseEvent(self, event): Tc2Config.settingsSetValue(self.SettingsKeySplitterState, self.splitter.saveState() ) topicsCollapsed = [] for item in Tc2Config.TreeWidgetItemIterator(self.tree): if not item.isExpanded(): topic = item.data(0, QtCore.Qt.UserRole).toString() topicsCollapsed.append(topic) Tc2Config.settingsSetValue(self.SettingsKeyTopicsCollapsed, topicsCollapsed)
def layout(self): grid = Tc2Config.GridBox(self) grid.col(self.flopEvalWidget) grid.row() grid.col(Tc2Config.HLine(self)) grid.row() grid.col(self.buttonBox)
def setStyleSheet(self, value): if Tc2Config.MaxHandStyleSheet >= 0: if len(value) > Tc2Config.MaxHandStyleSheet: Tc2Config.globalObject.feedback.emit(self, 'Style sheet too big -- maximum Is %s chars' % Tc2Config.MaxHandStyleSheet) return Tc2Config.globalObject.feedback.emit(self, '') Tc2Config.settingsSetValue(self.SettingsKeyStyleSheet, value) formatter = Tc2Config.handFormatter('HtmlTabular') formatter.setStyleSheet(value)
def toConfig(self, key): Tc2Config.settingsSetValue((key, 'ID'), self.id()) Tc2Config.settingsSetValue((key, 'Name'), self.name()) Tc2Config.settingsSetValue((key, 'Size'), self.size) Tc2Config.settingsSetValue((key, 'ItemIsExpanded'), self.itemIsExpanded) for pointName, point in self.points.items(): Tc2Config.settingsSetValue((key, pointName), point) return True
def setGuiStyle(self, value): style = QtGui.QStyleFactory.create(value) #TODO: we currently set no palette. QStyle docs say palette should not be set # for styles that use system defaults, but there seems to be no way to find out # so ..and where to find some kind of default palette. ##QtGui.qApp.setPalette(style.standardPalette()) QtGui.qApp.setStyle(style) Tc2Config.settingsSetValue(self.SettingsKeyGuiStyle, value) self.guiStyleChanged.emit(value)
def onActionValueChanged(self, edit, text): formatter = Tc2Config.handFormatter('HtmlTabular') if edit.isPrefix: formatter.setActionPrefix(edit.action, text) settingsKey = self.HandActionsMapping[edit.action][1] else: formatter.setActionPostfix(edit.action, text) settingsKey = self.HandActionsMapping[edit.action][2] Tc2Config.settingsSetValue(settingsKey, text)
def onItemSelectionChanged(self): items = self.tree.selectedItems() if not items: return item = items[0] topic = item.data(0, QtCore.Qt.UserRole).toString() url = QtCore.QUrl('%s.html' % topic) self.browser.setUrl(url) if self._settingsPersistent: Tc2Config.settingsSetValue(self.SettingsKeyHelpTopic, topic)
def toConfig(self, settingsKey): Tc2Config.settingsSetValue( (settingsKey, 'ID'), self.id() ) #TODO: rename to "Key" Tc2Config.settingsSetValue((settingsKey, 'Hotkey'), self.key() ) Tc2Config.settingsSetValue( (settingsKey, 'HotkeyName'), self.hotkeyName() ) if self.HasMultiplier: Tc2Config.settingsSetValue( (settingsKey, 'Multiplier'), self.multiplier()) if self.HasBaseValue: Tc2Config.settingsSetValue( (settingsKey, 'BaseValue'), self.baseValue()) return True
def closeEvent(self, event): self.singleApplication.close() Tc2Config.globalObject.closeEvent.emit(event) Tc2Config.globalObject.mouseHook.stop() Tc2Config.globalObject.keyboardHook.stop() Tc2Config.globalObject.windowHook.stop() Tc2Config.settingsSetValue(self.SettingsKeyTabCurrent, self._tabWidget.currentIndex()) Tc2Config.settingsSetValue(self.SettingsKeyGeometry, self.saveGeometry() ) return QtGui.QMainWindow.closeEvent(self, event)
def setGuiFont(self, value): Tc2Config.settingsSetValue(self.SettingsKeyGuiFont, value.toString()) QtGui.qApp.setFont(value) #NOTE: have to re-set style to make font changes work as expected self.setGuiStyle(self.guiStyle()) # take QWebKit StandardFont from application font settings = QtWebKit.QWebSettings.globalSettings() settings.setFontFamily(settings.StandardFont, value.family()) settings.setFontSize(settings.DefaultFontSize, value.pointSize()) self.guiFontChanged.emit(value)
def setTopic(self, topic): for item in Tc2Config.TreeWidgetItemIterator(self.tree): myTopic = item.data(0, QtCore.Qt.UserRole).toString() if myTopic == topic: self.tree.setCurrentItem(item) break else: raise ValueError('no such topic: %s' % topic) if not self._settingsPersistent: Tc2Config.settingsSetValue(self.SettingsKeyHelpTopic, topic)
def layout(self): grid = Tc2Config.GridBox(self) grid.addWidget(self.edit, 0, 0) n = 1 if self.labelPixmap is not None: grid.addWidget(self.labelPixmapName, 1, 0) grid.addWidget(self.labelPixmap, 2, 0) n = 3 grid.addWidget(Tc2Config.HLine(self), n + 1, 0) grid.addWidget(self.buttonBox, n + 2, 0)
def setGuiFont(self, value): Tc2Config.settingsSetValue(self.SettingsKeyGuiFont, value.toString()) QtGui.qApp.setFont(value) #NOTE: have to re-set style to make font changes work as expected self.setGuiStyle(self.guiStyle()) # take QWebKit StandardFont from application font settings = QtWebKit.QWebSettings.globalSettings() settings.setFontFamily(settings.StandardFont, value.family() ) settings.setFontSize(settings.DefaultFontSize, value.pointSize() ) self.guiFontChanged.emit(value)
def layout(self): grid = Tc2Config.GridBox(self._frame) grid.setContentsMargins(0, 0, 0, 0) grid.col(self._spinBox) grid.row() grid.col(self._browserFrame) self.sideBarContainer.layout() grid = Tc2Config.GridBox(self) grid.col(self._splitter)
def layout(self): grid = Tc2Config.GridBox(self) grid.col(self.labelVIPStatus).col(self.comboVIPStatus).col(Tc2Config.HStretch()) grid.row() grid.col(self.labelGameType).col(self.comboGameType).col(Tc2Config.HStretch()) grid.row() grid.col(self.labelCurrency).col(self.comboCurrency).col(Tc2Config.HStretch()) grid.row() grid.col(self.radioCash) grid.row() grid.col(self.radioFPPs) grid.row() grid.col(Tc2Config.HLine(self), colspan=3) grid.row() grid.col(self.labelAmount).col(self.editAmount).col(Tc2Config.HStretch()) grid.row() grid.col(self.buttonCalculate).col(self.editResult).col(Tc2Config.HStretch()) grid.row() grid.col(Tc2Config.HLine(self), colspan=3) grid.row() grid.col(self.editCache, colspan=3) grid.row() grid.col(self.buttonClearCache) grid.row() grid.col(Tc2Config.HLine(self), colspan=3) grid.row() grid.col(self.buttonBox, colspan=3)
def layout(self): grid = Tc2Config.GridBox(self) grid.col(Tc2Config.HLine(self), colspan=3) grid.row() grid.col(self.checkIsOn).col(Tc2Config.HStretch()) grid.row() grid.col(self.labelSpeed).col(self.spinSpeed).col(Tc2Config.HStretch()) grid.row() grid.col(self.labelPrecission).col(self.spinPrecission).col( Tc2Config.HStretch()) grid.row() grid.col(self.labelIncrement).col(self.spinIncrement).col( Tc2Config.HStretch()) grid.row() grid.col(self.checkRandomMode).col(Tc2Config.HStretch()) grid.row() grid.col(self.groupForegroundColor.label()).col( self.groupForegroundColor.colorButton()).col( self.groupForegroundColor.resetButton()) grid.row() grid.col(self.groupBackgroundColor.label()).col( self.groupBackgroundColor.colorButton()).col( self.groupBackgroundColor.resetButton()) grid.row() grid.col(Tc2Config.VStretch()) grid.row() grid.col(Tc2Config.HLine(self), colspan=3) grid.row() grid.col(self.buttonBox, colspan=3)
def onLabelFeedbackDoubleClicked(self): lastError = self._feedbackMessages[None] if lastError: dlg = Tc2DialogException.DialogException(lastError, parent=self) dlg.restoreGeometry( Tc2Config.settingsValue( self.SettingsKeyDialogExceptionGeometry, QtCore.QByteArray()).toByteArray()) dlg.exec_() Tc2Config.settingsSetValue(self.SettingsKeyDialogExceptionGeometry, dlg.saveGeometry())
def setStyleSheet(self, value): if Tc2Config.MaxHandStyleSheet >= 0: if len(value) > Tc2Config.MaxHandStyleSheet: Tc2Config.globalObject.feedback.emit( self, 'Style sheet too big -- maximum Is %s chars' % Tc2Config.MaxHandStyleSheet) return Tc2Config.globalObject.feedback.emit(self, '') Tc2Config.settingsSetValue(self.SettingsKeyStyleSheet, value) formatter = Tc2Config.handFormatter('HtmlTabular') formatter.setStyleSheet(value)
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 onEditCardsReturnPressed(self): text = self.editCards.text().toUtf8() text = unicode(text, 'utf-8') cards = [i.strip() for i in text.split(',')] try: cards = [PokerTools.Card(i) for i in cards] except ValueError: Tc2Config.msgWarning(self, 'Invalid cards') return #NOTE: we don't care about duplicate cards here. ok? self.setCards(cards)
def setBackgroundImage(self, fileName, pixmap): if fileName is not None: fileInfo = QtCore.QFileInfo(fileName) imageName = fileInfo.fileName() imageName = Tc2Config.truncateString(imageName, Tc2Config.MaxDisplayFileName) Tc2Config.settingsSetValue(self.SettingsKeyBackgroundImage, fileName) self.buttonBackgroundImage.setText(imageName) else: Tc2Config.settingsSetValue(self.SettingsKeyBackgroundImage, '') self.buttonBackgroundImage.setText('...') self._backgroundImage = pixmap self.backgroundImageChanged.emit(pixmap)
def handleInputEvent(self, hwnd, hotkey, inputEvent): if Tc2Win32.windowIsSameProcess(hwnd, self._hwndMain): return True if hotkey.id() == Tc2ConfigHotkeys.HotkeyScreenshot.id(): if inputEvent.keyIsDown: Tc2Config.widgetScreenshot(hwnd) Tc2Config.globalObject.feedbackMessage.emit(hotkey.action() ) inputEvent.accept = True return True #TODO: implement hide card protector if card protector has focus. we'd have # to translate Qt keyboard events to input events to do so. too much trouble for now. elif hotkey.id() == Tc2ConfigHotkeys.HotkeyCardProtector.id(): self._widgetCardProtector.handleInputEvent(hwnd, hotkey, inputEvent) return True
def layout(self): grid = Tc2Config.GridBox(self) grid.col(self.toolBar) grid.row() grid.col(self.splitterSettings) grid.row() grid.col(Tc2Config.HLine()) grid.row() grid.col(self.buttonBox) grid = Tc2Config.GridBox(self.frameSettings) grid.col(self.checkBoxChars).col(self.editChars) grid.row() grid.col(self.checkBoxGraylevel).col(self.spinGrayLevel) grid.row() grid.col(self.checkBoxDustSize).col(self.spinDustSize) grid.row() grid.col(self.checkBoxWordSpacing).col(self.spinWordSpacing) grid.row() grid.col(self.checkBoxCertainty).col(self.spinCertainty) grid.row() grid.col(Tc2Config.HLine(), colspan=2) grid.row() grid.col(self.checkBoxInvertImage) grid.row() grid.col(self.checkBoxAnalyzeLayout) grid.row() grid.col(self.checkBoxContextCorrection) grid.row() grid.col(self.checkBoxCompareUnknownChars) grid.row() grid.col(self.checkBoxDivideOverlappingChars) grid.row() grid.col(self.checkBoxPackChars) grid.row() grid.col(Tc2Config.HLine(), colspan=2) grid.row() grid.col(self.checkBoxOutputType).col(self.comboOutputType) grid.row() grid.col(self.checkBoxOutputPattern, colspan=2) grid.row() grid.col(self.editOutputPattern, colspan=2) self.restoreGeometry( Tc2Config.settingsValue(self.SettingsKeyGeometry, QtCore.QByteArray()).toByteArray()) self.splitterSettings.restoreState( Tc2Config.settingsValue(self.SettingsKeySplitterSettingsState, QtCore.QByteArray()).toByteArray() ) self.splitterImage.restoreState( Tc2Config.settingsValue(self.SettingsKeySplitterImageState, QtCore.QByteArray()).toByteArray() ) self.splitterOutput.restoreState( Tc2Config.settingsValue(self.SettingsKeySplitterOutputState, QtCore.QByteArray()).toByteArray() )
def hideEvent(self, event): Tc2Config.settingsSetValue(self.SettingsKeySplitterSettingsState, self.splitterSettings.saveState()) Tc2Config.settingsSetValue(self.SettingsKeySplitterImageState, self.splitterImage.saveState()) Tc2Config.settingsSetValue(self.SettingsKeySplitterOutputState, self.splitterOutput.saveState()) Tc2Config.settingsSetValue(self.SettingsKeyGeometry, self.saveGeometry() ) QtGui.QDialog.hideEvent(self, event)
def onEncryptDirectory(self, checked=False): dlg = QtGui.QFileDialog(self) dlg.setWindowTitle('Chosse directory to enecrypt ini files..') dlg.setFileMode(dlg.Directory) dlg.restoreState( Tc2Config.settingsValue(self.SettingsKeyDialogEncryptState, QtCore.QByteArray()).toByteArray() ) if dlg.exec_() == dlg.Rejected: return Tc2Config.settingsSetValue(self.SettingsKeyDialogEncryptState, dlg.saveState() ) directory = dlg.directory().canonicalPath() directory = directory.toUtf8() directory = unicode(directory, 'utf-8') self.lastDirectory = directory self.onEncrypt() self.adjustActions()
def onInitSettings(self): self.layout() formatter = Tc2Config.handFormatter('HtmlTabular') #NOTE: style sheet can not be '' #NOTE: have to connect before setText so we can catch MaxCharsExceeded value = Tc2Config.settingsValue(self.SettingsKeyStyleSheet, '').toString() if not value: value = formatter.styleSheet() self.edit.setPlainText(value) formatter.setStyleSheet(value) self.edit.textChanged.connect( lambda self=self: self.setStyleSheet(self.edit.toPlainText()) ) Tc2Config.globalObject.objectCreatedSettingsHandViewerStyleSheet.emit(self)
def onOpen(self, checked): fileName = Tc2Config.dlgOpenSaveFile( parent=self, openFile=True, title='Open Style Sheet..', fileFilters=('Style sheets (*.css)', 'All Files (*)'), #TODO: rename to HandViewerStyleSheet settingsKey=self.SettingsKeyDialogOpenState, ) if fileName is None: return fp = None try: fp = open(fileName, 'r') except Exception, d: Tc2Config.msgWarning(self, 'Could Not Open Style sheet\n\n%s' % d)