Beispiel #1
0
 def setup_ui(self):
     vertical_layout = QVBoxLayout(self)
     vertical_layout.setSpacing(6)
     vertical_layout.setContentsMargins(11, 11, 11, 11)
     splitter_v = QSplitter(self)
     splitter_v.setOrientation(PySide2.QtCore.Qt.Vertical)
     size_policy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
     size_policy.setHorizontalStretch(0)
     size_policy.setVerticalStretch(0)
     size_policy.setHeightForWidth(
         splitter_v.sizePolicy().hasHeightForWidth())
     splitter_v.setSizePolicy(size_policy)
     splitter_h = QSplitter(splitter_v)
     splitter_h.setOrientation(PySide2.QtCore.Qt.Horizontal)
     vertical_layout_widget = QWidget(splitter_h)
     self.vertical_layout_left = QVBoxLayout(vertical_layout_widget)
     self.vertical_layout_left.setSpacing(6)
     self.vertical_layout_left.setSizeConstraint(
         QLayout.SetDefaultConstraint)
     self.vertical_layout_left.setContentsMargins(0, 0, 0, 0)
     splitter_h.addWidget(vertical_layout_widget)
     vertical_layout_widget2 = QWidget(splitter_h)
     self.vertical_layout_right = QVBoxLayout(vertical_layout_widget2)
     self.vertical_layout_right.setContentsMargins(0, 0, 0, 0)
     splitter_h.addWidget(vertical_layout_widget2)
     splitter_v.addWidget(splitter_h)
     vertical_layout_widget3 = QWidget(splitter_v)
     vertical_layout_bottom = QVBoxLayout(vertical_layout_widget3)
     vertical_layout_bottom.setSpacing(6)
     vertical_layout_bottom.setSizeConstraint(QLayout.SetDefaultConstraint)
     vertical_layout_bottom.setContentsMargins(11, 0, 11, 11)
     text_browser = QTextBrowser(vertical_layout_widget3)
     vertical_layout_bottom.addWidget(text_browser)
     splitter_v.addWidget(vertical_layout_widget3)
     vertical_layout.addWidget(splitter_v)
Beispiel #2
0
    def __init__(self, items):
        QDialog.__init__(self)
        self.setWindowTitle("Select Dataset")
        self.setWindowFlags(self.windowFlags()
                            & ~Qt.WindowContextHelpButtonHint)
        self.setWindowModality(Qt.ApplicationModal)

        self.label = QLabel("Choose the dataset to load:")
        self.label.setStyleSheet("color: #000")
        self.view = QListWidget()

        for i in items:
            self.view.addItem(QListWidgetItem(i))

        self.buttons = QDialogButtonBox(QDialogButtonBox.Ok
                                        | QDialogButtonBox.Cancel)
        self.buttons.accepted.connect(self._button_ok)
        self.buttons.rejected.connect(self._button_cancel)

        layout = QVBoxLayout()
        layout.setSizeConstraint(QLayout.SetFixedSize)
        layout.addWidget(self.label)
        layout.addWidget(self.view)
        layout.addWidget(self.buttons)
        self.setLayout(layout)
Beispiel #3
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("QR Creator")

        # data input
        self.data = QLineEdit()
        self.data.setPlaceholderText("Data to encode...")

        # QR preview
        self.preview = QLivePreview(parent=self)

        # generate button
        self.generate = QPushButton(
            "Generate && Save")  # '&' is interpreted by PySide, see docs
        self.generate.setDefault(True)

        # output filebrowsing controls
        self.file_browse = QFileBrowse(parent=self)

        # window layout
        layout = QVBoxLayout()
        layout.setSizeConstraint(layout.SetFixedSize)
        layout.addWidget(self.preview)
        layout.addWidget(self.data)
        layout.addWidget(self.file_browse)
        layout.addWidget(self.generate)

        self.setLayout(layout)
Beispiel #4
0
 def setupLayout(self):
     layout = QVBoxLayout()
     layout.addWidget(self.runner)
     layout.addWidget(self.graph.view)
     layout.addWidget(self.sequenceInput)
     layout.addWidget(self.automatonManager)
     layout.addWidget(self.stateManager)
     layout.addWidget(self.symbolManager)
     self.setLayout(layout)
     layout.setSizeConstraint(QLayout.SetMaximumSize)
     self.graph.view.show()
Beispiel #5
0
    def initUI(self):
        image = QImage(self.file_name)
        if image.width() > image.height():
            pixmap = QPixmap(image.scaledToWidth(self.length_max))
        else:
            pixmap = QPixmap(image.scaledToHeight(self.length_max))

        label = QLabel(self)
        label.setPixmap(pixmap)

        vbox = QVBoxLayout(self)
        vbox.addWidget(label)
        vbox.setSizeConstraint(QLayout.SetFixedSize)
        self.setLayout(vbox)
