def testInternalRef(self):
        mw = QWidget()
        w = QWidget()
        ow = QWidget()

        topLayout = QGridLayout()

        # unique reference
        self.assertEqual(getrefcount(w), 2)
        self.assertEqual(getrefcount(ow), 2)

        topLayout.addWidget(w, 0, 0)
        topLayout.addWidget(ow, 1, 0)

        # layout keep the referemce
        self.assertEqual(getrefcount(w), 3)
        self.assertEqual(getrefcount(ow), 3)

        mainLayout = QGridLayout()

        mainLayout.addLayout(topLayout, 1, 0, 1, 4)

        # the same reference
        self.assertEqual(getrefcount(w), 3)
        self.assertEqual(getrefcount(ow), 3)

        mw.setLayout(mainLayout)

        # now trasfer the ownership to mw
        self.assertEqual(getrefcount(w), 3)
        self.assertEqual(getrefcount(ow), 3)

        del mw

        # remove the ref and invalidate the widget
        self.assertEqual(getrefcount(w), 2)
        self.assertEqual(getrefcount(ow), 2)
Beispiel #2
0
class DataProcessingDialog(QDialog):
    '''
    Signals
    '''
    newDataAdded = Signal(str, str, str)
    dataChanged = Signal(str, str, str)

    def __init__(self, dataManager, parent=None, inputList=None):
        self.operations = {
            'Filtering': [FilterGroup, 'Filter settings', -1],
            'Average': [AverageGroup, 'Window settings', -1],
            'Energy': [EnergyGroup, 'Window settings', -1],
            'Power': [PowerGroup, 'Window settings', -1],
            'Peak-To-Peak': [Peak2PeakGroup, 'Window settings', -1],
            'Variance': [VarianceGroup, 'Window settings', -1],
            'Entropy': [EntropyGroup, 'Window settings', -1],
            'Skewness': [SkewnessGroup, 'Window settings', -1],
            'Thresholding': [ThresholdGroup, 'Settings', -1],
            'Detrend': [DetrendGroup, 'Settings', -1],
            'STFT': [STFTGroup, 'Spectrum settings', -1],
            'CWT': [CWTGroup, 'CWT settings', -1]
        }
        QDialog.__init__(self, parent)
        self.dataManager = dataManager
        self.setWindowTitle('Data Processing')
        self.inputList = inputList

        #Setup Layouts
        self.mainLayout = QGridLayout(self)
        self.setupInLayout()
        self.setupProcessLayout()
        self.setupOutLayout()
        self.setupBtnBoxLayout()

    '''
    Input Layout
    '''

    def setupInLayout(self):
        inGroup = QGroupBox('Input to process')
        inLayout = QFormLayout(inGroup)

        self.inTree = DataSelector(self.dataManager, inputList=self.inputList)

        self.operChooser = QComboBox()
        [self.operChooser.addItem(i) for i in self.operations]
        self.operChooser.currentTextChanged.connect(self.setOperation)
        inLayout.addRow(QLabel('Select Input'))
        inLayout.addRow(self.inTree)
        inLayout.addRow(QLabel('Operation'), self.operChooser)

        self.mainLayout.addWidget(inGroup, 0, 0)

    def setOperation(self):
        print('Set Operation')
        index = self.operations[self.operChooser.currentText()][2]
        self.processLayout.setCurrentIndex(index)

    '''
    Signal Processing Settings Layout
    '''

    def setupProcessLayout(self):
        processGroup = QGroupBox('Processing settings')
        self.processLayout = QStackedLayout()
        self.mainLayout.addLayout(self.processLayout, 1, 0)

        # Setup Processing Sublayouts
        for op in self.operations:
            index = self.createGroup(self.operations[op][0], op,
                                     self.operations[op][1])
            self.operations[op][2] = index

    '''
    Create Groups
    '''

    def createGroup(self, GroupClass, name, title):
        newGroup = GroupClass(title, fs=self.dataManager.getFs())
        newGroup.progress.connect(self.updateProgress)
        index = self.processLayout.addWidget(newGroup)
        return index

    '''
    Output Layout
    '''

    def setupOutLayout(self):
        outGroup = QGroupBox('Output')
        outLayout = QFormLayout(outGroup)
        self.outNameEdit = QLineEdit()
        inAsOutCheck = QCheckBox('Replace input')
        inAsOutCheck.toggled.connect(self.setInputAsOutput)
        outLayout.addWidget(inAsOutCheck)
        outLayout.addRow('Output name', self.outNameEdit)
        self.mainLayout.addWidget(outGroup, 2, 0)

    def setInputAsOutput(self, isOn):
        if isOn:
            inStruct = self.inTree.getSelectedStruct()
            wName = list(inStruct.keys())[0]
            gName = list(inStruct[wName].keys())[0]
            self.outNameEdit.setText(gName)
            self.outNameEdit.setDisabled(True)
        else:
            self.outNameEdit.setEnabled(True)

    '''
    Button Box Layout
    '''

    def setupBtnBoxLayout(self):
        bottomLayout = QHBoxLayout()
        self.progBar = QProgressBar()
        self.progBar.setVisible(False)
        bottomLayout.addWidget(self.progBar)
        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok
                                     | QDialogButtonBox.Close)
        buttonBox.accepted.connect(self.okBtnBox)
        buttonBox.rejected.connect(self.close)
        bottomLayout.addWidget(buttonBox)
        self.mainLayout.addLayout(bottomLayout, 3, 0)

    def okBtnBox(self):
        inStruct = self.inTree.getSelectedStruct()
        data = self.dataManager.getData(inStruct, inv=True)
        wName = list(data.keys())[0]
        gName = list(data[wName].keys())[0]
        outName = self.outNameEdit.text()

        if outName in self.dataManager[wName].getColumnNames():
            msgBox = QMessageBox()
            msgBox.setText('Signal already exists')
            msgBox.setInformativeText("Do you want to replace it?")
            msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
            msgBox.setDefaultButton(QMessageBox.Ok)
            ret = msgBox.exec()
            if ret == QMessageBox.Ok:
                self.dataManager.removeSignal(wName, outName)
                print('removed')
            else:
                return

        self.progBar.setVisible(True)
        outData = self.processLayout.currentWidget().process(
            data[wName][gName])
        self.dataManager.appendSignal(wName, outName, inStruct[wName][gName],
                                      outData)
        self.newDataAdded.emit(wName, gName, self.outNameEdit.text())

    def updateProgress(self, prog):
        self.progBar.setValue(prog)
