Esempio n. 1
0
    def AddBookFromURL(self):
        # Create Resized Input Dialog
        dlg = QInputDialog()
        dlg.setInputMode(QInputDialog.TextInput)
        dlg.setLabelText('Enter URL:')
        dlg.setTextValue('https://www.readlightnovel.org/only-i-level-up')
        dlg.setWindowTitle('Add Novel')
        dlg.resize(500, 100)

        # If Cancelled
        if dlg.exec_() == 0:
            return

        # Get URL
        url = dlg.textValue()

        # Check URL
        if self.settings['MainURL'] not in url:
            print('{0} not in {1}'.format(self.settings['MainURL'], url))
            return

        # Dump Info
        try:
            info = Utils.dumpInfo(url, self.settings)
        except AttributeError:
            print('Incorrect URL')
            return

        # Dump Cover
        Utils.dumpCover(info, self.settings)

        self.UpdateList()
Esempio n. 2
0
 def start_gui(self, args):
     crypt_key = args.encryption
     if crypt_key is None:
         input_dialog = QInputDialog()
         input_dialog.setInputMode(QInputDialog.TextInput)
         input_dialog.setCancelButtonText("No Password")
         input_dialog.setLabelText("Please enter your Masterpassword")
         input_dialog.setWindowTitle("Masterpassword")
         input_dialog.setModal(False)
         while crypt_key is None:
             if input_dialog.exec_() == QInputDialog.Rejected:
                 crypt_key = u"0238jh74ngz23v84m90fcqewmn4f89"
             else:
                 crypt_key = input_dialog.textValue().strip()
             if not QtStarter.check_master_password(crypt_key):
                 crypt_key = None
                 input_dialog.setLabelText("Wrong Masterpassword, try again!")
     QtStarter.save_masterpassword_check(crypt_key)
     crypt = Coding(crypt_key.encode('utf-8'))
     self.window = ControlMainWindow(crypt)
     self.timer = threading.Timer(0.001, self.update_server_status,
                                  kwargs={'window': self.window}).start()
     self.window.show()
     ret = self.app.exec_()
     if self.timer is not None:
         self.timer.cancel()
     return ret
 def annotate_state(self, id):
     dialog = QInputDialog()
     dialog.setInputMode(QInputDialog.TextInput)
     dialog.setLabelText("Annotation:")
     dialog.resize(400, 100)
     if dialog.exec_():
         self.store_annotation(id, dialog.textValue())
         self.redraw_graph()
Esempio n. 4
0
 def testQDialog(self):
     dlg = QInputDialog()
     dlg.setInputMode(QInputDialog.TextInput)
     lst = dlg.children()
     self.assertTrue(len(lst))
     obj = lst[0]
     self._called = False
     obj.destroyed[QObject].connect(self.cb)
     obj = None
     del dlg
     self.assertTrue(self._called)
Esempio n. 5
0
 def testQDialog(self):
     dlg = QInputDialog()
     dlg.setInputMode(QInputDialog.TextInput)
     lst = dlg.children()
     self.assert_(len(lst))
     obj = lst[0]
     self._called = False
     obj.destroyed[QObject].connect(self.cb)
     obj = None
     del dlg
     self.assert_(self._called)
 def edit_watcher(self):
     index = self.watcherlist.currentRow()
     addr = self.workspace.cartprograph.watchers[index][0]
     dialog = QInputDialog()
     dialog.setInputMode(QInputDialog.TextInput)
     dialog.setLabelText("Edit watcher @ " + hex(addr) + ":")
     dialog.setTextValue(", ".join(
         self.workspace.cartprograph.watchers[index][1]))
     dialog.resize(500, 100)
     if dialog.exec_():
         self.workspace.cartprograph.watchers[index][
             1] = self._process_registers(dialog.textValue())
         self.update_watcherlist()