Beispiel #6
0
class Filer(QDialog):
    def __init__(self, parent=None) -> None:
        super(Filer, self).__init__(parent)
        self.setup_ui()
        self.setWindowTitle("Filer")
        self._left_tab_pane = self.setting_up_tabs(self.vertical_layout_left)
        self._right_tab_pane = self.setting_up_tabs(self.vertical_layout_right)

    def setup_ui(self):
        vertical_layout = QVBoxLayout(self)
        vertical_layout.setSpacing(6)
        vertical_layout.setContentsMargins(11, 11, 11, 11)
        splitter_v = QSplitter(self)
        splitter_v.setOrientation(PySide2.QtCore.Qt.Vertical)
        size_policy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        size_policy.setHorizontalStretch(0)
        size_policy.setVerticalStretch(0)
        size_policy.setHeightForWidth(
            splitter_v.sizePolicy().hasHeightForWidth())
        splitter_v.setSizePolicy(size_policy)
        splitter_h = QSplitter(splitter_v)
        splitter_h.setOrientation(PySide2.QtCore.Qt.Horizontal)
        vertical_layout_widget = QWidget(splitter_h)
        self.vertical_layout_left = QVBoxLayout(vertical_layout_widget)
        self.vertical_layout_left.setSpacing(6)
        self.vertical_layout_left.setSizeConstraint(
            QLayout.SetDefaultConstraint)
        self.vertical_layout_left.setContentsMargins(0, 0, 0, 0)
        splitter_h.addWidget(vertical_layout_widget)
        vertical_layout_widget2 = QWidget(splitter_h)
        self.vertical_layout_right = QVBoxLayout(vertical_layout_widget2)
        self.vertical_layout_right.setContentsMargins(0, 0, 0, 0)
        splitter_h.addWidget(vertical_layout_widget2)
        splitter_v.addWidget(splitter_h)
        vertical_layout_widget3 = QWidget(splitter_v)
        vertical_layout_bottom = QVBoxLayout(vertical_layout_widget3)
        vertical_layout_bottom.setSpacing(6)
        vertical_layout_bottom.setSizeConstraint(QLayout.SetDefaultConstraint)
        vertical_layout_bottom.setContentsMargins(11, 0, 11, 11)
        text_browser = QTextBrowser(vertical_layout_widget3)
        vertical_layout_bottom.addWidget(text_browser)
        splitter_v.addWidget(vertical_layout_widget3)
        vertical_layout.addWidget(splitter_v)

    def setting_up_tabs(self, layout: QVBoxLayout) -> MultiTabPane:
        multi_tab_pane = MultiTabPane(self)
        layout.addWidget(multi_tab_pane)
        multi_tab_pane.add_tab("C:/")
        multi_tab_pane.set_current_tab_index(0)
        return multi_tab_pane
Beispiel #7
0
    def create_view(self):
        grid_layout = QGridLayout()
        v_layout = QVBoxLayout()
        h_layout = QHBoxLayout()

        v_layout.setSizeConstraint(QLayout.SetFixedSize)

        self.login_btn = QPushButton('Login')
        self.register_btn = QPushButton('Register')
        self.cancel_btn = QPushButton('Cancel')
        self.username_lbl = QLabel('Username')
        self.password_lbl = QLabel('Password')
        self.top_label = QLabel('Login')
        self.username_box = QLineEdit()
        self.password_box = QLineEdit()

        self.password_box.setEchoMode(QLineEdit.Password)
        self.password_box.setMaxLength(30)
        self.username_box.setMaxLength(20)

        self.login_btn.setEnabled(False)
        self.register_btn.setEnabled(False)

        grid_layout.addWidget(self.username_lbl, 1, 0)
        grid_layout.addWidget(self.username_box, 1, 1)
        grid_layout.addWidget(self.password_lbl, 2, 0)
        grid_layout.addWidget(self.password_box, 2, 1)

        v_layout.addStretch(1)
        v_layout.addWidget(self.top_label, alignment=Qt.AlignCenter)
        v_layout.addLayout(grid_layout)
        v_layout.addWidget(self.login_btn)
        v_layout.addWidget(self.register_btn)
        v_layout.addWidget(self.cancel_btn)
        v_layout.addStretch(1)

        h_layout.addStretch(1)
        h_layout.addLayout(v_layout)
        h_layout.addStretch(1)

        self.setLayout(h_layout)

        # Connect button
        self.login_btn.clicked.connect(self.authenticate)
        self.register_btn.clicked.connect(self.register_action)
        self.cancel_btn.clicked.connect(self.exit_application)

        self.username_box.textChanged.connect(self.check_enabled)
        self.password_box.textChanged.connect(self.check_enabled)
Beispiel #8
0
    def __init__(self, text, parent, width):
        # type: (str, QWidget, int) -> None
        super().__init__(parent)
        self.__label = QLabel(text, self)
        self.__label.setFixedWidth(width)
        self.__input = PlainTextSingleLine(self)
        self.__input.setWordWrapMode(QTextOption.NoWrap)
        self.__input.setFixedSize(width, DEFAULT_WIDGET_HEIGHT)
        self.__input.enter_pressed.connect(self.enter_pressed)

        self.setContentsMargins(NO_MARGINS)
        layout = QVBoxLayout(self)
        layout.setSpacing(1)
        layout.setContentsMargins(NO_MARGINS)
        layout.setSizeConstraint(QVBoxLayout.SetFixedSize)
        layout.addWidget(self.__label)
        layout.addWidget(self.__input)
        self.setLayout(layout)

        self.setFocusProxy(self.__input)