Beispiel #3
0
    def __init__(self, parent, data):
        super(SectionsWidget, self).__init__(parent)

        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setVerticalSpacing(1)
        layout.setHorizontalSpacing(
            UIContext.getScaledWindowSize(16, 16).width())

        maxNameLen = 0
        for section in data.sections.values():
            if len(section.name) > maxNameLen:
                maxNameLen = len(section.name)
        if maxNameLen > 32:
            maxNameLen = 32

        self.sections = []
        for section in data.sections.values():
            if section.semantics != SectionSemantics.ExternalSectionSemantics:
                self.sections.append(section)
        self.sections.sort(key=lambda section: section.start)

        row = 0
        for section in self.sections:
            name = section.name
            if len(name) > maxNameLen:
                name = name[:maxNameLen - 1] + "…"

            begin = "0x%x" % section.start
            end = "0x%x" % section.end
            typeName = section.type

            permissions = ""
            if data.is_offset_readable(section.start):
                permissions += "r"
            else:
                permissions += "-"
            if data.is_offset_writable(section.start):
                permissions += "w"
            else:
                permissions += "-"
            if data.is_offset_executable(section.start):
                permissions += "x"
            else:
                permissions += "-"

            semantics = ""
            if section.semantics == SectionSemantics.ReadOnlyCodeSectionSemantics:
                semantics = "Code"
            elif section.semantics == SectionSemantics.ReadOnlyDataSectionSemantics:
                semantics = "Ready-only Data"
            elif section.semantics == SectionSemantics.ReadWriteDataSectionSemantics:
                semantics = "Writable Data"

            nameLabel = QLabel(name)
            nameLabel.setFont(binaryninjaui.getMonospaceFont(self))
            layout.addWidget(nameLabel, row, 0)

            rangeLayout = QHBoxLayout()
            rangeLayout.setContentsMargins(0, 0, 0, 0)
            beginLabel = headers.ClickableAddressLabel(begin)
            dashLabel = QLabel("-")
            dashLabel.setFont(binaryninjaui.getMonospaceFont(self))
            endLabel = headers.ClickableAddressLabel(end)
            rangeLayout.addWidget(beginLabel)
            rangeLayout.addWidget(dashLabel)
            rangeLayout.addWidget(endLabel)
            layout.addLayout(rangeLayout, row, 1)

            permissionsLabel = QLabel(permissions)
            permissionsLabel.setFont(binaryninjaui.getMonospaceFont(self))
            layout.addWidget(permissionsLabel, row, 2)
            typeLabel = QLabel(typeName)
            typeLabel.setFont(binaryninjaui.getMonospaceFont(self))
            layout.addWidget(typeLabel, row, 3)
            semanticsLabel = QLabel(semantics)
            semanticsLabel.setFont(binaryninjaui.getMonospaceFont(self))
            layout.addWidget(semanticsLabel, row, 4)

            row += 1

        layout.setColumnStretch(5, 1)
        self.setLayout(layout)
