Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
    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')
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def __init__(self):
        QDialog.__init__(self)
        self.l = QVBoxLayout(self)

        self.passwd = QLineEdit(self, "password")
        self.passwd.setEchoMode(QLineEdit.Password)
        self.l.addWidget(self.passwd)

        self.connect(self.passwd, SIGNAL("returnPressed()"), self.slotSetPass)
Ejemplo n.º 5
0
 def accept(self):
     if not self.settings.Dialogs:
         self.settings.Dialogs = DialogSettings()
     if self.checkOpen.isChecked():
         self.settings.Dialogs.UrlDialogTarget = unicode(self.comboOpen.currentText())    
     else:
         self.settings.Dialogs.UrlDialogTarget = ''
         
     QDialog.accept(self)
Ejemplo n.º 6
0
 def keyPressEvent(self, event):
     """use insert/delete keys for insert/delete"""
     key = event.key()
     if key == Qt.Key_Insert:
         self.slotInsert()
     elif key == Qt.Key_Delete:
         self.delete()
     else:
         QDialog.keyPressEvent(self, event)
Ejemplo n.º 7
0
 def keyPressEvent(self, event):
     """use insert/delete keys for insert/delete"""
     key = event.key()
     if key == Qt.Key_Insert:
         self.slotInsert()
     elif key == Qt.Key_Delete:
         self.delete()
     else:
         QDialog.keyPressEvent(self, event)
Ejemplo n.º 8
0
    def accept(self):
        if not self.settings.Dialogs:
            self.settings.Dialogs = DialogSettings()
        if self.checkOpen.isChecked():
            self.settings.Dialogs.UrlDialogTarget = unicode(
                self.comboOpen.currentText())
        else:
            self.settings.Dialogs.UrlDialogTarget = ''

        QDialog.accept(self)
Ejemplo n.º 9
0
 def keyPressEvent(self, event):
     """use insert/delete keys for insert/delete"""
     key = event.key()
     if key == Qt.Key_Insert:
         self.newEntry()
         return
     if key == Qt.Key_Delete:
         self.delete()
         event.ignore()
         return
     QDialog.keyPressEvent(self, event)
Ejemplo n.º 10
0
Archivo: games.py Proyecto: KDE/kajongg
 def keyPressEvent(self, event):
     """use insert/delete keys for insert/delete"""
     key = event.key()
     if key == Qt.Key_Insert:
         self.newEntry()
         return
     if key == Qt.Key_Delete:
         self.delete()
         event.ignore()
         return
     QDialog.keyPressEvent(self, event)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def keyPressEvent(self, event):
     """ESC selects default answer"""
     if not self.client.game or self.client.game.autoPlay:
         return
     if event.key() in [Qt.Key_Escape, Qt.Key_Space]:
         self.selectButton()
         event.accept()
     else:
         for btn in self.buttons:
             if str(event.text()).upper() == btn.message.shortcut:
                 self.selectButton(btn)
                 event.accept()
                 return
         QDialog.keyPressEvent(self, event)
Ejemplo n.º 16
0
 def keyPressEvent(self, event):
     """ESC selects default answer"""
     if not self.client.game or self.client.game.autoPlay:
         return
     if event.key() in [Qt.Key_Escape, Qt.Key_Space]:
         self.selectButton()
         event.accept()
     else:
         for btn in self.buttons:
             if str(event.text()).upper() == btn.message.shortcut:
                 self.selectButton(btn)
                 event.accept()
                 return
         QDialog.keyPressEvent(self, event)
Ejemplo n.º 17
0
 def accept(self):
     """execute the penalty"""
     offense = self.cbCrime.current
     payers = [x.current for x in self.payers if x.isVisible()]
     payees = [x.current for x in self.payees if x.isVisible()]
     for player in self.game.players:
         if player in payers:
             amount = -self.spPenalty.value() // len(payers)
         elif player in payees:
             amount = self.spPenalty.value() // len(payees)
         else:
             amount = 0
         player.getsPayment(amount)
         self.game.savePenalty(player, offense, amount)
     QDialog.accept(self)