Beispiel #9
0
    def setup_ui(self, parent):
        global clash_started

        self._height = 400
        self._width = 500
        self.resize(self._width, self._height)
        self.setMinimumSize(self._width, self._height)

        layout = QHBoxLayout(parent)
        controls = QVBoxLayout(parent)
        controls.setAlignment(Qt.AlignTop)
        controls.setSizeConstraint(QVBoxLayout.SetMinimumSize)

        start = QToolButton(parent)
        start.setIcon(QIcon("images/start.svg"))
        start.setToolTip("start clash")
        start.setIconSize(QSize(30, 30))
        start.clicked.connect(self.start)
        start.setFixedSize(50, 50)
        start.setDisabled(clash_started)
        controls.addWidget(start)

        stop = QToolButton(parent)
        stop.setIcon(QIcon("images/stop.svg"))
        stop.setToolTip("stop clash")
        stop.setIconSize(QSize(30, 30))
        stop.clicked.connect(self.stop)
        stop.setDisabled(not clash_started)
        stop.setFixedSize(50, 50)
        controls.addWidget(stop)

        layout.addLayout(controls)
        self._output = QTextBrowser(parent)
        self._output.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        layout.addWidget(self._output)

        for i in range(0, 100):
            self._output.append("current index is {}".format(i) * 5)

        self.setLayout(layout)
Beispiel #10
0
    def _gui(self):
        layout = QVBoxLayout()
        self.setLayout(layout)

        group = QGroupBox('Other', self)
        group.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
        layout.addWidget(group)

        layout = QVBoxLayout()
        group.setLayout(layout)

        problems = List(self)
        problems.problem_selected.connect(self.problem_selected)
        problems.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
        layout.addWidget(problems, 0)

        for i in PROBLEMS:
            problems.addItem(i)

        problems.clearSelection()
        layout.setSizeConstraint(QVBoxLayout.SetMinimumSize)
        layout.update()
Beispiel #11
0
    def init_ui(self):
        """Makes the layout"""

        # Barra de opciones y links de interés
        menu_bar = self.menuBar()

        options_menu = menu_bar.addMenu("&Opciones")
        act_allways_visible = options_menu.addAction("Siempre visible")
        act_allways_visible.setCheckable(True)
        act_allways_visible.toggled.connect(self.__allways_visible)

        calendars_menu = menu_bar.addMenu("&Calendarios")
        for calendar_group in OTHER_CALENDARS:
            section = calendars_menu.addMenu(calendar_group.name)
            for calendar in calendar_group.calendars:
                option = section.addAction(calendar.name)
                option.triggered.connect(
                    lambda s=None, l=calendar.url: self.__to_clipboard(l))

        go_to_menu = menu_bar.addMenu("&Ir a")
        for i, link_group in enumerate(LINKS):
            for link in link_group.links:
                new_option = go_to_menu.addAction(link.description)
                new_option.triggered.connect(
                    lambda s=None, l=link.url: webbrowser.open(l))
            if i - 1 != len(LINKS):
                go_to_menu.addSeparator()

        # Main widget

        main_widget = QFrame()
        self.setCentralWidget(main_widget)

        main_layout = QVBoxLayout(main_widget)
        main_widget.setLayout(main_layout)

        main_layout.setSizeConstraint(QLayout.SetMinimumSize)

        # Lista de códigos a ingresar
        code_layout = QHBoxLayout()
        main_layout.addLayout(code_layout)
        self.code_list = [QLineEdit(main_widget) for i in range(6)]
        code_validator = QIntValidator(main_layout, 10**4, 10**5)
        for code in self.code_list:
            code.setObjectName("code_field")
            code.setAlignment(Qt.AlignCenter)
            code.setMaxLength(5)
            code.setValidator(code_validator)
            code.textEdited.connect(self.check_codes)
            code_layout.addWidget(code)

        self.get_button = QPushButton("Obtener horario", main_widget)
        self.get_button.clicked.connect(self.get_schedule)
        self.get_button.setCursor(Qt.PointingHandCursor)
        self.get_button.setDisabled(True)
        main_layout.addWidget(self.get_button)

        self.schedule_view = ScheduleView(8, 6, main_widget)
        main_layout.addWidget(self.schedule_view)

        self.save_button = QPushButton("Guardar horario", main_widget)
        self.save_button.clicked.connect(self.save_schedule)
        self.save_button.setCursor(Qt.PointingHandCursor)
        self.save_button.setDisabled(True)
        main_layout.addWidget(self.save_button)

        self.status_bar = QStatusBar(self)
        self.status_bar.showMessage("Ingrese los códigos NRC")
        self.setStatusBar(self.status_bar)

        self.adjustSize()