class QWaitingForMissionResultWindow(QDialog):
    def __init__(self, gameEvent: Event, game: Game):
        super(QWaitingForMissionResultWindow, self).__init__()
        self.setModal(True)
        self.gameEvent = gameEvent
        self.game = game
        self.setWindowTitle("Waiting for mission completion.")
        self.setWindowIcon(QIcon("./resources/icon.png"))
        self.setMinimumHeight(570)

        self.initUi()
        DebriefingFileWrittenSignal.get_instance().debriefingReceived.connect(
            self.updateLayout)
        self.wait_thread = wait_for_debriefing(
            lambda debriefing: self.on_debriefing_udpate(debriefing),
            self.game)

    def initUi(self):
        self.layout = QGridLayout()

        header = QLabel(self)
        header.setGeometry(0, 0, 655, 106)
        pixmap = QPixmap("./resources/ui/conflict.png")
        header.setPixmap(pixmap)
        self.layout.addWidget(header, 0, 0)

        self.gridLayout = QGridLayout()
        TEXT = "" + \
                "<b>You are clear for takeoff</b>" + \
                "" + \
                "<h2>For Singleplayer :</h2>\n" + \
                "In DCS, open the Mission Editor, and load the file : \n" + \
                "<i>liberation_nextturn</i>\n" + \
                "<p>Then once the mission is loaded in ME, in menu \"Flight\",\n" + \
                "click on FLY Mission to launch.</p>\n" + \
                "" + \
                "<h2>For Multiplayer :</h2>" + \
                "In DCS, open the Mission Editor, and load the file : " + \
                "<i>liberation_nextturn</i>" + \
                "<p>Click on File/Save. Then exit the mission editor, and go to Multiplayer.</p>" + \
                "<p>Then host a server with the mission, and tell your friends to join !</p>" + \
                "<i>(The step in the mission editor is important, and fix a game breaking bug.)</i>" + \
                "<h2>Finishing</h2>" + \
                "<p>Once you have played the mission, click on the \"Accept Results\" button.</p>" + \
                "<p>If DCS Liberation does not detect mission end, use the manually submit button, and choose the state.json file.</p>"

        self.instructions_text = QTextEdit(TEXT)
        self.instructions_text.setReadOnly(True)
        self.gridLayout.addWidget(self.instructions_text, 1, 0)

        progress = QLabel("")
        progress.setAlignment(QtCore.Qt.AlignCenter)
        progress_bar = QMovie("./resources/ui/loader.gif")
        progress.setMovie(progress_bar)

        self.actions = QGroupBox("Actions :")
        self.actions_layout = QHBoxLayout()
        self.actions.setLayout(self.actions_layout)

        self.manually_submit = QPushButton("Manually Submit [Advanced users]")
        self.manually_submit.clicked.connect(self.submit_manually)
        self.actions_layout.addWidget(self.manually_submit)
        self.cancel = QPushButton("Abort mission")
        self.cancel.clicked.connect(self.close)
        self.actions_layout.addWidget(self.cancel)
        self.gridLayout.addWidget(self.actions, 2, 0)

        self.actions2 = QGroupBox("Actions :")
        self.actions2_layout = QHBoxLayout()
        self.actions2.setLayout(self.actions2_layout)
        self.manually_submit2 = QPushButton("Manually Submit [Advanced users]")
        self.manually_submit2.clicked.connect(self.submit_manually)
        self.actions2_layout.addWidget(self.manually_submit2)
        self.cancel2 = QPushButton("Abort mission")
        self.cancel2.clicked.connect(self.close)
        self.actions2_layout.addWidget(self.cancel2)
        self.proceed = QPushButton("Accept results")
        self.proceed.setProperty("style", "btn-success")
        self.proceed.clicked.connect(self.process_debriefing)
        self.actions2_layout.addWidget(self.proceed)

        progress_bar.start()
        self.layout.addLayout(self.gridLayout, 1, 0)
        self.setLayout(self.layout)

    def updateLayout(self, debriefing):
        updateBox = QGroupBox("Mission status")
        updateLayout = QGridLayout()
        updateBox.setLayout(updateLayout)
        self.debriefing = debriefing

        updateLayout.addWidget(QLabel("<b>Aircraft destroyed</b>"), 0, 0)
        updateLayout.addWidget(QLabel(str(len(debriefing.killed_aircrafts))),
                               0, 1)

        updateLayout.addWidget(QLabel("<b>Ground units destroyed</b>"), 1, 0)
        updateLayout.addWidget(
            QLabel(str(len(debriefing.killed_ground_units))), 1, 1)

        #updateLayout.addWidget(QLabel("<b>Weapons fired</b>"), 2, 0)
        #updateLayout.addWidget(QLabel(str(len(debriefing.weapons_fired))), 2, 1)

        updateLayout.addWidget(QLabel("<b>Base Capture Events</b>"), 2, 0)
        updateLayout.addWidget(
            QLabel(str(len(debriefing.base_capture_events))), 2, 1)

        # Clear previous content of the window
        for i in reversed(range(self.gridLayout.count())):
            try:
                self.gridLayout.itemAt(i).widget().setParent(None)
            except:
                pass

        # Set new window content
        self.gridLayout.addWidget(updateBox, 0, 0)

        if not debriefing.mission_ended:
            self.gridLayout.addWidget(QLabel("<b>Mission is being played</b>"),
                                      1, 0)
            self.gridLayout.addWidget(self.actions, 2, 0)
        else:
            self.gridLayout.addWidget(QLabel("<b>Mission is over</b>"), 1, 0)
            self.gridLayout.addWidget(self.actions2, 2, 0)

    def on_debriefing_udpate(self, debriefing):
        try:
            logging.info("On Debriefing update")
            print(debriefing)
            DebriefingFileWrittenSignal.get_instance().sendDebriefing(
                debriefing)
        except Exception as e:
            logging.error("Got an error while sending debriefing")
            logging.error(e)
        self.wait_thread = wait_for_debriefing(
            lambda debriefing: self.on_debriefing_udpate(debriefing),
            self.game)

    def process_debriefing(self):
        self.game.finish_event(event=self.gameEvent,
                               debriefing=self.debriefing)
        self.game.pass_turn(ignored_cps=[
            self.gameEvent.to_cp,
        ])

        GameUpdateSignal.get_instance().sendDebriefing(self.game,
                                                       self.gameEvent,
                                                       self.debriefing)
        self.close()

    def debriefing_directory_location(self) -> str:
        return os.path.join(base_path(), "liberation_debriefings")

    def closeEvent(self, evt):
        super(QWaitingForMissionResultWindow, self).closeEvent(evt)
        if self.wait_thread is not None:
            self.wait_thread.stop()

    def submit_manually(self):
        file = QFileDialog.getOpenFileName(self,
                                           "Select game file to open",
                                           filter="json(*.json)",
                                           dir=".")
        print(file)
        try:
            with open(file[0], "r") as json_file:
                json_data = json.load(json_file)
                json_data["mission_ended"] = True
                debriefing = Debriefing(json_data, self.game)
                self.on_debriefing_udpate(debriefing)
        except Exception as e:
            logging.error(e)
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText("Invalid file : " + file[0])
            msg.setWindowTitle("Invalid file.")
            msg.setStandardButtons(QMessageBox.Ok)
            msg.setWindowFlags(Qt.WindowStaysOnTopHint)
            msg.exec_()
            return
