class ToolGui(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) # self.grid.setAlignment(QtCore.Qt.AlignLeft) # add height image in grid self.h_image_lbl = LabelWordWrap(_("Image height"), self) self.h_image_lbl.setMaximumWidth(self.h_image_lbl.sizeHint().width()) self.h_image_lineedit = QtGui.QLineEdit(self) self.h_image_lineedit.setToolTip(_("Set a fixed height image for " "actions") + " " + _("0: hide images")) self.h_image_lineedit.setText(str(ClientObj.height_image)) self.grid.addWidget(self.h_image_lbl, 0, 0) self.grid.addWidget(self.h_image_lineedit, 0, 1) # add expers view result in grid self.expert_lbl = LabelWordWrap(_("Expert view"), self) self.expert_checkbox = QtGui.QCheckBox(self) self.expert_checkbox.setChecked(ClientObj.expert) self.expert_lbl.setToolTip(_("View results in expert mode")) self.expert_checkbox.setToolTip(_("View results in expert mode")) self.grid.addWidget(self.expert_lbl, 1, 0) self.grid.addWidget(self.expert_checkbox, 1, 1, 1, 2) # add count item in result table in grid self.count_row_lbl = LabelWordWrap(_("Rows in Table"), self) self.count_row_lbl.setMaximumWidth(self.count_row_lbl.sizeHint().width()) self.count_row_lineedit = QtGui.QLineEdit(self) self.count_row_lineedit.setText(str(ClientObj.count_row_res_table)) self.grid.addWidget(self.count_row_lbl, 2, 0) self.grid.addWidget(self.count_row_lineedit, 2, 1) # add spacer self.grid.addItem(QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding), 3, 0, 1, 2) # connect all with change value slot self.h_image_lineedit.textChanged.connect(self.changed_val) self.expert_checkbox.clicked.connect(self.changed_val) self.count_row_lineedit.textChanged.connect(self.changed_val) def changed_val(self): self._parent.changed_flag = True def set_opacity_lbl(self, val): self.opacity_lbl.setText(self.opacity_lbl_text + str(val)) 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 = [] # bg_color_flag = False count_row_flag = False expert_flag = False count_row_flag = False h_image_flag = False for line in config: if line.startswith("height_image "): h_image_flag = True try: height_image = int(self.h_image_lineedit.text()) except ValueError: height_image = ClientObj.height_image if height_image < 0 or height_image > 512: height_image = ClientObj.height_image new_config.append("height_image = %d\n" % height_image) elif line.startswith("expert "): expert_flag = True if self.expert_checkbox.isChecked(): expert = 1 else: expert = 0 new_config.append("expert = %d\n" % expert) elif line.startswith("count_row "): count_row_flag = True try: count_row = int(self.count_row_lineedit.text()) if count_row < 2: count_row = 2 except ValueError: count_row = ClientObj.count_row_res_table new_config.append("count_row = %d\n" % count_row) else: new_config.append(line) if self.expert_checkbox.isChecked(): expert = 1 else: expert = 0 new_config = self.check_cfg(expert_flag, new_config, "[gui]", "expert", expert) try: count_row = int(self.count_row_lineedit.text()) if count_row < 2: count_row = 2 except ValueError: count_row = ClientObj.count_row_res_table new_config = self.check_cfg(count_row_flag, new_config, "[gui]", "count_row", count_row) try: height_image = int(self.h_image_lineedit.text()) except ValueError: height_image = ClientObj.height_image if height_image < 0 or height_image > 512: height_image = ClientObj.height_image new_config = self.check_cfg(h_image_flag, new_config, "[gui]", "height_image", height_image) 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 return wrapper
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
def __init__(self, parent, ClientObj): # super(ViewProc, self).__init__(parent) QtGui.QWidget.__init__(self, parent) # self._parent = parent self.ClientObj = ClientObj self.client = ClientObj.client self.pid = 0 client_pid_info(ClientObj, ClientObj.client, 0) list_pid = client_list_pid(self.ClientObj.client) ClientObj._parent.setWindowTitle ( \ _('View information about the running processes')\ + ' - ' + self.ClientObj.Name) self.lable_list = [] self.button_list = [] self.status_list = [] self.grid_layout = QtGui.QGridLayout() self.helpLabel = LabelWordWrap \ (_('View information about the running processes'), self) self.grid_layout.addWidget(self.helpLabel, 0, 0, 1, 0) if not list_pid: list_pid = [] for num in range (0, len(list_pid)): if list_pid[num] == ClientObj._parent.sys_update_pid: continue # add method name if self.ClientObj.process_dict[str(list_pid[num])].has_key \ ('method_name'): method_name = self.ClientObj.process_dict[str(list_pid[num])] \ ['method_name'] else: method_name = self.ClientObj.process_dict[str(list_pid[num])] \ ['name'] if self.ClientObj.method_names.has_key(method_name): view_method_name = self.ClientObj.method_names[method_name] # try: # view_method_name = self.ClientObj.param_objects \ # [method_name]['view_method_name'] # except: else: view_method_name = method_name try: view_method_name = view_method_name.encode('utf-8') except (UnicodeEncodeError, UnicodeDecodeError): pass self.lable_list.append(LabelWordWrap(str(view_method_name), self)) self.grid_layout.addWidget(self.lable_list[num], num+2,0) # add start time process # del mircosec time_text = ClientObj.process_dict[str(list_pid[num])]['time'].\ rsplit('.', 1)[0] self.grid_layout.addWidget(LabelWordWrap(time_text, self), num+2,1) # add status button if self.ClientObj.process_dict[str(list_pid[num])]['status'] == '1': kill_but_text = _('Kill the process? (It\'s active)') kill_button = QtGui.QPushButton(kill_but_text, self) kill_button.clicked.connect(self.kill_process \ (int(list_pid[num]), num+2, 2)) self.status_list.append(kill_button) if self.ClientObj.process_dict[str(list_pid[num])]['status'] =='0': self.status_list.append(LabelWordWrap \ (_('Process completed'), self)) if self.ClientObj.process_dict[str(list_pid[num])]['status'] =='2': self.status_list.append(LabelWordWrap \ (_('Process killed'), self)) self.grid_layout.addWidget(self.status_list[num], num+2, 2) # add 'View result' button button_text = _('View the result, PID %s') %str(list_pid[num]) Button = QtGui.QPushButton(button_text, self) Button.clicked.connect(self.onActivated(str(list_pid[num]), \ str(view_method_name))) self.button_list.append(Button) self.grid_layout.addWidget(self.button_list[num], num+2, 3) if not len(list_pid): self.grid_layout.addWidget(LabelWordWrap(_('No running processes' ' in the current session'), self)) else: self.grid_layout.addWidget(LabelWordWrap(_('Task name'), self),1,0) self.grid_layout.addWidget(LabelWordWrap(_('Start time'),self),1,1) self.grid_layout.addWidget(LabelWordWrap(_('Status'), self), 1,2) lbl = LabelWordWrap(_('Result'), self) lbl.setMinimumHeight(lbl.sizeHint().height()*3) self.grid_layout.addWidget(lbl, 1,3) # for clear memory after closed this window self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.grid_layout.setAlignment(QtCore.Qt.AlignTop) self.setLayout(self.grid_layout) self.show()