Beispiel #12
0
    def __init__(self):
        super().__init__()

        w = QWidget()

        hb = QHBoxLayout()
        hb.setSizeConstraint(QLayout.SetFixedSize)

        self._timer = QTimer()
        self._timer.timeout.connect(self.update_timer)
        self._timer.start(1000)  # 1 second timer

        # tag::status[]
        self.mines = QLabel()
        self.mines.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)

        self.clock = QLabel()
        self.clock.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)

        f = self.mines.font()
        f.setPointSize(24)
        f.setWeight(75)
        self.mines.setFont(f)
        self.clock.setFont(f)

        self.clock.setText("000")

        self.button = QPushButton()
        self.button.setFixedSize(QSize(32, 32))
        self.button.setIconSize(QSize(32, 32))
        self.button.setIcon(QIcon("./icons/smiley.png"))
        self.button.setFlat(True)

        self.button.pressed.connect(self.button_pressed)

        self.statusBar()

        l = QLabel()
        l.setPixmap(QPixmap.fromImage(IMG_BOMB))
        l.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        hb.addWidget(l)

        hb.addWidget(self.mines)
        hb.addWidget(self.button)
        hb.addWidget(self.clock)

        l = QLabel()
        l.setPixmap(QPixmap.fromImage(IMG_CLOCK))
        l.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        hb.addWidget(l)

        vb = QVBoxLayout()
        vb.setSizeConstraint(QLayout.SetFixedSize)
        vb.addLayout(hb)
        # end::status[]

        # tag::grid[]
        self.grid = QGridLayout()
        self.grid.setSpacing(5)
        self.grid.setSizeConstraint(QLayout.SetFixedSize)
        # end::grid[]

        vb.addLayout(self.grid)
        w.setLayout(vb)

        self.setCentralWidget(w)

        self.menuBar().setNativeMenuBar(False)

        # tag::menuGame[]
        game_menu = self.menuBar().addMenu("&Game")

        new_game_action = QAction("New game", self)
        new_game_action.setStatusTip(
            "Start a new game (your current game will be lost)"
        )
        new_game_action.triggered.connect(self.reset_map)
        game_menu.addAction(new_game_action)

        levels = game_menu.addMenu("Levels")
        for n, level in enumerate(LEVELS):
            level_action = QAction(level[0], self)
            level_action.setStatusTip("{1}x{1} grid, with {2} mines".format(*level))
            level_action.triggered.connect(lambda _, n=n: self.set_level(n))
            levels.addAction(level_action)
        # end::menuGame[]

        # Start on easy
        self.set_level(0)
        self.show()
