예제 #1
0
def interpolate_color(
        start: QColor,
        end: QColor,
        percent: int,
        colorspace: typing.Optional[QColor.Spec] = QColor.Rgb
) -> QColor:
    """Get an interpolated color value.

    Args:
        start: The start color.
        end: The end color.
        percent: Which value to get (0 - 100)
        colorspace: The desired interpolation color system,
                    QColor::{Rgb,Hsv,Hsl} (from QColor::Spec enum)
                    If None, start is used except when percent is 100.

    Return:
        The interpolated QColor, with the same spec as the given start color.
    """
    qtutils.ensure_valid(start)
    qtutils.ensure_valid(end)

    if colorspace is None:
        if percent == 100:
            return QColor(*end.getRgb())
        else:
            return QColor(*start.getRgb())

    out = QColor()
    if colorspace == QColor.Rgb:
        a_c1, a_c2, a_c3, _alpha = start.getRgb()
        b_c1, b_c2, b_c3, _alpha = end.getRgb()
        components = _get_color_percentage(a_c1, a_c2, a_c3, b_c1, b_c2, b_c3,
                                           percent)
        out.setRgb(*components)
    elif colorspace == QColor.Hsv:
        a_c1, a_c2, a_c3, _alpha = start.getHsv()
        b_c1, b_c2, b_c3, _alpha = end.getHsv()
        components = _get_color_percentage(a_c1, a_c2, a_c3, b_c1, b_c2, b_c3,
                                           percent)
        out.setHsv(*components)
    elif colorspace == QColor.Hsl:
        a_c1, a_c2, a_c3, _alpha = start.getHsl()
        b_c1, b_c2, b_c3, _alpha = end.getHsl()
        components = _get_color_percentage(a_c1, a_c2, a_c3, b_c1, b_c2, b_c3,
                                           percent)
        out.setHsl(*components)
    else:
        raise ValueError("Invalid colorspace!")
    out = out.convertTo(start.spec())
    qtutils.ensure_valid(out)
    return out
예제 #2
0
def interpolate_color(
        start: QColor,
        end: QColor,
        percent: int,
        colorspace: Optional[QColor.Spec] = QColor.Rgb) -> QColor:
    """Get an interpolated color value.

    Args:
        start: The start color.
        end: The end color.
        percent: Which value to get (0 - 100)
        colorspace: The desired interpolation color system,
                    QColor::{Rgb,Hsv,Hsl} (from QColor::Spec enum)
                    If None, start is used except when percent is 100.

    Return:
        The interpolated QColor, with the same spec as the given start color.
    """
    ensure_valid(start)
    ensure_valid(end)

    if colorspace is None:
        if percent == 100:
            return QColor(*end.getRgb())
        else:
            return QColor(*start.getRgb())

    out = QColor()
    if colorspace == QColor.Rgb:
        r1, g1, b1, a1 = start.getRgb()
        r2, g2, b2, a2 = end.getRgb()
        components = _get_color_percentage(r1, g1, b1, a1, r2, g2, b2, a2,
                                           percent)
        out.setRgb(*components)
    elif colorspace == QColor.Hsv:
        h1, s1, v1, a1 = start.getHsv()
        h2, s2, v2, a2 = end.getHsv()
        components = _get_color_percentage(h1, s1, v1, a1, h2, s2, v2, a2,
                                           percent)
        out.setHsv(*components)
    elif colorspace == QColor.Hsl:
        h1, s1, l1, a1 = start.getHsl()
        h2, s2, l2, a2 = end.getHsl()
        components = _get_color_percentage(h1, s1, l1, a1, h2, s2, l2, a2,
                                           percent)
        out.setHsl(*components)
    else:
        raise ValueError("Invalid colorspace!")
    out = out.convertTo(start.spec())
    ensure_valid(out)
    return out