Beispiel #5
0
    def setup_ui(self):
        self.setFixedSize(self.width, self.height)
        self.setWindowTitle(self.today)
        self.setWindowIcon(QIcon("tomato.png"))

        main_layout = QGridLayout()
        today = QLabel(self.today)
        font = QFont("MesloLGS Nerd Font Mono", 42)
        font.setBold(True)
        today.setFont(font)
        today.setStyleSheet("border: 3px solid black;")
        main_layout.addWidget(today, 0, 0, 3, 8)
        main_layout.addWidget(self.total_minutes_lcd, 0, 8, 3, 8)
        self.total_minutes_lcd.display(self.calculate_all_tasks_time())
        main_layout.addWidget(self.timer_lcd, 3, 0, 6, 16)
        self.timer_lcd.display(self.calculate_display_time())

        button_layout = QGridLayout()
        button_layout.addWidget(self.start_button, 0, 0, 1, 1)
        button_layout.addWidget(self.skip_button, 0, 1, 1, 1)
        button_layout.addWidget(self.pause_resume_button, 0, 2, 1, 1)
        button_layout.addWidget(self.stop_button, 0, 3, 1, 1)
        button_layout.addWidget(self.interruptions_label, 1, 0, 1, 4)

        counter_layout = QGridLayout()
        counter_layout.addWidget(self.pomodoros_till_long_break_lcd, 0, 0, 1,
                                 2)
        self.pomodoros_till_long_break_lcd.display(
            self.calculate_pomodoros_till_long_break())
        counter_layout.addWidget(self.task_minutes_lcd, 0, 2, 1, 4)
        self.task_minutes_lcd.display(self.calculate_last_task_time())
        counter_layout.addLayout(button_layout, 0, 6, 1, 10)

        main_layout.addLayout(counter_layout, 10, 0, 3, 16)

        non_pomodoro_layout = QGridLayout()
        non_pomodoro_layout.addWidget(self.non_pomodoro_start_button, 0, 0, 1,
                                      1)
        non_pomodoro_layout.addWidget(self.non_pomodoro_start_hhmm_lcd, 0, 1,
                                      1, 5)
        self.non_pomodoro_start_hhmm_lcd.display("------")
        non_pomodoro_layout.addWidget(self.non_pomodoro_minutes_lcd, 0, 6, 1,
                                      4)
        self.non_pomodoro_minutes_lcd.display("---")
        non_pomodoro_layout.addWidget(self.non_pomodoro_stop_hhmm_lcd, 0, 10,
                                      1, 5)
        non_pomodoro_layout.addWidget(self.non_pomodoro_stop_button, 0, 15, 1,
                                      1)
        self.non_pomodoro_stop_hhmm_lcd.display("------")
        main_layout.addLayout(non_pomodoro_layout, 14, 0, 1, 16)

        counter_layout = QGridLayout()
        counter_layout.addWidget(self.total_pomodoros_lcd, 0, 0, 1, 4)
        self.total_pomodoros_lcd.display(self.calculate_total_pomodoro_count())
        counter_layout.addWidget(self.total_pomodoro_minutes_lcd, 0, 4, 1, 6)
        self.total_pomodoro_minutes_lcd.display(
            self.calculate_pomodoro_tasks_time())
        counter_layout.addWidget(self.total_non_pomodoro_minutes_lcd, 0, 10, 1,
                                 6)
        self.total_non_pomodoro_minutes_lcd.display(
            self.calculate_non_pomodoro_tasks_time())

        main_layout.addLayout(counter_layout, 15, 0, 3, 16)

        self.timer_lcd.setPalette(self.state.lcd_color)

        self.setLayout(main_layout)

        self.show()
    def __init__(self, plain_text_edit: QPlainTextEdit, parent=None):
        """
        Sets up the dialog.

        :param plain_text_edit: Text Editor to operate on.
        :param parent: QWidget parent
        """
        super().__init__(parent=parent, f=Qt.Tool)
        self.plain_text_edit = plain_text_edit
        self.cursors_needed = True
        self.find_flags = QTextDocument.FindFlags()
        self.found_cursors: List[QTextCursor] = []
        self.current_cursor = QTextCursor()

        # UI
        layout = QVBoxLayout()
        find_and_replace_layout = QGridLayout()
        layout.addLayout(
            find_and_replace_layout
        )  # if QGL is sub-layout, add to parent layout before doing stuff.

        self.find_line_edit = QLineEdit()
        find_label = QLabel("&Find")
        find_label.setBuddy(self.find_line_edit)

        options_layout = QHBoxLayout()
        self.match_case_check_box = QCheckBox("Match Case")
        self.whole_word_check_box = QCheckBox("Whole Word")
        options_layout.addWidget(self.match_case_check_box)
        options_layout.addWidget(self.whole_word_check_box)
        options_layout.addStretch()

        self.found_info_label = QLabel()

        self.replace_line_edit = QLineEdit()
        replace_label = QLabel("&Replace")
        replace_label.setBuddy(self.replace_line_edit)

        find_and_replace_layout.addWidget(find_label, 0, 0)
        find_and_replace_layout.addWidget(self.find_line_edit, 0, 1)
        find_and_replace_layout.addLayout(options_layout, 1, 1)
        find_and_replace_layout.setRowMinimumHeight(2, 20)
        find_and_replace_layout.addWidget(self.found_info_label, 2, 1)
        find_and_replace_layout.addWidget(replace_label, 3, 0)
        find_and_replace_layout.addWidget(self.replace_line_edit, 3, 1)

        self.btn_box = QDialogButtonBox(QDialogButtonBox.Close)
        self.find_next_btn = QPushButton("Next")
        self.find_next_btn.setEnabled(False)
        self.find_prev_btn = QPushButton("Previous")
        self.find_prev_btn.setEnabled(False)
        self.replace_btn = QPushButton("Replace")
        self.replace_btn.setEnabled(False)
        self.replace_all_btn = QPushButton("Replace All")
        self.replace_all_btn.setEnabled(False)
        self.btn_box.addButton(self.replace_btn, QDialogButtonBox.ActionRole)
        self.btn_box.addButton(self.replace_all_btn,
                               QDialogButtonBox.ActionRole)
        self.btn_box.addButton(self.find_prev_btn, QDialogButtonBox.ActionRole)
        self.btn_box.addButton(self.find_next_btn, QDialogButtonBox.ActionRole)

        layout.addWidget(self.btn_box)
        self.setLayout(layout)
        # End UI

        self.btn_box.rejected.connect(self.reject)
        self.find_line_edit.textEdited.connect(self.handle_text_edited)
        self.find_next_btn.clicked.connect(self.next)
        self.find_prev_btn.clicked.connect(self.prev)
        self.replace_btn.clicked.connect(self.replace)
        self.replace_all_btn.clicked.connect(self.replace_all)
        self.plain_text_edit.document().contentsChanged.connect(
            self.set_cursors_needed_true)
        self.whole_word_check_box.stateChanged.connect(
            self.toggle_whole_word_flag)
        self.match_case_check_box.stateChanged.connect(
            self.toggle_match_case_flag)