class MainStyleTransferWidget(BaseWidget):
    def __init__(self, parent=None, app_name='Style Transfer'):
        super(MainStyleTransferWidget, self).__init__(parent=parent,
                                                      widget_name=app_name)
        self.output_image_max_height = 640
        self.output_image_max_width = 768
        self.dual_mode = False
        self.choose_network()
        # make self.input_and_style_layout
        self.input_and_style_layout = QHBoxLayout()
        # make main layout
        self.main_layout = QHBoxLayout()
        self.output_image_label = QLabel(self)
        output_image_layout = self.make_image_layout(self.output_image_label,
                                                     'Output Image')
        self.output_image_label.setAlignment(QtCore.Qt.AlignHCenter)
        self.main_layout.addLayout(output_image_layout)
        # make sliders
        self.multi_alpha = False
        self.alpha_0 = 0
        self.alpha_1 = 0
        self.alpha_2 = 0
        self.slider_layout = QVBoxLayout()
        self.make_sliders()
        # make check boxes
        check_boxes_layout = QHBoxLayout()
        self.multi_alpha_check_box = QCheckBox("Multi Blocks")
        self.multi_alpha_check_box.stateChanged.connect(
            self.multi_alpha_check_box_state_changed)
        self.show_input_and_style_check_box = QCheckBox("Show Input and Style")
        self.show_input_and_style_check_box.stateChanged.connect(
            self.show_input_and_style_check_box_state_changed)
        check_boxes_layout.addWidget(self.multi_alpha_check_box)
        check_boxes_layout.addWidget(self.show_input_and_style_check_box)
        # make save image Button
        save_image_button = QPushButton('Save Image')
        save_image_button.clicked.connect(self.on_save_image_click)
        change_style_button = QPushButton('Change Style')
        change_style_button.clicked.connect(self.on_change_style_click)
        # make buttons layout
        self.buttons_layout = QHBoxLayout()
        self.buttons_layout.addWidget(save_image_button)
        self.buttons_layout.addWidget(change_style_button)
        # widget layout
        self.layout = QVBoxLayout()
        self.layout.addLayout(self.input_and_style_layout)
        self.layout.addLayout(self.main_layout)
        self.layout.addLayout(self.slider_layout)
        self.layout.addLayout(check_boxes_layout)
        self.layout.addLayout(self.buttons_layout)
        self.layout.setSizeConstraint(QLayout.SetFixedSize)
        self.setLayout(self.layout)
        # net init
        self.dynamic_model = None
        self.device = torch.device(
            "cuda" if torch.cuda.is_available() else "cpu")
        self.input_tensor = None
        self.output_tensor = None
        self.input_image = None
        self.style_image = None
        self.output_image = None
        self.saved_images_count = 0
        # show widget
        self.show()

    def make_input_and_style_layout(self):
        self.input_image_label = QLabel(self)
        input_image_layout = self.make_image_layout(self.input_image_label,
                                                    'Input Image')
        self.style_image_label = QLabel(self)
        style_image_layout = self.make_image_layout(self.style_image_label,
                                                    'style Image')
        self.input_and_style_layout.addLayout(input_image_layout)
        self.input_and_style_layout.addLayout(style_image_layout)

    # sliders functions
    def make_sliders(self):
        if self.multi_alpha:
            alpha_0_slider_layout, self.alpha_0_slider, self.alpha_0_txt = self.make_slider_layout(
                self.alpha_0_slider_changed, val=self.alpha_0)
            self.alpha_0_txt.setText(U"\U0001D6C2 0 = %.3f" % self.alpha_0)
            alpha_1_slider_layout, self.alpha_1_slider, self.alpha_1_txt = self.make_slider_layout(
                self.alpha_1_slider_changed, val=self.alpha_1)
            self.alpha_1_txt.setText(U"\U0001D6C2 1 = %.3f" % self.alpha_1)
            alpha_2_slider_layout, self.alpha_2_slider, self.alpha_2_txt = self.make_slider_layout(
                self.alpha_2_slider_changed, val=self.alpha_2)
            self.alpha_2_txt.setText(U"\U0001D6C2 2 = %.3f" % self.alpha_2)
            self.slider_layout.addLayout(alpha_0_slider_layout)
            self.slider_layout.addLayout(alpha_1_slider_layout)
            self.slider_layout.addLayout(alpha_2_slider_layout)
        else:
            alpha_slider_layout, self.alpha_slider, self.alpha_txt = self.make_slider_layout(
                self.alpha_slider_changed, val=self.alpha_0)
            self.alpha_txt.setText(U"\U0001D6C2 = %.3f" % self.alpha_0)
            self.slider_layout.addLayout(alpha_slider_layout)

    def alpha_0_slider_changed(self):
        self.alpha_0 = (self.alpha_0_slider.value() / 100)**1
        if self.alpha_0 > 0.96:
            self.alpha_0 = 1
        self.alpha_0_txt.setText(U"\U0001D6C2 0 = %.3f" % self.alpha_0)
        if self.input_tensor is not None:
            self.run()
            self.set_output_image()

    def alpha_1_slider_changed(self):
        self.alpha_1 = (self.alpha_1_slider.value() / 100)**1
        if self.alpha_1 > 0.96:
            self.alpha_1 = 1
        self.alpha_1_txt.setText(U"\U0001D6C2 1 = %.3f" % self.alpha_1)
        if self.input_tensor is not None:
            self.run()
            self.set_output_image()

    def alpha_2_slider_changed(self):
        self.alpha_2 = (self.alpha_2_slider.value() / 100)**1
        if self.alpha_2 > 0.96:
            self.alpha_2 = 1
        self.alpha_2_txt.setText(U"\U0001D6C2 2 = %.3f" % self.alpha_2)
        if self.input_tensor is not None:
            self.run()
            self.set_output_image()

    def alpha_slider_changed(self):
        self.alpha_0 = (self.alpha_slider.value() / 100)**1
        if self.alpha_0 > 0.96:
            self.alpha_0 = 1
        self.alpha_1 = self.alpha_0
        self.alpha_2 = self.alpha_0
        self.alpha_txt.setText(U"\U0001D6C2 = %.3f" % self.alpha_0)
        if self.input_tensor is not None:
            self.run()
            self.set_output_image()

    # check box changed
    def multi_alpha_check_box_state_changed(self):
        if self.multi_alpha_check_box.isChecked():
            self.multi_alpha = True
            self.clear_layout(self.slider_layout)
            self.make_sliders()
        else:
            self.multi_alpha = False
            self.clear_layout(self.slider_layout)
            self.make_sliders()
            self.alpha_slider_changed()
        self.show()

    def show_input_and_style_check_box_state_changed(self):
        if self.show_input_and_style_check_box.isChecked():
            self.make_input_and_style_layout()
            self.set_style_image()
            self.set_input_image()
        else:
            self.clear_layout(self.input_and_style_layout)
        self.show()

    # drop event
    def execute_drop_event(self, file_name):
        self.input_image = Image.open(file_name)
        if self.show_input_and_style_check_box.isChecked():
            self.set_input_image()
        if self.dynamic_model is not None:
            self.calc_input_tensor()
            self.run()
            self.set_output_image()

    # images functions
    def set_input_image(self):
        if self.input_image is not None:
            self.input_image_label.setPixmap(
                self.make_pix_map(self.input_image, max_size=128))

    def set_style_image(self):
        if self.show_input_and_style_check_box.isChecked(
        ) and self.style_image is not None:
            self.style_image_label.setPixmap(
                self.make_pix_map(self.style_image, max_size=128))

    def set_output_image(self):
        self.output_image = self.transformer.to_pil_image(
            self.output_tensor.clamp(min=0.0, max=1).cpu().squeeze(dim=0))
        if self.output_image.height > self.output_image_max_height:
            pix_map = self.make_pix_map(self.output_image,
                                        max_size=self.output_image_max_height)
        elif self.output_image.width > self.output_image_max_width:
            pix_map = self.make_pix_map(self.output_image,
                                        max_size=self.output_image_max_width)
        else:
            pix_map = self.make_pix_map(self.output_image)
        self.output_image_label.setPixmap(pix_map)

    def calc_input_tensor(self):
        self.input_tensor = self.transformer.to_tensor(self.input_image).to(
            self.dynamic_model.device)
        self.input_tensor = self.dynamic_model.normalize(self.input_tensor)
        self.input_tensor = self.input_tensor.expand(1, -1, -1, -1)
        if self.input_tensor.shape[2] % 2 is not 0:
            self.input_tensor = self.input_tensor[:, :, 0:-1, :]
        if self.input_tensor.shape[2] % 4 is not 0:
            self.input_tensor = self.input_tensor[:, :, 1:-1, :]
        if self.input_tensor.shape[3] % 2 is not 0:
            self.input_tensor = self.input_tensor[:, :, :, 0:-1]
        if self.input_tensor.shape[3] % 4 is not 0:
            self.input_tensor = self.input_tensor[:, :, :, 1:-1]

    def run(self):
        if self.multi_alpha:
            self.output_tensor = self.dynamic_model.forward_and_recover(
                self.input_tensor,
                alpha_0=self.alpha_0,
                alpha_1=self.alpha_1,
                alpha_2=self.alpha_2)
        else:
            self.output_tensor = self.dynamic_model.forward_and_recover(
                self.input_tensor, alpha_0=self.alpha_0)

    def on_save_image_click(self):
        self.save_image()

    def on_change_style_click(self):
        self.choose_network()

    def choose_network(self):
        self.widget = ChooseStyleWidget(main_widget=self)
        self.widget.show()

    def save_image(self):
        save_path = os.path.join('results', 'gui_results')
        if not os.path.exists(save_path):
            save_path = os.path.join('..', save_path)
        save_path = os.path.join(save_path,
                                 '%04d.png' % self.saved_images_count)
        self.output_image.save(save_path)
        print('image saved to %s' % save_path)
        self.saved_images_count += 1
        return save_path
