view RemoteViewer/ConnectionDialog.py @ 25:2e5a12e3598e

add a low color mode
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 26 Sep 2014 04:57:10 +0200
parents 6a62de088c00
children fb7442228526
line wrap: on
line source

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QDialog
from .Connection import Connection
from .Ui_ConnectionDialog import Ui_ConnectionDialog

class ConnectionDialog(QDialog):
    def __init__(self,  windowTitle='', connection=Connection()):
        super(QDialog, self).__init__()
        self.connection = connection
        self.__initUi(windowTitle)

    def __initUi(self, windowTitle):
        self.ui = Ui_ConnectionDialog()
        self.ui.setupUi(self)
        self.setWindowTitle(windowTitle)
        self.__initTypeDropDown()
        self.__loadConnection()
        self.__connectWidgetSlots()

    def __initTypeDropDown(self):
        self.ui.type.addItem('rdp')
        self.ui.type.addItem('vnc')

    def __loadConnection(self):
        self.ui.title.setText(self.connection.title)
        if self.connection.type == 'rdp':
            index = 0
        else:
            index = 1
        self.ui.type.setCurrentIndex(index)
        self.ui.hostname.setText(self.connection.host)
        self.ui.username.setText(self.connection.user)
        self.ui.geometry.setText(self.connection.geometry)
        checkState = Qt.Unchecked
        if self.connection.lowColor is True:
            checkState = Qt.Checked
        self.ui.lowColor.setCheckState(checkState)

    def __connectWidgetSlots(self):
        self.ui.title.textChanged.connect(self.connection.setTitle)
        self.ui.type.activated[str].connect(self.connection.setType)
        self.ui.hostname.textChanged.connect(self.connection.setHost)
        self.ui.username.textChanged.connect(self.connection.setUser)
        self.ui.geometry.textChanged.connect(self.connection.setGeometry)
        self.ui.lowColor.clicked[bool].connect(self.connection.setLowColor)

    def accept(self):
        validationErrors = self.connection.validate()
        if validationErrors is None:
            super(ConnectionDialog, self).accept()
        else:
            # TODO: display the error message
            print('connection has validation errors:',  validationErrors)