Ejemplo n.º 18
0
 def accept(self):
     """execute the penalty"""
     offense = self.cbCrime.current
     payers = [x.current for x in self.payers if x.isVisible()]
     payees = [x.current for x in self.payees if x.isVisible()]
     for player in self.game.players:
         if player in payers:
             amount = -self.spPenalty.value() // len(payers)
         elif player in payees:
             amount = self.spPenalty.value() // len(payees)
         else:
             amount = 0
         player.getsPayment(amount)
         self.game.savePenalty(player, offense, amount)
     QDialog.accept(self)
Ejemplo n.º 19
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)
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
 def onDockChartViewToggled(self, checked):
   if checked:
     self.chartPopupWindow = QDialog()
     self.chartPopupWindow.setWindowFlags(PythonQt.QtCore.Qt.WindowStaysOnTopHint)
     layout = QGridLayout()
     self.chartPopupWindow.setLayout(layout)
     layout.addWidget(self._multiVolumeIntensityChart.chartView)
     layout.addWidget(self.popupChartButton)
     self.chartPopupWindow.finished.connect(self.dockChartView)
     self.chartPopupWindow.resize(self.chartPopupSize)
     self.chartPopupWindow.move(self.chartPopupPosition)
     self.chartPopupWindow.show()
     self.popupChartButton.setText("Dock chart")
     self._multiVolumeIntensityChart.chartView.show()
   else:
     self.chartPopupWindow.close()
Ejemplo n.º 22
0
def main(args):
    qapp=QApplication(sys.argv)
    kuraapp.initApp(str(guiConf.username),
                    str(guiConf.database),
                    str(guiConf.password),
                    str(guiConf.hostname))
    
    kuraapp.initCurrentEnvironment(1, 1, 1)
        
    mainwin = QDialog()
    combobox = QComboBox(mainwin)
    comboproxy = ComboProxy(combobox,
                            kuraapp.app.getObjects("lng_user"),
                            guiConf.usernr)
    mainwin.show()
    qapp.connect(qapp, SIGNAL('lastWindowClosed()'), qapp, SLOT('quit()'))
    qapp.exec_loop()
Ejemplo n.º 23
0
    def test_profile_button_clicked(self):
        self.__run_test(self.__runner.run_profile)
        profile = self.__runner.profile_data

        dialog = QDialog(self)

        tabs = QTabWidget(dialog)

        for i, output in enumerate(profile):
            browser = QTextEdit(tabs, 'profile')
            browser.setReadOnly(True)
            browser.setWordWrap(browser.NoWrap)
            browser.setTextFormat(browser.PlainText)
            browser.setFamily('Monospace')
            browser.setText(output)
            tabs.addTab(browser, "profile %d" % i)

        layout = QVBoxLayout(dialog, 1, 1, "DialogLayout")
        layout.setResizeMode(QVBoxLayout.FreeResize)
        layout.addWidget(tabs)

        dialog.setCaption(self.tr("Profile"))
        dialog.setMinimumSize(QSize(400,500))

        dialog.show()
Ejemplo n.º 24
0
 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
Ejemplo n.º 25
0
 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
