コード例 #1
0
    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()
コード例 #2
0
    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()
コード例 #3
0
        def wrapper():
            sid = get_sid(self.client)

            # Call server method
            if hasattr (self, 'kill_process_thread'):
                if self.kill_process_thread.isRunning():
                    return 1
            self.kill_process_thread = ClientServiceThread(self.ClientObj,\
                                    'pid_kill', pid, sid)
            self.kill_process_thread.signal.connect(self.kill_process_after)
            self.kill_process_thread.start()
コード例 #4
0
    def onActivated(self):
        # Call server method
        if hasattr (self, 'onActivated_thread'):
            if self.onActivated_thread.isRunning():
                return 1
        self.setDisabled(True)
        method_name = self.sender().objectName()
#        view_method_name = self.sender().text()
        step = 0
        brief = False
        self.ClientObj.method_name = method_name

        self.ClientObj.sid = get_sid(self.ClientObj.client)
        if self.ClientObj.param_objects.has_key(method_name):
            self.ClientObj.param_objects[method_name]['step'] = 0

        view_params = get_view_params(self.ClientObj.client, \
                       str(method_name + '_view'), step = step, brief = brief)
        self.onActivated_thread = ClientServiceThread(self.ClientObj, \
                        str(method_name + '_view'), int(self.ClientObj.sid), \
                        view_params, return_except = True)
        self.onActivated_thread.signal.connect(self.onActivated_after)
        self.onActivated_thread.start()
コード例 #5
0
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()
コード例 #6
0
class DisplayMethod(QtGui.QWidget):
    def __init__(self, parent, ClientObj):
        super(DisplayMethod, self).__init__(parent)
        self.ClientObj = ClientObj
        self._parent = parent
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        ClientObj.back_step_list = []

    def initUI(self, results):
        GROUP = 0 # Getting group name
        METH = 1 # Getting method name
        LABEL = 2 # Get translate label
        IMAGE = 3 # Getting image path
        self.lable_list = []
        self.button_list = {}
        self.layout = QtGui.QVBoxLayout()
        self.groupbox_dict = {}
        self.layout_dict = {}

        # set new Title
        self.ClientObj._parent.setWindowTitle(self.ClientObj.Name)

        background_color = 'rgb(255,255,255)'
        self._parent.main_frame.viewport().setStyleSheet(\
        "background-color: %s ; " %background_color
        )

        self.setStyleSheet(self.styleSheet() + \
            'QWidget { background: transparent;}'

            'QGroupBox {font-weight: bold;'
            'border: 1px solid gray;'
            'border-left-color: qlineargradient( x1: 0, y1: 0, x2: 0, y2: 1,'
                                        'stop: 0 gray, stop: 1 transparent);'
            'border-top-color: qlineargradient( x1: 0, y1: 0, x2: 1, y2: 0,'
                                       'stop: 0 gray, stop: 1 transparent);'
            'border-right: 0px; border-bottom: 0px;'
            'border-top-left-radius: 2px;'

            'background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1,'
            'stop: 0 rgb(230, 230, 230), stop: 0.5 transparent,'
            'stop: 1 transparent);'
            'padding-top: 18px; padding-bottom: 18px;}'
            'QGroupBox::title {background-color: transparent;'

            'color: #555; subcontrol-position: top left;'
            'margin-top: 6px; margin-left: 8px;}')

        # transform a list into the dictionary {'group': [methods], ...}
        guiMethods = {}
        if type(results) == int:
#            self.layout.addWidget(LabelWordWrap(_('No Methods!'),self))
            self.setLayout(self.layout)
            self.show()
            return 1
        for num in range (0, len(results)):
            groups_name = results[num].string[GROUP]
            if results[num].string[GROUP] in [None,'None']:
                self.ClientObj.method_names[results[num].string[METH]] = \
                                        results[num].string[LABEL]
                continue
            if not groups_name in guiMethods.keys():
                guiMethods[groups_name] = []
            self.ClientObj.method_names[results[num].string[METH]] = \
                                        results[num].string[LABEL]
            guiMethods[groups_name].append(results[num].string[METH])
            guiMethods[groups_name].append(results[num].string[LABEL])
            guiMethods[groups_name].append(results[num].string[IMAGE])

        # display all groups and methods
        for group in guiMethods:
            if len (group.split('.')) > 1:
                group_name = group.split('.')[0].encode('utf-8')
                sub_group = group.split('.')[1].encode('utf-8')
                if not self.groupbox_dict.has_key(group_name):
                    self.groupbox_dict[group_name] = \
                              QtGui.QGroupBox(group_name.decode('utf-8'), self)

                    self.groupbox_dict[group_name].setAlignment \
                                                        (QtCore.Qt.AlignLeft)

                if not self.layout_dict.has_key(group_name):
                    self.layout_dict[group_name] = \
                                    FlowLayout(self.groupbox_dict[group_name])

                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] = []
                self.button_list[sub_group].append \
                        (attrubute_list + guiMethods[group])
                sub_group_list.append(group.split('.',1)[1].encode('utf-8'))
                self.button_list[sub_group].append \
                        (sub_group_list)

                Button = ButtonMenu(sub_group, sub_group, \
                                    'folder-documents,folder', self)
                Button.clicked.connect(self.groupActivated \
                                    (self.button_list[sub_group][0], \
                                     self.button_list[sub_group][1]))
