Esempio n. 1
0
    def create_parent_widget(self):

        from thlib.ui_classes.ui_search_classes import Ui_searchResultsWidget, DEFAULT_FILTER

        info = {
            'title': '',
            'filters': [DEFAULT_FILTER],
            'state': None,
            'offset': 0,
            'limit': 20,
            'simple_view': True,
            'group_by': None,
            'sort_by': None,
        }

        self.search_results_widget = Ui_searchResultsWidget(
            project=self.stype.project,
            stype=self.stype,
            info=info,
            parent=self
        )

        self.parent_tree_widget = self.search_results_widget.get_results_tree_widget()

        self.parent_vertical_layout.addWidget(self.search_results_widget)
Esempio n. 2
0
    def create_instances_widget(self):
        from thlib.ui_classes.ui_search_classes import Ui_searchResultsWidget

        parent_sobject = self.item.get_sobject()
        related_expr = parent_sobject.get_related_sobjects_tel_string(child_stype=self.stype, parent_stype=parent_sobject.get_stype())

        filters = [('_expression', 'in', related_expr)]

        info = {
            'title': '',
            'filters': filters,
            'state': None,
            'offset': 0,
            'limit': 20,
            'simple_view': True,
            'group_by': None,
            'sort_by': None,
        }

        self.instances_search_results_widget = Ui_searchResultsWidget(
            project=self.stype.project,
            stype=self.stype,
            info=info,
            parent=self
        )

        self.instances_tree_widget = self.instances_search_results_widget.get_results_tree_widget()

        self.instances_vertical_layout.addWidget(self.instances_search_results_widget)