예제 #3
0
 def seqInit(self):
     """
     Sequences are stored as double layer arrays of each character.
     First layer is SEQUENCE
     Second layer is SEQUENCE POSITION
     Third layer is RESIDUE and COLOR
     so self.seq = [SEQ = [Position = [HTML Char/Color, ResID, Dssp], ... ], ... ]
     """
     self.splitSeqs = []
     self.splitNames = []
     self.maxname = 0
     consv = True if self.theme == themes.Conservation().theme else False
     comments = True if self.theme == themes.Comments().theme else False
     for seq in self._seqs.values():
         if len(seq) > self.maxlen:
             self.maxlen = len(seq)
     for name, seq in self._seqs.items():
         self.splitNames.append(name)
         if len(name) > self.maxname:
             self.maxname = len(name)
         if len(seq) < self.maxlen:
             for n in range(self.maxlen - len(seq)):
                 seq.append(" ")
         local = []
         count = 0
         for i in range(self.maxlen):
             char = seq[i]
             if char not in ["-", " "]:
                 color = None
                 count += 1
                 tcount = count
                 dssp = None
                 if not consv:
                     #print("Consv theme is off, skipping alt colors")
                     color = self.theme[char]
                     #print("DEFAULTING %s to %s" % (char, color.name()))
                     if self.consvColors and self.refseq is not None:
                         ref = list(self._seqs.values())[self.refseq][i]
                         compare = utilities.checkConservation(char, ref)
                         if compare is not None:
                             #       print(compare)
                             if compare > 10:
                                 color = QColor(Qt.white)
                         else:
                             color = QColor(Qt.white)
                         del compare
                 elif consv:
                     #print("Consv theme iS ON", i)
                     if self.consvColors and self.refseq is not None:
                         ref = list(self._seqs.values())[self.refseq][i]
                         compare = utilities.checkConservation(char, ref)
                         if compare is not None and compare <= len(
                                 self.theme):
                             #       print(compare)
                             color = self.theme[compare]
                         else:
                             color = QColor(Qt.white)
                         del compare
                 if comments:
                     if i in self.comments.keys():
                         color = QColor(Qt.yellow)
                 if not color:
                     color = QColor(Qt.white)
                 #print(color.name())
                 tcolor = str(self.palette().color(self.alignPane.backgroundRole()).name()) if \
                     color.getHsl()[2] / 255 * 100 <= 50 else '#000000'
                 #print("tColor is %s" % tcolor)
                 char = '<span style=\"background-color: %s; color: %s\">%s</span>' % (
                     color.name(), tcolor, char)
                 #print('char is now %s' % char)
                 if self.dssps:
                     index = list(self._seqs.values()).index(seq)
                     try:
                         # print("adding dssp")
                         dssp = self.dssps[index][tcount]
                     except KeyError:
                         dssp = '-'
                     del index
                 else:
                     dssp = None
             else:
                 char = '<span style=\"background-color:#FFFFFF;\">' + seq[
                     i] + "</span>"
                 tcount = 0
                 dssp = "-"
             local.append([char, tcount, dssp])
         self.splitSeqs.append(local)
         del i, char, color, tcount, dssp
     self.alignPane.seqs = self.splitSeqs
     del consv, comments, seq, name, local, count