Beispiel #7
0
class RandomNumbersWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.data = Data(1000)

        self.tablesFrames = dict()
        self.tablesRatings = dict()

        self.globalLayout = QGridLayout()
        self.globalLayout.addLayout(self.drawTable("Табличный метод", "tab"),
                                    0, 0)
        self.globalLayout.addLayout(
            self.drawTable("Алгоритмический метод", "alg"), 0, 1)
        self.globalLayout.addLayout(self.drawHandInput("hand"), 0, 2)

        button = QPushButton("Рассчитать")
        button.clicked.connect(self.buttonCalculateClicked)
        button.setMinimumSize(100, 70)
        buttonLayout = QVBoxLayout()
        buttonLayout.setMargin(20)
        buttonLayout.addWidget(button)

        self.globalLayout.addLayout(buttonLayout, 2, 2)

        self.warningLabel = QLabel("")
        warningLayout = QVBoxLayout()
        warningLayout.addWidget(self.warningLabel)
        self.globalLayout.addLayout(warningLayout, 2, 1)

        button = QPushButton("Сгенерировать\nновые\nпоследовательности")
        button.setMinimumSize(170, 70)
        button.clicked.connect(self.buttonGenerateClicked)
        buttonLayout = QVBoxLayout()
        buttonLayout.setMargin(20)
        buttonLayout.addWidget(button)

        self.globalLayout.addLayout(buttonLayout, 2, 0)
        #widg = QLineEdit()7
        #widg.setMaxLength(30)
        #self.globalLayout.addWidget(widg)

        self.globalLayout.setSpacing(50)
        #self.globalLayout.setAlignment(Qt.AlignLeft)
        self.setLayout(self.globalLayout)

    def buttonGenerateClicked(self):
        self.data.refresh()

        for i in range(3):
            for j in range(10):
                self.tablesFrames['alg'][i][j].setText(
                    str(self.data.tables['alg'][i][j]))
                self.tablesFrames['tab'][i][j].setText(
                    str(self.data.tables['tab'][i][j]))
            self.tablesRatings['alg'][i].setText("{:6.5f}".format(
                self.data.ratings['alg'][i]))
            self.tablesRatings['tab'][i].setText("{:6.5f}".format(
                self.data.ratings['tab'][i]))

    def buttonCalculateClicked(self):
        self.data.tables['hand'] = []
        try:
            for i in range(10):
                field = self.tablesFrames['hand'][i].text()
                if field:
                    num = int(field)
                    self.data.tables['hand'].append(num)

            self.data.ratings['hand'] = Data.correlation(
                self.data.tables['hand'])
            self.tablesRatings['hand'].setText("{:6.5f}".format(
                self.data.ratings['hand']))

            self.warningLabel.setText("")
        except ValueError:
            self.warningLabel.setText("Ошибка:\nНеправильный ввод чисел")
            self.tablesRatings['hand'].setText("%###")
        except Exception as e:
            self.warningLabel.setText("Ошибка:\n" + str(e))
            self.tablesRatings['hand'].setText("%###")

    def drawTable(self, name, dictName):
        self.tablesFrames[dictName] = list()

        layout = QHBoxLayout()
        for _ in range(3):
            row = []
            column = QVBoxLayout()
            for _ in range(10):
                cell = QLabel()
                cell.setMinimumSize(80, 25)
                cell.setFrameShape(QFrame.WinPanel)
                cell.setFrameShadow(QFrame.Raised)
                row.append(cell)
                column.addWidget(cell)

            self.tablesFrames[dictName].append(row)
            layout.addLayout(column)

        layout.setSpacing(1)

        all = QVBoxLayout()
        temp = QVBoxLayout()
        header = QLabel(name)
        header.setAlignment(Qt.AlignBottom)
        temp.addWidget(header)
        temp.setSpacing(0)

        subHeader = QLabel("Оценка\nпослед-тей:")
        subHeader.setMaximumSize(100, 40)

        stat = QHBoxLayout()
        self.tablesRatings[dictName] = []
        for i in range(3):
            p = QLabel("%###")
            p.setFrameShape(QFrame.WinPanel)
            p.setFrameShadow(QFrame.Raised)
            stat.addWidget(p)
            self.tablesRatings[dictName].append(p)

        all.setSpacing(10)
        all.setMargin(20)
        all.addLayout(temp)
        all.addLayout(layout)
        all.addWidget(subHeader)
        all.addLayout(stat)

        return all

    def drawHandInput(self, dictName):
        self.tablesFrames[dictName] = []

        column = QVBoxLayout()
        column.setSpacing(1)
        for _ in range(10):
            cell = QLineEdit()
            cell.setMinimumSize(30, 25)
            cell.setMaximumSize(200, 50)
            column.addWidget(cell)
            self.tablesFrames[dictName].append(cell)

        all = QVBoxLayout()
        temp = QVBoxLayout()
        header = QLabel("Ручной ввод")
        header.setAlignment(Qt.AlignBottom)
        temp.addWidget(header)

        subHeader = QLabel("Оценка\nпослед-тей:")
        subHeader.setMaximumSize(100, 40)

        percent = QLabel("%###")
        percent.setFrameShape(QFrame.WinPanel)
        percent.setFrameShadow(QFrame.Raised)
        self.tablesRatings[dictName] = percent

        all.setSpacing(10)
        all.setMargin(20)
        all.addLayout(temp)
        all.addLayout(column)
        all.addWidget(subHeader)
        all.addWidget(percent)

        return all