Ejemplo n.º 26
0
def load_forms(splash, app, settings):
    splash.message("Loading form: Main", alignflag)
    qApp.processEvents()
    from PyQLogger.Dialogs import MainDialog
    wnd = MainDialog.MainDialog()
    wnd_c = qt_ui_loader.create('UI/maindialog.ui', wnd, None, True)
    wnd_c.closeEvent = wnd.closeEvent
    __FORMS__["Main"] = {"Class": wnd_c, "Impl": wnd}
    wnd.init_ui(settings, __FORMS__)
    UI.API.setupTray(app, __FORMS__["Main"])
    UI.API.setupDCOP(app, __FORMS__["Main"])
    splash.message("Loading form: Login", alignflag)
    qApp.processEvents()
    from PyQLogger.Dialogs import LoginDialog
    wnd = LoginDialog.LoginDialog()
    wnd_c = qt_ui_loader.create('UI/logindialog.ui', wnd, None, True)
    __FORMS__["Login"] = {"Class": wnd_c, "Impl": wnd}
    splash.message("Loading form: Settings", alignflag)
    qApp.processEvents()
    from PyQLogger.Dialogs import SettingsDialog
    wnd = SettingsDialog.SettingsDialog()
    wnd_c = qt_ui_loader.create('UI/settingsdialog.ui', wnd, None, True)
    __FORMS__["Settings"] = {"Class": wnd_c, "Impl": wnd}
    splash.message("Loading form: Account Settings", alignflag)
    qApp.processEvents()
    from PyQLogger.Dialogs import AccountSettingsDialog
    wnd = AccountSettingsDialog.AccountSettingsDialog()
    wnd_c = qt_ui_loader.create('UI/accountsettingsdialog.ui', wnd, None, True)
    wnd.init_ui()
    __FORMS__["AccountSettings"] = {"Class": wnd_c, "Impl": wnd}
    splash.message("Loading form: Image Insert", alignflag)
    qApp.processEvents()
    from PyQLogger.Dialogs import ImageDialog
    wnd = ImageDialog.ImageDialog()
    wnd_c = qt_ui_loader.create('UI/imagedialog.ui', wnd, None, True)
    __FORMS__["Image"] = {"Class": wnd_c, "Impl": wnd}
    splash.message("Loading form: Url Insert", alignflag)
    qApp.processEvents()
    from PyQLogger.Dialogs import UrlDialog
    wnd = UrlDialog.UrlDialog()
    wnd_c = qt_ui_loader.create('UI/urldialog.ui', wnd, None, True)
    __FORMS__["Url"] = {"Class": wnd_c, "Impl": wnd}
    splash.message("Loading form: Plugin settings", alignflag)
    qApp.processEvents()
    from PyQLogger.Dialogs import PluginSettingsDialog
    wnd = PluginSettingsDialog.PluginSettingsDialog()
    wnd_c = qt_ui_loader.create('UI/pluginsettingsdialog.ui', wnd, None, True)
    __FORMS__["PluginSettings"] = {"Class": wnd_c, "Impl": wnd}
    splash.message("Loading form: Template settings", alignflag)
    qApp.processEvents()
    wnd = QDialog()
    wnd_c = qt_ui_loader.create('UI/templatesettingsdialog.ui', wnd, None,
                                True)
    __FORMS__["TemplateSettings"] = {"Class": wnd_c, "Impl": wnd}
Ejemplo n.º 27
0
    def accept(self):
        #update gui changes
        self.settings.UI.EnableKde = int(self.chkKDE.isChecked())
        self.settings.Speller.Enabled = int(self.chkSpellEnable.isChecked())
        self.settings.Speller.Prefix = self.edtSpellPrefix.text()
        self.settings.Speller.Language = self.edtSpellLanguage.text()
        self.settings.UI.EnableTray = int(self.chkTray.isChecked())
        self.settings.UI.EnableDCOP = int(self.chkDCOP.isChecked())
        self.settings.UI.EnableText = int(self.chkShowText.isChecked())
        if self.rbOSD.isChecked():
            self.settings.UI.Notification = 0
        elif self.rbStatus.isChecked():
            self.settings.UI.Notification = 1
        else:
            self.settings.UI.Notification = 2

        #update plugin changes
        self.settings.save()
        self.manager.save()
        QDialog.accept(self)
