def __init__(self): SelectRuleset.__init__(self) Players.load() decorateWindow(self, m18n('Select four players')) self.names = None self.nameWidgets = [] for idx, wind in enumerate(Wind.all4): cbName = QComboBox() cbName.manualSelect = False # increase width, we want to see the full window title cbName.setMinimumWidth(350) # is this good for all platforms? cbName.addItems(list(Players.humanNames.values())) self.grid.addWidget(cbName, idx + 1, 1) self.nameWidgets.append(cbName) self.grid.addWidget(WindLabel(wind), idx + 1, 0) cbName.currentIndexChanged.connect(self.slotValidate) query = Query( "select p0,p1,p2,p3 from game where seed is null and game.id = (select max(id) from game)") if len(query.records): with BlockSignals(self.nameWidgets): for cbName, playerId in zip(self.nameWidgets, query.records[0]): try: playerName = Players.humanNames[playerId] playerIdx = cbName.findText(playerName) if playerIdx >= 0: cbName.setCurrentIndex(playerIdx) except KeyError: logError(u'database is inconsistent: player with id %d is in game but not in player' % playerId) self.slotValidate()
def updateSceneGUI(self): """update some actions, all auxiliary windows and the statusbar""" if not isAlive(self): return GameScene.updateSceneGUI(self) game = self.game mainWindow = self.mainWindow if not game: connections = list(x.connection for x in HumanClient.humanClients if x.connection) title = ', '.join('{name}/{url}'.format(name=x.username, url=x.url) for x in connections) if title: decorateWindow(mainWindow, title) else: decorateWindow(mainWindow, str(game.seed)) for action in [mainWindow.actionScoreGame, mainWindow.actionPlayGame]: action.setEnabled(not bool(game)) mainWindow.actionAbortGame.setEnabled(bool(game)) self.discardBoard.setVisible(bool(game)) mainWindow.actionAutoPlay.setEnabled(not self.startingGame) mainWindow.actionChat.setEnabled( bool(game) and bool(game.client) and bool(game.client.connection) and not game.client.connection.url.isLocalGame and not self.startingGame) # chatting on tables before game started works with chat button per # table mainWindow.actionChat.setChecked( mainWindow.actionChat.isEnabled() and bool(game.client.table.chatWindow))
def __init__(self, url, username, password): KDialog.__init__(self) decorateWindow(self, i18n('Create User Account')) self.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel)) vbox = QVBoxLayout() grid = QFormLayout() self.lbServer = QLabel() self.lbServer.setText(url) grid.addRow(i18n('Game server:'), self.lbServer) self.lbUser = QLabel() grid.addRow(i18n('Username:'******'Password:'******'Repeat password:'), self.edPassword2) vbox.addLayout(grid) widget = QWidget(self) widget.setLayout(vbox) self.setMainWidget(widget) pol = QSizePolicy() pol.setHorizontalPolicy(QSizePolicy.Expanding) self.lbUser.setSizePolicy(pol) self.edPassword.textChanged.connect(self.passwordChanged) self.edPassword2.textChanged.connect(self.passwordChanged) StateSaver(self) self.username = username self.password = password self.passwordChanged() self.edPassword2.setFocus()
def updateSceneGUI(self): """update some actions, all auxiliary windows and the statusbar""" if not isAlive(self): return GameScene.updateSceneGUI(self) game = self.game mainWindow = self.mainWindow if not game: connections = list( x.connection for x in HumanClient.humanClients if x.connection) title = u', '.join(u'{name}/{url}'.format(name=x.username, url=x.url) for x in connections) if title: decorateWindow(mainWindow, title) else: decorateWindow(mainWindow, str(game.seed)) for action in [mainWindow.actionScoreGame, mainWindow.actionPlayGame]: action.setEnabled(not bool(game)) mainWindow.actionAbortGame.setEnabled(bool(game)) self.discardBoard.setVisible(bool(game)) mainWindow.actionAutoPlay.setEnabled(not self.startingGame) mainWindow.actionChat.setEnabled(bool(game) and bool(game.client) and bool(game.client.connection) and not game.client.connection.url.isLocalGame and not self.startingGame) # chatting on tables before game started works with chat button per # table mainWindow.actionChat.setChecked( mainWindow.actionChat.isEnabled( ) and bool( game.client.table.chatWindow))
def __init__(self, parent): QDialog.__init__(self) self.parent = parent self._data = {} self.table = QTableWidget(self) self.table.horizontalHeader().setStretchLastSection(True) self.table.verticalHeader().setVisible(False) self.table.setEditTriggers(QTableWidget.NoEditTriggers) self.table.itemChanged.connect(self.itemChanged) self.updateTable() self.buttonBox = QDialogButtonBox() self.buttonBox.setStandardButtons( QDialogButtonBox.Close) # Close has the Rejected role self.buttonBox.rejected.connect(self.accept) self.newButton = self.buttonBox.addButton( m18nc('define a new player', "&New"), QDialogButtonBox.ActionRole) self.newButton.setIcon(KIcon("document-new")) self.newButton.clicked.connect(self.slotInsert) self.deleteButton = self.buttonBox.addButton( m18n("&Delete"), QDialogButtonBox.ActionRole) self.deleteButton.setIcon(KIcon("edit-delete")) self.deleteButton.clicked.connect(self.delete) cmdLayout = QHBoxLayout() cmdLayout.addWidget(self.buttonBox) layout = QVBoxLayout() layout.addWidget(self.table) layout.addLayout(cmdLayout) self.setLayout(layout) decorateWindow(self, m18n("Players")) self.setObjectName('Players')
def __init__(self, parent): QDialog.__init__(self) self.parent = parent self._data = {} self.table = QTableWidget(self) self.table.horizontalHeader().setStretchLastSection(True) self.table.verticalHeader().setVisible(False) self.table.setEditTriggers(QTableWidget.NoEditTriggers) self.table.itemChanged.connect(self.itemChanged) self.updateTable() self.buttonBox = QDialogButtonBox() self.buttonBox.setStandardButtons( QDialogButtonBox.Close) # Close has the Rejected role self.buttonBox.rejected.connect(self.accept) self.newButton = self.buttonBox.addButton( i18nc('define a new player', "&New"), QDialogButtonBox.ActionRole) self.newButton.setIcon(KIcon("document-new")) self.newButton.clicked.connect(self.slotInsert) self.deleteButton = self.buttonBox.addButton( i18n("&Delete"), QDialogButtonBox.ActionRole) self.deleteButton.setIcon(KIcon("edit-delete")) self.deleteButton.clicked.connect(self.delete) cmdLayout = QHBoxLayout() cmdLayout.addWidget(self.buttonBox) layout = QVBoxLayout() layout.addWidget(self.table) layout.addLayout(cmdLayout) self.setLayout(layout) decorateWindow(self, i18n("Players")) self.setObjectName('Players')
def __init__(self): SelectRuleset.__init__(self) Players.load() decorateWindow(self, i18n('Select four players')) self.names = None self.nameWidgets = [] for idx, wind in enumerate(Wind.all4): cbName = QComboBox() cbName.manualSelect = False # increase width, we want to see the full window title cbName.setMinimumWidth(350) # is this good for all platforms? cbName.addItems(list(Players.humanNames.values())) self.grid.addWidget(cbName, idx + 1, 1) self.nameWidgets.append(cbName) self.grid.addWidget(WindLabel(wind), idx + 1, 0) cbName.currentIndexChanged.connect(self.slotValidate) query = Query( "select p0,p1,p2,p3 from game where seed is null and game.id = (select max(id) from game)" ) if len(query.records): with BlockSignals(self.nameWidgets): for cbName, playerId in zip(self.nameWidgets, query.records[0]): try: playerName = Players.humanNames[playerId] playerIdx = cbName.findText(playerName) if playerIdx >= 0: cbName.setCurrentIndex(playerIdx) except KeyError: logError( 'database is inconsistent: player with id %d is in game but not in player' % playerId) self.slotValidate()
def __init__(self, scene=None, table=None): super(ChatWindow, self).__init__(None) self.scene = scene self.table = table or scene.game.client.table self.table.chatWindow = self self.setObjectName('chatWindow') title = m18n( 'Chat on table %1 at %2', self.table.tableid, self.table.client.connection.url) decorateWindow(self, title) self.messageView = ChatView() self.messageView.setModel(ChatModel()) self.messageView.setFocusPolicy(Qt.NoFocus) self.messageView.setShowGrid(False) self.messageView.setWordWrap(False) self.messageView.setSelectionMode(QAbstractItemView.NoSelection) if Debug.modelTest: self.debugModelTest = ModelTest( self.messageView.model(), self.messageView) self.edit = QLineEdit() layout = QVBoxLayout() layout.addWidget(self.messageView) layout.addWidget(self.edit) self.setLayout(layout) self.edit.returnPressed.connect(self.sendLine) self.edit.setFocus() self.show() StateSaver(self)
def __init__(self): """self.servers is a list of tuples containing server and last playername""" QDialog.__init__(self, None) decorateWindow(self, i18nc('kajongg', 'Login')) self.setupUi() localName = i18nc('kajongg name for local game server', Query.localServerName) self.servers = Query( 'select url,lastname from server order by lasttime desc').records servers = list(x[0] for x in self.servers if x[0] != Query.localServerName) # the first server combobox item should be default: either the last used server # or localName for autoPlay if localName not in servers: servers.append(localName) if 'kajongg.org' not in servers: servers.append('kajongg.org') if Internal.autoPlay: demoHost = Options.host or localName if demoHost in servers: servers.remove( demoHost ) # we want a unique list, it will be re-used for all following games servers.insert(0, demoHost) # in this process but they will not be autoPlay self.cbServer.addItems(servers) self.passwords = Query( 'select url, p.name, passwords.password from passwords, player p ' 'where passwords.player=p.id').records Players.load() self.cbServer.editTextChanged.connect(self.serverChanged) self.cbUser.editTextChanged.connect(self.userChanged) self.serverChanged() StateSaver(self)
def __init__(self, scene=None, table=None): super(ChatWindow, self).__init__(None) self.scene = scene self.table = table or scene.game.client.table self.table.chatWindow = self self.setObjectName('chatWindow') title = i18n('Chat on table %1 at %2', self.table.tableid, self.table.client.connection.url) decorateWindow(self, title) self.messageView = ChatView() self.messageView.setModel(ChatModel()) self.messageView.setFocusPolicy(Qt.NoFocus) self.messageView.setShowGrid(False) self.messageView.setWordWrap(False) self.messageView.setSelectionMode(QAbstractItemView.NoSelection) if Debug.modelTest: self.debugModelTest = ModelTest(self.messageView.model(), self.messageView) self.edit = QLineEdit() layout = QVBoxLayout() layout.addWidget(self.messageView) layout.addWidget(self.edit) self.setLayout(layout) self.edit.returnPressed.connect(self.sendLine) self.edit.setFocus() self.show() StateSaver(self)
def __init__(self, scene): QListView.__init__(self) self.scene = scene decorateWindow(self, i18n('Explain Scores').replace('&', '')) self.setGeometry(0, 0, 300, 400) self.model = QStringListModel() self.setModel(self.model) StateSaver(self) self.refresh()
def __init__(self, scene): QListView.__init__(self) self.scene = scene decorateWindow(self, m18n("Explain Scores").replace("&", "")) self.setGeometry(0, 0, 300, 400) self.model = QStringListModel() self.setModel(self.model) StateSaver(self) self.refresh()
def __init__(self, swappers): QMessageBox.__init__(self) decorateWindow(self, m18n("Swap Seats")) self.setText( m18n("By the rules, %1 and %2 should now exchange their seats. ", swappers[0].name, swappers[1].name)) self.yesAnswer = QPushButton(m18n("&Exchange")) self.addButton(self.yesAnswer, QMessageBox.YesRole) self.noAnswer = QPushButton(m18n("&Keep seat")) self.addButton(self.noAnswer, QMessageBox.NoRole)
def __init__(self, swappers): QMessageBox.__init__(self) decorateWindow(self, i18n("Swap Seats")) self.setText( i18n("By the rules, %1 and %2 should now exchange their seats. ", swappers[0].name, swappers[1].name)) self.yesAnswer = QPushButton(i18n("&Exchange")) self.addButton(self.yesAnswer, QMessageBox.YesRole) self.noAnswer = QPushButton(i18n("&Keep seat")) self.addButton(self.noAnswer, QMessageBox.NoRole)
def __init__(self, leftRulesets, rightRulesets, parent=None): QDialog.__init__(self, parent) if not isinstance(leftRulesets, list): leftRulesets = list([leftRulesets]) if not isinstance(rightRulesets, list): rightRulesets = list([rightRulesets]) leftRulesets, rightRulesets = leftRulesets[:], rightRulesets[:] # remove rulesets from right which are also on the left side for left in leftRulesets: left.load() for right in rightRulesets: right.load() for left in leftRulesets: for right in rightRulesets[:]: if left == right and left.name == right.name: # rightRulesets.remove(right) this is wrong because it # removes the first ruleset with the same hash rightRulesets = list( x for x in rightRulesets if id(x) != id(right)) self.leftRulesets = leftRulesets self.rightRulesets = rightRulesets self.model = None self.modelTest = None self.view = MJTableView(self) self.buttonBox = QDialogButtonBox() self.buttonBox.setStandardButtons(QDialogButtonBox.Ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) cbLayout = QHBoxLayout() self.cbRuleset1 = ListComboBox(self.leftRulesets) if len(self.leftRulesets) == 1: self.lblRuleset1 = QLabel(self.leftRulesets[0].name) cbLayout.addWidget(self.lblRuleset1) else: cbLayout.addWidget(self.cbRuleset1) self.cbRuleset2 = ListComboBox(self.rightRulesets) cbLayout.addWidget(self.cbRuleset2) cmdLayout = QHBoxLayout() cmdLayout.addWidget(self.buttonBox) layout = QVBoxLayout() layout.addLayout(cbLayout) layout.addWidget(self.view) layout.addLayout(cmdLayout) self.setLayout(layout) decorateWindow(self, i18n("Compare")) self.setObjectName('RulesetDiffer') self.cbRuleset1.currentIndexChanged.connect(self.leftRulesetChanged) self.cbRuleset2.currentIndexChanged.connect(self.rulesetChanged) self.leftRulesetChanged() StateSaver(self)
def __init__(self, game): """selection for this player, tiles are the still available tiles""" QDialog.__init__(self, None) decorateWindow(self, i18n("Penalty")) self.game = game grid = QGridLayout(self) lblOffense = QLabel(i18n('Offense:')) crimes = list([ x for x in game.ruleset.penaltyRules if not ('absolute' in x.options and game.winner) ]) self.cbCrime = ListComboBox(crimes) lblOffense.setBuddy(self.cbCrime) grid.addWidget(lblOffense, 0, 0) grid.addWidget(self.cbCrime, 0, 1, 1, 4) lblPenalty = QLabel(i18n('Total Penalty')) self.spPenalty = PenaltyBox(2) self.spPenalty.setRange(0, 9999) lblPenalty.setBuddy(self.spPenalty) self.lblUnits = QLabel(i18n('points')) grid.addWidget(lblPenalty, 1, 0) grid.addWidget(self.spPenalty, 1, 1) grid.addWidget(self.lblUnits, 1, 2) self.payers = [] self.payees = [] # a penalty can never involve the winner, neither as payer nor as payee for idx in range(3): self.payers.append(ListComboBox(game.losers())) self.payees.append(ListComboBox(game.losers())) for idx, payer in enumerate(self.payers): grid.addWidget(payer, 3 + idx, 0) payer.lblPayment = QLabel() grid.addWidget(payer.lblPayment, 3 + idx, 1) for idx, payee in enumerate(self.payees): grid.addWidget(payee, 3 + idx, 3) payee.lblPayment = QLabel() grid.addWidget(payee.lblPayment, 3 + idx, 4) grid.addWidget(QLabel(''), 6, 0) grid.setRowStretch(6, 10) for player in self.payers + self.payees: player.currentIndexChanged.connect(self.playerChanged) self.spPenalty.valueChanged.connect(self.penaltyChanged) self.cbCrime.currentIndexChanged.connect(self.crimeChanged) buttonBox = KDialogButtonBox(self) grid.addWidget(buttonBox, 7, 0, 1, 5) buttonBox.setStandardButtons(QDialogButtonBox.Cancel) buttonBox.rejected.connect(self.reject) self.btnExecute = buttonBox.addButton(i18n("&Execute"), QDialogButtonBox.AcceptRole) self.btnExecute.clicked.connect(self.accept) self.crimeChanged() StateSaver(self)
def __init__(self, leftRulesets, rightRulesets, parent=None): QDialog.__init__(self, parent) if not isinstance(leftRulesets, list): leftRulesets = list([leftRulesets]) if not isinstance(rightRulesets, list): rightRulesets = list([rightRulesets]) leftRulesets, rightRulesets = leftRulesets[:], rightRulesets[:] # remove rulesets from right which are also on the left side for left in leftRulesets: left.load() for right in rightRulesets: right.load() for left in leftRulesets: for right in rightRulesets[:]: if left == right and left.name == right.name: # rightRulesets.remove(right) this is wrong because it # removes the first ruleset with the same hash rightRulesets = list(x for x in rightRulesets if id(x) != id(right)) self.leftRulesets = leftRulesets self.rightRulesets = rightRulesets self.model = None self.modelTest = None self.view = MJTableView(self) self.buttonBox = QDialogButtonBox() self.buttonBox.setStandardButtons(QDialogButtonBox.Ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) cbLayout = QHBoxLayout() self.cbRuleset1 = ListComboBox(self.leftRulesets) if len(self.leftRulesets) == 1: self.lblRuleset1 = QLabel(self.leftRulesets[0].name) cbLayout.addWidget(self.lblRuleset1) else: cbLayout.addWidget(self.cbRuleset1) self.cbRuleset2 = ListComboBox(self.rightRulesets) cbLayout.addWidget(self.cbRuleset2) cmdLayout = QHBoxLayout() cmdLayout.addWidget(self.buttonBox) layout = QVBoxLayout() layout.addLayout(cbLayout) layout.addWidget(self.view) layout.addLayout(cmdLayout) self.setLayout(layout) decorateWindow(self, m18n("Compare")) self.setObjectName("RulesetDiffer") self.cbRuleset1.currentIndexChanged.connect(self.leftRulesetChanged) self.cbRuleset2.currentIndexChanged.connect(self.rulesetChanged) self.leftRulesetChanged() StateSaver(self)
def __init__(self, scene): super(ScoreTable, self).__init__(None) self.setObjectName("ScoreTable") self.scene = scene self.scoreModel = None self.scoreModelTest = None decorateWindow(self, m18nc("kajongg", "Scores")) self.setAttribute(Qt.WA_AlwaysShowToolTips) self.setMouseTracking(True) self.__tableFields = ["prevailing", "won", "wind", "points", "payments", "balance", "hand", "manualrules"] self.setupUi() self.refresh() StateSaver(self, self.splitter)
def refresh(self): """load this game and this player. Keep parameter list identical with ExplainView""" if not self.game: # keep scores of previous game on display return if self.scoreModel: expandGroups = [ self.viewLeft.isExpanded( self.scoreModel.index(x, 0, QModelIndex())) for x in range(4) ] else: expandGroups = [True, False, True, True] gameid = str(self.game.seed or self.game.gameid) if self.game.finished(): title = i18n('Final scores for game <numid>%1</numid>', gameid) else: title = i18n('Scores for game <numid>%1</numid>', gameid) decorateWindow(self, title) self.ruleTree.rulesets = list([self.game.ruleset]) self.scoreModel = ScoreModel(self) if Debug.modelTest: self.scoreModelTest = ModelTest(self.scoreModel, self) for view in [self.viewLeft, self.viewRight]: view.setModel(self.scoreModel) header = view.header() header.setStretchLastSection(False) view.setAlternatingRowColors(True) self.viewRight.header().setSectionResizeMode(QHeaderView.Fixed) for col in range(self.viewLeft.header().count()): self.viewLeft.header().setSectionHidden(col, col > 0) self.viewRight.header().setSectionHidden(col, col == 0) self.scoreLayout.setStretch(1, 100) self.scoreLayout.setSpacing(0) self.viewLeft.setFrameStyle(QFrame.NoFrame) self.viewRight.setFrameStyle(QFrame.NoFrame) self.viewLeft.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) for master, slave in ((self.viewRight, self.viewLeft), (self.viewLeft, self.viewRight)): master.expanded.connect(slave.expand) master.collapsed.connect(slave.collapse) master.verticalScrollBar().valueChanged.connect( slave.verticalScrollBar().setValue) for row, expand in enumerate(expandGroups): self.viewLeft.setExpanded( self.scoreModel.index(row, 0, QModelIndex()), expand) self.viewLeft.resizeColumnToContents(0) self.viewRight.setColWidth() # we need a timer since the scrollbar is not yet visible QTimer.singleShot(0, self.scrollRight)
def __init__(self, game): """selection for this player, tiles are the still available tiles""" QDialog.__init__(self, None) decorateWindow(self, m18n("Penalty")) self.game = game grid = QGridLayout(self) lblOffense = QLabel(m18n("Offense:")) crimes = list([x for x in game.ruleset.penaltyRules if not ("absolute" in x.options and game.winner)]) self.cbCrime = ListComboBox(crimes) lblOffense.setBuddy(self.cbCrime) grid.addWidget(lblOffense, 0, 0) grid.addWidget(self.cbCrime, 0, 1, 1, 4) lblPenalty = QLabel(m18n("Total Penalty")) self.spPenalty = PenaltyBox(2) self.spPenalty.setRange(0, 9999) lblPenalty.setBuddy(self.spPenalty) self.lblUnits = QLabel(m18n("points")) grid.addWidget(lblPenalty, 1, 0) grid.addWidget(self.spPenalty, 1, 1) grid.addWidget(self.lblUnits, 1, 2) self.payers = [] self.payees = [] # a penalty can never involve the winner, neither as payer nor as payee for idx in range(3): self.payers.append(ListComboBox(game.losers())) self.payees.append(ListComboBox(game.losers())) for idx, payer in enumerate(self.payers): grid.addWidget(payer, 3 + idx, 0) payer.lblPayment = QLabel() grid.addWidget(payer.lblPayment, 3 + idx, 1) for idx, payee in enumerate(self.payees): grid.addWidget(payee, 3 + idx, 3) payee.lblPayment = QLabel() grid.addWidget(payee.lblPayment, 3 + idx, 4) grid.addWidget(QLabel(""), 6, 0) grid.setRowStretch(6, 10) for player in self.payers + self.payees: player.currentIndexChanged.connect(self.playerChanged) self.spPenalty.valueChanged.connect(self.penaltyChanged) self.cbCrime.currentIndexChanged.connect(self.crimeChanged) buttonBox = KDialogButtonBox(self) grid.addWidget(buttonBox, 7, 0, 1, 5) buttonBox.setStandardButtons(QDialogButtonBox.Cancel) buttonBox.rejected.connect(self.reject) if not usingKDE: self.btnExecute = buttonBox.addButton(m18n("&Execute"), QDialogButtonBox.AcceptRole) self.btnExecute.clicked.connect(self.accept) else: self.btnExecute = buttonBox.addButton(m18n("&Execute"), QDialogButtonBox.AcceptRole, self, SLOT("accept()")) self.crimeChanged() StateSaver(self)
def __init__(self, parent=None): super(Games, self).__init__(parent) self.selectedGame = None self.onlyPending = True decorateWindow(self, m18nc('kajongg', 'Games')) self.setObjectName('Games') self.resize(700, 400) self.model = GamesModel() if Debug.modelTest: self.modelTest = ModelTest(self.model, self) self.view = MJTableView(self) self.view.setModel(self.model) self.selection = QItemSelectionModel(self.model, self.view) self.view.setSelectionModel(self.selection) self.view.setSelectionBehavior(QAbstractItemView.SelectRows) self.view.setSelectionMode(QAbstractItemView.SingleSelection) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel) self.newButton = self.buttonBox.addButton( m18nc('start a new game', "&New"), QDialogButtonBox.ActionRole) self.newButton.setIcon(KIcon("document-new")) self.newButton.clicked.connect(self.accept) self.loadButton = self.buttonBox.addButton( m18n("&Load"), QDialogButtonBox.AcceptRole) self.loadButton.clicked.connect(self.loadGame) self.loadButton.setIcon(KIcon("document-open")) self.deleteButton = self.buttonBox.addButton( m18n("&Delete"), QDialogButtonBox.ActionRole) self.deleteButton.setIcon(KIcon("edit-delete")) self.deleteButton.clicked.connect(self.delete) chkPending = QCheckBox(m18n("Show only pending games"), self) chkPending.setChecked(True) cmdLayout = QHBoxLayout() cmdLayout.addWidget(chkPending) cmdLayout.addWidget(self.buttonBox) layout = QVBoxLayout() layout.addWidget(self.view) layout.addLayout(cmdLayout) self.setLayout(layout) StateSaver(self) self.selection.selectionChanged.connect(self.selectionChanged) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.view.doubleClicked.connect(self.loadGame) chkPending.stateChanged.connect(self.pendingOrNot)
def __init__(self, parent=None): super(Games, self).__init__(parent) self.selectedGame = None self.onlyPending = True decorateWindow(self, i18nc('kajongg', 'Games')) self.setObjectName('Games') self.resize(700, 400) self.model = GamesModel() if Debug.modelTest: self.modelTest = ModelTest(self.model, self) self.view = MJTableView(self) self.view.setModel(self.model) self.selection = QItemSelectionModel(self.model, self.view) self.view.setSelectionModel(self.selection) self.view.setSelectionBehavior(QAbstractItemView.SelectRows) self.view.setSelectionMode(QAbstractItemView.SingleSelection) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel) self.newButton = self.buttonBox.addButton( i18nc('start a new game', "&New"), QDialogButtonBox.ActionRole) self.newButton.setIcon(KIcon("document-new")) self.newButton.clicked.connect(self.accept) self.loadButton = self.buttonBox.addButton( i18n("&Load"), QDialogButtonBox.AcceptRole) self.loadButton.clicked.connect(self.loadGame) self.loadButton.setIcon(KIcon("document-open")) self.deleteButton = self.buttonBox.addButton( i18n("&Delete"), QDialogButtonBox.ActionRole) self.deleteButton.setIcon(KIcon("edit-delete")) self.deleteButton.clicked.connect(self.delete) chkPending = QCheckBox(i18n("Show only pending games"), self) chkPending.setChecked(True) cmdLayout = QHBoxLayout() cmdLayout.addWidget(chkPending) cmdLayout.addWidget(self.buttonBox) layout = QVBoxLayout() layout.addWidget(self.view) layout.addLayout(cmdLayout) self.setLayout(layout) StateSaver(self) self.selection.selectionChanged.connect(self.selectionChanged) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.view.doubleClicked.connect(self.loadGame) chkPending.stateChanged.connect(self.pendingOrNot)
def __init__(self, server=None): QDialog.__init__(self, None) decorateWindow(self, m18n('Select a ruleset')) self.buttonBox = KDialogButtonBox(self) self.buttonBox.setStandardButtons( QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.cbRuleset = ListComboBox(Ruleset.selectableRulesets(server)) self.grid = QGridLayout() # our child SelectPlayers needs this self.grid.setColumnStretch(0, 1) self.grid.setColumnStretch(1, 6) vbox = QVBoxLayout(self) vbox.addLayout(self.grid) vbox.addWidget(self.cbRuleset) vbox.addWidget(self.buttonBox)
def __init__(self, server=None): QDialog.__init__(self, None) decorateWindow(self, i18n('Select a ruleset')) self.buttonBox = KDialogButtonBox(self) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.cbRuleset = ListComboBox(Ruleset.selectableRulesets(server)) self.grid = QGridLayout() # our child SelectPlayers needs this self.grid.setColumnStretch(0, 1) self.grid.setColumnStretch(1, 6) vbox = QVBoxLayout(self) vbox.addLayout(self.grid) vbox.addWidget(self.cbRuleset) vbox.addWidget(self.buttonBox)
def __init__(self, scene): super(ScoreTable, self).__init__(None) self.setObjectName('ScoreTable') self.scene = scene self.scoreModel = None self.scoreModelTest = None decorateWindow(self, i18nc('kajongg', 'Scores')) self.setAttribute(Qt.WA_AlwaysShowToolTips) self.setMouseTracking(True) self.__tableFields = [ 'prevailing', 'won', 'wind', 'points', 'payments', 'balance', 'hand', 'manualrules' ] self.setupUi() self.refresh() StateSaver(self, self.splitter)
def refresh(self): """load this game and this player. Keep parameter list identical with ExplainView""" if not self.game: # keep scores of previous game on display return if self.scoreModel: expandGroups = [self.viewLeft.isExpanded(self.scoreModel.index(x, 0, QModelIndex())) for x in range(4)] else: expandGroups = [True, False, True, True] gameid = str(self.game.seed or self.game.gameid) if self.game.finished(): title = m18n("Final scores for game <numid>%1</numid>", gameid) else: title = m18n("Scores for game <numid>%1</numid>", gameid) decorateWindow(self, title) self.ruleTree.rulesets = list([self.game.ruleset]) self.scoreModel = ScoreModel(self) if Debug.modelTest: self.scoreModelTest = ModelTest(self.scoreModel, self) for view in [self.viewLeft, self.viewRight]: view.setModel(self.scoreModel) header = view.header() header.setStretchLastSection(False) view.setAlternatingRowColors(True) if usingQt5: self.viewRight.header().setSectionResizeMode(QHeaderView.Fixed) else: self.viewRight.header().setResizeMode(QHeaderView.Fixed) for col in range(self.viewLeft.header().count()): self.viewLeft.header().setSectionHidden(col, col > 0) self.viewRight.header().setSectionHidden(col, col == 0) self.scoreLayout.setStretch(1, 100) self.scoreLayout.setSpacing(0) self.viewLeft.setFrameStyle(QFrame.NoFrame) self.viewRight.setFrameStyle(QFrame.NoFrame) self.viewLeft.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) for master, slave in ((self.viewRight, self.viewLeft), (self.viewLeft, self.viewRight)): master.expanded.connect(slave.expand) master.collapsed.connect(slave.collapse) master.verticalScrollBar().valueChanged.connect(slave.verticalScrollBar().setValue) for row, expand in enumerate(expandGroups): self.viewLeft.setExpanded(self.scoreModel.index(row, 0, QModelIndex()), expand) self.viewLeft.resizeColumnToContents(0) self.viewRight.setColWidth() # we need a timer since the scrollbar is not yet visible QTimer.singleShot(0, self.scrollRight)
def __init__(self, client, parent=None): QDialog.__init__(self, parent) decorateWindow(self, m18n('Choose')) self.setObjectName('ClientDialog') self.client = client self.layout = QGridLayout(self) self.progressBar = QProgressBar() self.timer = QTimer() if not client.game.autoPlay: self.timer.timeout.connect(self.timeout) self.deferred = None self.buttons = [] self.setWindowFlags(Qt.SubWindow | Qt.WindowStaysOnTopHint) self.setModal(False) self.btnHeight = 0 self.answered = False self.move = None self.sorry = None
def setupUi(self): """layout the window""" decorateWindow(self, i18n('Customize rulesets')) self.setObjectName('Rulesets') hlayout = QHBoxLayout(self) v1layout = QVBoxLayout() self.v1widget = QWidget() v1layout = QVBoxLayout(self.v1widget) v2layout = QVBoxLayout() hlayout.addWidget(self.v1widget) hlayout.addLayout(v2layout) for widget in [self.v1widget, hlayout, v1layout, v2layout]: widget.setContentsMargins(0, 0, 0, 0) hlayout.setStretchFactor(self.v1widget, 10) self.btnCopy = QPushButton() self.btnRemove = QPushButton() self.btnCompare = QPushButton() self.btnClose = QPushButton() self.rulesetView = RuleTreeView( i18ncE('kajongg', 'Rule'), self.btnCopy, self.btnRemove, self.btnCompare) v1layout.addWidget(self.rulesetView) self.rulesetView.setWordWrap(True) self.rulesetView.setMouseTracking(True) spacerItem = QSpacerItem( 20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding) v2layout.addWidget(self.btnCopy) v2layout.addWidget(self.btnRemove) v2layout.addWidget(self.btnCompare) self.btnCopy.clicked.connect(self.rulesetView.copyRow) self.btnRemove.clicked.connect(self.rulesetView.removeRow) self.btnCompare.clicked.connect(self.rulesetView.compareRow) self.btnClose.clicked.connect(self.hide) v2layout.addItem(spacerItem) v2layout.addWidget(self.btnClose) self.retranslateUi() StateSaver(self) self.show()
def setupUi(self): """layout the window""" decorateWindow(self, m18n('Customize rulesets')) self.setObjectName('Rulesets') hlayout = QHBoxLayout(self) v1layout = QVBoxLayout() self.v1widget = QWidget() v1layout = QVBoxLayout(self.v1widget) v2layout = QVBoxLayout() hlayout.addWidget(self.v1widget) hlayout.addLayout(v2layout) for widget in [self.v1widget, hlayout, v1layout, v2layout]: widget.setContentsMargins(0, 0, 0, 0) hlayout.setStretchFactor(self.v1widget, 10) self.btnCopy = QPushButton() self.btnRemove = QPushButton() self.btnCompare = QPushButton() self.btnClose = QPushButton() self.rulesetView = RuleTreeView( m18nc('kajongg', 'Rule'), self.btnCopy, self.btnRemove, self.btnCompare) v1layout.addWidget(self.rulesetView) self.rulesetView.setWordWrap(True) self.rulesetView.setMouseTracking(True) spacerItem = QSpacerItem( 20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding) v2layout.addWidget(self.btnCopy) v2layout.addWidget(self.btnRemove) v2layout.addWidget(self.btnCompare) self.btnCopy.clicked.connect(self.rulesetView.copyRow) self.btnRemove.clicked.connect(self.rulesetView.removeRow) self.btnCompare.clicked.connect(self.rulesetView.compareRow) self.btnClose.clicked.connect(self.hide) v2layout.addItem(spacerItem) v2layout.addWidget(self.btnClose) self.retranslateUi() StateSaver(self) self.show()
def __init__(self, client, parent=None): QDialog.__init__(self, parent) decorateWindow(self, i18n('Choose')) self.setObjectName('ClientDialog') self.client = client self.layout = QGridLayout(self) self.progressBar = QProgressBar() self.progressBar.setMinimumHeight(25) self.timer = QTimer() if not client.game.autoPlay: self.timer.timeout.connect(self.timeout) self.deferred = None self.buttons = [] self.setWindowFlags(Qt.SubWindow | Qt.WindowStaysOnTopHint) self.setModal(False) self.btnHeight = 0 self.answered = False self.move = None self.sorry = None
def __init__(self, scene): QWidget.__init__(self) self.scene = scene decorateWindow(self, i18n('Scoring for this Hand')) self.nameLabels = [None] * 4 self.spValues = [None] * 4 self.windLabels = [None] * 4 self.wonBoxes = [None] * 4 self.detailsLayout = [None] * 4 self.details = [None] * 4 self.__tilePixMaps = [] self.__meldPixMaps = [] grid = QGridLayout(self) pGrid = QGridLayout() grid.addLayout(pGrid, 0, 0, 2, 1) pGrid.addWidget(QLabel(i18nc('kajongg', "Player")), 0, 0) pGrid.addWidget(QLabel(i18nc('kajongg', "Wind")), 0, 1) pGrid.addWidget(QLabel(i18nc('kajongg', 'Score')), 0, 2) pGrid.addWidget(QLabel(i18n("Winner")), 0, 3) self.detailTabs = QTabWidget() self.detailTabs.setDocumentMode(True) pGrid.addWidget(self.detailTabs, 0, 4, 8, 1) for idx in range(4): self.setupUiForPlayer(pGrid, idx) self.draw = QCheckBox(i18nc('kajongg', 'Draw')) self.draw.clicked.connect(self.wonChanged) btnPenalties = QPushButton(i18n("&Penalties")) btnPenalties.clicked.connect(self.penalty) self.btnSave = QPushButton(i18n('&Save Hand')) self.btnSave.clicked.connect(self.game.nextScoringHand) self.btnSave.setEnabled(False) self.setupUILastTileMeld(pGrid) pGrid.setRowStretch(87, 10) pGrid.addWidget(self.draw, 7, 3) self.cbLastTile.currentIndexChanged.connect(self.slotLastTile) self.cbLastMeld.currentIndexChanged.connect(self.slotInputChanged) btnBox = QHBoxLayout() btnBox.addWidget(btnPenalties) btnBox.addWidget(self.btnSave) pGrid.addLayout(btnBox, 8, 4) StateSaver(self) self.refresh()
def __init__(self, scene): QWidget.__init__(self) self.scene = scene decorateWindow(self, m18n("Scoring for this Hand")) self.nameLabels = [None] * 4 self.spValues = [None] * 4 self.windLabels = [None] * 4 self.wonBoxes = [None] * 4 self.detailsLayout = [None] * 4 self.details = [None] * 4 self.__tilePixMaps = [] self.__meldPixMaps = [] grid = QGridLayout(self) pGrid = QGridLayout() grid.addLayout(pGrid, 0, 0, 2, 1) pGrid.addWidget(QLabel(m18nc("kajongg", "Player")), 0, 0) pGrid.addWidget(QLabel(m18nc("kajongg", "Wind")), 0, 1) pGrid.addWidget(QLabel(m18nc("kajongg", "Score")), 0, 2) pGrid.addWidget(QLabel(m18n("Winner")), 0, 3) self.detailTabs = QTabWidget() self.detailTabs.setDocumentMode(True) pGrid.addWidget(self.detailTabs, 0, 4, 8, 1) for idx in range(4): self.setupUiForPlayer(pGrid, idx) self.draw = QCheckBox(m18nc("kajongg", "Draw")) self.draw.clicked.connect(self.wonChanged) btnPenalties = QPushButton(m18n("&Penalties")) btnPenalties.clicked.connect(self.penalty) self.btnSave = QPushButton(m18n("&Save Hand")) self.btnSave.clicked.connect(self.game.nextScoringHand) self.btnSave.setEnabled(False) self.setupUILastTileMeld(pGrid) pGrid.setRowStretch(87, 10) pGrid.addWidget(self.draw, 7, 3) self.cbLastTile.currentIndexChanged.connect(self.slotLastTile) self.cbLastMeld.currentIndexChanged.connect(self.slotInputChanged) btnBox = QHBoxLayout() btnBox.addWidget(btnPenalties) btnBox.addWidget(self.btnSave) pGrid.addLayout(btnBox, 8, 4) StateSaver(self) self.refresh()
def show(self): """prepare the view and show it""" if self.client.hasLocalServer(): title = i18n('Local Games with Ruleset %1', self.client.ruleset.name) else: title = i18n('Tables at %1', self.client.connection.url) decorateWindow(self, ' - '.join([self.client.name, title])) self.view.hideColumn(1) tableCount = self.view.model().rowCount( None) if self.view.model() else 0 self.view.showColumn(0) self.view.showColumn(2) self.view.showColumn(4) if tableCount or not self.client.hasLocalServer(): QWidget.show(self) if self.client.hasLocalServer(): self.view.hideColumn(0) self.view.hideColumn(2) self.view.hideColumn(4)
def __init__(self, kongs, deferred): KDialogIgnoringEscape.__init__(self) decorateWindow(self) self.setButtons(0) self.kongs = kongs self.selectedKong = None self.deferred = deferred layout = QVBoxLayout() label = QLabel(m18n('Which kong do you want to declare?')) layout.addWidget(label) layout.setAlignment(label, Qt.AlignHCenter) self.buttons = [] for kong in kongs: button = QRadioButton((kong[0].name()), self) self.buttons.append(button) layout.addWidget(button) button.toggled.connect(self.toggled) widget = QWidget(self) widget.setLayout(layout) self.setMainWidget(widget)
def __init__(self, kongs, deferred): KDialogIgnoringEscape.__init__(self) decorateWindow(self) self.setButtons(0) self.kongs = kongs self.selectedKong = None self.deferred = deferred layout = QVBoxLayout() label = QLabel(i18n('Which kong do you want to declare?')) layout.addWidget(label) layout.setAlignment(label, Qt.AlignHCenter) self.buttons = [] for kong in kongs: button = QRadioButton((kong[0].name()), self) self.buttons.append(button) layout.addWidget(button) button.toggled.connect(self.toggled) widget = QWidget(self) widget.setLayout(layout) self.setMainWidget(widget)
def show(self): """prepare the view and show it""" if self.client.hasLocalServer(): title = m18n( 'Local Games with Ruleset %1', self.client.ruleset.name) else: title = m18n('Tables at %1', self.client.connection.url) decorateWindow(self, ' - '.join([self.client.name, title])) self.view.hideColumn(1) tableCount = self.view.model().rowCount( None) if self.view.model() else 0 self.view.showColumn(0) self.view.showColumn(2) self.view.showColumn(4) if tableCount or not self.client.hasLocalServer(): QWidget.show(self) if self.client.hasLocalServer(): self.view.hideColumn(0) self.view.hideColumn(2) self.view.hideColumn(4)
def __init__(self, chows, propose, deferred): KDialogIgnoringEscape.__init__(self) decorateWindow(self) self.setButtons(KDialog.NoButton) self.chows = chows self.selectedChow = None self.deferred = deferred layout = QVBoxLayout() label = QLabel(i18n('Which chow do you want to expose?')) layout.addWidget(label) layout.setAlignment(label, Qt.AlignHCenter) self.buttons = [] for chow in chows: button = QRadioButton('{}-{}-{}'.format(*(x.value for x in chow))) self.buttons.append(button) layout.addWidget(button) layout.setAlignment(button, Qt.AlignHCenter) button.toggled.connect(self.toggled) widget = QWidget(self) widget.setLayout(layout) self.setMainWidget(widget) for idx, chow in enumerate(chows): if chow == propose: self.buttons[idx].setFocus()
def __init__(self, chows, propose, deferred): KDialogIgnoringEscape.__init__(self) decorateWindow(self) self.setButtons(KDialog.NoButton) self.chows = chows self.selectedChow = None self.deferred = deferred layout = QVBoxLayout() label = QLabel(m18n('Which chow do you want to expose?')) layout.addWidget(label) layout.setAlignment(label, Qt.AlignHCenter) self.buttons = [] for chow in chows: button = QRadioButton('{}-{}-{}'.format(*(x.value for x in chow))) self.buttons.append(button) layout.addWidget(button) layout.setAlignment(button, Qt.AlignHCenter) button.toggled.connect(self.toggled) widget = QWidget(self) widget.setLayout(layout) self.setMainWidget(widget) for idx, chow in enumerate(chows): if chow == propose: self.buttons[idx].setFocus()