class MainDynamicDcGanWidget(BaseWidget):
    def __init__(self, parent=None, app_name='Dynamic DCGAN', manual_seed=None):
        super(MainDynamicDcGanWidget, self).__init__(parent=parent, widget_name=app_name)
        self.choose_network()
        # make main layout
        self.main_layout = QHBoxLayout()
        self.generated_image_label = QLabel(self)
        generated_image_layout = self.make_image_layout(self.generated_image_label, 'Generated Images')
        self.generated_image_label.setAlignment(QtCore.Qt.AlignHCenter)
        self.main_layout.addLayout(generated_image_layout)
        # make sliders
        self.multi_alpha = False
        self.alpha_0 = 0
        self.slider_layout = QVBoxLayout()
        self.make_sliders()
        # make check boxes
        check_boxes_layout = QHBoxLayout()
        self.show_8_check_box = QCheckBox("Show 8 images")
        self.show_16_check_box = QCheckBox("Show 16 images")
        self.show_24_check_box = QCheckBox("Show 24 images")
        self.show_8_check_box.stateChanged.connect(self.show_8_check_box_state_changed)
        self.show_16_check_box.stateChanged.connect(self.show_16_check_box_state_changed)
        self.show_24_check_box.stateChanged.connect(self.show_24_check_box_state_changed)
        check_boxes_layout.addWidget(self.show_8_check_box)
        check_boxes_layout.addWidget(self.show_16_check_box)
        check_boxes_layout.addWidget(self.show_24_check_box)
        # make generation Button
        generation_button = QPushButton('Generate')
        generation_button.clicked.connect(self.on_generation_button_click)
        # make save image Button
        save_image_button = QPushButton('Save Image')
        save_image_button.clicked.connect(self.on_save_image_click)
        # make change attributes Button
        change_attributes_button = QPushButton('Change Attributes')
        change_attributes_button.clicked.connect(self.on_change_attributes_click)
        # make buttons layout
        self.buttons_layout = QHBoxLayout()
        self.buttons_layout.addWidget(generation_button)
        self.buttons_layout.addWidget(change_attributes_button)
        self.buttons_layout.addWidget(save_image_button)
        # widget layout
        self.layout = QVBoxLayout()
        self.layout.addLayout(self.main_layout)
        self.layout.addLayout(self.slider_layout)
        self.layout.addLayout(check_boxes_layout)
        self.layout.addLayout(self.buttons_layout)
        self.layout.setSizeConstraint(QLayout.SetFixedSize)
        self.setLayout(self.layout)
        # net init
        self.dynamic_model = None
        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        self.input_tensor = None
        self.output_tensor = None
        self.output_image = None
        self.saved_images_count = 0
        if manual_seed is not None:
            torch.manual_seed(manual_seed)
        self.transformer = Transformer()
        # show widget
        self.show()

    def make_input_and_style_layout(self):
        self.input_image_label = QLabel(self)
        input_image_layout = self.make_image_layout(self.input_image_label, 'Input Image')
        self.style_image_label = QLabel(self)
        style_image_layout = self.make_image_layout(self.style_image_label, 'style Image')
        self.input_and_style_layout.addLayout(input_image_layout)
        self.input_and_style_layout.addLayout(style_image_layout)

    # sliders functions
    def make_sliders(self):
        alpha_slider_layout, self.alpha_slider, self.alpha_txt = self.make_slider_layout(self.alpha_slider_changed, val=self.alpha_0)
        self.alpha_txt.setText(U"\U0001D6C2 = %.3f" % self.alpha_0)
        self.slider_layout.addLayout(alpha_slider_layout)

    def alpha_slider_changed(self):
        self.alpha_0 = (self.alpha_slider.value() / 100) ** 2
        if self.alpha_0 > 0.96:
            self.alpha_0 = 1
        self.alpha_txt.setText(U"\U0001D6C2 0 = %.3f" % self.alpha_0)
        if self.input_tensor is not None:
            self.run()
            self.set_output_image()

    # images functions
    def generate(self):
        return torch.randn((128, self.dynamic_model.opt.z_size)).view(-1, self.dynamic_model.opt.z_size, 1, 1).to(self.device)

    def set_output_image(self):
        nrow = 8
        num_of_images = 1
        if self.show_8_check_box.isChecked():
            num_of_images = 8
        elif self.show_16_check_box.isChecked():
            num_of_images = 16
        elif self.show_24_check_box.isChecked():
            num_of_images = 24
        image = torchvision.utils.make_grid(self.output_tensor[:num_of_images, :, :, :].clamp(min=0.0, max=1), nrow=nrow)
        self.output_image = self.transformer.to_pil_image(image.cpu())
        # self.output_image = self.output_image.resize((int(self.output_image.width * 1.5), int(self.output_image.height * 1.5)), Image.ANTIALIAS)
        pix_map = self.transformer.pil2pixmap(self.output_image)
        self.generated_image_label.setPixmap(pix_map)

    def run(self):
        self.output_tensor = self.dynamic_model.forward_and_recover(self.input_tensor, alpha=self.alpha_0)

    def on_save_image_click(self):
        self.save_image()

    def on_change_attributes_click(self):
        self.widget = ChooseAttributesWidget(main_widget=self)
        self.widget.show()

    def show_8_check_box_state_changed(self):
        if self.show_8_check_box.isChecked():
            self.show_16_check_box.setChecked(False)
            self.show_24_check_box.setChecked(False)
        if self.input_tensor is not None:
            self.run()
            self.set_output_image()

    def show_16_check_box_state_changed(self):
        if self.show_16_check_box.isChecked():
            self.show_8_check_box.setChecked(False)
            self.show_24_check_box.setChecked(False)
        if self.input_tensor is not None:
            self.run()
            self.set_output_image()

    def show_24_check_box_state_changed(self):
        if self.show_24_check_box.isChecked():
            self.show_8_check_box.setChecked(False)
            self.show_16_check_box.setChecked(False)
        if self.input_tensor is not None:
            self.run()
            self.set_output_image()

    def save_image(self):
        save_path = os.path.join('results', 'gui_results')
        if not os.path.exists(save_path):
            save_path = os.path.join('..', save_path)
        save_path = os.path.join(save_path, '%04d.png' % self.saved_images_count)
        self.output_image.save(save_path)
        print('image saved to %s' % save_path)
        self.saved_images_count += 1
        return save_path

    def choose_network(self):
        self.widget = ChooseAttributesWidget(main_widget=self)
        self.widget.show()

    def on_generation_button_click(self):
        self.generation_noise = self.generate()
        self.input_tensor = self.generation_noise
        self.run()
        self.set_output_image()
