Exemplo n.º 1
0
    def init_radio_buttons(self):
        """
        Creates section with mode selection
        """

        top_margin = 115
        radio_label = QLabel('2. Select mode', self)
        radio_label.setObjectName("headline")
        radio_label.move(60, top_margin)

        radiobutton = QRadioButton(
            "csv (Images in selected folder are labeled and then csv file with assigned labels is generated.)",
            self)
        radiobutton.setChecked(True)
        radiobutton.mode = "csv"
        radiobutton.toggled.connect(self.mode_changed)
        radiobutton.move(60, top_margin + 35)

        radiobutton = QRadioButton(
            "copy (Creates folder for each label. Labeled images are copied to these folders. Csv is also generated)",
            self)
        radiobutton.mode = "copy"
        radiobutton.toggled.connect(self.mode_changed)
        radiobutton.move(60, top_margin + 65)

        radiobutton = QRadioButton(
            "move (Creates folder for each label. Labeled images are moved to these folders. Csv is also generated)",
            self)
        radiobutton.mode = "move"
        radiobutton.toggled.connect(self.mode_changed)
        radiobutton.move(60, top_margin + 95)
Exemplo n.º 2
0
    def GroupBoxTwoLayout(self):
        groupBoxTwo = QGroupBox()
        middleHBox = QHBoxLayout()

        # ------------ Part one (left side) of middle section - Mode radio buttons -------

        self.middleLeftGroupBox.setTitle("Select Mode")
        midLeftVBox = QVBoxLayout()

        radioButton = QRadioButton("Normal (Default)")
        radioButton.setToolTip("Play through the normal story")
        radioButton.setChecked(True)
        radioButton.mode = "normal"
        radioButton.clicked.connect(
            lambda: self.updateRadioSelection("normal"))
        midLeftVBox.addWidget(radioButton)

        radioButton = QRadioButton("Ancient Cave")
        radioButton.setToolTip("Play though a long randomized dungeon")
        radioButton.mode = "ancientcave"
        radioButton.clicked.connect(
            lambda: self.updateRadioSelection("ancientcave"))
        midLeftVBox.addWidget(radioButton)

        radioButton = QRadioButton("Speed Cave")
        radioButton.setToolTip(
            "Play through a medium-sized randomized dungeon")
        radioButton.mode = "speedcave"
        radioButton.clicked.connect(
            lambda: self.updateRadioSelection("speedcave"))
        midLeftVBox.addWidget(radioButton)

        radioButton = QRadioButton("Race Cave")
        radioButton.setToolTip("Play through a short randomized dungeon")
        radioButton.mode = "racecave"
        radioButton.clicked.connect(
            lambda: self.updateRadioSelection("racecave"))
        midLeftVBox.addWidget(radioButton)

        radioButton = QRadioButton("Kefka@Narshe")
        radioButton.setToolTip("Play the normal story up to Kefka at Narshe, "
                               "with extra wackiness. Intended for racing.")
        radioButton.mode = "katn"
        radioButton.clicked.connect(lambda: self.updateRadioSelection("katn"))
        midLeftVBox.addWidget(radioButton)

        radioButton = QRadioButton("Dragon Hunt")
        radioButton.setToolTip(
            "Kill all 8 dragons in the World of Ruin. Intended for racing.")
        radioButton.mode = "dragonhunt"
        radioButton.clicked.connect(
            lambda: self.updateRadioSelection("dragonhunt"))
        midLeftVBox.addWidget(radioButton)

        self.middleLeftGroupBox.setLayout(midLeftVBox)
        # ------------- Part one (left side) end ----------------------------------------------

        # ------------- Part two (right side) of middle section - Flag tabs -----------------
        middleRightGroupBox = QGroupBox("Flag Selection")
        tabVBoxLayout = QVBoxLayout()
        tabs = QTabWidget()
        tabNames = [
            "Simple", "Aesthetic", "Major", "Minor", "Experimental",
            "Gamebreaking"
        ]

        ############## Only checkboxes, no inline description ###############

        # # loop to add tab objects to 'tabs' TabWidget
        #
        # for tabObj, name in zip(self.tablist, tabNames):
        #     tabs.addTab(tabObj, name)
        #
        # for t, d in zip(self.tablist, self.dictionaries):
        #     flagGrid = QGridLayout()
        #     count = 0
        #     for flagname, flagdesc in d.items():
        #         cbox = FlagCheckBox(flagname, flagname)
        #         cbox.setCheckable(True)
        #         if flagdesc['checked']:
        #             cbox.isChecked = True
        #         cbox.setToolTip(flagdesc['explanation'])
        #         cbox.clicked.connect(lambda checked : self.flagButtonClicked())
        #         flagGrid.addWidget(cbox, count / 3, count % 3)
        #         count += 1
        #     t.setLayout(flagGrid)

        ############## Checkboxes and inline descriptions #####################

        # loop to add tab objects to 'tabs' TabWidget
        for t, d, names in zip(self.tablist, self.dictionaries, tabNames):
            tabObj = QScrollArea()
            tabs.addTab(tabObj, names)
            tablayout = QVBoxLayout()
            for flagname, flagdesc in d.items():
                cbox = FlagCheckBox(
                    f"{flagname}  -  {flagdesc['explanation']}", flagname)
                tablayout.addWidget(cbox)
                #cbox.setCheckable(True)
                #cbox.setToolTip(flagdesc['explanation'])
                cbox.clicked.connect(lambda checked: self.flagButtonClicked())
            t.setLayout(tablayout)
            #tablayout.addStretch(1)
            tabObj.setWidgetResizable(True)
            tabObj.setWidget(t)

        tabVBoxLayout.addWidget(tabs)
        #----------- tabs done ----------------------------

        # this is the line in the layout that displays the string of selected flags
        #   and the button to save those flags
        widgetV = QWidget()
        widgetVBoxLayout = QVBoxLayout()
        widgetV.setLayout(widgetVBoxLayout)

        widgetVBoxLayout.addWidget(QLabel("Text-string of selected flags:"))

        self.flagString.setReadOnly(True)
        self.flagString.setStyleSheet("background:lightgrey;")
        widgetVBoxLayout.addWidget(self.flagString)

        saveButton = QPushButton("Save flags selection")
        saveButton.clicked.connect(lambda: self.saveSeed())
        widgetVBoxLayout.addWidget(saveButton)

        # This part makes a group box and adds the selected-flags display
        #   and a button to clear the UI
        flagTextWidget = QGroupBox()
        flagTextHBox = QHBoxLayout()
        flagTextHBox.addWidget(widgetV)
        clearUiButton = QPushButton("Reset")
        clearUiButton.setStyleSheet("font-size:12px; height:60px")
        clearUiButton.clicked.connect(lambda: self.clearUI())
        flagTextHBox.addWidget(clearUiButton)
        flagTextWidget.setLayout(flagTextHBox)

        tabVBoxLayout.addWidget(flagTextWidget)
        middleRightGroupBox.setLayout(tabVBoxLayout)
        # ------------- Part two (right) end ---------------------------------------

        # add widgets to HBoxLayout and assign to middle groupbox layout
        middleHBox.addWidget(self.middleLeftGroupBox)
        middleHBox.addWidget(middleRightGroupBox)
        groupBoxTwo.setLayout(middleHBox)

        return groupBoxTwo