예제 #4
0
class ColourPallet2(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):

        self.col = QColor(0, 84, 154)

        red = QLabel('Red')
        green = QLabel('Green')
        blue = QLabel('Blue')
        hue = QLabel('Hue')
        saturation = QLabel('Saturation')
        luminace = QLabel('Luminace')

        self.redSlider = QSlider()
        self.redSlider.setSingleStep(1)
        self.redSlider.setMaximum(255)
        self.redSlider.valueChanged.connect(self.rgb1SlidersChanged)
        self.greenSlider = QSlider()
        self.greenSlider.setSingleStep(1)
        self.greenSlider.setMaximum(255)
        self.greenSlider.valueChanged.connect(self.rgb1SlidersChanged)
        self.blueSlider = QSlider()
        self.blueSlider.setSingleStep(1)
        self.blueSlider.setMaximum(255)
        self.blueSlider.valueChanged.connect(self.rgb1SlidersChanged)

        self.hueSlider = QSlider()
        self.hueSlider.setSingleStep(1)
        self.hueSlider.setMaximum(359)
        self.hueSlider.valueChanged.connect(self.hslSliderChanged)
        self.saturationSlider = QSlider()
        self.saturationSlider.setSingleStep(1)
        self.saturationSlider.setMaximum(255)
        self.saturationSlider.valueChanged.connect(self.hslSliderChanged)
        self.luminaceSlider = QSlider()
        self.luminaceSlider.setSingleStep(1)
        self.luminaceSlider.setMaximum(255)
        self.luminaceSlider.valueChanged.connect(self.hslSliderChanged)

        grid1 = QGridLayout()
        grid1.setHorizontalSpacing(10)
        grid1.setContentsMargins(0, 0, 0, 0)
        for i in range(6):
            grid1.setColumnStretch(i, 1)
            grid1.setColumnMinimumWidth(i, 50)
            grid1.setRowMinimumHeight(i, 10)

        grid1.addWidget(red, 0, 0, alignment=Qt.AlignCenter)
        grid1.addWidget(self.redSlider, 1, 0, alignment=Qt.AlignCenter)
        grid1.addWidget(green, 0, 1, alignment=Qt.AlignCenter)
        grid1.addWidget(self.greenSlider, 1, 1, alignment=Qt.AlignCenter)
        grid1.addWidget(blue, 0, 2, alignment=Qt.AlignCenter)
        grid1.addWidget(self.blueSlider, 1, 2, alignment=Qt.AlignCenter)

        grid1.addWidget(hue, 0, 3, alignment=Qt.AlignCenter)
        grid1.addWidget(self.hueSlider, 1, 3, alignment=Qt.AlignCenter)
        grid1.addWidget(saturation, 0, 4, alignment=Qt.AlignCenter)
        grid1.addWidget(self.saturationSlider, 1, 4, alignment=Qt.AlignCenter)
        grid1.addWidget(luminace, 0, 5, alignment=Qt.AlignCenter)
        grid1.addWidget(self.luminaceSlider, 1, 5, alignment=Qt.AlignCenter)

        rgb1_ = QLabel('rgb')
        rgb255_ = QLabel('RGB')
        hex_ = QLabel('Hex')
        hsl_ = QLabel('hsl')

        self.rgb1Edit = QLineEdit()
        self.rgb1Edit.editingFinished.connect(self.rg1EditChanged)
        self.rgb255Edit = QLineEdit()
        self.rgb255Edit.editingFinished.connect(self.rgb255EditChanged)
        self.hexEdit = QLineEdit()
        self.hexEdit.editingFinished.connect(self.hexEditChanged)
        self.hslEdit = QLineEdit()
        self.hslEdit.editingFinished.connect(self.hslEditChanged)

        grid2 = QGridLayout()
        grid2.setVerticalSpacing(2)
        grid2.setHorizontalSpacing(20)
        grid2.setContentsMargins(0, 0, 0, 0)

        grid2.addWidget(rgb1_, 0, 0)
        grid2.addWidget(rgb255_, 0, 1)
        grid2.addWidget(hex_, 0, 2)
        grid2.addWidget(hsl_, 0, 3)

        grid2.addWidget(self.rgb1Edit, 1, 0)
        grid2.addWidget(self.rgb255Edit, 1, 1)
        grid2.addWidget(self.hexEdit, 1, 2)
        grid2.addWidget(self.hslEdit, 1, 3)

        self.square = QFrame(self)
        self.square.setStyleSheet("QWidget { background-color: %s }" %
                                  self.col.name())

        grid = QGridLayout()
        grid.addLayout(grid1, 0, 0)
        grid.addLayout(grid2, 1, 0)
        grid.addWidget(self.square, 2, 0)
        for i in (0, 2):
            grid.setRowStretch(i, 1)
        grid.setVerticalSpacing(10)

        self.setLayout(grid)

        self.setEverything()
        self.setGeometry(400, 400, 500, 400)
        self.setWindowTitle('Colour Pallet 2')
        self.show()

    def rg1EditChanged(self):
        rgb1 = ast.literal_eval(self.rgb1Edit.text())
        rgb255 = [round(i * 255) for i in rgb1]
        self.col.setRgb(*rgb255)
        self.setEverything()

    def rgb255EditChanged(self):
        rgb255 = ast.literal_eval(self.rgb255Edit.text())
        self.col.setRgb(*rgb255)
        self.setEverything()

    def hexEditChanged(self):
        self.col.setNamedColor(self.hexEdit.text())
        self.setEverything()

    def hslEditChanged(self):
        hsl = ast.literal_eval(self.hslEdit.text())
        self.col.setHsl(*hsl)
        self.setEverything()

    def rgb1SlidersChanged(self):
        self.col.setRgb(self.redSlider.value(), self.greenSlider.value(),
                        self.blueSlider.value())
        self.setEverything()

    def hslSliderChanged(self):
        self.col.setHsl(self.hueSlider.value(), self.saturationSlider.value(),
                        self.luminaceSlider.value())
        self.setEverything()

    def setEverything(self):
        hsl = self.col.getHsl()[0:3]
        Hex = self.col.name()
        rgb255 = self.col.getRgb()[0:3]
        rgb1 = [i / 255 for i in rgb255][0:3]

        self.BlockSignals(True)
        self.hslEdit.setText(str(hsl))
        self.hexEdit.setText(Hex)
        self.rgb255Edit.setText(str(rgb255))
        self.rgb1Edit.setText(str(rgb1))

        self.redSlider.setValue(rgb255[0])
        self.greenSlider.setValue(rgb255[1])
        self.blueSlider.setValue(rgb255[2])

        self.hueSlider.setValue(hsl[0])
        self.saturationSlider.setValue(hsl[1])
        self.luminaceSlider.setValue(hsl[2])

        self.square.setStyleSheet("QWidget { background-color: %s }" %
                                  self.col.name())
        self.BlockSignals(False)

    def BlockSignals(self, state):
        self.hslEdit.blockSignals(state)
        self.hexEdit.blockSignals(state)
        self.rgb255Edit.blockSignals(state)
        self.rgb1Edit.blockSignals(state)
        self.redSlider.blockSignals(state)
        self.greenSlider.blockSignals(state)
        self.blueSlider.blockSignals(state)
        self.hueSlider.blockSignals(state)
        self.saturationSlider.blockSignals(state)
        self.luminaceSlider.blockSignals(state)
