Esempio n. 1
0
 def setupUi(self):
     """create all Ui elements but do not fill them"""
     buttonBox = KDialogButtonBox(self)
     buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
     # Ubuntu 11.10 unity is a bit strange - without this, it sets focus on
     # the cancel button (which it shows on the left). I found no obvious
     # way to use setDefault and setAutoDefault for fixing this.
     buttonBox.button(QDialogButtonBox.Ok).setFocus(True)
     buttonBox.accepted.connect(self.accept)
     buttonBox.rejected.connect(self.reject)
     vbox = QVBoxLayout(self)
     self.grid = QFormLayout()
     self.cbServer = QComboBox()
     self.cbServer.setEditable(True)
     self.grid.addRow(m18n('Game server:'), self.cbServer)
     self.cbUser = QComboBox()
     self.cbUser.setEditable(True)
     self.grid.addRow(m18n('Username:'******'Password:'******'kajongg', 'Ruleset:'), self.cbRuleset)
     vbox.addLayout(self.grid)
     vbox.addWidget(buttonBox)
     pol = QSizePolicy()
     pol.setHorizontalPolicy(QSizePolicy.Expanding)
     self.cbUser.setSizePolicy(pol)
Esempio n. 2
0
 def setupUi(self):
     """create all Ui elements but do not fill them"""
     self.buttonBox = KDialogButtonBox(self)
     self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                       | QDialogButtonBox.Ok)
     # Ubuntu 11.10 unity is a bit strange - without this, it sets focus on
     # the cancel button (which it shows on the left). I found no obvious
     # way to use setDefault and setAutoDefault for fixing this.
     self.buttonBox.button(QDialogButtonBox.Ok).setFocus(True)
     self.buttonBox.accepted.connect(self.accept)
     self.buttonBox.rejected.connect(self.reject)
     vbox = QVBoxLayout(self)
     self.grid = QFormLayout()
     self.cbServer = QComboBox()
     self.cbServer.setEditable(True)
     self.grid.addRow(i18n('Game server:'), self.cbServer)
     self.cbUser = QComboBox()
     self.cbUser.setEditable(True)
     self.grid.addRow(i18n('Username:'******'Password:'******'kajongg', 'Ruleset:'), self.cbRuleset)
     vbox.addLayout(self.grid)
     vbox.addWidget(self.buttonBox)
     pol = QSizePolicy()
     pol.setHorizontalPolicy(QSizePolicy.Expanding)
     self.cbUser.setSizePolicy(pol)
     self.__port = None
Esempio n. 3
0
    def __init__(self, url, username, password):
        MustChooseDialog.__init__(self, None)
        self.setWindowTitle(m18n('Create User Account') + ' - Kajongg')
        self.buttonBox = KDialogButtonBox(self)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                          | QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        vbox = QVBoxLayout(self)
        grid = QFormLayout()
        self.lbServer = QLabel()
        self.lbServer.setText(url)
        grid.addRow(m18n('Game server:'), self.lbServer)
        self.lbUser = QLabel()
        grid.addRow(m18n('Username:'******'Password:'******'Repeat password:'), self.edPassword2)
        vbox.addLayout(grid)
        vbox.addWidget(self.buttonBox)
        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()
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
    def __init__(self, url, username, password):
        MustChooseDialog.__init__(self, None)
        self.setWindowTitle(m18n('Create User Account') + ' - Kajongg')
        self.buttonBox = KDialogButtonBox(self)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        vbox = QVBoxLayout(self)
        grid = QFormLayout()
        self.lbServer = QLabel()
        self.lbServer.setText(url)
        grid.addRow(m18n('Game server:'), self.lbServer)
        self.lbUser = QLabel()
        grid.addRow(m18n('Username:'******'Password:'******'Repeat password:'), self.edPassword2)
        vbox.addLayout(grid)
        vbox.addWidget(self.buttonBox)
        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()
