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 create_menu(self, display_wgt, groups, sub_groups, ClientObj): self.display_wgt = display_wgt # create left subgroup menu self.old_title = self._parent.ClientObj._parent.windowTitle() # icon_visible(self._parent.ClientObj.MainWidget, 'Methods', True) icon_visible(self._parent.ClientObj.MainWidget, "Back", True) self.widget = QtGui.QWidget(self) # self.cur_palette = display_wgt._parent.viewport().palette() self.widget.setPalette(self.cur_palette) # self.widget.setStyleSheet("QWidget { background-color: rgb(%s) }" \ # %ClientObj.method_background_color.replace(' ',',',2)) self.widget.setStyleSheet("QWidget { background-color: #EEEEEE;}") self.lable_list = [] self.button_list = {} self.layout = QtGui.QVBoxLayout(self.widget) self.layout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter) self.group_name = LabelWordWrap(sub_groups[0].split(".")[0], self) self.group_name.setStyleSheet("QLabel" "{" "border-bottom: 2px outset black;" "border-radius: 3px;" "}") self.group_name.setAlignment(QtCore.Qt.AlignHCenter) self.layout.addWidget(self.group_name) for num in range(len(sub_groups)): if len(sub_groups[num].split(".")) > 1: # try: sub_group = sub_groups[num].split(".")[1] # except (UnicodeDecodeError, UnicodeEncodeError): # pass attrubute_list = [] sub_group_list = [] if self.button_list.has_key(sub_group): attrubute_list = self.button_list[sub_group][0] sub_group_list = self.button_list[sub_group][1] self.button_list[sub_group] = [] param_list = [groups[num * 3], groups[num * 3 + 1], groups[num * 3 + 2]] self.button_list[sub_group].append(attrubute_list + param_list) sub_group_list.append(sub_groups[num].split(".", 1)[1]) self.button_list[sub_group].append(sub_group_list) Button = ButtonMenu(sub_group, sub_group, "folder-documents,folder", self) Button.clicked.connect( display_wgt.groupActivated(self.button_list[sub_group][0], self.button_list[sub_group][1]) ) self.button_list[sub_group].append(Button) continue for i in range(0, len(groups), 3): try: if len(sub_groups[i / 3].split(".")) > 1: continue except IndexError: pass Button = ButtonMenu(groups[i], groups[i + 1], groups[i + 2], self) Button.clicked.connect(self.onActivated) if not self.button_list.has_key(sub_groups[num]): self.button_list[sub_groups[num]] = [] self.button_list[sub_groups[num]].append(Button) for num in range(len(self.button_list)): # add subgroup if len(sub_groups[num].split(".")) > 1: sub_group = sub_groups[num].split(".")[1] self.layout.addWidget(self.button_list[sub_group][len(self.button_list[sub_group]) - 1]) continue # add methos for button in self.button_list[sub_groups[num]]: self.layout.addWidget(button) self.setWidget(self.widget) self.setWidgetResizable(True) # self.setFixedWidth(self.sizeHint().width() + \ # self.verticalScrollBar().sizeHint().width()) self.setFixedWidth(self.sizeHint().width())
class LeftMenu(QtGui.QScrollArea): def __init__(self, parent, ClientObj): QtGui.QScrollArea.__init__(self, parent) self._parent = parent self.ClientObj = ClientObj self.horizontalScrollBar().hide() self.old_title = None # self.setStyleSheet("QWidget { background-color: rgb (%s) ;}" \ # %ClientObj.method_background_color.replace(' ',',',2)) # Set style self.setStyleSheet( "QScrollArea {" # D6D2D0 # "background-color: #EEEEEE;" "background-color: qlineargradient(" "x1: 0, y1: 0, x2: 0, y2: 1, " "stop: 0 #EEEEEE, stop: 0.8 #EEEEEE, " "stop: 1 #E4E1E0);" # "border: 4px solid red;" "border-right: 1px solid qlineargradient(" "x1: 0, y1: 0, x2: 0, y2: 1, " "stop: 0 #A8A3A0, stop: 0.8 #A8A3A0, " "stop: 0.95 transparent, stop: 1 transparent);" # "border-bottom-color: qlineargradient(" # "x1: 0, y1: 0, x2: 0, y2: 1, " # "stop: 0 transparent, stop: 1 #888380);" # "border-left-color: qlineargradient(" # "x1: 1, y1: 0, x2: 0, y2: 0, " # "stop: 0 transparent, stop: 1 #888380);" # "border-top-color: qlineargradient(" # "x1: 0, y1: 1, x2: 0, y2: 0, " # "stop: 0 transparent, stop: 1 #888380);}") "border-bottom: 0px;" "border-left: 0px;" "border-top: 0px;}" ) self.setFrameShape(QtGui.QFrame.Shape.NoFrame) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) def create_menu(self, display_wgt, groups, sub_groups, ClientObj): self.display_wgt = display_wgt # create left subgroup menu self.old_title = self._parent.ClientObj._parent.windowTitle() # icon_visible(self._parent.ClientObj.MainWidget, 'Methods', True) icon_visible(self._parent.ClientObj.MainWidget, "Back", True) self.widget = QtGui.QWidget(self) # self.cur_palette = display_wgt._parent.viewport().palette() self.widget.setPalette(self.cur_palette) # self.widget.setStyleSheet("QWidget { background-color: rgb(%s) }" \ # %ClientObj.method_background_color.replace(' ',',',2)) self.widget.setStyleSheet("QWidget { background-color: #EEEEEE;}") self.lable_list = [] self.button_list = {} self.layout = QtGui.QVBoxLayout(self.widget) self.layout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter) self.group_name = LabelWordWrap(sub_groups[0].split(".")[0], self) self.group_name.setStyleSheet("QLabel" "{" "border-bottom: 2px outset black;" "border-radius: 3px;" "}") self.group_name.setAlignment(QtCore.Qt.AlignHCenter) self.layout.addWidget(self.group_name) for num in range(len(sub_groups)): if len(sub_groups[num].split(".")) > 1: # try: sub_group = sub_groups[num].split(".")[1] # except (UnicodeDecodeError, UnicodeEncodeError): # pass attrubute_list = [] sub_group_list = [] if self.button_list.has_key(sub_group): attrubute_list = self.button_list[sub_group][0] sub_group_list = self.button_list[sub_group][1] self.button_list[sub_group] = [] param_list = [groups[num * 3], groups[num * 3 + 1], groups[num * 3 + 2]] self.button_list[sub_group].append(attrubute_list + param_list) sub_group_list.append(sub_groups[num].split(".", 1)[1]) self.button_list[sub_group].append(sub_group_list) Button = ButtonMenu(sub_group, sub_group, "folder-documents,folder", self) Button.clicked.connect( display_wgt.groupActivated(self.button_list[sub_group][0], self.button_list[sub_group][1]) ) self.button_list[sub_group].append(Button) continue for i in range(0, len(groups), 3): try: if len(sub_groups[i / 3].split(".")) > 1: continue except IndexError: pass Button = ButtonMenu(groups[i], groups[i + 1], groups[i + 2], self) Button.clicked.connect(self.onActivated) if not self.button_list.has_key(sub_groups[num]): self.button_list[sub_groups[num]] = [] self.button_list[sub_groups[num]].append(Button) for num in range(len(self.button_list)): # add subgroup if len(sub_groups[num].split(".")) > 1: sub_group = sub_groups[num].split(".")[1] self.layout.addWidget(self.button_list[sub_group][len(self.button_list[sub_group]) - 1]) continue # add methos for button in self.button_list[sub_groups[num]]: self.layout.addWidget(button) self.setWidget(self.widget) self.setWidgetResizable(True) # self.setFixedWidth(self.sizeHint().width() + \ # self.verticalScrollBar().sizeHint().width()) self.setFixedWidth(self.sizeHint().width()) def groupActivated(self, groups, sub_group, title, ClientObj, back=False): ClientObj.MainWidget.delete_MainFrameWgt() ClientObj.MainWidget.MainFrameWgt = QtGui.QWidget(ClientObj.MainWidget) hlayout = QtGui.QHBoxLayout() hlayout.addItem(QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)) ClientObj.MainWidget.MainFrameWgt.setLayout(hlayout) ClientObj.MainWidget.main_frame.setWidget(ClientObj.MainWidget.MainFrameWgt) ClientObj.MainWidget.main_frame.setWidgetResizable(True) ClientObj.MainWidget.left_frame.update() ClientObj.MainWidget.left_frame.show() ClientObj._parent.setWindowTitle(title) self.old_title = title self.create_menu(self.display_wgt, groups, sub_group, ClientObj) def onActivated(self): method_name = self.sender().objectName() # set new Title new_title = self.sender().text() try: new_title = new_title.decode("utf-8") except (UnicodeDecodeError, UnicodeEncodeError): pass self._parent.ClientObj._parent.setWindowTitle(new_title + " - " + self.old_title) step = 0 self._parent.ClientObj.method_name = method_name self._parent.ClientObj.sid = get_sid(self._parent.ClientObj.client) # switch to the desired step if self._parent.ClientObj.param_objects.has_key(method_name): self._parent.ClientObj.param_objects[method_name]["step"] = step # Call server method if hasattr(self, "onActivated_thread"): if self.onActivated_thread.isRunning(): return 1 view_params = get_view_params(self._parent.ClientObj.client, str(method_name + "_view"), step=step) self.onActivated_thread = ClientServiceThread( self._parent.ClientObj, str(method_name + "_view"), int(self._parent.ClientObj.sid), view_params, return_except=True, ) self.onActivated_thread.signal.connect(self.onActivated_after) self.onActivated_thread.start() def onActivated_after(self, view): if type(view) == Exception: if hasattr(view.message, "message"): view = view.message if type(view.message) == tuple: if view.message[0] == 403: msg = _("Permission denied") else: msg = " ".join(map(lambda x: str(x), view.message)) else: msg = view.message.__str__() show_msg(msg) return 1 self._parent.ClientObj.MainWidget.main_frame_view(view, self._parent.ClientObj.method_name) def create_steps(self, method_name, steps, icons=None): self.old_title = self._parent.ClientObj._parent.windowTitle() if not hasattr(self, "step"): self.step = 0 # icon_visible(self._parent.ClientObj.MainWidget, 'Methods', True) icon_visible(self._parent.ClientObj.MainWidget, "Back", True) self.widget = QtGui.QWidget(self) self.widget.setPalette(self.cur_palette) # self.widget.setStyleSheet("QWidget { background-color: rgb (%s) }" \ # %self._parent.ClientObj.method_background_color.\ # replace(' ',',',2)) self.widget.setObjectName("QQQ") self.widget.setStyleSheet( "QWidget#QQQ { " # "background-color: #EEEEEE;}") # self.setStyleSheet("QScrollArea { " "background-color: qlineargradient(" "x1: 0, y1: 0, x2: 0, y2: 1, " "stop: 0 #EEEEEE, stop: 0.7 #EEEEEE, " "stop: 0.9 #E4E1E0, stop: 1 #E4E1E0);}" ) self.button_list = [] self.layout = QtGui.QVBoxLayout(self.widget) self.layout.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter) # self.layout.setContentsMargins(28,28,28,0) self.layout.setContentsMargins(2, 28, 2, 0) self.layout.setSpacing(5) if not icons: icons = [] width_list = [] for num_step in range(len(steps)): self.button_list.append(StepLabel(steps[num_step], self)) # if len(icons) > num_step: # themeName = QtGui.QIcon.themeName() # icon = QtGui.QIcon() # icon.setThemeName(themeName) # icon = icon.fromTheme(icons[num_step]) # if icon.isNull(): # icon.setThemeName('Tango') # icon = icon.fromTheme(icons[num_step]) # if not icon.isNull(): # self.button_list[num_step].setIcon(icon) # collect parameters object self.button_list[num_step].clicked.connect(self.collect_object(method_name, num_step)) # call function (or check parameters) self.button_list[num_step].clicked.connect(self.calling_method(method_name, num_step)) # self.button_list[num_step].clicked.connect \ # (self.check_step(method_name, num_step)) # calculate button width fmn = QtGui.QFontMetrics(QtGui.QFont("", -1, QtGui.QFont.Normal)) normal_width = fmn.width(self.button_list[num_step].text()) fmb = QtGui.QFontMetrics(QtGui.QFont("", -1, QtGui.QFont.Bold)) bold_width = fmb.width(self.button_list[num_step].text()) diff = bold_width - normal_width + 6 # self.button_list[num_step].setFixedWidth \ # (self.button_list[num_step].sizeHint().width() + diff) width_list.append(self.button_list[num_step].sizeHint().width() + diff) self.layout.addWidget(self.button_list[num_step]) if width_list: width_list.sort() max_width = width_list.pop() else: max_width = 0 for num_step in range(len(steps)): self.button_list[num_step].setFixedWidth(max_width) # set bold button self.changed_step(self._parent.ClientObj.param_objects[method_name]["step"]) # self.layout.addItem(QtGui.QSpacerItem(100, 100, \ # QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)) self.setWidget(self.widget) self.setWidgetResizable(True) self.setFixedWidth(self.sizeHint().width()) # + \ # self.verticalScrollBar().sizeHint().width()) if not self.isVisible(): self.show() # create helper signals collect = QtCore.Signal() calling = QtCore.Signal() def collect_object(self, method_name, set_step=None): def wrapper(): self.setDisabled(True) if hasattr(self, "check_step_thread"): if self.check_step_thread.isRunning(): _print("check_step_thread is running") self.setEnabled(True) return 1 change_step = set_step if set_step else 0 if self._parent.ClientObj.param_objects[method_name]["step"] > change_step: # self.setEnabled(True) return try: self.collect.disconnect() except RuntimeError: pass self.collect.connect(self._parent.ClientObj.MainWidget.MainFrameWgt.collect_object(False)) self.collect.emit() return wrapper def calling_method(self, method_name, set_step=None): def wrapper(): if hasattr(self, "check_step_thread"): if self.check_step_thread.isRunning(): self.setEnabled(True) _print("check_step_thread is running") return 1 change_step = set_step if set_step else 0 if self._parent.ClientObj.param_objects[method_name]["step"] > change_step: self.check_step(method_name, set_step) # self.setEnabled(True) return try: self.calling.disconnect() except RuntimeError: pass self.calling.connect(self._parent.ClientObj.MainWidget.MainFrameWgt.calling(True, from_left_frame=True)) self.calling.emit() self.check_step(method_name, set_step) return wrapper def check_step(self, method_name, set_step=None): # def wrapper(): # Call server method if hasattr(self, "check_step_thread"): if self.check_step_thread.isRunning(): _print("check_step_thread is running") self.setEnabled(True) return 1 self.step = set_step if set_step else 0 self._parent.ClientObj.method_name = method_name self._parent.ClientObj.sid = get_sid(self._parent.ClientObj.client) expert = None if self._parent.ClientObj.MainWidget.MainFrameWgt.isBrief(self.step): num = None brief = True expert = True else: brief = False num = self.step view_params = get_view_params( self._parent.ClientObj.client, str(method_name + "_view"), step=num, expert=expert, brief=brief ) self.check_step_thread = ClientServiceThread( self._parent.ClientObj, str(method_name + "_view"), int(self._parent.ClientObj.sid), view_params ) self.check_step_thread.signal.connect(self.check_step_after) self.check_step_thread.start() # return wrapper def check_step_after(self, view=None): method_name = self._parent.ClientObj.method_name if self._parent.ClientObj.param_objects[method_name]["error"]: if self._parent.ClientObj.param_objects[method_name]["step"] < self.step: text = _("Error at this step.") informative_text = _("Do you want to continue?") reply = show_question(self._parent, text, informative_text, not_move=True, title=_("Calculate Console")) if reply == QtGui.QMessageBox.No: self.setEnabled(True) return if not view: self.setEnabled(True) return # set bold for current step self.changed_step(self.step) self._parent.ClientObj.param_objects[method_name]["step"] = self.step self._parent.ClientObj.MainWidget.main_frame_view(view, method_name) self.setEnabled(True) def changed_step(self, step): if not hasattr(self, "button_list"): return 1 # set bold for current step for i in range(len(self.button_list)): if i == step: self.button_list[i].text() self.button_list[i].setBold(True) else: self.button_list[i].setBold(False) def hideEvent(self, event): if hasattr(self, "onActivated_thread"): if self.onActivated_thread.isRunning(): self.onActivated_thread.close() self.onActivated_thread.wait() if hasattr(self, "send_password_thread"): if self.check_step_thread.isRunning(): self.check_step_thread.close() self.check_step_thread.wait() event.accept()
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)
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
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
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()
def __init__(self, parent): QtGui.QWidget.__init__(self) cur_year = str(datetime.date.today().year) copy_right = "©" motto = 'Easy Linux from the Source.<br>' help_text = '%s v%s. \n' %(parent.ClientObj.Name, \ parent.ClientObj.Version) + \ _('Makes part of Calculate Utilities 3.0.0') + '<br>' + \ _('Company') + ' Calculate %s 2007-%s' %(copy_right,cur_year) html_help = ("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN' " "'http://www.w3.org/TR/REC-html40/strict.dtd'>" "<html><head><style type=text/css>" "</style></head><body>" + help_text + "</body></html>") helpLabel = LabelWordWrap(html_help, self) helpLabel.setContentsMargins(10,10,10,5) company_name = _('Company website') company_site = 'http://www.calculate.ru' distr_name = _('Distribution website') distr_site = 'http://www.calculate-linux.org' linkLabel = LabelWordWrap(company_name + \ ": <br><a href='http://www.calculate.ru'>" + \ company_site + "</a><br><br>" + distr_name+ \ ": <br><a href='http://www.calculate-linux.org'>" + \ distr_site + "</a>", self) linkLabel.setContentsMargins(10,5,10,5) linkLabel.setOpenExternalLinks(True) helpQuit = QtGui.QPushButton(_("Close"), self) helpQuit.setShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Escape)) helpQuit.setFixedWidth(100) self.image_lbl = QtGui.QLabel(self) filename = '/usr/share/icons/Calculate/128x128/apps/' \ 'calculate-console.png' ir = QtGui.QImageReader(filename) diff = ir.size().width() / 140.0 w = ir.size().width() / diff h = ir.size().height() / diff if w > 2 * h: ir.setScaledSize(QtCore.QSize(1.7 * w, 1.7 * h)) else: ir.setScaledSize(QtCore.QSize(w, h)) img = ir.read() pm2 = QtGui.QPixmap().fromImage(img) self.image_lbl.setPixmap(pm2) layout = QtGui.QGridLayout(self) layout.setContentsMargins(24,10,24,10) layout.setAlignment(QtCore.Qt.AlignTop) layout.addWidget(self.image_lbl, 0,0,3,1) layout.addWidget(helpLabel,0,1) layout.addWidget(linkLabel,1,1) layout.addWidget(helpQuit,2,1, QtCore.Qt.AlignRight) self.setLayout(layout) helpQuit.clicked.connect(self.close) # self.setFixedSize(400 + x ,200) self.setFixedSize(self.sizeHint().width() + 50, \ self.sizeHint().height()) self.setWindowTitle (_('Calculate Console ')) help_icon = QtGui.QIcon \ ('/usr/share/pixmaps/calculate-console-online.png') if help_icon.isNull(): help_icon = QtGui.QIcon.fromTheme("help-about") self.setWindowIcon (help_icon) self.move(parent.window().geometry().x() + \ parent.window().geometry().width() / 2 \ - self.size().width() / 2, \ parent.window().geometry().y() + \ parent.window().geometry().height() / 2 \ - self.size().height() / 2) # for clear memory after closed this window self.setAttribute(QtCore.Qt.WA_DeleteOnClose)