Esempio n. 3
0
class Ui_linkSobjectsWidget(QtGui.QDialog):
    def __init__(self, stype, parent_stype=None, item=None, parent=None):
        super(self.__class__, self).__init__(parent=parent)

        self.item = item
        self.stype = stype
        self.parent_stype = parent_stype
        self.current_mode = 'add'
        self.include_set = set()
        self.exclude_set = set()
        self.current_set = set()

        self.create_ui()

    def create_ui(self):
        self.create_layout()

        self.resize(750, 800)
        self.setMinimumSize(600, 500)

        self.setWindowModality(QtCore.Qt.ApplicationModal)
        self.setSizeGripEnabled(True)
        self.setWindowFlags(QtCore.Qt.Dialog)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.create_all_layouts()

        self.create_parent_search_line()
        self.create_instances_search_line()

        self.create_parent_widget()
        self.create_instances_widget()

        self.create_buttons()

        self.set_title()

        self.controls_actions()

        self.parent_search_line_edit.setFocus()

    def controls_actions(self):

        self.parent_tree_widget.itemSelectionChanged.connect(self.set_arrow_right)
        self.parent_search_line_edit.returnPressed.connect(self.do_parent_search)
        self.parent_search_line_edit.item_selected.connect(self.do_parent_search)
        self.parent_search_line_edit.item_clicked.connect(self.do_parent_search)

        self.instances_search_line_edit.returnPressed.connect(self.do_instance_search)
        self.instances_search_line_edit.item_selected.connect(self.do_instance_search)
        self.instances_search_line_edit.item_clicked.connect(self.do_instance_search)

        self.instances_tree_widget.itemSelectionChanged.connect(self.set_arrow_left)

        self.add_remove_tool_button.clicked.connect(self.add_remove_tool_button_clicked)

        self.cancel_button.clicked.connect(self.close)
        self.save_button.clicked.connect(self.save_instances_state)

    def keyPressEvent(self, event):
        event.ignore()

    def save_instances_state(self):
        tc.edit_multiple_instance_sobjects(
            self.stype.project.get_code(),
            insert_search_keys=self.include_set,
            exclude_search_keys=self.exclude_set,
            parent_key=self.item.sobject.get_search_key(),
            instance_type=self.item.child.get('instance_type')
        )

        self.close()

    def set_arrow_right(self):
        self.add_remove_tool_button.setIcon(gf.get_icon('arrow-right-bold', icons_set='mdi'))
        self.instances_tree_widget.clearSelection()

        self.current_mode = 'add'

    def set_arrow_left(self):
        self.add_remove_tool_button.setIcon(gf.get_icon('arrow-left-bold', icons_set='mdi'))
        self.parent_tree_widget.clearSelection()

        self.current_mode = 'remove'

    def add_remove_tool_button_clicked(self):
        for sobject in self.instances_search_results_widget.sobjects:
            self.current_set.add(sobject)

        # TODO DUPLICATES CHECK

        if self.current_mode == 'remove':
            selected_instaces = self.instances_tree_widget.selectedItems()
            for item in selected_instaces:

                item_widget = self.instances_tree_widget.itemWidget(item, 0)

                item_info = {
                    'relates_to': 'checkin_out',
                    'sep_versions': True,
                    'children_states': None,
                    'simple_view': True,
                }
                gf.add_sobject_item(
                    self.parent_tree_widget,
                    self,
                    item_widget.sobject,
                    self.stype,
                    item_info,
                    ignore_dict=None,
                )

                sobject = item_widget.sobject
                search_key = sobject.get_search_key()

                if search_key not in self.include_set:
                    self.exclude_set.add(search_key)

                if search_key in self.include_set:
                    self.include_set.remove(search_key)

                idx = self.instances_tree_widget.indexFromItem(item)
                self.instances_tree_widget.takeTopLevelItem(idx.row())

        elif self.current_mode == 'add':
            selected_parents = self.parent_tree_widget.selectedItems()
            for item in selected_parents:

                item_widget = self.parent_tree_widget.itemWidget(item, 0)
                sobject = item_widget.sobject
                search_key = sobject.get_search_key()

                item_info = {
                    'relates_to': 'checkin_out',
                    'sep_versions': True,
                    'children_states': None,
                    'simple_view': True,
                }
                gf.add_sobject_item(
                    self.instances_tree_widget,
                    self,
                    item_widget.sobject,
                    self.stype,
                    item_info,
                    ignore_dict=None,
                )

                if search_key in self.exclude_set:
                    self.exclude_set.remove(search_key)

                if search_key not in self.current_set:
                    self.include_set.add(search_key)

                idx = self.parent_tree_widget.indexFromItem(item)
                self.parent_tree_widget.takeTopLevelItem(idx.row())

    def create_layout(self):

        self.grid_layout = QtGui.QGridLayout(self)

    def create_all_layouts(self):
        self.splitter = QtGui.QSplitter(self)
        self.splitter.setOrientation(QtCore.Qt.Horizontal)
        self.splitter.setObjectName("splitter")

        self.gridLayoutWidget = QtGui.QWidget(self.splitter)
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")

        self.parent_grid_layout = QtGui.QGridLayout(self.gridLayoutWidget)
        self.parent_grid_layout.setContentsMargins(0, 0, 0, 0)
        self.parent_grid_layout.setObjectName("parent_grid_layout")

        self.add_remove_tool_button = QtGui.QToolButton(self.gridLayoutWidget)

        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.add_remove_tool_button.sizePolicy().hasHeightForWidth())

        self.add_remove_tool_button.setSizePolicy(sizePolicy)
        self.add_remove_tool_button.setObjectName("add_remove_tool_button")
        self.add_remove_tool_button.setAutoRaise(True)

        self.parent_grid_layout.addWidget(self.add_remove_tool_button, 0, 1, 1, 1)

        self.add_remove_tool_button.setIcon(gf.get_icon('arrow-right-bold', icons_set='mdi'))

        self.parent_vertical_layout = QtGui.QVBoxLayout()

        self.parent_vertical_layout.setObjectName("parent_vertical_layout")

        self.parent_grid_layout.addLayout(self.parent_vertical_layout, 0, 0, 1, 1)

        self.verticalLayoutWidget = QtGui.QWidget(self.splitter)
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")

        self.instances_vertical_layout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
        self.instances_vertical_layout.setContentsMargins(0, 0, 0, 0)
        self.instances_vertical_layout.setObjectName("instances_vertical_layout")

        self.buttons_layout = QtGui.QHBoxLayout()
        self.buttons_layout.setObjectName("buttons_layout")
        self.grid_layout.addLayout(self.buttons_layout, 1, 0, 1, 1)

        self.grid_layout.addWidget(self.splitter, 0, 0, 1, 1)

    def create_buttons(self):

        self.save_button = QtGui.QPushButton('Save')
        self.save_button.setMaximumWidth(80)
        self.save_button.setIcon(gf.get_icon('content-save', icons_set='mdi'))
        self.save_button.setFlat(True)
        self.save_button.setFocusPolicy(QtCore.Qt.NoFocus)

        self.cancel_button = QtGui.QPushButton('Close')
        self.cancel_button.setMaximumWidth(80)
        self.cancel_button.setIcon(gf.get_icon('close', icons_set='mdi'))
        self.cancel_button.setFlat(True)
        self.cancel_button.setFocusPolicy(QtCore.Qt.NoFocus)

        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)

        self.buttons_layout.addItem(spacerItem)

        self.buttons_layout.addWidget(self.save_button)
        self.buttons_layout.addWidget(self.cancel_button)

    def create_parent_search_line(self):
        from thlib.ui_classes.ui_custom_qwidgets import SuggestedLineEdit

        self.parent_search_line_edit = SuggestedLineEdit(self.stype, self.stype.project, parent=self)
        self.parent_search_line_edit.setObjectName("parent_search_line_edit")
        self.parent_search_line_edit.setToolTip('Enter Your search query here')
        self.parent_vertical_layout.addWidget(self.parent_search_line_edit)
        self.parent_search_line_edit.set_autofill_selected_items(True)

    def create_instances_search_line(self):
        from thlib.ui_classes.ui_custom_qwidgets import SuggestedLineEdit

        self.instances_search_line_edit = SuggestedLineEdit(self.stype, self.stype.project, parent=self)
        self.instances_search_line_edit.setObjectName("instances_search_line_edit")
        self.instances_search_line_edit.setToolTip('Enter Your search query here')
        self.instances_vertical_layout.addWidget(self.instances_search_line_edit)
        self.instances_search_line_edit.set_autofill_selected_items(True)

        # parent_sobject = self.item.get_sobject()
        # related_expr = parent_sobject.get_related_sobjects_tel_string(self.stype)
        # self.instances_search_line_edit.set_default_filter(('_expression', 'in', related_expr))

    def create_parent_widget(self):

        from thlib.ui_classes.ui_search_classes import Ui_searchResultsWidget, DEFAULT_FILTER

        info = {
            'title': '',
            'filters': [DEFAULT_FILTER],
            'state': None,
            'offset': 0,
            'limit': 20,
            'simple_view': True,
            'group_by': None,
            'sort_by': None,
        }

        self.search_results_widget = Ui_searchResultsWidget(
            project=self.stype.project,
            stype=self.stype,
            info=info,
            parent=self
        )

        self.parent_tree_widget = self.search_results_widget.get_results_tree_widget()

        self.parent_vertical_layout.addWidget(self.search_results_widget)

    def do_parent_search(self):
        query_text = self.parent_search_line_edit.text()
        if query_text:
            self.search_results_widget.set_filters([('name', 'EQI', query_text)])
            self.search_results_widget.search_query(query_text)
        else:
            self.search_results_widget.set_filters([])
            self.search_results_widget.search_query('')

    def do_instance_search(self):
        query_text = self.instances_search_line_edit.text()

        parent_sobject = self.item.get_sobject()

        related_expr = parent_sobject.get_related_sobjects_tel_string(child_stype=self.stype, parent_stype=parent_sobject.get_stype())

        if query_text:
            self.instances_search_results_widget.set_filters([
                ('name', 'EQI', query_text),
                ('_expression', 'in', related_expr)
            ])
            self.instances_search_results_widget.search_query(query_text)
        else:
            self.instances_search_results_widget.set_filters([('_expression', 'in', related_expr)])
            self.instances_search_results_widget.search_query('')

    @env_inst.async_engine
    def create_instances_widget(self):
        from thlib.ui_classes.ui_search_classes import Ui_searchResultsWidget

        parent_sobject = self.item.get_sobject()
        related_expr = parent_sobject.get_related_sobjects_tel_string(child_stype=self.stype, parent_stype=parent_sobject.get_stype())

        filters = [('_expression', 'in', related_expr)]

        info = {
            'title': '',
            'filters': filters,
            'state': None,
            'offset': 0,
            'limit': 20,
            'simple_view': True,
            'group_by': None,
            'sort_by': None,
        }

        self.instances_search_results_widget = Ui_searchResultsWidget(
            project=self.stype.project,
            stype=self.stype,
            info=info,
            parent=self
        )

        self.instances_tree_widget = self.instances_search_results_widget.get_results_tree_widget()

        self.instances_vertical_layout.addWidget(self.instances_search_results_widget)

    def set_title(self):
        stype_tytle = self.stype.info.get('title')
        stype_code = self.stype.info.get('code')
        if stype_tytle:
            title = stype_tytle.capitalize()
        else:
            title = 'Unknown'

        self.setWindowTitle('Linking SObjects {0} ({1})'.format(title, stype_code))

    def create_loading_label(self):
        self.loading_label = QtGui.QLabel()
        self.loading_label.setText('Loading...')
        self.loading_label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
        self.loading_label.setVisible(False)

        self.grid_layout.addWidget(self.loading_label, 0, 0)

    def toggle_loading_label(self):
        if self.loading_label.isVisible():
            self.loading_label.setVisible(False)
        else:
            self.loading_label.setVisible(True)