def gatherControls(config, ui_mode="file"):
    config_inputs = {
        'anki_db_path': '',
        'anki_db_field_indices': '',
        'media_dir_path': '',
        'file_or_dir': '',
        'input_encoding': ''
    }

    ui_inputs = {
        'file_to_scan':
        '''<span><b>File to scan:</b><br>This is the input file which
                will be scanned for new words. Note, it is possible to scan
                a whole collection of files at once by changing the file_or_dir
                property in the config to dir, and then putting the dir path here.</span>''',
        'scan_mode':
        '''<br><span><b>Mode:</b><br>Choose whether to produce a card for every new words, every new inidividual character, or only new words using new characters</span>''',
        'output_path':
        '''<br><span><b>Output path:</b><br>Where the resulting .apkg file should be placed
                (including the filename.apkg)</span>''',
        'tag_for_new_cards':
        '''<br><span><b>Imported deck/tag name:</b><br>This string cannot contain
                spaces. It will be applied to all new notes as a tag,
                and will also be the name of the deck imported.</span>''',
        'anki_tags_to_exclude':
        '''<br><span><b>Tags to exclude:</b><br>
                A comma separated list of tags, these will be excluded from
                the de-duping process. That means the scanner will still
                consider a word to be new, even if it contains a character
                in one of your existing notes tagged with one of these tags</span>''',
        'include_sound':
        '''<br><span><b>Include sound files:</b><br>If this is true, the scanner will
                download sound files of the word readings and include them as media in the generated notes.</span>'''
    }

    hidden_cfg = {}
    for item in config_inputs:
        if item == 'file_or_dir' and ui_mode == 'clipboard':
            hidden_cfg[item] = 'clipboard'
        else:
            hidden_cfg[item] = config['textScanner'][item]['val']

    new_words = "All new words"
    new_chars = "Individual new characters"
    new_char_words = "Only words using new chars"

    def interpretRadioBtn(b, input):
        input['mode'] = b.mode

    controls = []
    if ui_mode == 'dev':
        label = QLabel()
        label.setWordWrap(True)
        label_text = '''<br><span><b>Query anki db:</b><br>You can run a sqlite query to probe the anki notes db</span>'''
        label.setText(label_text)
        query_input = QPlainTextEdit()
        controls.append({
            "key": "query_db",
            "label": label,
            "input": query_input
        })
    else:
        for ipt in ui_inputs:
            label = QLabel()
            label.setWordWrap(True)
            label.setText(ui_inputs[ipt])
            tryConfig = config['textScanner'].get(ipt)
            default = str(
                tryConfig['val']) if tryConfig != None else "Uninitialized"
            if ipt == 'scan_mode':
                b1 = QRadioButton(new_char_words)
                b1.mode = 'new_char_words'
                b2 = QRadioButton(new_chars)
                b2.mode = 'new_chars'
                b3 = QRadioButton(new_words)
                b3.mode = 'new_words'

                if default == 'new_char_words':
                    b1.setChecked(True)
                if default == 'new_chars':
                    b2.setChecked(True)
                if default == 'new_words':
                    b3.setChecked(True)

                radioLayout = QHBoxLayout()
                btnGrp = QButtonGroup()
                btnGrp.addButton(b1)
                btnGrp.addButton(b2)
                btnGrp.addButton(b3)
                radioLayout.addWidget(b1)
                radioLayout.addWidget(b2)
                radioLayout.addWidget(b3)

                scan_input = {
                    "mode": default,
                    "layout": radioLayout,
                    "btnGrp": btnGrp
                }
                b1.toggled.connect(lambda: interpretRadioBtn(b1, scan_input))
                b2.toggled.connect(lambda: interpretRadioBtn(b2, scan_input))
                b3.toggled.connect(lambda: interpretRadioBtn(b3, scan_input))
                controls.append({
                    "key": ipt,
                    "label": label,
                    "input": scan_input
                })
            elif ipt == 'file_to_scan' and ui_mode == 'clipboard':
                clipboard_input = QPlainTextEdit()
                label.setText("<span><b>Input text:</b></span>")
                controls.append({
                    "key": ipt,
                    "label": label,
                    "input": clipboard_input
                })
            elif ipt == 'include_sound':
                sb1 = QRadioButton("True")
                sb1.mode = 'true'
                sb2 = QRadioButton("False")
                sb2.mode = 'false'

                if default == 'true':
                    sb1.setChecked(True)
                else:
                    sb2.setChecked(True)
                soundLayout = QHBoxLayout()
                btnGrp = QButtonGroup()
                btnGrp.addButton(sb1)
                btnGrp.addButton(sb2)
                soundLayout.addWidget(sb1)
                soundLayout.addWidget(sb2)

                sound_input = {
                    "mode": default,
                    "layout": soundLayout,
                    "btnGrp": btnGrp
                }
                sb1.toggled.connect(
                    lambda: interpretRadioBtn(sb1, sound_input))
                sb2.toggled.connect(
                    lambda: interpretRadioBtn(sb2, sound_input))
                controls.append({
                    "key": ipt,
                    "label": label,
                    "input": sound_input
                })
            else:
                input = QLineEdit()
                input.setText(default)
                controls.append({"key": ipt, "label": label, "input": input})

    return controls, hidden_cfg