#                try:
#                    Button.setStatusTip(sub_group.decode('utf-8'))
#                except (UnicodeDecodeError, UnicodeEncodeError):
#                    Button.setStatusTip(sub_group)

                self.button_list[sub_group].append(Button)
                continue

            if not self.groupbox_dict.has_key(group):
                self.groupbox_dict[group] = \
                                QtGui.QGroupBox(group, self)
                self.groupbox_dict[group].setAlignment(QtCore.Qt.AlignLeft)

            if not self.layout_dict.has_key(group):
                self.layout_dict[group] = FlowLayout(self.groupbox_dict[group])
            view_name_sort = filter(lambda x: guiMethods[group].index(x) % 3 \
                                    == 1, guiMethods[group])
            view_name_sort.sort()
            guiMethods_sort = []
            for sort_name in view_name_sort:
                ind = guiMethods[group].index(sort_name)
                for i in range(ind-1, ind+2):
                    guiMethods_sort.append(guiMethods[group][i])
            for method_name in range (0, len(guiMethods_sort), 3):
                Button = ButtonMenu(guiMethods_sort[method_name],\
                                guiMethods_sort[method_name + 1], \
                                guiMethods_sort[method_name + 2], \
                                self)
                Button.clicked.connect(self.onActivated)

#                try:
#                    Button.setStatusTip(sub_group.decode('utf-8'))
#                except (UnicodeDecodeError, UnicodeEncodeError):
#                    Button.setStatusTip(sub_group)
 
                if not self.button_list.has_key(group):
                    self.button_list[group] = []
                self.button_list[group].append(Button)

                self.layout_dict[group].addWidget \
                                (self.button_list[group]\
                                [len(self.button_list[group]) - 1])

            self.layout_dict[group].setAlignment(QtCore.Qt.AlignLeft | \
                                                       QtCore.Qt.AlignTop)
            self.groupbox_dict[group].setLayout(self.layout_dict[group])

        keys_sort = guiMethods.keys()
        keys_sort.sort()
        for group in keys_sort:
            if len (group.split('.')) > 1:

                group_name = group.split('.')[0].encode('utf-8')
                sub_group = group.split('.')[1].encode('utf-8')

#                for i in range (20):
#                    self.layout_dict[group_name].addWidget(ButtonMenu \
#                                ('gggggggg',\
#                                'qqqqww wwwww', \
#                                'code-block', \
#                                self))
                self.layout_dict[group_name].addWidget \
                                (self.button_list[sub_group]\
                                [len(self.button_list[sub_group]) - 1])

                self.layout_dict[group_name].setAlignment(QtCore.Qt.AlignLeft)
                if self.groupbox_dict[group_name]:
                    self.groupbox_dict[group_name].setLayout \
                                                (self.layout_dict[group_name])

                if self.groupbox_dict[group_name]:
                    self.layout.addWidget(self.groupbox_dict[group_name])
                    self.groupbox_dict[group_name] = None
                continue
            elif self.groupbox_dict[group]:
                self.layout.addWidget(self.groupbox_dict[group])
                self.groupbox_dict[group] = None

        self.layout.setAlignment(QtCore.Qt.AlignTop)
        self.setLayout(self.layout)
        self.resize(self.layout.sizeHint())

    def refresh(self):
        results = self.ClientObj.methods_list
        self.initUI(results)
        self.ClientObj.app.processEvents()

        self.ClientObj.MainWidget.left_frame.cur_palette = \
                    self._parent.main_frame.viewport().palette()
        self.ClientObj._parent.setWindowTitle(_("Calculate Console"))

    def onActivated(self):
        # Call server method
        if hasattr (self, 'onActivated_thread'):
            if self.onActivated_thread.isRunning():
                return 1
        self.setDisabled(True)
        method_name = self.sender().objectName()