class qSlicerMultiVolumeExplorerSimplifiedModuleWidget:

  def __init__(self, parent=None):
    logging.debug("qSlicerMultiVolumeExplorerSimplifiedModuleWidget:init() called")
    if not parent or not hasattr(parent, "layout"):
      self.parent = slicer.qMRMLWidget()
      self.parent.setLayout(QVBoxLayout())
    else:
      self.parent = parent

    self.layout = self.parent.layout()

    self._bgMultiVolumeNode = None
    self._fgMultiVolumeNode = None

    self.styleObserverTags = []
    self.sliceWidgetsPerStyle = {}

    self.chartPopupWindow = None
    self.chartPopupSize = QSize(600, 300)
    self.chartPopupPosition = QPoint(0,0)

  def hide(self):
    self.widget.hide()

  def show(self):
    self.widget.show()

  def setup(self):
    self.widget = QWidget()
    layout = QGridLayout()
    self.widget.setLayout(layout)
    self.layout.addWidget(self.widget)
    self.widget.show()
    self.layout = layout

    self.setupInputFrame()
    self.setupFrameControlFrame()
    self.setupAdditionalFrames()
    self.setupPlottingFrame()

    self.setFramesEnabled(False)

    self.timer = QTimer()
    self.timer.setInterval(50)

    self.setupConnections()

    # initialize slice observers (from DataProbe.py)
    # keep list of pairs: [observee,tag] so they can be removed easily
    self.styleObserverTags = []
    # keep a map of interactor styles to sliceWidgets so we can easily get sliceLogic
    self.sliceWidgetsPerStyle = {}
    self.refreshObservers()

  def setupInputFrame(self, parent=None):
    if not parent:
      parent = self.layout
    self.bgMultiVolumeSelector = slicer.qMRMLNodeComboBox()
    self.bgMultiVolumeSelector.nodeTypes = ['vtkMRMLMultiVolumeNode']
    self.bgMultiVolumeSelector.setMRMLScene(slicer.mrmlScene)
    self.bgMultiVolumeSelector.addEnabled = 0
    self._bgMultiVolumeSelectorLabel = QLabel('Input multivolume')
    inputFrameWidget = QWidget()
    self.inputFrameLayout = QFormLayout()
    inputFrameWidget.setLayout(self.inputFrameLayout)
    self.inputFrameLayout.addRow(self._bgMultiVolumeSelectorLabel, self.bgMultiVolumeSelector)
    parent.addWidget(inputFrameWidget)

  def setupFrameControlFrame(self):
    # TODO: initialize the slider based on the contents of the labels array
    self.frameSlider = ctk.ctkSliderWidget()
    self.frameLabel = QLabel('Current frame number')
    self.playButton = QPushButton('Play')
    self.playButton.toolTip = 'Iterate over multivolume frames'
    self.playButton.checkable = True
    frameControlHBox = QHBoxLayout()
    frameControlHBox.addWidget(self.frameLabel)
    frameControlHBox.addWidget(self.frameSlider)
    frameControlHBox.addWidget(self.playButton)
    self.inputFrameLayout.addRow(frameControlHBox)

  def setupAdditionalFrames(self):
    pass

  def setupPlottingFrame(self, parent=None):
    if not parent:
      parent = self.layout
    self.plottingFrameWidget = QWidget()
    self.plottingFrameLayout = QGridLayout()
    self.plottingFrameWidget.setLayout(self.plottingFrameLayout)
    self._multiVolumeIntensityChart = MultiVolumeIntensityChartView()
    self.popupChartButton = QPushButton("Undock chart")
    self.popupChartButton.setCheckable(True)
    self.plottingFrameLayout.addWidget(self._multiVolumeIntensityChart.chartView)
    self.plottingFrameLayout.addWidget(self.popupChartButton)
    parent.addWidget(self.plottingFrameWidget)

  def setupConnections(self):
    self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)', self.onVCMRMLSceneChanged)
    self.bgMultiVolumeSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onBackgroundInputChanged)
    self.playButton.connect('toggled(bool)', self.onPlayButtonToggled)
    self.frameSlider.connect('valueChanged(double)', self.onSliderChanged)
    self.timer.connect('timeout()', self.goToNext)
    self.popupChartButton.connect('toggled(bool)', self.onDockChartViewToggled)

  def onDockChartViewToggled(self, checked):
    if checked:
      self.chartPopupWindow = QDialog()
      self.chartPopupWindow.setWindowFlags(PythonQt.QtCore.Qt.WindowStaysOnTopHint)
      layout = QGridLayout()
      self.chartPopupWindow.setLayout(layout)
      layout.addWidget(self._multiVolumeIntensityChart.chartView)
      layout.addWidget(self.popupChartButton)
      self.chartPopupWindow.finished.connect(self.dockChartView)
      self.chartPopupWindow.resize(self.chartPopupSize)
      self.chartPopupWindow.move(self.chartPopupPosition)
      self.chartPopupWindow.show()
      self.popupChartButton.setText("Dock chart")
      self._multiVolumeIntensityChart.chartView.show()
    else:
      self.chartPopupWindow.close()

  def dockChartView(self):
    self.chartPopupSize = self.chartPopupWindow.size
    self.chartPopupPosition = self.chartPopupWindow.pos
    self.plottingFrameLayout.addWidget(self._multiVolumeIntensityChart.chartView)
    self.plottingFrameLayout.addWidget(self.popupChartButton)
    self.popupChartButton.setText("Undock chart")
    self.popupChartButton.disconnect('toggled(bool)', self.onDockChartViewToggled)
    self.popupChartButton.checked = False
    self.popupChartButton.connect('toggled(bool)', self.onDockChartViewToggled)

  def onSliderChanged(self, frameId):
    if self._bgMultiVolumeNode is None:
      return
    newValue = int(frameId)
    self.setCurrentFrameNumber(newValue)

  def onVCMRMLSceneChanged(self, mrmlScene):
    logging.debug("qSlicerMultiVolumeExplorerSimplifiedModuleWidget:onVCMRMLSceneChanged")
    self.bgMultiVolumeSelector.setMRMLScene(slicer.mrmlScene)
    self.onBackgroundInputChanged()

  def refreshGUIForNewBackgroundImage(self):
    self._multiVolumeIntensityChart.reset()
    self.setFramesEnabled(True)
    if self._fgMultiVolumeNode and self._bgMultiVolumeNode:
      Helper.SetBgFgVolumes(self._bgMultiVolumeNode.GetID(), self._fgMultiVolumeNode.GetID())
    else:
      Helper.SetBgVolume(self._bgMultiVolumeNode.GetID())
    self.refreshFrameSlider()
    self._multiVolumeIntensityChart.bgMultiVolumeNode = self._bgMultiVolumeNode
    self.refreshObservers()

  def getBackgroundMultiVolumeNode(self):
    return self.bgMultiVolumeSelector.currentNode()

  def onBackgroundInputChanged(self):
    self._bgMultiVolumeNode = self.getBackgroundMultiVolumeNode()

    if self._bgMultiVolumeNode is not None:
      self.refreshGUIForNewBackgroundImage()
    else:
      self.setFramesEnabled(False)

  def onPlayButtonToggled(self, checked):
    if self._bgMultiVolumeNode is None:
      return
    if checked:
      self.timer.start()
      self.playButton.text = 'Stop'
    else:
      self.timer.stop()
      self.playButton.text = 'Play'

  def processEvent(self, observee, event):
    # logging.debug("processing event %s" % event)
    if self._bgMultiVolumeNode is None:
      return

    # TODO: use a timer to delay calculation and compress events
    if event == 'LeaveEvent':
      # reset all the readouts
      # TODO: reset the label text
      return

    if not self.sliceWidgetsPerStyle.has_key(observee):
      return

    interactor = observee.GetInteractor()
    self.createChart(self.sliceWidgetsPerStyle[observee], interactor.GetEventPosition())

  def createChart(self, sliceWidget, position):
    self._multiVolumeIntensityChart.createChart(sliceWidget, position)

  def setCurrentFrameNumber(self, frameNumber):
    mvDisplayNode = self._bgMultiVolumeNode.GetDisplayNode()
    mvDisplayNode.SetFrameComponent(frameNumber)

  def setFramesEnabled(self, enabled):
    pass

  def refreshObservers(self):
    """ When the layout changes, drop the observers from
    all the old widgets and create new observers for the
    newly created widgets"""
    self.removeObservers()
    # get new slice nodes
    layoutManager = slicer.app.layoutManager()
    sliceNodeCount = slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLSliceNode')
    for nodeIndex in xrange(sliceNodeCount):
      # find the widget for each node in scene
      sliceNode = slicer.mrmlScene.GetNthNodeByClass(nodeIndex, 'vtkMRMLSliceNode')
      sliceWidget = layoutManager.sliceWidget(sliceNode.GetLayoutName())
      if sliceWidget:
        # add observers and keep track of tags
        style = sliceWidget.sliceView().interactorStyle()
        self.sliceWidgetsPerStyle[style] = sliceWidget
        events = ("MouseMoveEvent", "EnterEvent", "LeaveEvent")
        for event in events:
          tag = style.AddObserver(event, self.processEvent)
          self.styleObserverTags.append([style,tag])

  def removeObservers(self):
    for observee,tag in self.styleObserverTags:
      observee.RemoveObserver(tag)
    self.styleObserverTags = []
    self.sliceWidgetsPerStyle = {}

  def refreshFrameSlider(self):
    self.frameSlider.minimum = 0
    if not self._bgMultiVolumeNode:
      self.frameSlider.maximum = 0
      return
    nFrames = self._bgMultiVolumeNode.GetNumberOfFrames()
    self.frameSlider.maximum = nFrames - 1

  def goToNext(self):
    currentElement = self.frameSlider.value
    currentElement += 1
    if currentElement > self.frameSlider.maximum:
      currentElement = 0
    self.frameSlider.value = currentElement
