Example #1
0
	def newCombo(self):
		taskList  = [u'--請選擇--', u'值班', u'救護勤務', u'備勤', u'待命服勤', u'水源查察', u'消防查察', u'宣導勤務', u'訓(演)練', u'專案勤務', u'南山救護站']
		nComboBox = QComboBox()
		nComboBox.addItems(taskList)
		for i in xrange(len(taskList)):
			if i == 0:
				nComboBox.setItemData(i, QColor('#550000'), Qt.BackgroundColorRole)
			nComboBox.setItemData(i, Qt.AlignCenter, Qt.TextAlignmentRole)
		nComboBox.setStyleSheet("text-align: right; font: bold 13px;")		
		return nComboBox
Example #2
0
class ToolOther(QtGui.QWidget):
    def __init__(self, parent, ClientObj):
        QtGui.QWidget.__init__(self, parent)
        self.user_config = ClientObj.user_config
        self._parent = parent

        self.grid = QtGui.QGridLayout(self)

        self.grid.setContentsMargins(2, 2, 2, 2)
        self.grid.setSpacing(2)
        self.grid.setColumnStretch(0, 3)
        self.grid.setColumnStretch(1, 5)

        # lang settings
        self.lang_lbl = LabelWordWrap(_("Select Language"), self)
        self.lang_lbl.setMaximumWidth(self.lang_lbl.sizeHint().width())

        self.lang_ComboBox = QComboBox(self)
        lang_dict = {"en": _("English"), "ru": _("Russian"), "fr": _("French")}

        for lang in lang_dict:
            self.lang_ComboBox.addItem(lang_dict[lang])
            self.lang_ComboBox.setItemData(self.lang_ComboBox.count() - 1, lang)
            if ClientObj.lang == lang:
                self.lang_ComboBox.setCurrentIndex(self.lang_ComboBox.count() - 1)

        # add lang settings in grid
        self.grid.addWidget(self.lang_lbl, 0, 0)
        self.grid.addWidget(self.lang_ComboBox, 0, 1)

        # add open file in grid
        self.cert_path_lbl = LabelWordWrap(_("Path to Certificates"), self)
        self.cert_path_lbl.setMaximumWidth(self.cert_path_lbl.sizeHint().width())

        self.fd_cert = FileOpenWgt(self, "dir", _("Certificate Directory"), "~/.calculate")

        self.fd_cert.setToolTip(_("Empty to default path"))
        self.fd_cert.setText(ClientObj.path_to_cert)

        self.grid.addWidget(self.cert_path_lbl, 1, 0)
        self.grid.addWidget(self.fd_cert, 1, 1)

        #        # add timeout in grid
        #        self.timeout_lbl = LabelWordWrap(_('Timeout'), self)
        #        self.timeout_lbl.setMaximumWidth(self.timeout_lbl.sizeHint().width())
        #
        #        self.timeout_lineedit = QtGui.QLineEdit(self)
        #
        #        self.timeout_lineedit.setText(str(ClientObj.timeout))
        #
        #        self.grid.addWidget(self.timeout_lbl, 2, 0)
        #        self.grid.addWidget(self.timeout_lineedit, 2, 1)

        # add spacer
        self.grid.addItem(QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding), 5, 0, 1, 2)

        # connect all with change value slot
        self.lang_ComboBox.currentIndexChanged.connect(self.changed_val)
        self.fd_cert.textChanged.connect(self.changed_val)
        #        self.timeout_lineedit.textChanged.connect(self.changed_val)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

    def changed_val(self):
        self._parent.changed_flag = True

    def check_cfg(self, flag, config, part, param, value):
        # if param not exists in config
        if not flag:
            part_flag = False
            temp_cfg = []
            for line in config:
                temp_cfg.append(line)
                # add new line in config
                if line.startswith(part):
                    temp_cfg.append("%s = %s\n" % (param, value))
                    part_flag = True

            config = temp_cfg
            # if part not exists
            if not part_flag:
                config.append("\n")
                config.append("%s\n" % part)
                config.append("%s = %s\n" % (param, value))
        return config

    def save_changes(self, ClientObj):
        def wrapper():
            if not os.path.isfile(self.user_config):
                f = open(self.user_config, "w")
                f.close()

            fc = open(self.user_config, "r")
            config = fc.readlines()
            fc.close()
            new_config = []

            lang_flag = False
            cert_flag = False
            #            timeout_flag = False
            for line in config:
                if line.startswith("lang "):
                    lang_flag = True
                    new_config.append("lang = %s\n" % self.lang_ComboBox.itemData(self.lang_ComboBox.currentIndex()))
                elif line.startswith("path_to_cert "):
                    cert_flag = True
                    if os.path.isdir(self.fd_cert.text()):
                        new_config.append("path_to_cert = %s\n" % self.fd_cert.text())
                    elif not self.fd_cert.text():
                        new_config.append("path_to_cert = no\n")
                    else:
                        new_config.append(line)
                #                elif line.startswith('timeout '):
                #                    timeout_flag = True
                #                    try:
                #                        timeout = int(self.timeout_lineedit.text())
                #                    except ValueError:
                #                        timeout = ClientObj.timeout
                #                    new_config.append('timeout = %d\n' %timeout)
                else:
                    new_config.append(line)

            new_config = self.check_cfg(
                lang_flag, new_config, "[other]", "lang", self.lang_ComboBox.itemData(self.lang_ComboBox.currentIndex())
            )

            if not self.fd_cert.text().lower():
                new_config = self.check_cfg(cert_flag, new_config, "[other]", "path_to_cert", "no")
            elif os.path.isdir(self.fd_cert.text()):
                new_config = self.check_cfg(cert_flag, new_config, "[other]", "path_to_cert", self.fd_cert.text())

            #            try:
            #                timeout = int(self.timeout_lineedit.text())
            #            except ValueError:
            #                timeout = ClientObj.timeout
            #            new_config = self.check_cfg (timeout_flag, new_config, \
            #                                '[other]', 'timeout', timeout)

            fnc = open(self.user_config, "w")
            for line in new_config:
                fnc.write(line)
            fnc.close()

            # read config for changed parameters
            ClientObj.create_user_config()
            ClientObj.read_user_config(ClientObj.user_config)

            # reset unsaved changes flag
            self._parent.changed_flag = False
            if ClientObj.client:
                from session_function import client_post_cert

                ClientObj.lang = self.lang_ComboBox.itemData(self.lang_ComboBox.currentIndex())
                if ClientObj.client:
                    try:
                        client_post_cert(ClientObj.client, ClientObj.lang)
                    except:
                        return
                    ClientObj.methods_list = client_list_methods(ClientObj.sid, ClientObj.client)
                    from DisplayMethod import DisplayMethod

                    if type(ClientObj.MainWidget.MainFrameWgt) == DisplayMethod:
                        ClientObj.MainWidget.display_methods()

        return wrapper