Esempio n. 8
0
class SelectRuleset(QDialog):
    """a dialog for selecting a ruleset"""
    def __init__(self, server=None):
        QDialog.__init__(self, None)
        self.setWindowTitle(m18n('Select a ruleset') + ' - Kajongg')
        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)
Esempio n. 9
0
class SelectRuleset(QDialog):
    """a dialog for selecting a ruleset"""
    def __init__(self, server=None):
        QDialog.__init__(self, None)
        self.setWindowTitle(m18n('Select a ruleset') + ' - Kajongg')
        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)
Esempio n. 10
0
 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)
Esempio n. 11
0
class LoginDlg(QDialog):
    """login dialog for server"""
    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 returns(self, dummyButton=None):
        """login data returned by this dialog"""
        return (Url(self.url), self.username, self.password,
                self.__defineRuleset())

    def setupUi(self):
        """create all Ui elements but do not fill them"""
        self.buttonBox = KDialogButtonBox(self)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                          | QDialogButtonBox.Ok)
        # Ubuntu 11.10 unity is a bit strange - without this, it sets focus on
        # the cancel button (which it shows on the left). I found no obvious
        # way to use setDefault and setAutoDefault for fixing this.
        self.buttonBox.button(QDialogButtonBox.Ok).setFocus(True)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        vbox = QVBoxLayout(self)
        self.grid = QFormLayout()
        self.cbServer = QComboBox()
        self.cbServer.setEditable(True)
        self.grid.addRow(i18n('Game server:'), self.cbServer)
        self.cbUser = QComboBox()
        self.cbUser.setEditable(True)
        self.grid.addRow(i18n('Username:'******'Password:'******'kajongg', 'Ruleset:'), self.cbRuleset)
        vbox.addLayout(self.grid)
        vbox.addWidget(self.buttonBox)
        pol = QSizePolicy()
        pol.setHorizontalPolicy(QSizePolicy.Expanding)
        self.cbUser.setSizePolicy(pol)
        self.__port = None

    def serverChanged(self, dummyText=None):
        """the user selected a different server"""
        records = Query(
            'select player.name from player, passwords '
            'where passwords.url=? and passwords.player = player.id',
            (self.url, )).records
        players = list(x[0] for x in records)
        preferPlayer = Options.player
        if preferPlayer:
            if preferPlayer in players:
                players.remove(preferPlayer)
            players.insert(0, preferPlayer)
        self.cbUser.clear()
        self.cbUser.addItems(players)
        if not self.cbUser.count():
            user = KUser() if os.name == 'nt' else KUser(os.geteuid())
            self.cbUser.addItem(user.fullName() or user.loginName())
        if not preferPlayer:
            userNames = [x[1] for x in self.servers if x[0] == self.url]
            if userNames:
                userIdx = self.cbUser.findText(userNames[0])
                if userIdx >= 0:
                    self.cbUser.setCurrentIndex(userIdx)
        showPW = bool(self.url) and not Url(self.url).isLocalHost
        self.grid.labelForField(self.edPassword).setVisible(showPW)
        self.edPassword.setVisible(showPW)
        self.grid.labelForField(self.cbRuleset).setVisible(
            not showPW and not Options.ruleset)
        self.cbRuleset.setVisible(not showPW and not Options.ruleset)
        if not showPW:
            self.cbRuleset.clear()
            if Options.ruleset:
                self.cbRuleset.items = [Options.ruleset]
            else:
                self.cbRuleset.items = Ruleset.selectableRulesets(self.url)
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(bool(self.url))

    def __defineRuleset(self):
        """find out what ruleset to use"""
        if Options.ruleset:
            return Options.ruleset
        elif Internal.autoPlay or bool(Options.host):
            return Ruleset.selectableRulesets()[0]
        else:
            return self.cbRuleset.current

    def userChanged(self, text):
        """the username has been changed, lookup password"""
        if text == '':
            self.edPassword.clear()
            return
        passw = None
        for entry in self.passwords:
            if entry[0] == self.url and entry[1] == text:
                passw = entry[2]
        if passw:
            self.edPassword.setText(passw)
        else:
            self.edPassword.clear()

    @property
    def url(self):
        """abstracts the url of the dialog"""
        return english(self.cbServer.currentText())

    @property
    def username(self):
        """abstracts the username of the dialog"""
        return self.cbUser.currentText()

    @property
    def password(self):
        """abstracts the password of the dialog"""
        return self.edPassword.text()

    @password.setter
    def password(self, password):
        """abstracts the password of the dialog"""
        self.edPassword.setText(password)