Ejemplo n.º 29
0
 def reject(self):
     QDialog.reject(self)
class qSlicerMultiVolumeExplorerSimplifiedModuleWidget:
    def __init__(self, parent=None):
        logging.debug(
            "qSlicerMultiVolumeExplorerSimplifiedModuleWidget:init() called")
        if not parent or not hasattr(parent, "layout"):
            self.parent = slicer.qMRMLWidget()
            self.parent.setLayout(QVBoxLayout())
        else:
            self.parent = parent

        self.layout = self.parent.layout()

        self._bgMultiVolumeNode = None
        self._fgMultiVolumeNode = None

        self.styleObserverTags = []
        self.sliceWidgetsPerStyle = {}

        self.chartPopupWindow = None
        self.chartPopupSize = QSize(600, 300)
        self.chartPopupPosition = QPoint(0, 0)

    def hide(self):
        self.widget.hide()

    def show(self):
        self.widget.show()

    def setup(self):
        self.widget = QWidget()
        layout = QGridLayout()
        self.widget.setLayout(layout)
        self.layout.addWidget(self.widget)
        self.widget.show()
        self.layout = layout

        self.setupInputFrame()
        self.setupFrameControlFrame()
        self.setupAdditionalFrames()
        self.setupPlottingFrame()

        self.setFramesEnabled(False)

        self.timer = QTimer()
        self.timer.setInterval(50)

        self.setupConnections()

        # initialize slice observers (from DataProbe.py)
        # keep list of pairs: [observee,tag] so they can be removed easily
        self.styleObserverTags = []
        # keep a map of interactor styles to sliceWidgets so we can easily get sliceLogic
        self.sliceWidgetsPerStyle = {}
        self.refreshObservers()

    def setupInputFrame(self, parent=None):
        if not parent:
            parent = self.layout
        self.bgMultiVolumeSelector = slicer.qMRMLNodeComboBox()
        self.bgMultiVolumeSelector.nodeTypes = ['vtkMRMLMultiVolumeNode']
        self.bgMultiVolumeSelector.setMRMLScene(slicer.mrmlScene)
        self.bgMultiVolumeSelector.addEnabled = 0
        self._bgMultiVolumeSelectorLabel = QLabel('Input multivolume')
        inputFrameWidget = QWidget()
        self.inputFrameLayout = QFormLayout()
        inputFrameWidget.setLayout(self.inputFrameLayout)
        self.inputFrameLayout.addRow(self._bgMultiVolumeSelectorLabel,
                                     self.bgMultiVolumeSelector)
        parent.addWidget(inputFrameWidget)

    def setupFrameControlFrame(self):
        # TODO: initialize the slider based on the contents of the labels array
        self.frameSlider = ctk.ctkSliderWidget()
        self.frameSlider.setSizePolicy(QSizePolicy.Ignored,
                                       QSizePolicy.Preferred)
        self.frameLabel = QLabel('Current frame number')
        self.playButton = QPushButton('Play')
        self.playButton.toolTip = 'Iterate over multivolume frames'
        self.playButton.checkable = True
        frameControlHBox = QHBoxLayout()
        frameControlHBox.addWidget(self.frameLabel)
        frameControlHBox.addWidget(self.frameSlider)
        frameControlHBox.addWidget(self.playButton)
        self.inputFrameLayout.addRow(frameControlHBox)

    def setupAdditionalFrames(self):
        pass

    def setupPlottingFrame(self, parent=None):
        if not parent:
            parent = self.layout
        self.plottingFrameWidget = QWidget()
        self.plottingFrameLayout = QGridLayout()
        self.plottingFrameWidget.setLayout(self.plottingFrameLayout)
        self._multiVolumeIntensityChart = MultiVolumeIntensityChartView()
        self.popupChartButton = QPushButton("Undock chart")
        self.popupChartButton.setCheckable(True)
        self.plottingFrameLayout.addWidget(
            self._multiVolumeIntensityChart.chartView)
        self.plottingFrameLayout.addWidget(self.popupChartButton)
        parent.addWidget(self.plottingFrameWidget)

    def setupConnections(self):
        self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)',
                            self.onVCMRMLSceneChanged)
        self.bgMultiVolumeSelector.connect('currentNodeChanged(vtkMRMLNode*)',
                                           self.onBackgroundInputChanged)
        self.playButton.connect('toggled(bool)', self.onPlayButtonToggled)
        self.frameSlider.connect('valueChanged(double)', self.onSliderChanged)
        self.timer.connect('timeout()', self.goToNext)
        self.popupChartButton.connect('toggled(bool)',
                                      self.onDockChartViewToggled)

    def onDockChartViewToggled(self, checked):
        if checked:
            self.chartPopupWindow = QDialog()
            self.chartPopupWindow.setWindowFlags(
                PythonQt.QtCore.Qt.WindowStaysOnTopHint)
            layout = QGridLayout()
            self.chartPopupWindow.setLayout(layout)
            layout.addWidget(self._multiVolumeIntensityChart.chartView)
            layout.addWidget(self.popupChartButton)
            self.chartPopupWindow.finished.connect(self.dockChartView)
            self.chartPopupWindow.resize(self.chartPopupSize)
            self.chartPopupWindow.move(self.chartPopupPosition)
            self.chartPopupWindow.show()
            self.popupChartButton.setText("Dock chart")
            self._multiVolumeIntensityChart.chartView.show()
        else:
            self.chartPopupWindow.close()

    def dockChartView(self):
        self.chartPopupSize = self.chartPopupWindow.size
        self.chartPopupPosition = self.chartPopupWindow.pos
        self.plottingFrameLayout.addWidget(
            self._multiVolumeIntensityChart.chartView)
        self.plottingFrameLayout.addWidget(self.popupChartButton)
        self.popupChartButton.setText("Undock chart")
        self.popupChartButton.disconnect('toggled(bool)',
                                         self.onDockChartViewToggled)
        self.popupChartButton.checked = False
        self.popupChartButton.connect('toggled(bool)',
                                      self.onDockChartViewToggled)

    def onSliderChanged(self, frameId):
        if self._bgMultiVolumeNode is None:
            return
        newValue = int(frameId)
        self.setCurrentFrameNumber(newValue)

    def onVCMRMLSceneChanged(self, mrmlScene):
        logging.debug(
            "qSlicerMultiVolumeExplorerSimplifiedModuleWidget:onVCMRMLSceneChanged"
        )
        self.bgMultiVolumeSelector.setMRMLScene(slicer.mrmlScene)
        self.onBackgroundInputChanged()

    def refreshGUIForNewBackgroundImage(self):
        self._multiVolumeIntensityChart.reset()
        self.setFramesEnabled(True)
        if self._fgMultiVolumeNode and self._bgMultiVolumeNode:
            Helper.SetBgFgVolumes(self._bgMultiVolumeNode.GetID(),
                                  self._fgMultiVolumeNode.GetID())
        else:
            Helper.SetBgVolume(self._bgMultiVolumeNode.GetID())
        self.refreshFrameSlider()
        self._multiVolumeIntensityChart.bgMultiVolumeNode = self._bgMultiVolumeNode
        self.refreshObservers()

    def getBackgroundMultiVolumeNode(self):
        return self.bgMultiVolumeSelector.currentNode()

    def onBackgroundInputChanged(self):
        self._bgMultiVolumeNode = self.getBackgroundMultiVolumeNode()

        if self._bgMultiVolumeNode is not None:
            self.refreshGUIForNewBackgroundImage()
        else:
            self.setFramesEnabled(False)

    def onPlayButtonToggled(self, checked):
        if self._bgMultiVolumeNode is None:
            return
        if checked:
            self.timer.start()
            self.playButton.text = 'Stop'
        else:
            self.timer.stop()
            self.playButton.text = 'Play'

    def processEvent(self, observee, event):
        # logging.debug("processing event %s" % event)
        if self._bgMultiVolumeNode is None:
            return

        # TODO: use a timer to delay calculation and compress events
        if event == 'LeaveEvent':
            # reset all the readouts
            # TODO: reset the label text
            return

        if not self.sliceWidgetsPerStyle.has_key(observee):
            return

        interactor = observee.GetInteractor()
        self.createChart(self.sliceWidgetsPerStyle[observee],
                         interactor.GetEventPosition())

    def createChart(self, sliceWidget, position):
        self._multiVolumeIntensityChart.createChart(sliceWidget, position)

    def setCurrentFrameNumber(self, frameNumber):
        mvDisplayNode = self._bgMultiVolumeNode.GetDisplayNode()
        mvDisplayNode.SetFrameComponent(frameNumber)

    def setFramesEnabled(self, enabled):
        pass

    def refreshObservers(self):
        """ When the layout changes, drop the observers from
    all the old widgets and create new observers for the
    newly created widgets"""
        self.removeObservers()
        # get new slice nodes
        layoutManager = slicer.app.layoutManager()
        sliceNodeCount = slicer.mrmlScene.GetNumberOfNodesByClass(
            'vtkMRMLSliceNode')
        for nodeIndex in xrange(sliceNodeCount):
            # find the widget for each node in scene
            sliceNode = slicer.mrmlScene.GetNthNodeByClass(
                nodeIndex, 'vtkMRMLSliceNode')
            sliceWidget = layoutManager.sliceWidget(sliceNode.GetLayoutName())
            if sliceWidget:
                # add observers and keep track of tags
                style = sliceWidget.sliceView().interactorStyle()
                self.sliceWidgetsPerStyle[style] = sliceWidget
                events = ("MouseMoveEvent", "EnterEvent", "LeaveEvent")
                for event in events:
                    tag = style.AddObserver(event, self.processEvent)
                    self.styleObserverTags.append([style, tag])

    def removeObservers(self):
        for observee, tag in self.styleObserverTags:
            observee.RemoveObserver(tag)
        self.styleObserverTags = []
        self.sliceWidgetsPerStyle = {}

    def refreshFrameSlider(self):
        self.frameSlider.minimum = 0
        if not self._bgMultiVolumeNode:
            self.frameSlider.maximum = 0
            return
        nFrames = self._bgMultiVolumeNode.GetNumberOfFrames()
        self.frameSlider.maximum = nFrames - 1

    def goToNext(self):
        currentElement = self.frameSlider.value
        currentElement += 1
        if currentElement > self.frameSlider.maximum:
            currentElement = 0
        self.frameSlider.value = currentElement
Ejemplo n.º 31
0
 def accept(self):
     if self.accepted:
         QDialog.accept(self)