Пример #1
0
    def __init__(self):
        super().__init__()

        self.layout = QHBoxLayout()
        i = 0
        self.names = []
        self.ebutons = []
        folder = './results'
        #------------loading result images from api call into result page----------
        if (len(os.listdir(folder)) == 0):
            #print oput nothing saved
            self.label = QLabel("No matching result")
            self.layout.addWidget(self.label)
        else:
            for filename in os.listdir(folder):
                self.names.append(filename)
                self.ebutons.append(i)
                lay = QVBoxLayout()
                gbox = QGroupBox('Result' + str(i + 1))
                path = folder + "/" + filename
                with open(path, 'rb') as thefile:
                    imag = pickle.load(thefile)
                path += ".jpg"
                im = Image.open(
                    requests.get(imag['urls']['thumb'], stream=True).raw)
                im.save(path)
                self.ebutons[i] = QPushButton("Save result" + str(i + 1))
                self.ebutons[i].clicked.connect(
                    lambda state=i, a=i: self.saveme(state))
                self.ebutons[i].setStyleSheet("background-color: lightGray")
                pixmap = QPixmap(path)
                self.image = QLabel()
                self.image.setPixmap(pixmap)
                lay.addWidget(self.image)
                lay.addWidget(self.ebutons[i])
                gbox.setLayout(lay)
                gbox.setStyleSheet("background-color: grey")
                self.layout.addWidget(gbox)
                try:
                    if os.path.isfile(path) or os.path.islink(path):
                        os.unlink(path)
                    elif os.path.isdir(path):
                        shutil.rmtree(path)
                except Exception as e:
                    print('Failed to delete %s. Reason: %s' % (file_path, e))
                i += 1
        print("done")
        self.setLayout(self.layout)
Пример #2
0
    def __init__(self):
        super().__init__()

        # Declare Widgets
        self.homepage_label = QLabel('Home')
        self.search_label = QLabel('Find an Image!')
        self.srch_box = QLineEdit()  # input field for search
        self.srch_btn = QPushButton("Search")

        # Create U.I. Layout
        mbox = QVBoxLayout()

        vbox = QVBoxLayout()
        vbox.addWidget(self.homepage_label)
        vbox.addWidget(self.search_label)
        vbox.addWidget(self.srch_box)
        vbox.addWidget(self.srch_btn)

        gbox1 = QGroupBox()
        gbox1.setLayout(vbox)
        mbox.addWidget(gbox1)

        # Homes Images Layout
        images = []
        images = self.getHomepageImages()

        # Create layout for images
        vbox2 = QHBoxLayout()

        i = 0
        for img in images:
            self.label = QLabel()
            # pic = Image.open(requests.get(img['urls']['thumb'], stream=True).raw)

            pixmap1 = QPixmap(img)

            pixmap1 = pixmap1.scaled(300, 300, Qt.KeepAspectRatio)

            self.label.setPixmap(pixmap1)

            temp_vbox = QVBoxLayout()
            temp_vbox.addWidget(self.label)

            gbox2 = QGroupBox()
            gbox2.setLayout(temp_vbox)
            gbox2.setStyleSheet("background-color: grey")

            vbox2.addWidget(gbox2)
            i += 1

        gbox3 = QGroupBox()
        gbox3.setLayout(vbox2)
        mbox.addWidget(gbox3)
        self.setLayout(mbox)

        # Styling
        self.setStyleSheet("""
            color: orange;
            font-family: Comfortaa;
            """)
        self.srch_btn.setStyleSheet(":hover { background-color:cyan }")
        gbox1.setStyleSheet("""
            font-size: 18px
            """)

        # Listeners
        self.srch_btn.clicked.connect(self.find_images)