예제 #5
0
class MainApplication(QMainWindow, Ui_MainWindow):

    def __init__(self):
        super(MainApplication, self).__init__()

        # Load TextParser
        # self.textParser = TextParser()

        self.tag = None

        # Set up the user interface from Designer.
        self.setupUi(self)

        # connect Textedit buttons
        self.textEditApply.clicked.connect(self.applyAllText)
        self.textEditSave.clicked.connect(self.saveTextEdit)
        self.textEditApplyMarked.clicked.connect(self.applyChoosenText)
        self.spinBox.valueChanged.connect(self.setTextSize)
        self.setTextSize()
        self.fontComboBox.currentFontChanged.connect(self.setTextSize)

        # set default colors
        self.worstColor = QColor(173, 50, 31)
        self.neutralColor = QColor(255, 255, 255)
        self.bestColor = QColor(51, 71, 153)
        self.setWorstColorButton(self.worstColor)
        self.setNeutralColorButton(self.neutralColor)
        self.setBestColorButton(self.bestColor)

        # colorwidget
        self.colorDia = QColorDialog(self.neutralColor, self.centralwidget)

        # connect widget with buttons
        self.bestColorButton.clicked.connect(self.chooseBestColor)
        self.neutralColorButton.clicked.connect(self.chooseNeutralColor)
        self.worstColorButton.clicked.connect(self.chooseWorstColor)
        self.comboBox.currentIndexChanged.connect(self.changeColor)

        # open Buttons
        self.openButton_1.clicked.connect(self.open_text)
        self.openButton_2.clicked.connect(self.open_text)

        # progressBar
        self.progress = 0
        self.progressBar.setValue(self.progress)
        self.progressBar_2.setValue(self.progress)
        self.progressBar_3.setValue(self.progress)
        self.progressBar.setVisible(False)
        self.progressBar_2.setVisible(False)
        self.progressBar_3.setVisible(False)

        # numWords
        self.numWords.setText("0")

        # numSent
        self.numSent.setText("0")

        # remove qttextWidget and setup own textwidget (detailview)
        self.verticalLayout.removeWidget(self.plainTextEdit)
        self.plainTextEdit.close()
        self.taggedTextWidget = MQTaggedTextWidget(self.centralwidget, self)
        self.taggedTextWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.verticalLayout.addWidget(self.taggedTextWidget)
        self.verticalLayout.update()

        # remove qttextWidget and setup own textwidget (documentview)
        self.verticalLayout_3.removeWidget(self.plainTextEdit_2)
        self.plainTextEdit_2.close()
        self.taggedDocumentWidget = MQTaggedTextWidget(self.centralwidget, self)
        self.taggedDocumentWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.gridLayout_9.addWidget(self.taggedDocumentWidget)
        self.gridLayout_9.update()

        # menue actions
        self.actionText_ffnen.triggered.connect(self.open_text)
        self.action_ber.triggered.connect(self.showAbout)
        self.actionDocumentView.triggered.connect(self.setActiveTabDocumentView)
        self.actionDetailView.triggered.connect(self.setActiveTabDetailView)
        self.actionChangeView.triggered.connect(self.changeView)
        self.actionSave.triggered.connect(self.saveTextEdit)
        self.actionEditorView.triggered.connect(self.setActiveTabEditorView)

        # initilize features
        self.kompVokIsActive = False
        self.wlengthIsActive = False
        self.nomIsActive = False
        self.slenghtIsActive = False
        self.kompSatzIsActive = False

        self.kompVokWeight = 0
        self.wlengthWeight = 0
        self.nomWeight = 0
        self.slenghtWeight = 0
        self.kompSatzWeight = 0

        self.checkBoxKompVok.clicked.connect(self.updateFeatureWeights)
        self.checkBoxWortlaenge.clicked.connect(self.updateFeatureWeights)
        self.checkBoxSatzlaenge.clicked.connect(self.updateFeatureWeights)
        self.checkBoxNom.clicked.connect(self.updateFeatureWeights)
        self.checkBoxKompSatz.clicked.connect(self.updateFeatureWeights)

        self.sliderKompVok.actionTriggered.connect(self.updateFeatureWeights)
        self.sliderWortlaenge.actionTriggered.connect(self.updateFeatureWeights)
        self.sliderSatzlaenge.actionTriggered.connect(self.updateFeatureWeights)
        self.sliderKompSatz.actionTriggered.connect(self.updateFeatureWeights)
        self.sliderNom.actionTriggered.connect(self.updateFeatureWeights)

        # updating the css
        self.checkBoxKompVok.clicked.connect(self.sliderChanged)
        self.checkBoxWortlaenge.clicked.connect(self.sliderChanged)
        self.checkBoxSatzlaenge.clicked.connect(self.sliderChanged)
        self.checkBoxNom.clicked.connect(self.sliderChanged)
        self.checkBoxKompSatz.clicked.connect(self.sliderChanged)

        self.sliderKompVok.sliderReleased.connect(self.sliderChanged)
        self.sliderWortlaenge.sliderReleased.connect(self.sliderChanged)
        self.sliderSatzlaenge.sliderReleased.connect(self.sliderChanged)
        self.sliderKompSatz.sliderReleased.connect(self.sliderChanged)
        self.sliderNom.sliderReleased.connect(self.sliderChanged)

        self.setAllWeights(100)

        # fill colorBar
        self.colorBar.page().mainFrame().setScrollBarPolicy(QtCore.Qt.Vertical, QtCore.Qt.ScrollBarAlwaysOff)
        self.colorBar.page().mainFrame().setScrollBarPolicy(QtCore.Qt.Horizontal, QtCore.Qt.ScrollBarAlwaysOff)
        self.update_colorbar()


        # on click handling document
        self.jsbridge = JSBridge(self.taggedTextWidget, self.taggedDocumentWidget, self)
        self.taggedTextWidget.page().mainFrame().javaScriptWindowObjectCleared.connect(self.add_js_to_page)


    def add_js_to_page(self):
        self.taggedTextWidget.page().mainFrame().addToJavaScriptWindowObject("jsbridge", self.jsbridge)

    def update_colorbar(self):
        ViewGenerator.genterate_colorbar(self)
        self.colorBar.load(QtCore.QUrl('file:///'+os.getcwd()+"/generated_html/color_bar.html"))
        self.colorBar.reload()

    def show_data(self):
        self.taggedTextWidget.stop()
        self.taggedTextWidget.showData(self.tag)

        self.taggedDocumentWidget.stop()
        self.taggedDocumentWidget.showDataNoGeneration(self.tag)

    def finishOpen(self):
        self.openButton_1.setEnabled(True)
        self.openButton_2.setEnabled(True)
        self.actionText_ffnen.setEnabled(True)
        self.textEditApply.setEnabled(True)
        self.textEditApplyMarked.setEnabled(True)
        self.textEditSave.setEnabled(True)
        self.progressBar.setVisible(False)
        self.progressBar_2.setVisible(False)
        self.progressBar_3.setVisible(False)

        self.tag = self.tag[0].FinishedText
        self.show_data()

        self.updateNumSent(len(self.tag.Sentences))
        self.updateNumWords(self.tag.WordCount)

    def updateWorkerInfo(self, value):
        self.updateProgressBar(value * 100.0)

    def open_text(self):
        # Show loading page
        self.taggedTextWidget.stop()
        self.taggedTextWidget.showLoading()

        self.taggedDocumentWidget.stop()
        self.taggedDocumentWidget.showLoading()

        dialog = QFileDialog(self)
        dialog.setNameFilters([self.tr('Text Files (*.txt)'), self.tr('All Files (*)')])
        dialog.setDefaultSuffix('.txt')
        file_name = dialog.getOpenFileName(self, 'Open file')
        self.progressBar.setVisible(True)
        self.progressBar_2.setVisible(True)
        self.progressBar_3.setVisible(True)
        if file_name[0] != '':
            text = codecs.open(file_name[0], "r", "utf-8").read()
            # We need to create new TextWorker
            self.tag = (TextWorker(), QtCore.QThread())

            # prompt for custom common words list
            msg = QMessageBox()
            question = "Do you want to choose a custom list of domain specific common words?"
            reply = msg.question(self, 'Message', question, msg.Yes, msg.No)
            if reply == msg.Yes:
                dialog = QFileDialog(self)
                dialog.setNameFilters([self.tr('Text Files (*.txt)'), self.tr('All Files (*)')])
                dialog.setDefaultSuffix('.txt')
                file_name = dialog.getOpenFileName(self, 'Open file')
                self.tag[0].common_words_file = file_name[0]
            else:
                self.tag[0].common_words_file = "textparser/wordlist.txt"

            self.tag[0].TextToParse = text
            self.textEdit.setText(text)
            # Gray out all buttons
            self.openButton_1.setEnabled(False)
            self.openButton_2.setEnabled(False)
            self.actionText_ffnen.setEnabled(False)
            self.textEditApply.setEnabled(False)
            self.textEditApplyMarked.setEnabled(False)
            self.textEditSave.setEnabled(False)

            # Create Thread
            self.tag[1].objThread = QtCore.QThread()
            self.tag[0].moveToThread(self.tag[1])
            self.tag[0].finished.connect(self.tag[1].quit)
            self.tag[0].updated.connect(self.updateWorkerInfo);
            # self.tag[0].finished.connect(self.finishOpen)
            self.tag[1].started.connect(self.tag[0].longRunning)
            self.tag[1].finished.connect(self.finishOpen)

            self.tag[1].start()

    def updateView(self):
        v = self.ViewSlider.sliderPosition()
        if v == 0:
            self.ActiveViewText.setText("Document")
        elif v == 1:
            self.ActiveViewText.setText("Words - Details")
        else:
            self.ActiveViewText.setText("No View available")

    def updateFeatureWeights(self):
        if self.checkBoxKompVok.isChecked():
            self.checkBoxKompVok.setText(str(self.sliderKompVok.sliderPosition()) + "%")
            self.kompVokIsActive = True
            self.kompVokWeight = self.sliderKompVok.sliderPosition()
        else:
            self.checkBoxKompVok.setText("-")
            self.kompVokIsActive = False
            self.kompVokWeight = 0

        if self.checkBoxKompSatz.isChecked():
            self.checkBoxKompSatz.setText(str(self.sliderKompSatz.sliderPosition()) + "%")
            self.kompSatzIsActive = True
            self.kompSatzWeight = self.sliderKompSatz.sliderPosition()
        else:
            self.checkBoxKompSatz.setText("-")
            self.kompSatzIsActive = False
            self.kompSatzWeight = 0

        if self.checkBoxNom.isChecked():
            self.checkBoxNom.setText(str(self.sliderNom.sliderPosition()) + "%")
            self.nomIsActive = True
            self.nomWeight = self.sliderNom.sliderPosition()
        else:
            self.checkBoxNom.setText("-")
            self.nomIsActive = False
            self.nomWeight = 0

        if self.checkBoxSatzlaenge.isChecked():
            self.checkBoxSatzlaenge.setText(str(self.sliderSatzlaenge.sliderPosition()) + "%")
            self.slenghtIsActive = True
            self.slenghtWeight = self.sliderSatzlaenge.sliderPosition()
        else:
            self.checkBoxSatzlaenge.setText("-")
            self.slenghtIsActive = False
            self.slenghtWeight = 0

        if self.checkBoxWortlaenge.isChecked():
            self.checkBoxWortlaenge.setText(str(self.sliderWortlaenge.sliderPosition()) + "%")
            self.wlengthIsActive = True
            self.wlengthWeight = self.sliderWortlaenge.sliderPosition()
        else:
            self.checkBoxWortlaenge.setText("-")
            self.wlengthIsActive = False
            self.wlengthWeight = 0

    def updateProgressBar(self, int_value):
        self.progressBar.setValue(int_value)
        self.progressBar_2.setValue(int_value)
        self.progressBar_3.setValue(int_value)

    def updateNumSent(self, int_value):
        self.numSent.setText(str(int_value))

    def updateNumWords(self, int_value):
        self.numWords.setText(str(int_value))

    def updateCorpora(self):
        self.activeCorporaIndex = self.CorporaBox.currentIndex()

    def setAllWeights(self, int_weight):
        if int_weight > 100 or int_weight < 0:
            int_weight = 0
        self.checkBoxKompVok.setChecked(True)
        self.checkBoxWortlaenge.setChecked(True)
        self.checkBoxSatzlaenge.setChecked(True)
        self.checkBoxNom.setChecked(True)
        self.checkBoxKompSatz.setChecked(True)

        self.sliderKompVok.setValue(int_weight)
        self.sliderWortlaenge.setValue(int_weight)
        self.sliderSatzlaenge.setValue(int_weight)
        self.sliderKompSatz.setValue(int_weight)
        self.sliderNom.setValue(int_weight)

        self.updateFeatureWeights()

    def sliderChanged(self):
        if self.tag != None:
            self.taggedTextWidget.showDataNoWait(self.tag)

    def setActiveTabDocumentView(self):
        self.tabWidget.setCurrentIndex(1)

    def setActiveTabDetailView(self):
        self.tabWidget.setCurrentIndex(0)

    def setActiveTabEditorView(self):
        self.tabWidget.setCurrentIndex(2)

    def changeView(self):
        # print(self.tabWidget.currentIndex())
        if self.tabWidget.currentIndex() == 0:
            self.tabWidget.setCurrentIndex(1)
        elif self.tabWidget.currentIndex() == 1:
            self.tabWidget.setCurrentIndex(2)
        elif self.tabWidget.currentIndex() == 2:
            self.tabWidget.setCurrentIndex(0)

    def showAbout(self):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        # msg.setTextFormat(QLabel.openExternalLinks);   #this is what makes the links clickable
        msg.setText("Applied Visualization and Analysis of Multivariate Datasets - Text Visualization")
        msg.setInformativeText("Git repository: " + "https://github.com/Zarnosch/AVaAoMDTV")
        msg.setWindowTitle("About")
        msg.setDetailedText(
            "Version: " + "0.1.0" + "\n \n" + "This Project is done in the context of Applied Visualization and Analysis of Multivariate Datasets at the"
                                              "OVGU University." + "\n \n" + "This tool can load .txt files and shows the readability difficulty.")
        msg.setStandardButtons(QMessageBox.Ok)
        retval = msg.exec_()

    def setBestColorButton(self, color):
        r = str(color.red())
        g = str(color.green())
        b = str(color.blue())
        self.bestColorButton.setStyleSheet(
            "background-color: rgb(" + r + ", " + g + ", " + b + "); border: 1px dashed black; padding: 2px;")
        # self.bestColorButton.setStyleSheet("border: 1px solid black")

    def setNeutralColorButton(self, color):
        r = str(color.red())
        g = str(color.green())
        b = str(color.blue())
        self.neutralColorButton.setStyleSheet(
            "background-color: rgb(" + r + ", " + g + ", " + b + "); border: 1px dashed black; padding: 2px;")
        # self.neutralColorButton.setStyleSheet("border: 1px solid black")

    def setWorstColorButton(self, color):
        r = str(color.red())
        g = str(color.green())
        b = str(color.blue())
        self.worstColorButton.setStyleSheet(
            "background-color: rgb(" + r + ", " + g + ", " + b + "); border: 1px dashed black; padding: 2px;")
        # self.worstColorButton.setStyleSheet("border: 1px solid black")

    def chooseWorstColor(self):
        self.worstColor = QColorDialog.getColor(self.worstColor)
        self.setWorstColorButton(self.worstColor)
        if self.tag != None:
            self.taggedTextWidget.showDataNoWait(self.tag)
            self.taggedDocumentWidget.showDateNoWaitDetails(self.tag)
        self.update_colorbar()

    def chooseNeutralColor(self):
        self.neutralColor = QColorDialog.getColor(self.neutralColor)
        self.setNeutralColorButton(self.neutralColor)
        if self.tag != None:
            self.taggedTextWidget.showDataNoWait(self.tag)
            self.taggedDocumentWidget.showDateNoWaitDetails(self.tag)
        self.update_colorbar()

    def chooseBestColor(self):
        self.bestColor = QColorDialog.getColor(self.bestColor)
        self.setBestColorButton(self.bestColor)
        if self.tag != None:
            self.taggedTextWidget.showDataNoWait(self.tag)
            self.taggedDocumentWidget.showDateNoWaitDetails(self.tag)
        self.update_colorbar()

    def getWorstColorHSL(self):
        return self.worstColor.getHsl()

    def getNeutralColorHSL(self):
        return self.neutralColor.getHsl()

    def getBestColorHSL(self):
        return self.bestColor.getHsl()

    def applyChoosenText(self):
        cursor = self.textEdit.textCursor()
        # cursor = QTextCursor()
        stext = cursor.selection()
        mtext = stext.toPlainText()
        self.applyTextEdit(mtext)

    def applyAllText(self):
        self.applyTextEdit(self.textEdit.toPlainText())

    def applyTextEdit(self, text):
        # Show loading page
        self.taggedTextWidget.stop()
        self.taggedTextWidget.showLoading()

        self.progressBar.setVisible(True)
        self.progressBar_2.setVisible(True)
        self.progressBar_3.setVisible(True)

        self.taggedDocumentWidget.stop()
        self.taggedDocumentWidget.showLoading()

        # We need to create new TextWorker
        self.tag = (TextWorker(), QtCore.QThread())

        # prompt for custom common words list
        msg = QMessageBox()
        question = "Do you want to choose a custom list of domain specific common words?"
        reply = msg.question(self, 'Message', question, msg.Yes, msg.No)
        if reply == msg.Yes:
            dialog = QFileDialog(self)
            dialog.setNameFilters([self.tr('Text Files (*.txt)'), self.tr('All Files (*)')])
            dialog.setDefaultSuffix('.txt')
            file_name = dialog.getOpenFileName(self, 'Open file')
            self.tag[0].common_words_file = file_name[0]

        self.tag[0].TextToParse = text
        # self.textEdit.setText(text)
        # Gray out all buttons
        self.openButton_1.setEnabled(False)
        self.openButton_2.setEnabled(False)
        self.actionText_ffnen.setEnabled(False)
        self.textEditApply.setEnabled(False)
        self.textEditApplyMarked.setEnabled(False)
        self.textEditSave.setEnabled(False)

        # Create Thread
        self.tag[1].objThread = QtCore.QThread()
        self.tag[0].moveToThread(self.tag[1])
        self.tag[0].finished.connect(self.tag[1].quit)
        self.tag[0].updated.connect(self.updateWorkerInfo);
        # self.tag[0].finished.connect(self.finishOpen)
        self.tag[1].started.connect(self.tag[0].longRunning)
        self.tag[1].finished.connect(self.finishOpen)

        self.tag[1].start()

    def saveTextEdit(self):
        filename = ""
        dialog = QFileDialog(self, 'Save File')
        dialog.setNameFilters([self.tr('Text Files (*.txt)'), self.tr('All Files (*)')])
        dialog.setDefaultSuffix('.txt')
        filename = dialog.getSaveFileName()
        file = filename[0]
        if not file.endswith('.txt'):
            file += ".txt"
        f = open(file, 'w')
        filedata = self.textEdit.toPlainText()
        f.write(filedata)
        f.close()

    def setTextSize(self):
        self.textEdit.setAcceptRichText(True)
        font = self.fontComboBox.currentFont()
        font.setPixelSize(self.spinBox.value())
        self.textEdit.setFont(font)

    def changeColor(self):
        if self.comboBox.currentIndex() == 0:
            self.setTemperatureScale()
        elif self.comboBox.currentIndex() == 1:
            self.setGreyScale()
        else :
            self.setRainbowScale()
        self.setBestColorButton(self.bestColor)
        self.setNeutralColorButton(self.neutralColor)
        self.setWorstColorButton(self.worstColor)
        if self.tag != None:
            self.taggedTextWidget.showDataNoWait(self.tag)
            self.taggedDocumentWidget.showDateNoWaitDetails(self.tag)
        self.update_colorbar()

    def setTemperatureScale(self):
        self.worstColor = QColor(173, 50, 31)
        self.neutralColor = QColor(255, 255, 255)
        self.bestColor = QColor(51, 71, 153)

    def setGreyScale(self):
        self.worstColor = QColor(50, 50, 50)
        self.neutralColor = QColor(102, 102, 102)
        self.bestColor = QColor(255, 255, 255)

    def setRainbowScale(self):
        self.worstColor = QColor(187, 34, 34)
        self.neutralColor = QColor(255, 215, 0)
        self.bestColor = QColor(50, 205, 50)