def __init__(self, parent=None): QtGui.QFrame.__init__(self, parent) self.labelPrefix = QtGui.QLabel('<i>Prefix</i>', self) self.labelAction = QtGui.QLabel('<i>Action</i>', self) self.labelPostfix = QtGui.QLabel('<i>Postfix</i>', self) self.actionWidgets = {} formatter = Tc2Config.handFormatter('HtmlTabular') for i, action in enumerate(formatter.listHandActions()): prefix, postfix = formatter.actionPrefix(action), formatter.actionPostfix(action) editPrefix = self.ActionLineEdit(self, action, isPrefix=True) editPrefix.setMaxLength(Tc2Config.MaxHandGrabberPrefix) labelAction = QtGui.QLabel('<i>%s</i>' % self.HandActionsMapping[action][0], self) editPostfix = None if postfix is not None: editPostfix = self.ActionLineEdit(self, action, isPrefix=False) editPostfix.setMaxLength(Tc2Config.MaxHandGrabberPrefix) self.actionWidgets[action] = {'EditPrefix': editPrefix, 'LabelAction': labelAction, 'EditPostfix': editPostfix, 'no': i} self.comboSideBarPosition = QtGui.QComboBox(self) self.comboSideBarPosition.addItems(Tc2Config.HandViewerSideBarPositions) self.labelSideBarPosition = QtGui.QLabel('&Side bar position:', self) self.labelSideBarPosition.setBuddy(self.comboSideBarPosition) self.comboDeckStyle = QtGui.QComboBox(self) self.comboDeckStyle.addItems(formatter.deckStyles()) self.labelDeckStyle = QtGui.QLabel('Deck st&yle:', self) self.labelDeckStyle.setBuddy(self.comboDeckStyle) self.spinMaxPlayerName = QtGui.QSpinBox(self) self.spinMaxPlayerName.setRange(Tc2Config.HandViewerMaxPlayerNameMin, Tc2Config.HandViewerMaxPlayerNameMax) self.labelMaxPlayerName = QtGui.QLabel('Ma&x Player Name:', self) self.labelMaxPlayerName.setBuddy(self.spinMaxPlayerName) self.checkNoFloatingPoint = QtGui.QCheckBox('No floating &Point', self) self.buttonBox = QtGui.QDialogButtonBox(self) self.buttonRestoreDefault = QtGui.QPushButton('Restore Default', self) self.buttonRestoreDefault.setToolTip('Restore Default (Ctrl+R)') self.buttonRestoreDefault.clicked.connect(self.onRestoreDefault) self.buttonBox.addButton(self.buttonRestoreDefault, self.buttonBox.ResetRole) action = QtGui.QAction(self) action.setShortcut(QtGui.QKeySequence('Ctrl+R') ) action.triggered.connect(self.onRestoreDefault) self.addAction(action) self.buttonHelp = QtGui.QPushButton('Help', self) self.buttonHelp.setToolTip('Help (F1)') self.buttonHelp.clicked.connect(self.onHelp) self.buttonBox.addButton(self.buttonHelp, self.buttonBox.HelpRole) action = QtGui.QAction(self) action.setShortcut(QtGui.QKeySequence('F1') ) action.triggered.connect(self.onHelp) self.addAction(action) Tc2Config.globalObject.initSettings.connect(self.onInitSettings)
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 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 onRestoreDefault(self, *args): formatter = Tc2Config.handFormatter('HtmlTabular') formatter.resetHandActions() for data in self.actionWidgets.values(): editPrefix = data['EditPrefix'] editPrefix.setText(formatter.actionPrefix(editPrefix.action)) editPrefix.editingFinished.emit() editPostfix = data['EditPostfix'] if editPostfix is not None: editPostfix.setText(formatter.actionPostfix(editPostfix.action)) editPostfix.editingFinished.emit()
def onInitSettings(self): self.layout() formatter = Tc2Config.handFormatter('HtmlTabular') value = Tc2Config.settingsValue(self.SettingsKeySideBarPosition, '').toString() if value not in Tc2Config.HandViewerSideBarPositions: value = Tc2Config.HandViewerSideBarPositionDefault self.comboSideBarPosition.setCurrentIndex( self.comboSideBarPosition.findText(value, QtCore.Qt.MatchExactly) ) #NOTE: pySlot decorator does not work as expected so we have to connect slot the old fashioned way self.connect(self.comboSideBarPosition, QtCore.SIGNAL('currentIndexChanged(QString)'), self.setSideBarPosition) value = Tc2Config.settingsValue(self.SettingsKeyDeckStyle, '').toString() if value in formatter.deckStyles(): value = unicode(value.toUtf8(), 'utf-8') else: value = Tc2Config.HandViewerDeckStyleDefault formatter.setDeckStyle(value) self.comboDeckStyle.setCurrentIndex( self.comboDeckStyle.findText(value, QtCore.Qt.MatchExactly) ) #NOTE: pySlot decorator does not work as expected so we have to connect slot the old fashioned way self.connect(self.comboDeckStyle, QtCore.SIGNAL('currentIndexChanged(QString)'), self.onDeckStyleChanged) value, ok = Tc2Config.settingsValue(self.SettingsKeyMaxPlayerName, Tc2Config.HandViewerMaxPlayerNameDefault).toInt() if not ok or value < Tc2Config.HandViewerMaxPlayerNameMin or value > Tc2Config.HandViewerMaxPlayerNameMax: value = Tc2Config.WebView.HandViewerMaxPlayerNameDefault formatter.setMaxPlayerName(value) self.spinMaxPlayerName.setValue(value) self.spinMaxPlayerName.valueChanged.connect(self.onMaxPlayerNameChanged) value = Tc2Config.settingsValue(self.SettingsKeyNoFloatingPoint, Tc2Config.HandViewerNoFloatingPointDefault).toBool() formatter.setNoFloatingPoint(value) self.checkNoFloatingPoint.setCheckState(value) self.checkNoFloatingPoint.stateChanged.connect(self.onNoFloatingPointChanged) for data in self.actionWidgets.values(): editPrefix = data['EditPrefix'] settingsKey = self.HandActionsMapping[editPrefix.action][1] text = Tc2Config.settingsValue(settingsKey, formatter.actionPrefix(editPrefix.action)).toString() editPrefix.setText(text) formatter.setActionPrefix(editPrefix.action, text) editPrefix.textChanged.connect( lambda text, edit=editPrefix: self.onActionValueChanged(edit, text) ) editPostfix = data['EditPostfix'] if editPostfix is not None: settingsKey = self.HandActionsMapping[editPrefix.action][2] text = Tc2Config.settingsValue(settingsKey, formatter.actionPostfix(editPostfix.action)).toString() editPostfix.setText(text) formatter.setActionPostfix(editPostfix.action, text) editPostfix.textChanged.connect( lambda text, edit=editPostfix: self.onActionValueChanged(edit, text) ) Tc2Config.globalObject.objectCreatedSettingsHandViewer.emit(self)
def onNetworkGetData(self, networkReply): url = networkReply.url() if url.scheme() == 'hand': handNo = int(url.path()[1:]) if handNo > 0: data = self.handHistoryFile[handNo -1] try: hand = self.handParser.parse(data) except: Tc2Config.handleException('\n' + data) #TODO: data = ? else: formatter = Tc2Config.handFormatter('HtmlTabular') data = formatter.dump(hand) self.sideBarContainer.handleHandSet(hand) networkReply.setData(data, 'text/html; charset=UTF-8')
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 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 __init__(self, *args, **kws): PokerStarsWindow.__init__(self, *args, **kws) self._timer = QtCore.QTimer(self.siteHandler) self._timer.setInterval(Tc2Config.HandGrabberTimeout * 1000) self._timer.timeout.connect(self.grabHand) #self._timer.setSingleShot(True) self._handParser = Tc2SitePokerStarsHandGrabber.HandParser() self._handFormatter = Tc2Config.handFormatter('HtmlTabular') self._data = '' self._hwndEdit = None for hwnd in Tc2Win32.windowChildren(self.hwnd): if Tc2Win32.windowGetClassName(hwnd) == self.WidgetClassName: self._hwndEdit = hwnd break if self._hwndEdit is None: try: raise ValueError('Instant hand history edit box not found') except: Tc2Config.handleException() else: self._timer.start()
def onDeckStyleChanged(self, value): Tc2Config.settingsSetValue(self.SettingsKeyDeckStyle, value) formatter = Tc2Config.handFormatter('HtmlTabular') formatter.setDeckStyle(unicode(value.toUtf8(), 'utf-8'))
def onInitSettings(self): self.layout() formatter = Tc2Config.handFormatter('HtmlTabular') value = Tc2Config.settingsValue(self.SettingsKeySideBarPosition, '').toString() if value not in Tc2Config.HandViewerSideBarPositions: value = Tc2Config.HandViewerSideBarPositionDefault self.comboSideBarPosition.setCurrentIndex( self.comboSideBarPosition.findText(value, QtCore.Qt.MatchExactly)) #NOTE: pySlot decorator does not work as expected so we have to connect slot the old fashioned way self.connect(self.comboSideBarPosition, QtCore.SIGNAL('currentIndexChanged(QString)'), self.setSideBarPosition) value = Tc2Config.settingsValue(self.SettingsKeyDeckStyle, '').toString() if value in formatter.deckStyles(): value = unicode(value.toUtf8(), 'utf-8') else: value = Tc2Config.HandViewerDeckStyleDefault formatter.setDeckStyle(value) self.comboDeckStyle.setCurrentIndex( self.comboDeckStyle.findText(value, QtCore.Qt.MatchExactly)) #NOTE: pySlot decorator does not work as expected so we have to connect slot the old fashioned way self.connect(self.comboDeckStyle, QtCore.SIGNAL('currentIndexChanged(QString)'), self.onDeckStyleChanged) value, ok = Tc2Config.settingsValue( self.SettingsKeyMaxPlayerName, Tc2Config.HandViewerMaxPlayerNameDefault).toInt() if not ok or value < Tc2Config.HandViewerMaxPlayerNameMin or value > Tc2Config.HandViewerMaxPlayerNameMax: value = Tc2Config.WebView.HandViewerMaxPlayerNameDefault formatter.setMaxPlayerName(value) self.spinMaxPlayerName.setValue(value) self.spinMaxPlayerName.valueChanged.connect( self.onMaxPlayerNameChanged) value = Tc2Config.settingsValue( self.SettingsKeyNoFloatingPoint, Tc2Config.HandViewerNoFloatingPointDefault).toBool() formatter.setNoFloatingPoint(value) self.checkNoFloatingPoint.setCheckState(value) self.checkNoFloatingPoint.stateChanged.connect( self.onNoFloatingPointChanged) for data in self.actionWidgets.values(): editPrefix = data['EditPrefix'] settingsKey = self.HandActionsMapping[editPrefix.action][1] text = Tc2Config.settingsValue( settingsKey, formatter.actionPrefix(editPrefix.action)).toString() editPrefix.setText(text) formatter.setActionPrefix(editPrefix.action, text) editPrefix.textChanged.connect(lambda text, edit=editPrefix: self. onActionValueChanged(edit, text)) editPostfix = data['EditPostfix'] if editPostfix is not None: settingsKey = self.HandActionsMapping[editPrefix.action][2] text = Tc2Config.settingsValue( settingsKey, formatter.actionPostfix(editPostfix.action)).toString() editPostfix.setText(text) formatter.setActionPostfix(editPostfix.action, text) editPostfix.textChanged.connect( lambda text, edit=editPostfix: self.onActionValueChanged( edit, text)) Tc2Config.globalObject.objectCreatedSettingsHandViewer.emit(self)
def handFromHtml(self, html): handFormatter = Tc2Config.handFormatter('HtmlTabular') hand = handFormatter.handFromHtml(html) return hand
def onMaxPlayerNameChanged(self, value): Tc2Config.settingsSetValue(self.SettingsKeyMaxPlayerName, value) formatter = Tc2Config.handFormatter('HtmlTabular') formatter.setMaxPlayerName(value)
def onNoFloatingPointChanged(self, state): flag = state == QtCore.Qt.Checked Tc2Config.settingsSetValue(self.SettingsKeyNoFloatingPoint, flag) formatter = Tc2Config.handFormatter('HtmlTabular') formatter.setNoFloatingPoint(flag)
def onRestoreDefault(self): formatter = Tc2Config.handFormatter('HtmlTabular') formatter.resetStyleSheet() self.edit.setPlainText(formatter.styleSheet())
def __init__(self, parent=None): QtGui.QFrame.__init__(self, parent) self.labelPrefix = QtGui.QLabel('<i>Prefix</i>', self) self.labelAction = QtGui.QLabel('<i>Action</i>', self) self.labelPostfix = QtGui.QLabel('<i>Postfix</i>', self) self.actionWidgets = {} formatter = Tc2Config.handFormatter('HtmlTabular') for i, action in enumerate(formatter.listHandActions()): prefix, postfix = formatter.actionPrefix( action), formatter.actionPostfix(action) editPrefix = self.ActionLineEdit(self, action, isPrefix=True) editPrefix.setMaxLength(Tc2Config.MaxHandGrabberPrefix) labelAction = QtGui.QLabel( '<i>%s</i>' % self.HandActionsMapping[action][0], self) editPostfix = None if postfix is not None: editPostfix = self.ActionLineEdit(self, action, isPrefix=False) editPostfix.setMaxLength(Tc2Config.MaxHandGrabberPrefix) self.actionWidgets[action] = { 'EditPrefix': editPrefix, 'LabelAction': labelAction, 'EditPostfix': editPostfix, 'no': i } self.comboSideBarPosition = QtGui.QComboBox(self) self.comboSideBarPosition.addItems( Tc2Config.HandViewerSideBarPositions) self.labelSideBarPosition = QtGui.QLabel('&Side bar position:', self) self.labelSideBarPosition.setBuddy(self.comboSideBarPosition) self.comboDeckStyle = QtGui.QComboBox(self) self.comboDeckStyle.addItems(formatter.deckStyles()) self.labelDeckStyle = QtGui.QLabel('Deck st&yle:', self) self.labelDeckStyle.setBuddy(self.comboDeckStyle) self.spinMaxPlayerName = QtGui.QSpinBox(self) self.spinMaxPlayerName.setRange(Tc2Config.HandViewerMaxPlayerNameMin, Tc2Config.HandViewerMaxPlayerNameMax) self.labelMaxPlayerName = QtGui.QLabel('Ma&x Player Name:', self) self.labelMaxPlayerName.setBuddy(self.spinMaxPlayerName) self.checkNoFloatingPoint = QtGui.QCheckBox('No floating &Point', self) self.buttonBox = QtGui.QDialogButtonBox(self) self.buttonRestoreDefault = QtGui.QPushButton('Restore Default', self) self.buttonRestoreDefault.setToolTip('Restore Default (Ctrl+R)') self.buttonRestoreDefault.clicked.connect(self.onRestoreDefault) self.buttonBox.addButton(self.buttonRestoreDefault, self.buttonBox.ResetRole) action = QtGui.QAction(self) action.setShortcut(QtGui.QKeySequence('Ctrl+R')) action.triggered.connect(self.onRestoreDefault) self.addAction(action) self.buttonHelp = QtGui.QPushButton('Help', self) self.buttonHelp.setToolTip('Help (F1)') self.buttonHelp.clicked.connect(self.onHelp) self.buttonBox.addButton(self.buttonHelp, self.buttonBox.HelpRole) action = QtGui.QAction(self) action.setShortcut(QtGui.QKeySequence('F1')) action.triggered.connect(self.onHelp) self.addAction(action) Tc2Config.globalObject.initSettings.connect(self.onInitSettings)