예제 #1
0
    def __init__(self, parent):
        MultipleDatabaseWidget.__init__(self, parent)

        self.toplabel.setText(_("Known connections"))

        self.grid_layout.addWidget(self.list_widget, 0, 0)
        self.grid_layout.addWidget(self.details_browser,0, 1)
    def __init__(self, parent):
        MultipleDatabaseWidget.__init__(self, parent)

        self.toplabel.setText(_("Known connections"))

        self.grid_layout.addWidget(self.list_widget, 0, 0)
        self.grid_layout.addWidget(self.details_browser, 0, 1)
예제 #3
0
    def __init__(self, parent=None):
        ExtendableDialog.__init__(self, parent)

        self.setWindowTitle(_("Connect to Database"))

        self.enableApply()

        self.multiple_db_widg = MultipleDatabaseWidget(self)

        self.add_advanced_widget(self.multiple_db_widg)

        self.label = QtGui.QLabel()

        self.insertWidget(self.label)

        self.set_advanced_but_text(_("other databases"))
예제 #4
0
    def __init__(self, parent=None):
        ExtendableDialog.__init__(self, parent)

        self.setWindowTitle(_("Connect to Database"))

        self.enableApply()

        self.multiple_db_widg = MultipleDatabaseWidget(self)

        self.add_advanced_widget(self.multiple_db_widg)

        self.label = QtGui.QLabel()

        self.insertWidget(self.label)

        self.set_advanced_but_text(_("other databases"))
예제 #5
0
class ConnectDialog(ExtendableDialog):
    '''
    this dialog will invite the user to enter the parameters required to
    connect to a database
    '''

    _known_connections = []
    _chosen_index = 0

    def __init__(self, parent=None):
        ExtendableDialog.__init__(self, parent)

        self.setWindowTitle(_("Connect to Database"))

        self.enableApply()

        self.multiple_db_widg = MultipleDatabaseWidget(self)

        self.add_advanced_widget(self.multiple_db_widg)

        self.label = QtGui.QLabel()

        self.insertWidget(self.label)

        self.set_advanced_but_text(_("other databases"))

    def _connect_signals(self):
        self.multiple_db_widg.connection_chosen.connect(self.alternate_chosen)

    @property
    def known_connections(self):
        '''
        returns a list of type :doc:`ConnectionData`
        '''
        return self._known_connections

    def set_known_connections(self, connections):
        '''
        set connections
        '''
        logging.debug("setting known connections")
        assert type(connections) == types.ListType, "connections must be list"
        for conn_data in connections:
            logging.debug(conn_data)
            assert type(conn_data) == ConnectionData, "connection type unknown"

        self._known_connections = connections
        self.multiple_db_widg.set_connections(connections)

    @property
    def connection(self):
        if not self.known_connections:
            QtGui.QMessageBox.information(self.parent(), _("information"),
            u'<b>%s</b><br/>%s'%(
            _('NO database details found'),
            _('will offer connection to the demo database on localhost.')))

            conn_data = ConnectionData()
            conn_data.demo_connection()
            self._known_connections = [conn_data]
            return conn_data

        return self.known_connections[self._chosen_index]

    def _clicked(self, but):
        '''
        Overwrite :doc:`ExtendableDialog` function to enable the active widget
        '''
        self.multiple_db_widg.setEnabled(True)
        ExtendableDialog._clicked(self, but)

    def set_label(self):
        header = _('Connect to this database?')

        message = u'<div align="center"><b>%s</b></div><ul>%s'% (header,
            self.connection.to_html())

        self.label.setText(message)

    def sizeHint(self):
        return QtCore.QSize(400,150)

    def alternate_chosen(self, conn_data):
        if QtGui.QMessageBox.question(self, _("Confirm"),
            u"%s %s" %(_("use connection"), conn_data.brief_name),
            QtGui.QMessageBox.Ok|QtGui.QMessageBox.Cancel,
            QtGui.QMessageBox.Ok) == QtGui.QMessageBox.Ok:
            self._chosen_index = self.known_connections.index(conn_data)

            self.set_label()
            self.multiple_db_widg.setEnabled(False)
            QtCore.QTimer.singleShot(500, self.more_but.click)

    @property
    def chosen_connection(self):
        return self.connection

    def exec_(self):
        self.set_label()
        self._connect_signals()
        return ExtendableDialog.exec_(self)
예제 #6
0
class ConnectDialog(ExtendableDialog):
    '''
    this dialog will invite the user to enter the parameters required to
    connect to a database
    '''

    _known_connections = []
    _chosen_index = 0

    def __init__(self, parent=None):
        ExtendableDialog.__init__(self, parent)

        self.setWindowTitle(_("Connect to Database"))

        self.enableApply()

        self.multiple_db_widg = MultipleDatabaseWidget(self)

        self.add_advanced_widget(self.multiple_db_widg)

        self.label = QtGui.QLabel()

        self.insertWidget(self.label)

        self.set_advanced_but_text(_("other databases"))

    def _connect_signals(self):
        self.multiple_db_widg.connection_chosen.connect(self.alternate_chosen)

    @property
    def known_connections(self):
        '''
        returns a list of type :doc:`ConnectionData`
        '''
        return self._known_connections

    def set_known_connections(self, connections):
        '''
        set connections
        '''
        logging.debug("setting known connections")
        assert type(connections) == types.ListType, "connections must be list"
        for conn_data in connections:
            logging.debug(conn_data)
            assert type(conn_data) == ConnectionData, "connection type unknown"

        self._known_connections = connections
        self.multiple_db_widg.set_connections(connections)

    @property
    def connection(self):
        if not self.known_connections:
            QtGui.QMessageBox.information(
                self.parent(), _("information"), u'<b>%s</b><br/>%s' %
                (_('NO database details found'),
                 _('will offer connection to the demo database on localhost.'))
            )

            conn_data = ConnectionData()
            conn_data.demo_connection()
            self._known_connections = [conn_data]
            return conn_data

        return self.known_connections[self._chosen_index]

    def _clicked(self, but):
        '''
        Overwrite :doc:`ExtendableDialog` function to enable the active widget
        '''
        self.multiple_db_widg.setEnabled(True)
        ExtendableDialog._clicked(self, but)

    def set_label(self):
        header = _('Connect to this database?')

        message = u'<div align="center"><b>%s</b></div><ul>%s' % (
            header, self.connection.to_html())

        self.label.setText(message)

    def sizeHint(self):
        return QtCore.QSize(400, 150)

    def alternate_chosen(self, conn_data):
        if QtGui.QMessageBox.question(
                self, _("Confirm"),
                u"%s %s" % (_("use connection"), conn_data.brief_name),
                QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel,
                QtGui.QMessageBox.Ok) == QtGui.QMessageBox.Ok:
            self._chosen_index = self.known_connections.index(conn_data)

            self.set_label()
            self.multiple_db_widg.setEnabled(False)
            QtCore.QTimer.singleShot(500, self.more_but.click)

    @property
    def chosen_connection(self):
        return self.connection

    def exec_(self):
        self.set_label()
        self._connect_signals()
        return ExtendableDialog.exec_(self)