Beispiel #8
0
class IccToolBarView(QWidget):
    """
    Eine View, von QWidget abgeleitet, die eine Toolbar besitzt.
    Die Toolbar ist standardmäßig mit einem Save-Button ausgestattet.
    Wird dieser gedrückt, wird ein save-Signal gesendet.
    Mit der Methode setSaveButtonEnabled kann der Save-Button enabled/disabled werden.
    Mittels der addTool-Methode können der Toolbar weitere Widgets hinzugefügt werden.
    Mittels der addWidget-Methode können der View Widgets hinzugefügt werden.
    """
    save = Signal()

    def __init__(self):
        QWidget.__init__(self, None)
        self._btnSave = QPushButton()
        self._layout = QGridLayout()
        self.setLayout(self._layout)
        self._toolbarLayout = QHBoxLayout()
        self._layout.addLayout(self._toolbarLayout,
                               0,
                               0,
                               alignment=Qt.AlignLeft)
        self._addSaveButtonToToolBar()

    def _addSaveButtonToToolBar(self):
        self._btnSave.setFixedSize(QSize(30, 30))
        #self._btnSave.setFlat( True )
        self._btnSave.setIcon(QIcon(ICON_DIR + "save.png"))
        self._btnSave.setIconSize(QSize(22, 22))
        self._btnSave.setToolTip("Änderungen speichern.")
        self._btnSave.clicked.connect(self.save.emit)
        self.addTool(self._btnSave)

    def addTool(self, widget: QWidget):
        """
        Fügt der Toolbar ein Tool hinzu
        :param widget:
        :return:
        """
        self._toolbarLayout.addWidget(widget)

    def addWidget(self,
                  widget: QWidget,
                  r: int,
                  c: int,
                  alignment=None,
                  rowspan: int = 1,
                  colspan: int = 1):
        """
        Fügt dem Layout an gewünschter Stelle <widget> hinzu.
        :param widget:
        :param r:
        :param c:
        :param alignment: todo: FUNKTIONIERT NICHT!! (Wird nicht verwendet)
        :param rowspan:
        :param colspan:
        :return:
        """
        if alignment is None:
            self._layout.addWidget(widget, r, c)
        else:
            self._layout.addWidget(widget, r, c, alignment=alignment)
        return self._layout.columnCount()

    def getLayout(self) -> QGridLayout:
        return self._layout

    def getColumnCount(self) -> int:
        return self._layout.columnCount()

    def createHLine(self, r: int, colspan: int):
        line = HLine()
        self._layout.addWidget(line, r, 0, 1, colspan)

    def createDummyRow(self, r: int, h: int):
        dummy = QWidget()
        dummy.setFixedHeight(h)
        self._layout.addWidget(dummy, r, 0)

    def clear(self):
        raise NotImplementedError("IccView2.clear()")

    def applyChanges(self):
        raise NotImplementedError("IccView2.applyChanges()")

    def setSaveButtonEnabled(self, enabled: bool = True):
        self._btnSave.setEnabled(enabled)

    def showException(self, title, msg, more=None):
        box = ErrorBox(title, msg, more)
        crsr = QCursor.pos()
        box.move(crsr.x(), crsr.y())
        box.exec_()