Beispiel #15
0
    def init_ui(self):
        """Makes the layout"""

        # Barra de opciones y links de interés
        menu_bar = self.menuBar()

        options_menu = menu_bar.addMenu("&Opciones")
        act_allways_visible = options_menu.addAction("Siempre visible")
        act_allways_visible.setCheckable(True)
        act_allways_visible.toggled.connect(self.__allways_visible)

        uc_calendars_menu = menu_bar.addMenu("&Calendarios")
        for name, link in OTHER_CALENDARS:
            calendar_option = uc_calendars_menu.addAction(name)
            # TODO: Ni idea pq se necesita tener una variable `s`, sin esta no funciona
            calendar_option.triggered.connect(
                lambda s=None, l=link: self.__to_clipboard(l))

        go_to_menu = menu_bar.addMenu("&Ir a")
        go_to_options = [
            ("Feed del calendario de Canvas",
             "https://cursos.canvas.uc.cl/calendar"),
            (
                "Importar calendario a Google",
                "https://calendar.google.com/calendar/a/uc.cl/r/settings/export",
            ),
        ]

        for name, link in go_to_options:
            new_option = go_to_menu.addAction(name)
            new_option.triggered.connect(
                lambda s=None, l=link: webbrowser.open(l))

        # Main widget

        main_widget = QFrame()
        self.setCentralWidget(main_widget)

        main_layout = QVBoxLayout(main_widget)
        main_widget.setLayout(main_layout)

        main_layout.setSizeConstraint(QLayout.SetMinimumSize)

        # Lista de códigos a ingresar
        code_layout = QHBoxLayout()
        main_layout.addLayout(code_layout)
        self.code_list = [QLineEdit(main_widget) for i in range(6)]
        code_validator = QIntValidator(main_layout, 10**4, 10**5)
        for code in self.code_list:
            code.setObjectName("code_field")
            code.setAlignment(Qt.AlignCenter)
            code.setMaxLength(5)
            code.setValidator(code_validator)
            code.textEdited.connect(self.check_codes)
            code_layout.addWidget(code)

        self.get_button = QPushButton("Obtener horario", main_widget)
        self.get_button.clicked.connect(self.get_schedule)
        self.get_button.setCursor(Qt.PointingHandCursor)
        self.get_button.setDisabled(True)
        main_layout.addWidget(self.get_button)

        self.schedule_view = ScheduleView(8, 6, main_widget)
        main_layout.addWidget(self.schedule_view)

        self.save_button = QPushButton("Guardar horario", main_widget)
        self.save_button.clicked.connect(self.save_schedule)
        self.save_button.setCursor(Qt.PointingHandCursor)
        self.save_button.setDisabled(True)
        main_layout.addWidget(self.save_button)

        self.status_bar = QStatusBar(self)
        self.status_bar.showMessage("Ingrese los códigos NRC")
        self.setStatusBar(self.status_bar)

        self.adjustSize()