Esempio n. 7
0
    def get_text(parent=None,
                 title='Input Text Value',
                 label='Value:',
                 default_value=None):
        input_dialog = QInputDialog(parent)
        input_dialog.setInputMode(InputDialog.TextInput)
        input_dialog.setWindowTitle(title)
        input_dialog.setLabelText(label)
        input_dialog.setOkButtonText('确定')
        input_dialog.setCancelButtonText('取消')
        if parent:
            input_dialog.setFont(parent.font())

        return default_value if not input_dialog.exec_(
        ) else input_dialog.textValue()
Esempio n. 8
0
    def get_charname(self):
        """
        :param mailurl: url to call for sending an authcode per mail
        :return: the authcode
        """
        inputDialog = QInputDialog(self)
        inputDialog.setInputMode(QInputDialog.TextInput)
        inputDialog.setLabelText("Please enter a Charname")
        inputDialog.setWindowTitle("Charname Challange")
        inputDialog.setModal(True)

        if inputDialog.exec_() == QInputDialog.Rejected:
            return None

        return inputDialog.textValue().strip()
Esempio n. 9
0
    def get_int(parent=None,
                title='Input Int Value',
                label='Value:',
                default_value=None,
                minimum=1,
                maximum=100):
        input_dialog = QInputDialog(parent)
        input_dialog.setInputMode(InputDialog.IntInput)
        input_dialog.setWindowTitle(title)
        input_dialog.setLabelText(label)
        input_dialog.setOkButtonText('确定')
        input_dialog.setCancelButtonText('取消')
        input_dialog.setIntRange(minimum, maximum)
        input_dialog.setIntValue(default_value or minimum)
        if parent:
            input_dialog.setFont(parent.font())

        return default_value if not input_dialog.exec_(
        ) else input_dialog.intValue()
Esempio n. 10
0
    def connectStream(self):
        dlg = QInputDialog(self)
        dlg.setInputMode(QInputDialog.TextInput)
        dlg.setLabelText("URL:")
        dlg.setTextEchoMode(QLineEdit.Normal)
        dlg.setTextValue(self.current_stream)
        dlg.resize(400, 100)
        dlg.exec()

        if dlg.result() and validators.url(
                dlg.textValue()) and dlg.textValue() != self.current_stream:
            self.current_stream = dlg.textValue()
            self.player.setMedia(QUrl(self.current_stream))
        elif dlg.result() and not validators.url(dlg.textValue()):
            msg_box = QMessageBox()
            msg_box.setText("Error URL. Please try again")
            msg_box.setWindowTitle("Error URL")
            msg_box.exec()
            self.connectStream()
Esempio n. 11
0
    def get_double(parent=None,
                   title='Input Double Value',
                   label='Value:',
                   default_value=None,
                   decimals=1,
                   minimum=1,
                   maximum=1e9):
        input_dialog = QInputDialog(parent)
        input_dialog.setInputMode(InputDialog.DoubleInput)
        input_dialog.setWindowTitle(title)
        input_dialog.setLabelText(label)
        input_dialog.setOkButtonText('确定')
        input_dialog.setCancelButtonText('取消')
        input_dialog.setDoubleDecimals(decimals)
        input_dialog.setDoubleRange(minimum, maximum)
        input_dialog.setDoubleValue(default_value or minimum)
        if parent:
            input_dialog.setFont(parent.font())

        return default_value if not input_dialog.exec_(
        ) else input_dialog.doubleValue()
Esempio n. 12
0
def askGenericText(message, title, parent=None, previous=""):
    """Uses `QInputDialog` to ask a text answer for a given question.

    Parameters:
        message: the question to be displayed
        title: the window title
        parent (optional, default None): the parent of the window

    Output:
        return a tuple containing the text as first element
        and True/False
            (depending if the user selected "Ok" or "Cancel")
            as the second element
    """
    dialog = QInputDialog(parent)
    dialog.setInputMode(QInputDialog.TextInput)
    dialog.setWindowTitle(title)
    dialog.setLabelText(message)
    dialog.setTextValue(previous)
    out = dialog.exec_()
    return dialog.textValue(), out