#        view_method_name = self.sender().text()
        step = 0
        brief = False
        self.ClientObj.method_name = method_name

        self.ClientObj.sid = get_sid(self.ClientObj.client)
        if self.ClientObj.param_objects.has_key(method_name):
            self.ClientObj.param_objects[method_name]['step'] = 0

        view_params = get_view_params(self.ClientObj.client, \
                       str(method_name + '_view'), step = step, brief = brief)
        self.onActivated_thread = ClientServiceThread(self.ClientObj, \
                        str(method_name + '_view'), int(self.ClientObj.sid), \
                        view_params, return_except = True)
        self.onActivated_thread.signal.connect(self.onActivated_after)
        self.onActivated_thread.start()

    def onActivated_after(self, view):
        self.setDisabled(False)
        #self.con_lost_lbl.hide()
        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

        method_name = self.ClientObj.method_name
        self._parent.main_frame.viewport().setStyleSheet('')

        # set new Title
        if self.ClientObj.method_names.has_key(method_name):
            view_method = self.ClientObj.method_names[method_name]
        else:
            view_method = method_name
        self.ClientObj._parent.setWindowTitle \
                (view_method + ' - ' + self.ClientObj._parent.windowTitle())
        self.ClientObj.MainWidget.main_frame_view(view, method_name)

    def groupActivated(self, groups, sub_group, back = False):
        def wrapper():
            self._parent.main_frame.viewport().setStyleSheet('')
            self.ClientObj.MainWidget.delete_MainFrameWgt()

            self.ClientObj.MainWidget.MainFrameWgt = \
                                      QtGui.QWidget(self.ClientObj.MainWidget)
            if not back:
                # save data for a step back
                self.ClientObj.back_step_list.append ([groups, sub_group, \
                                    self.ClientObj._parent.windowTitle()])

            hlayout = QtGui.QHBoxLayout()
            hlayout.addItem(QtGui.QSpacerItem( 0, 0, \
                    QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))
            self.ClientObj.MainWidget.MainFrameWgt.setLayout(hlayout)

            self.ClientObj.MainWidget.main_frame.setWidget \
                                    (self.ClientObj.MainWidget.MainFrameWgt)
            self.ClientObj.MainWidget.main_frame.setWidgetResizable(True)

            self.ClientObj.MainWidget.left_frame.update()
            self.ClientObj.MainWidget.left_frame.show()

            try:
                new_title = sub_group[0].split('.')[0].decode('utf-8')
            except (UnicodeDecodeError, UnicodeEncodeError):
                pass
            if self.ClientObj.MainWidget.left_frame.old_title:                
                self.ClientObj._parent.setWindowTitle(new_title +' - '+ \
                               self.ClientObj.MainWidget.left_frame.old_title)
            else:
                self.ClientObj._parent.setWindowTitle(new_title + ' - ' + \
                                       self.ClientObj._parent.windowTitle())
            self.ClientObj.MainWidget.left_frame.create_menu \
                                    (self, groups, sub_group, self.ClientObj)
        return wrapper

    def closeEvent(self, event):
        self._parent.main_frame.viewport().setStyleSheet ('')
        if hasattr (self, 'onActivated_thread'):
            if self.onActivated_thread.isRunning():
                self.onActivated_thread.close()
                self.onActivated_thread.wait()
        event.accept()
コード例 #7
0
class ViewProc(QtGui.QWidget):
    
    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 onActivated(self, pid, method_name):
        def wrapper():
#            pid = self.sender().text()
            for i in self.ClientObj.process_dict:
                if i == pid:
                    # set new window title
                    n = method_name
                    try:
                        name = n.decode('utf-8')
                    except (UnicodeEncodeError, UnicodeDecodeError):
                        pass
                    self.ClientObj._parent.setWindowTitle \
                                    (self.ClientObj._parent.windowTitle() +\
                                    ' - ' + name)

    #                try:
    #                    self.ClientObj.process_dict[i]['result']
    #                except:
    #                    self.ClientObj.process_dict[i]['result'] = {}
                    self.ClientObj.MainWidget.main_view_process \
                            (self.ClientObj.process_dict[i]['method_name'], \
                            self.ClientObj.process_dict[i]['result'], str(i))
                    self.ClientObj.app.processEvents()
                    self.ClientObj.MainWidget.main_frame.verticalScrollBar() \
                                     .setValue(self.ClientObj.MainWidget. \
                                     main_frame.verticalScrollBar().maximum())
                    break
        return wrapper

    def kill_process(self, pid, x, y):
        def wrapper():
            sid = get_sid(self.client)

            # Call server method
            if hasattr (self, 'kill_process_thread'):
                if self.kill_process_thread.isRunning():
                    return 1
            self.kill_process_thread = ClientServiceThread(self.ClientObj,\
                                    'pid_kill', pid, sid)
            self.kill_process_thread.signal.connect(self.kill_process_after)
            self.kill_process_thread.start()
        return wrapper

    def kill_process_after(self, result):
        if result == 0:
            msg = _("Well killed!")
        elif result == 2:
            msg = _("Process completed")
        elif result == -1:
            msg = _("Certificate not found in the server!")
        elif result == -2:
            msg = _("Session not matching your certificate!")
        elif result == 1:
            msg = _("Failed to kill the process!")
        else:
            msg = 'error'
        
        show_msg(msg)
        self.ClientObj.MainWidget.view_processes()        
        
    def closeEvent(self, event):
        if hasattr (self, 'kill_process_thread'):
            if self.kill_process_thread.isRunning():
                self.kill_process_thread.close()
                self.kill_process_thread.wait()
        event.accept()