Beispiel #16
0
    def _updateSelector(self):
        sequences = list(self._possibleSequences())
        
        # Build a new widget with all the new options
        selector = QWidget()
        layout = QVBoxLayout()
        layout.setSizeConstraint(layout.SetMinAndMaxSize)
        layout.addWidget(self.selector_placeholder)
        selector.setLayout(layout)
        self.selector_scroll_area.setWidget(selector)
        self.selector_button_group = QButtonGroup()
        self.selector = selector
        
        if len(sequences) == 0:
            self.selector_placeholder.show()
            return
        self.selector_placeholder.hide()

        # Some black magic because of problems with scopes
        def selectSequence(seq):
            self.scheme().clearSelection()
            seq[0].selectAll()

        def makeSelectSequence(seq):
            return lambda: selectSequence(seq)
        # End of black magic

        self._sequences = []
        for sgraph, slist in sequences:
            label = " → ".join([node.title() for node in slist])

            button = QRadioButton(label)
            button.clicked.connect(makeSelectSequence((sgraph, slist)))

            self.selector_button_group.addButton(button)
            layout.addWidget(button)
            self._sequences.append((sgraph, slist, button))
        
        # Now that the new widget was built, determine which point should be selected considering previous selection
        selected = self.selectedSequence()

        if selected is None:
            # If no previous selection, select the first one
            self._sequences[0][2].setChecked(True)
            return

        candidates = []
        for sgraph, slist, button in self._sequences:
            # Analyze every new option
            if selected[0] <= sgraph:
                # If old selection is a subset of a new option, that means a new node was attached and current selection
                # should be expanded
                button.setChecked(True)
                return
            
            if sgraph <= selected[0]:
                # This option is a subset of previous option, which means that something was deleted. If an edge was
                # removed, there may be other parts of previous options, add them all to candidates for new selection.
                candidates.append((sgraph, slist, button))

        if len(candidates) == 0:
            # If there are no candidates, select the first option.
            self._sequences[0][2].setChecked(True)
            return

        for node in selected[1]:
            # For each node in order in prev. selection, see if any candidates have it. Select the first mathcing one.
            for sgraph, slist, button in candidates:
                if node in sgraph:
                    button.setChecked(True)
                    return
Beispiel #17
0
class WdParameterEditBase(QWidget):
    def __init__(self, prop, parent=None):
        super().__init__(parent)
        self.layout = QVBoxLayout()
        self.layout.setSizeConstraint(self.layout.SetFixedSize)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
        self.setLayout(self.layout)
        self._updating_semaphore = Lock()
        self.property = prop
        self.widgets = []
        self.wdparameter: Optional[Parameter] = None
        self._model_handler = lambda change: self._on_model_changed(change)

    def add_subwidget(self, widget: QWidget):
        self.layout.addWidget(widget)
        self.setSizePolicy(widget.sizePolicy())

    # def minimumSizeHint(self) -> QSize:
    #     size = super().minimumSizeHint()
    #     for w in self.children():
    #         size.expandedTo(w.minimumSizeHint())
    #     return size
    #
    # def sizeHint(self) -> QSize:
    #     size = super().sizeHint()
    #     for w in self.children():
    #         size.expandedTo(w.sizeHint())
    #     return size

    def set_parameter(self, parameter: Parameter):
        try:
            self.wdparameter.unobserve(self._model_handler, self.property)
        except (AttributeError, ValueError):
            pass
        self.wdparameter = parameter
        self.update_from_model()
        self.wdparameter.observe(self._model_handler, self.property)

    def update_from_model(self):
        try:
            self._updating_semaphore.acquire(blocking=False)
            if self.wdparameter is None:
                self.set_view_value('')
            else:
                val = getattr(self.wdparameter, self.property)
                self.set_view_value(val)
        finally:
            self._updating_semaphore.release()

    def _on_model_changed(self, change):
        if not self._updating_semaphore.locked():
            self.update_from_model()

    def set_view_value(self, value):
        raise NotImplementedError

    def set_model_value(self, value):
        try:
            if self._updating_semaphore.acquire(blocking=True):
                setattr(self.wdparameter, self.property, value)
        finally:
            self._updating_semaphore.release()
Beispiel #18
0
 def _create_main_vertical_layout(self) -> QLayout:
     layout = QVBoxLayout(self)
     layout.setSizeConstraint(QLayout.SetDefaultConstraint)
     return layout