Beispiel #9
0
class Ui_dlg_new_tool(object):
    def setupUi(self, dlg_new_tool):
        if not dlg_new_tool.objectName():
            dlg_new_tool.setObjectName(u"dlg_new_tool")
        dlg_new_tool.resize(570, 463)
        dlg_new_tool.setModal(True)
        self.gridLayout_2 = QGridLayout(dlg_new_tool)
        self.gridLayout_2.setObjectName(u"gridLayout_2")
        self.gridLayout = QGridLayout()
        self.gridLayout.setObjectName(u"gridLayout")
        self.te_description = QTextEdit(dlg_new_tool)
        self.te_description.setObjectName(u"te_description")

        self.gridLayout.addWidget(self.te_description, 3, 0, 1, 6)

        self.label = QLabel(dlg_new_tool)
        self.label.setObjectName(u"label")

        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)

        self.lbl_file_exists = QLabel(dlg_new_tool)
        self.lbl_file_exists.setObjectName(u"lbl_file_exists")
        self.lbl_file_exists.setPixmap(QPixmap(u"../resources/OK.png"))

        self.gridLayout.addWidget(self.lbl_file_exists, 0, 5, 1, 1)

        self.label_5 = QLabel(dlg_new_tool)
        self.label_5.setObjectName(u"label_5")

        self.gridLayout.addWidget(self.label_5, 0, 3, 1, 1)

        self.chk_mask_required = QCheckBox(dlg_new_tool)
        self.chk_mask_required.setObjectName(u"chk_mask_required")

        self.gridLayout.addWidget(self.chk_mask_required, 5, 0, 1, 6)

        self.label_4 = QLabel(dlg_new_tool)
        self.label_4.setObjectName(u"label_4")

        self.gridLayout.addWidget(self.label_4, 0, 2, 1, 1)

        self.le_tool_name = QLineEdit(dlg_new_tool)
        self.le_tool_name.setObjectName(u"le_tool_name")

        self.gridLayout.addWidget(self.le_tool_name, 0, 1, 1, 1)

        self.label_3 = QLabel(dlg_new_tool)
        self.label_3.setObjectName(u"label_3")

        self.gridLayout.addWidget(self.label_3, 1, 3, 1, 1)

        self.le_file_name = QLineEdit(dlg_new_tool)
        self.le_file_name.setObjectName(u"le_file_name")
        self.le_file_name.setReadOnly(True)

        self.gridLayout.addWidget(self.le_file_name, 0, 4, 1, 1)

        self.label_6 = QLabel(dlg_new_tool)
        self.label_6.setObjectName(u"label_6")
        font = QFont()
        font.setPointSize(8)
        self.label_6.setFont(font)

        self.gridLayout.addWidget(self.label_6, 1, 2, 1, 1)

        self.le_class_name = QLineEdit(dlg_new_tool)
        self.le_class_name.setObjectName(u"le_class_name")
        self.le_class_name.setReadOnly(True)

        self.gridLayout.addWidget(self.le_class_name, 1, 4, 1, 1)

        self.label_2 = QLabel(dlg_new_tool)
        self.label_2.setObjectName(u"label_2")

        self.gridLayout.addWidget(self.label_2, 2, 0, 1, 6)

        self.label_7 = QLabel(dlg_new_tool)
        self.label_7.setObjectName(u"label_7")

        self.gridLayout.addWidget(self.label_7, 4, 0, 1, 1)

        self.le_package_name = QLineEdit(dlg_new_tool)
        self.le_package_name.setObjectName(u"le_package_name")

        self.gridLayout.addWidget(self.le_package_name, 4, 1, 1, 5)

        self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 2)

        self.verticalLayout_4 = QVBoxLayout()
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.groupBox = QGroupBox(dlg_new_tool)
        self.groupBox.setObjectName(u"groupBox")
        self.groupBox.setCheckable(False)
        self.verticalLayout = QVBoxLayout(self.groupBox)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.rb_output_image = QRadioButton(self.groupBox)
        self.rb_output_image.setObjectName(u"rb_output_image")
        self.rb_output_image.setChecked(True)

        self.verticalLayout.addWidget(self.rb_output_image)

        self.rb_output_mask = QRadioButton(self.groupBox)
        self.rb_output_mask.setObjectName(u"rb_output_mask")

        self.verticalLayout.addWidget(self.rb_output_mask)

        self.rb_output_data = QRadioButton(self.groupBox)
        self.rb_output_data.setObjectName(u"rb_output_data")

        self.verticalLayout.addWidget(self.rb_output_data)

        self.rb_output_none = QRadioButton(self.groupBox)
        self.rb_output_none.setObjectName(u"rb_output_none")

        self.verticalLayout.addWidget(self.rb_output_none)

        self.verticalLayout_4.addWidget(self.groupBox)

        self.gb_pipeline_tool_groups = QGroupBox(dlg_new_tool)
        self.gb_pipeline_tool_groups.setObjectName(u"gb_pipeline_tool_groups")

        self.verticalLayout_4.addWidget(self.gb_pipeline_tool_groups)

        self.verticalSpacer = QSpacerItem(
            20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding
        )

        self.verticalLayout_4.addItem(self.verticalSpacer)

        self.gridLayout_2.addLayout(self.verticalLayout_4, 1, 0, 1, 1)

        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.groupBox_2 = QGroupBox(dlg_new_tool)
        self.groupBox_2.setObjectName(u"groupBox_2")
        self.verticalLayout_2 = QVBoxLayout(self.groupBox_2)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.rb_rt_yes = QRadioButton(self.groupBox_2)
        self.rb_rt_yes.setObjectName(u"rb_rt_yes")

        self.verticalLayout_2.addWidget(self.rb_rt_yes)

        self.rb_rt_no = QRadioButton(self.groupBox_2)
        self.rb_rt_no.setObjectName(u"rb_rt_no")
        self.rb_rt_no.setChecked(True)

        self.verticalLayout_2.addWidget(self.rb_rt_no)

        self.rb_rt_widget = QRadioButton(self.groupBox_2)
        self.rb_rt_widget.setObjectName(u"rb_rt_widget")

        self.verticalLayout_2.addWidget(self.rb_rt_widget)

        self.rb_rt_property = QRadioButton(self.groupBox_2)
        self.rb_rt_property.setObjectName(u"rb_rt_property")

        self.verticalLayout_2.addWidget(self.rb_rt_property)

        self.verticalLayout_3.addWidget(self.groupBox_2)

        self.gb_no_pipeline_tool_groups = QGroupBox(dlg_new_tool)
        self.gb_no_pipeline_tool_groups.setObjectName(u"gb_no_pipeline_tool_groups")

        self.verticalLayout_3.addWidget(self.gb_no_pipeline_tool_groups)

        self.verticalSpacer_2 = QSpacerItem(
            20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding
        )

        self.verticalLayout_3.addItem(self.verticalSpacer_2)

        self.gridLayout_2.addLayout(self.verticalLayout_3, 1, 1, 1, 1)

        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalSpacer = QSpacerItem(
            40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum
        )

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.bt_save = QPushButton(dlg_new_tool)
        self.bt_save.setObjectName(u"bt_save")

        self.horizontalLayout.addWidget(self.bt_save)

        self.bt_cancel = QPushButton(dlg_new_tool)
        self.bt_cancel.setObjectName(u"bt_cancel")

        self.horizontalLayout.addWidget(self.bt_cancel)

        self.gridLayout_2.addLayout(self.horizontalLayout, 2, 1, 1, 1)

        self.gridLayout_2.setColumnStretch(0, 1)
        self.gridLayout_2.setColumnStretch(1, 1)

        self.retranslateUi(dlg_new_tool)

        QMetaObject.connectSlotsByName(dlg_new_tool)

    # setupUi

    def retranslateUi(self, dlg_new_tool):
        dlg_new_tool.setWindowTitle(
            QCoreApplication.translate("dlg_new_tool", u"New tool wizard", None)
        )
        self.te_description.setPlaceholderText(
            QCoreApplication.translate(
                "dlg_new_tool",
                u"Write your tool's description here.\\nYou can use HTML tags",
                None,
            )
        )
        self.label.setText(
            QCoreApplication.translate("dlg_new_tool", u"Tool name:", None)
        )
        self.lbl_file_exists.setText("")
        self.label_5.setText(
            QCoreApplication.translate("dlg_new_tool", u"File name:", None)
        )
        self.chk_mask_required.setText(
            QCoreApplication.translate("dlg_new_tool", u"Requires mask in input", None)
        )
        self.label_4.setText(u"\ud83e\udc62")
        self.label_6.setText(u"\ud83e\udc62")
        self.label_3.setText(
            QCoreApplication.translate("dlg_new_tool", u"Class name", None)
        )
        self.label_2.setText(
            QCoreApplication.translate("dlg_new_tool", u"Description:", None)
        )
        self.label_7.setText(
            QCoreApplication.translate("dlg_new_tool", u"Package:", None)
        )
        self.groupBox.setTitle(
            QCoreApplication.translate("dlg_new_tool", u"Output:", None)
        )
        self.rb_output_image.setText(
            QCoreApplication.translate("dlg_new_tool", u"Image", None)
        )
        self.rb_output_mask.setText(
            QCoreApplication.translate("dlg_new_tool", u"Mask", None)
        )
        self.rb_output_data.setText(
            QCoreApplication.translate("dlg_new_tool", u"Data", None)
        )
        self.rb_output_none.setText(
            QCoreApplication.translate("dlg_new_tool", u"None", None)
        )
        self.gb_pipeline_tool_groups.setTitle(
            QCoreApplication.translate(
                "dlg_new_tool", u"Groups that can be added to pipelines", None
            )
        )
        self.groupBox_2.setTitle(
            QCoreApplication.translate("dlg_new_tool", u"Real time:", None)
        )
        self.rb_rt_yes.setText(QCoreApplication.translate("dlg_new_tool", u"Yes", None))
        self.rb_rt_no.setText(QCoreApplication.translate("dlg_new_tool", u"No", None))
        self.rb_rt_widget.setText(
            QCoreApplication.translate("dlg_new_tool", u"Widget", None)
        )
        self.rb_rt_property.setText(
            QCoreApplication.translate("dlg_new_tool", u"Property", None)
        )
        self.gb_no_pipeline_tool_groups.setTitle(
            QCoreApplication.translate(
                "dlg_new_tool", u"Groups forbiden in pipelines", None
            )
        )
        self.bt_save.setText(QCoreApplication.translate("dlg_new_tool", u"Save", None))
        self.bt_cancel.setText(
            QCoreApplication.translate("dlg_new_tool", u"Close", None)
        )