Esempio n. 13
0
    def _renameItem(self):
        item = self._list.currentItem()
        
        input_dialog = QInputDialog(self.parentWidget(), Qt.WindowSystemMenuHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
        font = input_dialog.font()
        font.setPixelSize(16)
        input_dialog.setFont(font)
        input_dialog.setMinimumWidth(300)
        input_dialog.setInputMode(QInputDialog.TextInput)
        input_dialog.setWindowTitle("Renommer l'analyse")
        input_dialog.setLabelText("Nouveau nom pour '%s' :" % item.data(Qt.UserRole + 1))
        input_dialog.setTextValue(item.data(Qt.UserRole + 1))
        input_dialog.setOkButtonText("OK")
        input_dialog.setCancelButtonText("Annuler")

        if not input_dialog.exec_():
            return
        
        new_name = input_dialog.textValue()

        if self._analysis is None:
            return

        if new_name == self._analysis.parameters().name():
            return
        
        regexp = QRegExp("^[a-zA-Z0-9_-#éèêëàîï ]{5,30}$")
        
        if not regexp.exactMatch(new_name):
            QMessageBox.warning(self, "Nouveau nom invalide", "Caractères autorisés : alphanumérique, espace, #, - et _ avec une longueur maximale de 30 caractères")
            return


        self._analysis.parameters().setName(new_name)
        HistoryManager.renameAnalysis(item.data(Qt.UserRole), self._analysis)
        
        current_row = self._list.currentRow()
        self.reset(self._analysis)
        self._list.setCurrentRow(current_row)
        self.currentAnalysisChanged.emit(self._analysis)
Esempio n. 14
0
    def get_auth_code(self, opener, request):
        """
        :param opener: urllib.request.build_opener for sending an authcode per mail
        :param request: request to send using the given opener
        :return: the authcode
        """
        inputDialog = QInputDialog(self)
        inputDialog.setInputMode(QInputDialog.TextInput)
        inputDialog.setCancelButtonText("Cancel")
        inputDialog.setLabelText("Please enter your Authcode")
        inputDialog.setWindowTitle("TwoFactorAuth")
        inputDialog.setModal(True)

        response = None

        if inputDialog.exec_() == QInputDialog.Rejected:  # send mail
            return None, None
        else:
            return response, inputDialog.textValue().strip()

        inputDialog.setCancelButtonText("Cancel")
        if inputDialog.exec_() == QInputDialog.Rejected:
            return response, None
        return response, inputDialog.textValue().strip()
def snip(bounding_box=None,
         file_name_pattern=DEFAULT_OUTPUT_FILE_NAME_PATTERN,
         override=False,
         show_time=1000,
         assign_description=0):
    """ Snip screen image and save it to file.

    :param bounding_box: [tuple] The image rectangle in screen, formatted in (left, upper, width, height).
    :param file_name_pattern: [string] The file name pattern (absolute path or relative path to this python script file). For example: "ScreenSnippingImages/ScreenSnippingImage_%Y-%m-%d_%H-%M-%S.png".
    :param override: [bool] Whether to override the output file if it exists before.
    :param show_time: [int] Milliseconds time to show the screen image (if 0, the image won't be shown).
    :param assign_description: [int] Whether to assign description to the screen image (1 for manually input, 2 for OCR, others for no description).
    """

    logging.info("Started snipping screen.")

    screen_image = get_screen_image(bounding_box=bounding_box)
    file_name = save_image(image=screen_image,
                           file_name_pattern=file_name_pattern,
                           override=override)

    if file_name:
        logging.info(
            "Screen image has been saved in file: {}".format(file_name))

        if show_time > 0:
            image_dialog = QDialog()
            image_dialog.setWindowTitle(APP_DESCRIPTION + " " + APP_VERSION)
            image_dialog.setWindowFlags(Qt.WindowStaysOnTopHint)
            image_dialog.setFixedSize(640, 360)
            image_dialog.setContentsMargins(0, 0, 0, 0)
            image_label = QLabel()
            image_dialog_layout = QGridLayout(image_dialog)
            image_dialog_layout.setContentsMargins(0, 0, 0, 0)
            image_dialog_layout.addWidget(image_label)
            image_label.setPixmap(screen_image)
            image_label.setScaledContents(True)
            QTimer().singleShot(10, image_dialog.activateWindow)
            QTimer().singleShot(show_time, image_dialog.close)
            image_dialog.exec()

            if assign_description == 1:
                description_input_dialog = QInputDialog()
                description_input_dialog.setWindowTitle(APP_DESCRIPTION + " " +
                                                        APP_VERSION)
                description_input_dialog.setWindowFlags(
                    Qt.WindowStaysOnTopHint)
                description_input_dialog.setFixedSize(400, 200)
                description_input_dialog.setInputMode(
                    description_input_dialog.TextInput)
                description_input_dialog.setLabelText(
                    "Please input description:")
                QTimer().singleShot(10,
                                    description_input_dialog.activateWindow)
                description_input_dialog.exec()
                description = description_input_dialog.textValue()
                if description:
                    description_file_name = file_name + ".txt"
                    with open(description_file_name, "w") as file:
                        file.write(description)
                    logging.info(
                        "Assigned a description for screen image file: {}".
                        format(file_name))
                    logging.debug("Description: {}".format(description))
            elif assign_description == 2:
                import pytesseract
                text_from_image = pytesseract.image_to_string(
                    Image.open(file_name))
                description_file_name = file_name + "-OCR.txt"
                with open(description_file_name, "w") as file:
                    file.write(text_from_image)
                os.startfile(description_file_name)
            else:
                pass
    else:
        logging.error("Error occurred.")
Esempio n. 16
0
    def GenerateBook(self):
        wdgList = self.ui.wdgList

        # Get Selected List
        selected = [
            item.text().split(' | ') for item in wdgList.selectedItems()
        ]

        if len(selected) <= 0:
            return

        # Dump not downloaded chapters
        notDumped = [x for x in selected if x[1][-1] != ']']

        # Download chapters
        if not self.downloadChapters(notDumped):
            self.UpdateList()
            # If canceled stop epub generation
            return

        self.UpdateList()

        # Update selected list
        selected = [[x[0][1:], x[1][:-1]] for x in selected if x[1][-1] == ']']
        selected += notDumped

        # Get dicts from Info dictionary
        chapters = [
            chp for chp in self.info['chapters'] for volume, name in selected
            if name == chp['name'] and volume == chp['volume']
        ]

        # Generate Title for book
        volume = chapters[0]['volume']
        for chapter in chapters:
            if chapter['volume'] != volume or 'chapters' in volume.lower():
                volume = 'Chapters:'

        title = self.info['title'] + ' ' + volume

        try:
            # If chapters are not from the same volume
            if volume == 'Chapters:':
                numbers = [
                    int(
                        float(''.join(s for s in name
                                      if s.isdigit() or s == '.' or s == '-')))
                    for name in selected
                ]
                numbers = list(set(numbers))

                # Generate ranges for number list
                ranges = Utils.ranges(numbers)

                for r in ranges:
                    if r[0] == r[1]:
                        title += ' {0},'.format(r[0])
                    else:
                        title += ' {0} - {1},'.format(r[0], r[1])

                if title[-1] == ',':
                    title = title[:-1]
        except ValueError:
            pass

        # Show Title Input Dialog
        dlg = QInputDialog()
        dlg.setInputMode(QInputDialog.TextInput)
        dlg.setLabelText('Enter Title:')
        dlg.setWindowTitle('Select Book Title')
        dlg.setTextValue(title)
        dlg.resize(500, 100)

        # If Cancelled
        if dlg.exec_() == 0:
            return

        # Get URL
        title = dlg.textValue()

        # Show File Dialog
        ans = QFileDialog.getSaveFileName(caption='Save ePUB',
                                          filter='ePUB (*.epub)',
                                          dir=title + '.epub')
        filename = ans[0]

        # Add file format if not present
        if filename[-5:] != '.epub':
            filename += '.epub'

        # Generate ePUB file
        Utils.generateEPUB(filename, title, self.info, chapters, self.settings)