Esempio n. 12
0
class AddUserDialog(MustChooseDialog):
    """add a user account on a server: This dialog asks for the needed attributes"""
    # pylint: disable=R0902
    # pylint we need more than 10 instance attributes

    def __init__(self, url, username, password):
        MustChooseDialog.__init__(self, None)
        self.setWindowTitle(m18n('Create User Account') + ' - Kajongg')
        self.buttonBox = KDialogButtonBox(self)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        vbox = QVBoxLayout(self)
        grid = QFormLayout()
        self.lbServer = QLabel()
        self.lbServer.setText(url)
        grid.addRow(m18n('Game server:'), self.lbServer)
        self.lbUser = QLabel()
        grid.addRow(m18n('Username:'******'Password:'******'Repeat password:'), self.edPassword2)
        vbox.addLayout(grid)
        vbox.addWidget(self.buttonBox)
        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 passwordChanged(self, dummyText=None):
        """password changed"""
        self.validate()

    def validate(self):
        """does the dialog hold valid data?"""
        equal = self.edPassword.size() and self.edPassword.text() == self.edPassword2.text()
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(equal)

    @property
    def username(self):
        """abstracts the username of the dialog"""
        return unicode(self.lbUser.text())

    @username.setter
    def username(self, username):
        """abstracts the username of the dialog"""
        self.lbUser.setText(username)

    @property
    def password(self):
        """abstracts the password of the dialog"""
        return unicode(self.edPassword.text())

    @password.setter
    def password(self, password):
        """abstracts the password of the dialog"""
        self.edPassword.setText(password)
Esempio n. 13
0
class AddUserDialog(MustChooseDialog):
    """add a user account on a server: This dialog asks for the needed attributes"""

    # pylint: disable=R0902
    # pylint we need more than 10 instance attributes

    def __init__(self, url, username, password):
        MustChooseDialog.__init__(self, None)
        self.setWindowTitle(m18n('Create User Account') + ' - Kajongg')
        self.buttonBox = KDialogButtonBox(self)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                          | QDialogButtonBox.Ok)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        vbox = QVBoxLayout(self)
        grid = QFormLayout()
        self.lbServer = QLabel()
        self.lbServer.setText(url)
        grid.addRow(m18n('Game server:'), self.lbServer)
        self.lbUser = QLabel()
        grid.addRow(m18n('Username:'******'Password:'******'Repeat password:'), self.edPassword2)
        vbox.addLayout(grid)
        vbox.addWidget(self.buttonBox)
        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 passwordChanged(self, dummyText=None):
        """password changed"""
        self.validate()

    def validate(self):
        """does the dialog hold valid data?"""
        equal = self.edPassword.size() and self.edPassword.text(
        ) == self.edPassword2.text()
        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(equal)

    @property
    def username(self):
        """abstracts the username of the dialog"""
        return unicode(self.lbUser.text())

    @username.setter
    def username(self, username):
        """abstracts the username of the dialog"""
        self.lbUser.setText(username)

    @property
    def password(self):
        """abstracts the password of the dialog"""
        return unicode(self.edPassword.text())

    @password.setter
    def password(self, password):
        """abstracts the password of the dialog"""
        self.edPassword.setText(password)