Пример #3
0
class ArrayRequirementEditor:
    def __init__(self, parent: QWidget, parent_layout: QVBoxLayout,
                 line_layout: QHBoxLayout, resource_database: ResourceDatabase,
                 requirement: RequirementArrayBase):
        self._editors = []
        self.resource_database = resource_database
        self._array_type = type(requirement)

        # the parent is added to a layout which is added to parent_layout, so we
        index = parent_layout.indexOf(line_layout) + 1

        self.group_box = QGroupBox(parent)
        self.group_box.setStyleSheet("QGroupBox { margin-top: 2px; }")
        parent_layout.insertWidget(index, self.group_box)
        self.item_layout = QVBoxLayout(self.group_box)
        self.item_layout.setContentsMargins(8, 2, 2, 6)
        self.item_layout.setAlignment(Qt.AlignTop)

        self.new_item_button = QPushButton(self.group_box)
        self.new_item_button.setMaximumWidth(75)
        self.new_item_button.setText("New Row")
        self.new_item_button.clicked.connect(self.new_item)

        self.comment_text_box = QLineEdit(parent)
        self.comment_text_box.setText(requirement.comment or "")
        self.comment_text_box.setPlaceholderText("Comment")
        line_layout.addWidget(self.comment_text_box)

        for item in requirement.items:
            self._create_item(item)

        self.item_layout.addWidget(self.new_item_button)

    def _create_item(self, item: Requirement):
        def on_remove():
            self._editors.remove(nested_editor)
            nested_editor.deleteLater()

        nested_editor = RequirementEditor(self.group_box,
                                          self.item_layout,
                                          self.resource_database,
                                          on_remove=on_remove)
        nested_editor.create_specialized_editor(item)
        self._editors.append(nested_editor)

    def new_item(self):
        self._create_item(
            _create_default_resource_requirement(self.resource_database))

        self.item_layout.removeWidget(self.new_item_button)
        self.item_layout.addWidget(self.new_item_button)

    def deleteLater(self):
        self.group_box.deleteLater()
        self.comment_text_box.deleteLater()
        for editor in self._editors:
            editor.deleteLater()
        self.new_item_button.deleteLater()

    @property
    def current_requirement(self) -> RequirementArrayBase:
        comment = self.comment_text_box.text().strip()
        if comment == "":
            comment = None

        return self._array_type(
            [editor.current_requirement for editor in self._editors],
            comment=comment,
        )
Пример #4
0
    def __init__(self):
        super().__init__()

        # Declare Widgets
        self.homepage_label = QLabel('Home')
        self.search_label = QLabel('Find an Image!')
        self.srch_box = QLineEdit()  # input field for search
        self.srch_btn = QPushButton("Search")

        # Create U.I. Layout
        mbox = QVBoxLayout()  # Main layout

        vbox = QVBoxLayout()  # Layout for search feature
        vbox.addWidget(self.homepage_label)
        vbox.addWidget(self.search_label)
        vbox.addWidget(self.srch_box)
        vbox.addWidget(self.srch_btn)

        gbox1 = QGroupBox()  # Set group for search feature layout
        gbox1.setLayout(vbox)
        mbox.addWidget(gbox1)

        # Home Images
        images = []
        images = self.getHomepageImages()

        # Create layout for images
        vbox2 = QHBoxLayout()  # horizontal layout

        i = 0
        for img in images:  # iterate through images list
            self.label = QLabel()

            pixmap1 = QPixmap(img)  # set image
            pixmap1 = pixmap1.scaled(300, 300, Qt.KeepAspectRatio)

            self.label.setPixmap(pixmap1)

            temp_vbox = QVBoxLayout()
            temp_vbox.addWidget(self.label)

            gbox2 = QGroupBox()  # group box for current image
            gbox2.setLayout(temp_vbox)
            gbox2.setStyleSheet("background-color: grey")

            vbox2.addWidget(gbox2)
            i += 1

        gbox3 = QGroupBox()  # main group box for images
        gbox3.setLayout(vbox2)
        mbox.addWidget(gbox3)
        self.setLayout(mbox)

        # Styling
        self.setStyleSheet("""
            color: orange;
            font-family: Comfortaa;
            """)
        self.srch_btn.setStyleSheet(":hover { background-color:cyan }")
        gbox1.setStyleSheet("""
            font-size: 18px
            """)

        # Listeners
        self.srch_btn.clicked.connect(self.find_images)