def data(self, index, role=Qt.EditRole): level = 0 i = index while i.parent() != QModelIndex(): i = i.parent() level += 1 if role == Qt.BackgroundRole: if level == 0: return QBrush(QColor(S.highlightLight)) if role == Qt.TextAlignmentRole: if level == 0: return Qt.AlignCenter if role == Qt.FontRole: if level in [0, 1]: f = qApp.font() f.setBold(True) return f if role == Qt.ForegroundRole: if level == 0: return QBrush(QColor(S.highlightedTextDark)) if role == Qt.SizeHintRole: fm = QFontMetrics(qApp.font()) h = fm.height() if level == 0: return QSize(0, h + 12) elif level == 1: return QSize(0, h + 6) return QStandardItemModel.data(self, index, role)
def data(self, index, role=Qt.EditRole): level = 0 i = index while i.parent() != QModelIndex(): i = i.parent() level += 1 if role == Qt.BackgroundRole: if level == 0: return QBrush(lightBlue()) if role == Qt.TextAlignmentRole: if level == 0: return Qt.AlignCenter if role == Qt.FontRole: if level in [0, 1]: f = qApp.font() f.setBold(True) return f if role == Qt.ForegroundRole: if level == 0: return QBrush(Qt.darkBlue) if role == Qt.SizeHintRole: fm = QFontMetrics(qApp.font()) h = fm.height() if level == 0: return QSize(0, h + 12) elif level == 1: return QSize(0, h + 6) return QStandardItemModel.data(self, index, role)
def loadThemeDatas(themeFile): settings = QSettings(themeFile, QSettings.IniFormat) _themeData = {} # Theme name _themeData["Name"] = getThemeName(themeFile) # Window Background loadThemeSetting(_themeData, settings, "Background/Color", "#000000") loadThemeSetting(_themeData, settings, "Background/ImageFile", "") loadThemeSetting(_themeData, settings, "Background/Type", 0) # Text Background loadThemeSetting(_themeData, settings, "Foreground/Color", "#ffffff") loadThemeSetting(_themeData, settings, "Foreground/Opacity", 50) loadThemeSetting(_themeData, settings, "Foreground/Margin", 40) loadThemeSetting(_themeData, settings, "Foreground/Padding", 10) loadThemeSetting(_themeData, settings, "Foreground/Position", 1) loadThemeSetting(_themeData, settings, "Foreground/Rounding", 5) loadThemeSetting(_themeData, settings, "Foreground/Width", 700) # Text Options loadThemeSetting(_themeData, settings, "Text/Color", "#ffffff") loadThemeSetting(_themeData, settings, "Text/Font", qApp.font().toString()) loadThemeSetting(_themeData, settings, "Text/Misspelled", "#ff0000") # Paragraph Options loadThemeSetting(_themeData, settings, "Spacings/IndendFirstLine", False) loadThemeSetting(_themeData, settings, "Spacings/LineSpacing", 100) loadThemeSetting(_themeData, settings, "Spacings/ParagraphAbove", 0) loadThemeSetting(_themeData, settings, "Spacings/ParagraphBelow", 0) loadThemeSetting(_themeData, settings, "Spacings/TabWidth", 48) return _themeData
def loadThemeDatas(themeFile): settings = QSettings(themeFile, QSettings.IniFormat) _themeData = {} # Theme name _themeData["Name"] = getThemeName(themeFile) # Window Background loadThemeSetting(_themeData, settings, "Background/Color", "#000000") loadThemeSetting(_themeData, settings, "Background/ImageFile", "") loadThemeSetting(_themeData, settings, "Background/Type", 0) # Text Background loadThemeSetting(_themeData, settings, "Foreground/Color", "#ffffff") loadThemeSetting(_themeData, settings, "Foreground/Opacity", 50) loadThemeSetting(_themeData, settings, "Foreground/Margin", 40) loadThemeSetting(_themeData, settings, "Foreground/Padding", 10) loadThemeSetting(_themeData, settings, "Foreground/Position", 1) loadThemeSetting(_themeData, settings, "Foreground/Rounding", 5) loadThemeSetting(_themeData, settings, "Foreground/Width", 700) # Text Options loadThemeSetting(_themeData, settings, "Text/Color", "#ffffff") loadThemeSetting(_themeData, settings, "Text/Font", qApp.font().toString()) loadThemeSetting(_themeData, settings, "Text/Misspelled", "#ff0000") # Paragraph Options loadThemeSetting(_themeData, settings, "Spacings/Alignment", 0) loadThemeSetting(_themeData, settings, "Spacings/IndentFirstLine", False) loadThemeSetting(_themeData, settings, "Spacings/LineSpacing", 100) loadThemeSetting(_themeData, settings, "Spacings/ParagraphAbove", 0) loadThemeSetting(_themeData, settings, "Spacings/ParagraphBelow", 0) loadThemeSetting(_themeData, settings, "Spacings/TabWidth", 48) return _themeData
def __init__(self, editor, charFormat, name="Default"): self.editor = editor self.name = name self._defaultCharFormat = charFormat # Defaults # self.defaultFontPointSize = self.editor.defaultFontPointSize self.defaultFontFamily = qApp.font().family() self.tabStopWidth = 40 self.setupEditor() if self.name == "Default": self.initDefaults() # Temporary other theme elif self.name == "Monospace": self.defaultFontFamily = "Monospace" self.initDefaults() for i in self.styles: f = self.styles[i] f.setFontFixedPitch(True) f.setFontFamily(self.defaultFontFamily) f.setFontPointSize(self._defaultCharFormat.font().pointSize()) self.styles[i] = f
def __init__(self, asset_path: Union[Path, str]) -> None: super().__init__(asset_path) self.gui_font_db = QFontDatabase() self.load_new_fonts() self.gui_font = qApp.font() self.gui_font_fixed = QFontDatabase.systemFont(QFontDatabase.FixedFont)
def setAppFontSize(self, val): """ Set application default font point size. """ f = qApp.font() f.setPointSize(val) qApp.setFont(f) mainWindow().setFont(f) sttgs = QSettings(qApp.organizationName(), qApp.applicationName()) sttgs.setValue("appFontSize", val)
def showSteps(workspace): """Renders step-by-step solution in matplotlib figure Arguments: workspace {QtWidgets.QWidget} -- main layout """ workspace.stepsfigure.suptitle(workspace.output, y=0.98, horizontalalignment='center', verticalalignment='top', size=qApp.font().pointSize() * workspace.stepsFontSize) workspace.stepscanvas.draw()
def answer_font_action_triggered(self, checked): """ :param checked: :return: """ font = qApp.font() font, changed = QFontDialog().getFont(font, self, caption="字体设置") if changed: qApp.setFont(font) qApp.processEvents() update_contents("preferences", "font-family", font.family()) update_contents("preferences", "font-style", font.styleName()) update_contents("preferences", "font-size", str(font.pointSize()))
def compute_font_for_text(text: str, flags: int, size: QSize) -> QFont: """ Calculates the font for the text for the area of the specified dimensions :param text: input text :param flags: the alignment flags of the text :param size: the size of the area :return: QFont """ font = qApp.font() for i in range(2, 14): font.setPixelSize(i) rect = QFontMetrics(font).boundingRect(0, 0, size.width(), size.height(), flags, text) if rect.width() > size.width() or rect.height() > size.height(): font.setPixelSize(i - 1) break return font
def set_font(parent=None, dynamic=True): """ :param parent: :param dynamic: :return: """ font = qApp.font() font, changed = QFontDialog().getFont(font, parent, caption="字体设置") if changed: if dynamic: qApp.setFont(font) qApp.processEvents() default_json2python4file["preferences"]["personalise"][ "font-family"] = font.family() default_json2python4file["preferences"]["personalise"][ "font-style"] = font.styleName() default_json2python4file["preferences"]["personalise"][ "font-size"] = font.pointSize() python2json2file(default_json2python4file)
def __init__(self, index, parent=None): QWidget.__init__(self, parent) self._background = None self._index = index self._theme = findThemePath(settings.fullScreenTheme) self._themeDatas = loadThemeDatas(self._theme) self.setMouseTracking(True) self._geometries = {} # Text editor self.editor = textEditView(self, index=index, spellcheck=settings.spellcheck, highlighting=True, dict=settings.dict) self.editor.setFrameStyle(QFrame.NoFrame) self.editor.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.editor.installEventFilter(self) self.editor.setMouseTracking(True) self.editor.setVerticalScrollBar(myScrollBar()) self.scrollBar = self.editor.verticalScrollBar() self.scrollBar.setParent(self) # Top Panel self.topPanel = myPanel(parent=self) # self.topPanel.layout().addStretch(1) # Spell checking if enchant: self.btnSpellCheck = QPushButton(self) self.btnSpellCheck.setFlat(True) self.btnSpellCheck.setIcon(QIcon.fromTheme("tools-check-spelling")) self.btnSpellCheck.setCheckable(True) self.btnSpellCheck.setChecked(self.editor.spellcheck) self.btnSpellCheck.toggled.connect(self.editor.toggleSpellcheck) self.topPanel.layout().addWidget(self.btnSpellCheck) self.topPanel.layout().addStretch(1) # Formatting self.textFormat = textFormat(self) self.topPanel.layout().addWidget(self.textFormat) self.topPanel.layout().addStretch(1) self.btnClose = QPushButton(self) self.btnClose.setIcon(qApp.style().standardIcon(QStyle.SP_DialogCloseButton)) self.btnClose.clicked.connect(self.close) self.btnClose.setFlat(True) self.topPanel.layout().addWidget(self.btnClose) # Left Panel self._locked = False self.leftPanel = myPanel(vertical=True, parent=self) self.locker = locker(self) self.locker.lockChanged.connect(self.setLocked) self.leftPanel.layout().addWidget(self.locker) # Bottom Panel self.bottomPanel = myPanel(parent=self) self.bottomPanel.layout().addSpacing(24) self.lstThemes = QComboBox(self) self.lstThemes.setAttribute(Qt.WA_TranslucentBackground) paths = allPaths("resources/themes") for p in paths: lst = [i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme"] for t in lst: themeIni = os.path.join(p, t) name = loadThemeDatas(themeIni)["Name"] # self.lstThemes.addItem(os.path.splitext(t)[0]) self.lstThemes.addItem(name) self.lstThemes.setItemData(self.lstThemes.count()-1, os.path.splitext(t)[0]) self.lstThemes.setCurrentIndex(self.lstThemes.findData(settings.fullScreenTheme)) # self.lstThemes.setCurrentText(settings.fullScreenTheme) self.lstThemes.currentTextChanged.connect(self.setTheme) self.lstThemes.setMaximumSize(QSize(300, QFontMetrics(qApp.font()).height())) self.bottomPanel.layout().addWidget(QLabel(self.tr("Theme:"), self)) self.bottomPanel.layout().addWidget(self.lstThemes) self.bottomPanel.layout().addStretch(1) self.lblProgress = QLabel(self) self.lblProgress.setMaximumSize(QSize(200, 14)) self.lblProgress.setMinimumSize(QSize(100, 14)) self.lblWC = QLabel(self) self.bottomPanel.layout().addWidget(self.lblWC) self.bottomPanel.layout().addWidget(self.lblProgress) self.updateStatusBar() self.bottomPanel.layout().addSpacing(24) # Connection self._index.model().dataChanged.connect(self.dataChanged) # self.updateTheme() self.showFullScreen()
def __init__(self, theParent): self.mainConf = nw.CONFIG self.theParent = theParent self.theIcons = GuiIcons(self.theParent) self.guiPalette = QPalette() self.guiPath = "gui" self.fontPath = "fonts" self.syntaxPath = "syntax" self.cssName = "style.qss" self.confName = "theme.conf" self.themeList = [] self.syntaxList = [] # Loaded Theme Settings ## Theme self.themeName = "" self.themeDescription = "" self.themeAuthor = "" self.themeCredit = "" self.themeUrl = "" self.themeLicense = "" self.themeLicenseUrl = "" ## GUI self.statNone = [120, 120, 120] self.statUnsaved = [200, 15, 39] self.statSaved = [2, 133, 37] self.helpText = [0, 0, 0] # Loaded Syntax Settings ## Main self.syntaxName = "" self.syntaxDescription = "" self.syntaxAuthor = "" self.syntaxCredit = "" self.syntaxUrl = "" self.syntaxLicense = "" self.syntaxLicenseUrl = "" ## Colours self.colBack = [255, 255, 255] self.colText = [0, 0, 0] self.colLink = [0, 0, 0] self.colHead = [0, 0, 0] self.colHeadH = [0, 0, 0] self.colEmph = [0, 0, 0] self.colDialN = [0, 0, 0] self.colDialD = [0, 0, 0] self.colDialS = [0, 0, 0] self.colHidden = [0, 0, 0] self.colKey = [0, 0, 0] self.colVal = [0, 0, 0] self.colSpell = [0, 0, 0] self.colTagErr = [0, 0, 0] self.colRepTag = [0, 0, 0] self.colMod = [0, 0, 0] # Changeable Settings self.guiTheme = None self.guiSyntax = None self.themeRoot = None self.themePath = None self.syntaxFile = None self.confFile = None self.cssFile = None self.guiFontDB = QFontDatabase() self.loadFonts() self.updateFont() self.updateTheme() self.theIcons.updateTheme() self.getIcon = self.theIcons.getIcon self.getPixmap = self.theIcons.getPixmap self.loadDecoration = self.theIcons.loadDecoration # Extract Other Info self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX() self.guiScale = qApp.primaryScreen().logicalDotsPerInchX() / 96.0 self.mainConf.guiScale = self.guiScale logger.verbose("GUI DPI: %.1f" % self.guiDPI) logger.verbose("GUI Scale: %.2f" % self.guiScale) # Fonts self.guiFont = qApp.font() qMetric = QFontMetrics(self.guiFont) self.fontPointSize = self.guiFont.pointSizeF() self.fontPixelSize = int(round(qMetric.height())) self.baseIconSize = int(round(qMetric.ascent())) self.textNHeight = qMetric.boundingRect("N").height() self.textNWidth = qMetric.boundingRect("N").width() # Monospace Font self.guiFontFixed = QFont() self.guiFontFixed.setPointSizeF(0.95 * self.fontPointSize) self.guiFontFixed.setFamily( QFontDatabase.systemFont(QFontDatabase.FixedFont).family()) logger.verbose("GUI Font Family: %s" % self.guiFont.family()) logger.verbose("GUI Font Point Size: %.2f" % self.fontPointSize) logger.verbose("GUI Font Pixel Size: %d" % self.fontPixelSize) logger.verbose("GUI Base Icon Size: %d" % self.baseIconSize) logger.verbose("Text 'N' Height: %d" % self.textNHeight) logger.verbose("Text 'N' Width: %d" % self.textNWidth) # Internal Mapping self.makeAlert = self.theParent.makeAlert self.tr = partial(QCoreApplication.translate, "GuiTheme") return
autoSaveNoChangesDelay = 5 saveOnQuit = True outlineViewColumns = [ Outline.title.value, Outline.POV.value, Outline.status.value, Outline.compile.value, Outline.wordCount.value, Outline.goal.value, Outline.goalPercentage.value, Outline.label.value ] corkBackground = {"color": "#926239", "image": "writingdesk"} corkStyle = "new" defaultTextType = "md" fullScreenTheme = "spacedreams" textEditor = { "background": "#fff", "fontColor": "#000", "font": qApp.font().toString(), "misspelled": "#F00", "lineSpacing": 100, "tabWidth": 20, "indent": True, "spacingAbove": 5, "spacingBelow": 5, "textAlignment": 0, # 0: left, 1: center, 2: right, 3: justify "cursorWidth": 1, "cursorNotBlinking": False, "maxWidth": 0, "marginsLR": 0, "marginsTB": 0, } revisions = {
def __init__(self, parent=None, index=None, html=None, spellcheck=None, highlighting=False, dict="", autoResize=False): QTextEdit.__init__(self, parent) self._column = Outline.text self._index = None self._indexes = None self._model = None self._placeholderText = self.placeholderText() self._updating = QMutex() self._item = None self._highlighting = highlighting self._textFormat = "text" self.setAcceptRichText(False) # When setting up a theme, this becomes true. self._fromTheme = False self._themeData = None self._highlighterClass = BasicHighlighter if spellcheck == None: spellcheck = settings.spellcheck self.spellcheck = spellcheck self.currentDict = dict if dict else settings.dict self._defaultFontSize = qApp.font().pointSize() self.highlighter = None self.setAutoResize(autoResize) self._defaultBlockFormat = QTextBlockFormat() self._defaultCharFormat = QTextCharFormat() self.highlightWord = "" self.highligtCS = False self._dict = None self._tooltip = {'depth': 0, 'active': 0} # self.document().contentsChanged.connect(self.submit, F.AUC) # Submit text changed only after 500ms without modifications self.updateTimer = QTimer() self.updateTimer.setInterval(500) self.updateTimer.setSingleShot(True) self.updateTimer.timeout.connect(self.submit) # self.updateTimer.timeout.connect(lambda: LOGGER.debug("Timeout.")) self.updateTimer.stop() self.document().contentsChanged.connect(self.updateTimer.start, F.AUC) # self.document().contentsChanged.connect(lambda: LOGGER.debug("Document changed.")) # self.document().contentsChanged.connect(lambda: LOGGER.debug("Contents changed: %s", self.objectName())) self.setEnabled(False) if index: self.setCurrentModelIndex(index) elif html: self.document().setHtml(html) self.setReadOnly(True) # Spellchecking if self.spellcheck: self._dict = Spellchecker.getDictionary(self.currentDict) if not self._dict: self.spellcheck = False if self._highlighting and not self.highlighter: self.highlighter = self._highlighterClass(self) self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def __init__(self, index, parent=None, screenNumber=None): QWidget.__init__(self, parent) self.setAttribute(Qt.WA_DeleteOnClose, True) self._background = None self._index = index self._theme = findThemePath(settings.fullScreenTheme) self._themeDatas = loadThemeDatas(self._theme) self.setMouseTracking(True) self._geometries = {} # Text editor self.editor = MDEditView(self, index=index, spellcheck=settings.spellcheck, highlighting=True, dict=settings.dict) self.editor.setFrameStyle(QFrame.NoFrame) self.editor.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.editor.installEventFilter(self) self.editor.setMouseTracking(True) self.editor.setVerticalScrollBar(myScrollBar()) self.scrollBar = self.editor.verticalScrollBar() self.scrollBar.setParent(self) # Top Panel self.topPanel = myPanel(parent=self) # self.topPanel.layout().addStretch(1) # Spell checking if Spellchecker.isInstalled(): self.btnSpellCheck = QPushButton(self) self.btnSpellCheck.setFlat(True) self.btnSpellCheck.setIcon(QIcon.fromTheme("tools-check-spelling")) self.btnSpellCheck.setCheckable(True) self.btnSpellCheck.setChecked(self.editor.spellcheck) self.btnSpellCheck.toggled.connect(self.editor.toggleSpellcheck) else: self.btnSpellCheck = None # Navigation Buttons self.btnPrevious = QPushButton(self) self.btnPrevious.setFlat(True) self.btnPrevious.setIcon(QIcon.fromTheme("arrow-left")) self.btnPrevious.clicked.connect(self.switchPreviousItem) self.btnNext = QPushButton(self) self.btnNext.setFlat(True) self.btnNext.setIcon(QIcon.fromTheme("arrow-right")) self.btnNext.clicked.connect(self.switchNextItem) self.btnNew = QPushButton(self) self.btnNew.setFlat(True) self.btnNew.setIcon(QIcon.fromTheme("document-new")) self.btnNew.clicked.connect(self.createNewText) # Path and New Text Buttons self.wPath = myPath(self) # Close self.btnClose = QPushButton(self) self.btnClose.setIcon(qApp.style().standardIcon( QStyle.SP_DialogCloseButton)) self.btnClose.clicked.connect(self.leaveFullscreen) self.btnClose.setFlat(True) # Top panel Layout if self.btnSpellCheck: self.topPanel.layout().addWidget(self.btnSpellCheck) self.topPanel.layout().addSpacing(15) self.topPanel.layout().addWidget(self.btnPrevious) self.topPanel.layout().addWidget(self.btnNext) self.topPanel.layout().addWidget(self.btnNew) self.topPanel.layout().addStretch(1) self.topPanel.layout().addWidget(self.wPath) self.topPanel.layout().addStretch(1) self.topPanel.layout().addWidget(self.btnClose) self.updateTopBar() # Left Panel self._locked = False self.leftPanel = myPanel(vertical=True, parent=self) self.locker = locker(self) self.locker.lockChanged.connect(self.setLocked) self.leftPanel.layout().addWidget(self.locker) # Bottom Panel self.bottomPanel = myPanel(parent=self) self.bottomPanel.layout().addSpacing(24) self.lstThemes = QComboBox(self) self.lstThemes.setAttribute(Qt.WA_TranslucentBackground) paths = allPaths("resources/themes") for p in paths: lst = [ i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme" ] for t in lst: themeIni = os.path.join(p, t) name = loadThemeDatas(themeIni)["Name"] # self.lstThemes.addItem(os.path.splitext(t)[0]) self.lstThemes.addItem(name) self.lstThemes.setItemData(self.lstThemes.count() - 1, os.path.splitext(t)[0]) self.lstThemes.setCurrentIndex( self.lstThemes.findData(settings.fullScreenTheme)) # self.lstThemes.setCurrentText(settings.fullScreenTheme) self.lstThemes.currentTextChanged.connect(self.setTheme) self.lstThemes.setMaximumSize( QSize(300, QFontMetrics(qApp.font()).height())) themeLabel = QLabel(self.tr("Theme:"), self) self.bottomPanel.layout().addWidget(themeLabel) self.bottomPanel.layout().addWidget(self.lstThemes) self.bottomPanel.layout().addStretch(1) self.lblProgress = QLabel(self) self.lblProgress.setMaximumSize(QSize(200, 14)) self.lblProgress.setMinimumSize(QSize(100, 14)) self.lblWC = QLabel(self) self.lblClock = myClockLabel(self) self.bottomPanel.layout().addWidget(self.lblWC) self.bottomPanel.layout().addWidget(self.lblProgress) self.bottomPanel.layout().addSpacing(15) self.bottomPanel.layout().addWidget(self.lblClock) self.updateStatusBar() self.bottomPanel.layout().addSpacing(24) # Add Widget Settings if self.btnSpellCheck: self.topPanel.addWidgetSetting(self.tr("Spellcheck"), 'top-spellcheck', (self.btnSpellCheck, )) self.topPanel.addWidgetSetting(self.tr("Navigation"), 'top-navigation', (self.btnPrevious, self.btnNext)) self.topPanel.addWidgetSetting(self.tr("New Text"), 'top-new-doc', (self.btnNew, )) self.topPanel.addWidgetSetting(self.tr("Title"), 'top-title', (self.wPath, )) self.topPanel.addSetting(self.tr("Title: Show Full Path"), 'title-show-full-path', True) self.topPanel.setSettingCallback('title-show-full-path', lambda var, val: self.updateTopBar()) self.bottomPanel.addWidgetSetting(self.tr("Theme selector"), 'bottom-theme', (self.lstThemes, themeLabel)) self.bottomPanel.addWidgetSetting(self.tr("Word count"), 'bottom-wc', (self.lblWC, )) self.bottomPanel.addWidgetSetting(self.tr("Progress"), 'bottom-progress', (self.lblProgress, )) self.bottomPanel.addSetting(self.tr("Progress: Auto Show/Hide"), 'progress-auto-show', True) self.bottomPanel.addWidgetSetting(self.tr("Clock"), 'bottom-clock', (self.lblClock, )) self.bottomPanel.addSetting(self.tr("Clock: Show Seconds"), 'clock-show-seconds', True) self.bottomPanel.setAutoHideVariable('autohide-bottom') self.topPanel.setAutoHideVariable('autohide-top') self.leftPanel.setAutoHideVariable('autohide-left') # Set the screen to the same screen as the main window if screenNumber is not None: screenres = QDesktopWidget().screenGeometry(screenNumber) self.move(QPoint(screenres.x(), screenres.y())) self.resize(screenres.width(), screenres.height()) # Connection self._index.model().dataChanged.connect(self.dataChanged) # self.updateTheme() self.showFullScreen()
def __init__(self, parent=None, index=None, html=None, spellcheck=True, highlighting=False, dict="", autoResize=False): QTextEdit.__init__(self, parent) self._column = Outline.text.value self._index = None self._indexes = None self._model = None self._placeholderText = self.placeholderText() self._updating = False self._item = None self._highlighting = highlighting self._textFormat = "text" self.setAcceptRichText(False) # When setting up a theme, this becomes true. self._fromTheme = False self.spellcheck = spellcheck self.currentDict = dict if dict else settings.dict self.highlighter = None self.setAutoResize(autoResize) self._defaultBlockFormat = QTextBlockFormat() self._defaultCharFormat = QTextCharFormat() self.highlightWord = "" self.highligtCS = False self.defaultFontPointSize = qApp.font().pointSize() self._dict = None # self.document().contentsChanged.connect(self.submit, F.AUC) # Submit text changed only after 500ms without modifications self.updateTimer = QTimer() self.updateTimer.setInterval(500) self.updateTimer.setSingleShot(True) self.updateTimer.timeout.connect(self.submit) # self.updateTimer.timeout.connect(lambda: print("Timeout")) self.updateTimer.stop() self.document().contentsChanged.connect(self.updateTimer.start, F.AUC) # self.document().contentsChanged.connect(lambda: print("Document changed")) # self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed")) self.setEnabled(False) if index: self.setCurrentModelIndex(index) elif html: self.document().setHtml(html) self.setReadOnly(True) # Spellchecking if enchant and self.spellcheck: try: self._dict = enchant.Dict(self.currentDict if self.currentDict else self.getDefaultLocale()) except enchant.errors.DictNotFoundError: self.spellcheck = False else: self.spellcheck = False if self._highlighting and not self.highlighter: self.highlighter = basicHighlighter(self) self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def __init__(self): self.mainConf = novelwriter.CONFIG self.iconCache = GuiIcons(self) # Loaded Theme Settings # ===================== # Theme self.themeName = "" self.themeDescription = "" self.themeAuthor = "" self.themeCredit = "" self.themeUrl = "" self.themeLicense = "" self.themeLicenseUrl = "" # GUI self.statNone = [120, 120, 120] self.statUnsaved = [200, 15, 39] self.statSaved = [2, 133, 37] self.helpText = [0, 0, 0] # Loaded Syntax Settings # ====================== # Main self.syntaxName = "" self.syntaxDescription = "" self.syntaxAuthor = "" self.syntaxCredit = "" self.syntaxUrl = "" self.syntaxLicense = "" self.syntaxLicenseUrl = "" # Colours self.colBack = [255, 255, 255] self.colText = [0, 0, 0] self.colLink = [0, 0, 0] self.colHead = [0, 0, 0] self.colHeadH = [0, 0, 0] self.colEmph = [0, 0, 0] self.colDialN = [0, 0, 0] self.colDialD = [0, 0, 0] self.colDialS = [0, 0, 0] self.colHidden = [0, 0, 0] self.colKey = [0, 0, 0] self.colVal = [0, 0, 0] self.colSpell = [0, 0, 0] self.colError = [0, 0, 0] self.colRepTag = [0, 0, 0] self.colMod = [0, 0, 0] # Changeable Settings self.guiTheme = None self.guiSyntax = None self.syntaxFile = None self.cssFile = None self.guiFontDB = QFontDatabase() # Class Setup # =========== self._guiPalette = QPalette() self._themeList = [] self._syntaxList = [] self._availThemes = {} self._availSyntax = {} self._listConf(self._availSyntax, os.path.join(self.mainConf.dataPath, "syntax")) self._listConf(self._availSyntax, os.path.join(self.mainConf.assetPath, "syntax")) self._listConf(self._availThemes, os.path.join(self.mainConf.dataPath, "themes")) self._listConf(self._availThemes, os.path.join(self.mainConf.assetPath, "themes")) self.updateFont() self.updateTheme() self.iconCache.updateTheme() # Icon Functions self.getIcon = self.iconCache.getIcon self.getPixmap = self.iconCache.getPixmap self.getItemIcon = self.iconCache.getItemIcon self.loadDecoration = self.iconCache.loadDecoration # Extract Other Info self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX() self.guiScale = qApp.primaryScreen().logicalDotsPerInchX() / 96.0 self.mainConf.guiScale = self.guiScale logger.verbose("GUI DPI: %.1f", self.guiDPI) logger.verbose("GUI Scale: %.2f", self.guiScale) # Fonts self.guiFont = qApp.font() qMetric = QFontMetrics(self.guiFont) self.fontPointSize = self.guiFont.pointSizeF() self.fontPixelSize = int(round(qMetric.height())) self.baseIconSize = int(round(qMetric.ascent())) self.textNHeight = qMetric.boundingRect("N").height() self.textNWidth = qMetric.boundingRect("N").width() # Monospace Font self.guiFontFixed = QFont() self.guiFontFixed.setPointSizeF(0.95 * self.fontPointSize) self.guiFontFixed.setFamily( QFontDatabase.systemFont(QFontDatabase.FixedFont).family()) logger.verbose("GUI Font Family: %s", self.guiFont.family()) logger.verbose("GUI Font Point Size: %.2f", self.fontPointSize) logger.verbose("GUI Font Pixel Size: %d", self.fontPixelSize) logger.verbose("GUI Base Icon Size: %d", self.baseIconSize) logger.verbose("Text 'N' Height: %d", self.textNHeight) logger.verbose("Text 'N' Width: %d", self.textNWidth) return
def __init__(self, mainWindow): QWidget.__init__(self) self.setupUi(self) self.mw = mainWindow # UI for l in [ self.lblTitleGeneral, self.lblTitleGeneral_2, self.lblTitleViews, self.lblTitleLabels, self.lblTitleStatus, self.lblTitleFullscreen, ]: l.setStyleSheet(S.titleLabelSS()) icons = [ QIcon.fromTheme("configure"), QIcon.fromTheme("history-view"), QIcon.fromTheme("gnome-settings"), themeIcon("label"), themeIcon("status"), QIcon.fromTheme("preferences-desktop-theme") ] for i in range(self.lstMenu.count()): item = self.lstMenu.item(i) item.setSizeHint(QSize(item.sizeHint().width(), 42)) item.setTextAlignment(Qt.AlignCenter) if icons[i]: item.setIcon(icons[i]) self.lstMenu.setMaximumWidth(140) self.lstMenu.setMinimumWidth(140) # General self.cmbStyle.addItems(list(QStyleFactory.keys())) self.cmbStyle.setCurrentIndex([ i.lower() for i in list(QStyleFactory.keys()) ].index(qApp.style().objectName())) self.cmbStyle.currentIndexChanged[str].connect(self.setStyle) self.cmbTranslation.clear() tr = OrderedDict() tr["English"] = "" tr["Arabic (Saudi Arabia)"] = "manuskript_ar_SA.qm" tr["German"] = "manuskript_de.qm" tr["English (Great Britain)"] = "manuskript_en_GB.qm" tr["Spanish"] = "manuskript_es.qm" tr["Persian"] = "manuskript_fa.qm" tr["French"] = "manuskript_fr.qm" tr["Hungarian"] = "manuskript_hu.qm" tr["Indonesian"] = "manuskript_id.qm" tr["Italian"] = "manuskript_it.qm" tr["Japanese"] = "manuskript_ja.qm" tr["Korean"] = "manuskript_ko.qm" tr["Norwegian Bokmål"] = "manuskript_nb_NO.qm" tr["Dutch"] = "manuskript_nl.qm" tr["Polish"] = "manuskript_pl.qm" tr["Portuguese (Brazil)"] = "manuskript_pt_BR.qm" tr["Portuguese (Portugal)"] = "manuskript_pt_PT.qm" tr["Romanian"] = "manuskript_ro.qm" tr["Russian"] = "manuskript_ru.qm" tr["Svenska"] = "manuskript_sv.qm" tr["Turkish"] = "manuskript_tr.qm" tr["Ukrainian"] = "manuskript_uk.qm" tr["Chinese (Simplified)"] = "manuskript_zh_CN.qm" tr["Chinese (Traditional)"] = "manuskript_zh_HANT.qm" self.translations = tr for name in tr: self.cmbTranslation.addItem(name, tr[name]) sttgs = QSettings(qApp.organizationName(), qApp.applicationName()) if (sttgs.contains("applicationTranslation") and sttgs.value("applicationTranslation") in tr.values()): # Sets the correct translation self.cmbTranslation.setCurrentText([ i for i in tr if tr[i] == sttgs.value("applicationTranslation") ][0]) self.cmbTranslation.currentIndexChanged.connect(self.setTranslation) f = qApp.font() self.spnGeneralFontSize.setValue(f.pointSize()) self.spnGeneralFontSize.valueChanged.connect(self.setAppFontSize) self.txtAutoSave.setValidator(QIntValidator(0, 999, self)) self.txtAutoSaveNoChanges.setValidator(QIntValidator(0, 999, self)) self.chkAutoSave.setChecked(settings.autoSave) self.chkAutoSaveNoChanges.setChecked(settings.autoSaveNoChanges) self.txtAutoSave.setText(str(settings.autoSaveDelay)) self.txtAutoSaveNoChanges.setText(str(settings.autoSaveNoChangesDelay)) self.chkSaveOnQuit.setChecked(settings.saveOnQuit) self.chkSaveToZip.setChecked(settings.saveToZip) self.chkAutoSave.stateChanged.connect(self.saveSettingsChanged) self.chkAutoSaveNoChanges.stateChanged.connect( self.saveSettingsChanged) self.chkSaveOnQuit.stateChanged.connect(self.saveSettingsChanged) self.chkSaveToZip.stateChanged.connect(self.saveSettingsChanged) self.txtAutoSave.textEdited.connect(self.saveSettingsChanged) self.txtAutoSaveNoChanges.textEdited.connect(self.saveSettingsChanged) autoLoad, last = self.mw.welcome.getAutoLoadValues() self.chkAutoLoad.setChecked(autoLoad) self.chkAutoLoad.stateChanged.connect(self.saveSettingsChanged) # Revisions opt = settings.revisions self.chkRevisionsKeep.setChecked(opt["keep"]) self.chkRevisionsKeep.stateChanged.connect( self.revisionsSettingsChanged) self.chkRevisionRemove.setChecked(opt["smartremove"]) self.chkRevisionRemove.toggled.connect(self.revisionsSettingsChanged) self.spnRevisions10Mn.setValue(60 / opt["rules"][10 * 60]) self.spnRevisions10Mn.valueChanged.connect( self.revisionsSettingsChanged) self.spnRevisionsHour.setValue(60 * 10 / opt["rules"][60 * 60]) self.spnRevisionsHour.valueChanged.connect( self.revisionsSettingsChanged) self.spnRevisionsDay.setValue(60 * 60 / opt["rules"][60 * 60 * 24]) self.spnRevisionsDay.valueChanged.connect( self.revisionsSettingsChanged) self.spnRevisionsMonth.setValue(60 * 60 * 24 / opt["rules"][60 * 60 * 24 * 30]) self.spnRevisionsMonth.valueChanged.connect( self.revisionsSettingsChanged) self.spnRevisionsEternity.setValue(60 * 60 * 24 * 7 / opt["rules"][None]) self.spnRevisionsEternity.valueChanged.connect( self.revisionsSettingsChanged) # Views self.tabViews.setCurrentIndex(0) lst = ["Nothing", "POV", "Label", "Progress", "Compile"] for cmb in self.viewSettingsDatas(): item, part = self.viewSettingsDatas()[cmb] cmb.setCurrentIndex(lst.index(settings.viewSettings[item][part])) cmb.currentIndexChanged.connect(self.viewSettingsChanged) for chk in self.outlineColumnsData(): col = self.outlineColumnsData()[chk] chk.setChecked(col in settings.outlineViewColumns) chk.stateChanged.connect(self.outlineColumnsChanged) self.chkOutlinePOV.setVisible( settings.viewMode != "simple") # Hides checkbox if non-fiction view mode for item, what, value in [ (self.rdoTreeItemCount, "InfoFolder", "Count"), (self.rdoTreeWC, "InfoFolder", "WC"), (self.rdoTreeProgress, "InfoFolder", "Progress"), (self.rdoTreeSummary, "InfoFolder", "Summary"), (self.rdoTreeNothing, "InfoFolder", "Nothing"), (self.rdoTreeTextWC, "InfoText", "WC"), (self.rdoTreeTextProgress, "InfoText", "Progress"), (self.rdoTreeTextSummary, "InfoText", "Summary"), (self.rdoTreeTextNothing, "InfoText", "Nothing"), ]: item.setChecked(settings.viewSettings["Tree"][what] == value) item.toggled.connect(self.treeViewSettignsChanged) self.sldTreeIconSize.valueChanged.connect(self.treeViewSettignsChanged) self.sldTreeIconSize.valueChanged.connect( lambda v: self.lblTreeIconSize.setText("{}x{}".format(v, v))) self.sldTreeIconSize.setValue( settings.viewSettings["Tree"]["iconSize"]) self.rdoCorkOldStyle.setChecked(settings.corkStyle == "old") self.rdoCorkNewStyle.setChecked(settings.corkStyle == "new") self.rdoCorkNewStyle.toggled.connect(self.setCorkStyle) self.rdoCorkOldStyle.toggled.connect(self.setCorkStyle) self.populatesCmbBackgrounds(self.cmbCorkImage) self.setCorkImageDefault() self.updateCorkColor() self.cmbCorkImage.currentIndexChanged.connect(self.setCorkBackground) self.btnCorkColor.clicked.connect(self.setCorkColor) # Text editor opt = settings.textEditor # Font self.setButtonColor(self.btnEditorFontColor, opt["fontColor"]) self.btnEditorFontColor.clicked.connect(self.choseEditorFontColor) self.setButtonColor(self.btnEditorMisspelledColor, opt["misspelled"]) self.btnEditorMisspelledColor.clicked.connect( self.choseEditorMisspelledColor) self.setButtonColor(self.btnEditorBackgroundColor, opt["background"]) self.btnEditorBackgroundColor.clicked.connect( self.choseEditorBackgroundColor) self.chkEditorBackgroundTransparent.setChecked( opt["backgroundTransparent"]) self.chkEditorBackgroundTransparent.stateChanged.connect( self.updateEditorSettings) self.btnEditorColorDefault.clicked.connect(self.restoreEditorColors) f = QFont() f.fromString(opt["font"]) self.cmbEditorFontFamily.setCurrentFont(f) self.cmbEditorFontFamily.currentFontChanged.connect( self.updateEditorSettings) self.spnEditorFontSize.setValue(f.pointSize()) self.spnEditorFontSize.valueChanged.connect(self.updateEditorSettings) # Cursor self.chkEditorCursorWidth.setChecked(opt["cursorWidth"] != 1) self.chkEditorCursorWidth.stateChanged.connect( self.updateEditorSettings) self.spnEditorCursorWidth.setValue( opt["cursorWidth"] if opt["cursorWidth"] != 1 else 9) self.spnEditorCursorWidth.valueChanged.connect( self.updateEditorSettings) self.spnEditorCursorWidth.setEnabled(opt["cursorWidth"] != 1) self.chkEditorNoBlinking.setChecked(opt["cursorNotBlinking"]) self.chkEditorNoBlinking.stateChanged.connect( self.setApplicationCursorBlinking) self.chkEditorTypeWriterMode.setChecked(opt["alwaysCenter"]) self.chkEditorTypeWriterMode.stateChanged.connect( self.updateEditorSettings) self.cmbEditorFocusMode.setCurrentIndex( 0 if not opt["focusMode"] else 1 if opt["focusMode"] == "sentence" else 2 if opt["focusMode"] == "line" else 3) self.cmbEditorFocusMode.currentIndexChanged.connect( self.updateEditorSettings) # Text areas self.chkEditorMaxWidth.setChecked(opt["maxWidth"] != 0) self.chkEditorMaxWidth.stateChanged.connect(self.updateEditorSettings) self.spnEditorMaxWidth.setEnabled(opt["maxWidth"] != 0) self.spnEditorMaxWidth.setValue(500 if opt["maxWidth"] == 0 else opt["maxWidth"]) self.spnEditorMaxWidth.valueChanged.connect(self.updateEditorSettings) self.spnEditorMarginsLR.setValue(opt["marginsLR"]) self.spnEditorMarginsLR.valueChanged.connect(self.updateEditorSettings) self.spnEditorMarginsTB.setValue(opt["marginsTB"]) self.spnEditorMarginsTB.valueChanged.connect(self.updateEditorSettings) # Paragraphs self.cmbEditorAlignment.setCurrentIndex(opt["textAlignment"]) self.cmbEditorAlignment.currentIndexChanged.connect( self.updateEditorSettings) self.cmbEditorLineSpacing.setCurrentIndex( 0 if opt["lineSpacing"] == 100 else 1 if opt["lineSpacing"] == 150 else 2 if opt["lineSpacing"] == 200 else 3) self.cmbEditorLineSpacing.currentIndexChanged.connect( self.updateEditorSettings) self.spnEditorLineSpacing.setValue(opt["lineSpacing"]) self.spnEditorLineSpacing.valueChanged.connect( self.updateEditorSettings) self.spnEditorLineSpacing.setEnabled( opt["lineSpacing"] not in [100, 150, 200]) self.spnEditorLineSpacing.valueChanged.connect( self.updateEditorSettings) self.spnEditorTabWidth.setValue(opt["tabWidth"]) self.spnEditorTabWidth.valueChanged.connect(self.updateEditorSettings) self.chkEditorIndent.setChecked(opt["indent"]) self.chkEditorIndent.stateChanged.connect(self.updateEditorSettings) self.spnEditorParaAbove.setValue(opt["spacingAbove"]) self.spnEditorParaAbove.valueChanged.connect(self.updateEditorSettings) self.spnEditorParaBelow.setValue(opt["spacingBelow"]) self.spnEditorParaBelow.valueChanged.connect(self.updateEditorSettings) self.timerUpdateWidgets = QTimer() self.timerUpdateWidgets.setSingleShot(True) self.timerUpdateWidgets.setInterval(250) self.timerUpdateWidgets.timeout.connect(self.updateAllWidgets) # Labels self.lstLabels.setModel(self.mw.mdlLabels) self.lstLabels.setRowHidden(0, True) self.lstLabels.clicked.connect(self.updateLabelColor) self.btnLabelAdd.clicked.connect(self.addLabel) self.btnLabelRemove.clicked.connect(self.removeLabel) self.btnLabelColor.clicked.connect(self.setLabelColor) # Statuses self.lstStatus.setModel(self.mw.mdlStatus) self.lstStatus.setRowHidden(0, True) self.btnStatusAdd.clicked.connect(self.addStatus) self.btnStatusRemove.clicked.connect(self.removeStatus) # Fullscreen self._editingTheme = None self.btnThemeEditOK.setIcon(qApp.style().standardIcon( QStyle.SP_DialogApplyButton)) self.btnThemeEditOK.clicked.connect(self.saveTheme) self.btnThemeEditCancel.setIcon(qApp.style().standardIcon( QStyle.SP_DialogCancelButton)) self.btnThemeEditCancel.clicked.connect(self.cancelEdit) self.cmbThemeEdit.currentIndexChanged.connect( self.themeEditStack.setCurrentIndex) self.cmbThemeEdit.setCurrentIndex(0) self.cmbThemeEdit.currentIndexChanged.emit(0) self.themeStack.setCurrentIndex(0) self.lstThemes.currentItemChanged.connect(self.themeSelected) self.populatesThemesList() self.btnThemeAdd.clicked.connect(self.newTheme) self.btnThemeEdit.clicked.connect(self.editTheme) self.btnThemeRemove.clicked.connect(self.removeTheme) self.timerUpdateFSPreview = QTimer() self.timerUpdateFSPreview.setSingleShot(True) self.timerUpdateFSPreview.setInterval(250) self.timerUpdateFSPreview.timeout.connect(self.updatePreview)
def prepare(tests=False): app = QApplication(sys.argv) app.setOrganizationName("manuskript"+("_tests" if tests else "")) app.setOrganizationDomain("www.theologeek.ch") app.setApplicationName("manuskript"+("_tests" if tests else "")) app.setApplicationVersion(getVersion()) print("Running manuskript version {}.".format(getVersion())) icon = QIcon() for i in [16, 32, 64, 128, 256, 512]: icon.addFile(appPath("icons/Manuskript/icon-{}px.png".format(i))) qApp.setWindowIcon(icon) app.setStyle("Fusion") # Load style from QSettings settings = QSettings(app.organizationName(), app.applicationName()) if settings.contains("applicationStyle"): style = settings.value("applicationStyle") app.setStyle(style) # Translation process locale = QLocale.system().name() appTranslator = QTranslator(app) # By default: locale def extractLocale(filename): # len("manuskript_") = 13, len(".qm") = 3 return filename[11:-3] if len(filename) >= 16 else "" def tryLoadTranslation(translation, source): if appTranslator.load(appPath(os.path.join("i18n", translation))): app.installTranslator(appTranslator) print(app.tr("Loaded translation from {}: {}.").format(source, translation)) return True else: print(app.tr("Note: No translator found or loaded from {} for locale {}."). format(source, extractLocale(translation))) return False # Load translation from settings translation = "" if settings.contains("applicationTranslation"): translation = settings.value("applicationTranslation") print("Found translation in settings:", translation) if (translation != "" and not tryLoadTranslation(translation, "settings")) or translation == "": # load from settings failed or not set, fallback translation = "manuskript_{}.qm".format(locale) tryLoadTranslation(translation, "system locale") QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + [appPath("icons")]) QIcon.setThemeName("NumixMsk") # Font siue if settings.contains("appFontSize"): f = qApp.font() f.setPointSize(settings.value("appFontSize", type=int)) app.setFont(f) # Main window from manuskript.mainWindow import MainWindow MW = MainWindow() # We store the system default cursor flash time to be able to restore it # later if necessary MW._defaultCursorFlashTime = qApp.cursorFlashTime() # Command line project if len(sys.argv) > 1 and sys.argv[1][-4:] == ".msk": if os.path.exists(sys.argv[1]): path = os.path.abspath(sys.argv[1]) MW._autoLoadProject = path return app, MW
def __init__(self, index, parent=None): QWidget.__init__(self, parent) self._background = None self._index = index self._theme = findThemePath(settings.fullScreenTheme) self._themeDatas = loadThemeDatas(self._theme) self.setMouseTracking(True) self._geometries = {} # Text editor self.editor = textEditView(self, index=index, spellcheck=settings.spellcheck, highlighting=True, dict=settings.dict) self.editor.setFrameStyle(QFrame.NoFrame) self.editor.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.editor.installEventFilter(self) self.editor.setMouseTracking(True) self.editor.setVerticalScrollBar(myScrollBar()) self.scrollBar = self.editor.verticalScrollBar() self.scrollBar.setParent(self) # Top Panel self.topPanel = myPanel(parent=self) # self.topPanel.layout().addStretch(1) # Spell checking if enchant: self.btnSpellCheck = QPushButton(self) self.btnSpellCheck.setFlat(True) self.btnSpellCheck.setIcon(QIcon.fromTheme("tools-check-spelling")) self.btnSpellCheck.setCheckable(True) self.btnSpellCheck.setChecked(self.editor.spellcheck) self.btnSpellCheck.toggled.connect(self.editor.toggleSpellcheck) self.topPanel.layout().addWidget(self.btnSpellCheck) self.topPanel.layout().addStretch(1) # Formatting self.textFormat = textFormat(self) self.topPanel.layout().addWidget(self.textFormat) self.topPanel.layout().addStretch(1) self.btnClose = QPushButton(self) self.btnClose.setIcon(qApp.style().standardIcon(QStyle.SP_DialogCloseButton)) self.btnClose.clicked.connect(self.close) self.btnClose.setFlat(True) self.topPanel.layout().addWidget(self.btnClose) # Left Panel self._locked = False self.leftPanel = myPanel(vertical=True, parent=self) self.locker = locker(self) self.locker.lockChanged.connect(self.setLocked) self.leftPanel.layout().addWidget(self.locker) # Bottom Panel self.bottomPanel = myPanel(parent=self) self.bottomPanel.layout().addSpacing(24) self.lstThemes = QComboBox(self) self.lstThemes.setAttribute(Qt.WA_TranslucentBackground) paths = allPaths("resources/themes") for p in paths: lst = [i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme"] for t in lst: themeIni = os.path.join(p, t) self.lstThemes.addItem(os.path.splitext(t)[0]) self.lstThemes.setCurrentText(settings.fullScreenTheme) self.lstThemes.currentTextChanged.connect(self.setTheme) self.lstThemes.setMaximumSize(QSize(300, QFontMetrics(qApp.font()).height())) self.bottomPanel.layout().addWidget(QLabel(self.tr("Theme:"), self)) self.bottomPanel.layout().addWidget(self.lstThemes) self.bottomPanel.layout().addStretch(1) self.lblProgress = QLabel(self) self.lblProgress.setMaximumSize(QSize(200, 14)) self.lblProgress.setMinimumSize(QSize(100, 14)) self.lblWC = QLabel(self) self.bottomPanel.layout().addWidget(self.lblWC) self.bottomPanel.layout().addWidget(self.lblProgress) self.updateStatusBar() self.bottomPanel.layout().addSpacing(24) # Connection self._index.model().dataChanged.connect(self.dataChanged) # self.updateTheme() self.showFullScreen()
def on_spin_box_font_size_editing_finished(self): constants.SETTINGS.setValue("font_size", self.ui.spinBoxFontSize.value()) font = qApp.font() font.setPointSize(self.ui.spinBoxFontSize.value()) qApp.setFont(font)
def on_spin_box_font_size_editing_finished(self): settings.write("font_size", self.ui.spinBoxFontSize.value()) font = qApp.font() font.setPointSize(self.ui.spinBoxFontSize.value()) qApp.setFont(font)
saveOnQuit = True outlineViewColumns = [Outline.title, Outline.POV, Outline.status, Outline.compile, Outline.wordCount, Outline.goal, Outline.goalPercentage, Outline.label] corkBackground = { "color": "#926239", "image": "writingdesk" } corkStyle = "new" defaultTextType = "md" fullScreenTheme = "spacedreams" textEditor = { "background": "", "fontColor": "", "font": qApp.font().toString(), "misspelled": "#F00", "lineSpacing": 100, "tabWidth": 20, "indent": False, "spacingAbove": 5, "spacingBelow": 5, "textAlignment": 0, # 0: left, 1: center, 2: right, 3: justify "cursorWidth": 1, "cursorNotBlinking": False, "maxWidth": 600, "marginsLR": 0, "marginsTB": 20, "backgroundTransparent": False, "alwaysCenter": False, "focusMode": False # "line", "paragraph", "sentence"
def __init__(self, mainWindow): QWidget.__init__(self) self.setupUi(self) self.mw = mainWindow # UI for l in [self.lblTitleGeneral, self.lblTitleGeneral_2, self.lblTitleViews, self.lblTitleLabels, self.lblTitleStatus, self.lblTitleFullscreen, ]: l.setStyleSheet(S.titleLabelSS()) icons = [QIcon.fromTheme("configure"), QIcon.fromTheme("history-view"), QIcon.fromTheme("gnome-settings"), themeIcon("label"), themeIcon("status"), QIcon.fromTheme("preferences-desktop-theme") ] for i in range(self.lstMenu.count()): item = self.lstMenu.item(i) item.setSizeHint(QSize(item.sizeHint().width(), 42)) item.setTextAlignment(Qt.AlignCenter) if icons[i]: item.setIcon(icons[i]) self.lstMenu.setMaximumWidth(140) self.lstMenu.setMinimumWidth(140) # General self.cmbStyle.addItems(list(QStyleFactory.keys())) self.cmbStyle.setCurrentIndex( [i.lower() for i in list(QStyleFactory.keys())] .index(qApp.style().objectName())) self.cmbStyle.currentIndexChanged[str].connect(self.setStyle) self.cmbTranslation.clear() tr = OrderedDict() tr["English"] = "" tr["Arabic (Saudi Arabia)"] = "manuskript_ar_SA.qm" tr["Deutsch"] = "manuskript_de.qm" tr["Español"] = "manuskript_es.qm" tr["Français"] = "manuskript_fr.qm" tr["Hungarian"] = "manuskript_hu.qm" tr["Indonesian"] = "manuskript_id.qm" tr["Italian"] = "manuskript_it.qm" tr["Norwegian Bokmål"] = "manuskript_nb_NO.qm" tr["Dutch"] = "manuskript_nl.qm" tr["Polish"] = "manuskript_pl.qm" tr["Portuguese (Brazil)"] = "manuskript_pt_BR.qm" tr["Portuguese (Portugal)"] = "manuskript_pt_PT.qm" tr["Russian"] = "manuskript_ru.qm" tr["Svenska"] = "manuskript_sv.qm" tr["Ukranian"] = "manuskript_uk.qm" tr["Chinese (Simplified)"] = "manuskript_zh_CN.qm" self.translations = tr for name in tr: self.cmbTranslation.addItem(name, tr[name]) sttgs = QSettings(qApp.organizationName(), qApp.applicationName()) if (sttgs.contains("applicationTranslation") and sttgs.value("applicationTranslation") in tr.values()): # Sets the correct translation self.cmbTranslation.setCurrentText( [i for i in tr if tr[i] == sttgs.value("applicationTranslation")][0]) self.cmbTranslation.currentIndexChanged.connect(self.setTranslation) f = qApp.font() self.spnGeneralFontSize.setValue(f.pointSize()) self.spnGeneralFontSize.valueChanged.connect(self.setAppFontSize) self.txtAutoSave.setValidator(QIntValidator(0, 999, self)) self.txtAutoSaveNoChanges.setValidator(QIntValidator(0, 999, self)) self.chkAutoSave.setChecked(settings.autoSave) self.chkAutoSaveNoChanges.setChecked(settings.autoSaveNoChanges) self.txtAutoSave.setText(str(settings.autoSaveDelay)) self.txtAutoSaveNoChanges.setText(str(settings.autoSaveNoChangesDelay)) self.chkSaveOnQuit.setChecked(settings.saveOnQuit) self.chkSaveToZip.setChecked(settings.saveToZip) self.chkAutoSave.stateChanged.connect(self.saveSettingsChanged) self.chkAutoSaveNoChanges.stateChanged.connect(self.saveSettingsChanged) self.chkSaveOnQuit.stateChanged.connect(self.saveSettingsChanged) self.chkSaveToZip.stateChanged.connect(self.saveSettingsChanged) self.txtAutoSave.textEdited.connect(self.saveSettingsChanged) self.txtAutoSaveNoChanges.textEdited.connect(self.saveSettingsChanged) autoLoad, last = self.mw.welcome.getAutoLoadValues() self.chkAutoLoad.setChecked(autoLoad) self.chkAutoLoad.stateChanged.connect(self.saveSettingsChanged) # Revisions opt = settings.revisions self.chkRevisionsKeep.setChecked(opt["keep"]) self.chkRevisionsKeep.stateChanged.connect(self.revisionsSettingsChanged) self.chkRevisionRemove.setChecked(opt["smartremove"]) self.chkRevisionRemove.toggled.connect(self.revisionsSettingsChanged) self.spnRevisions10Mn.setValue(60 / opt["rules"][10 * 60]) self.spnRevisions10Mn.valueChanged.connect(self.revisionsSettingsChanged) self.spnRevisionsHour.setValue(60 * 10 / opt["rules"][60 * 60]) self.spnRevisionsHour.valueChanged.connect(self.revisionsSettingsChanged) self.spnRevisionsDay.setValue(60 * 60 / opt["rules"][60 * 60 * 24]) self.spnRevisionsDay.valueChanged.connect(self.revisionsSettingsChanged) self.spnRevisionsMonth.setValue(60 * 60 * 24 / opt["rules"][60 * 60 * 24 * 30]) self.spnRevisionsMonth.valueChanged.connect(self.revisionsSettingsChanged) self.spnRevisionsEternity.setValue(60 * 60 * 24 * 7 / opt["rules"][None]) self.spnRevisionsEternity.valueChanged.connect(self.revisionsSettingsChanged) # Views self.tabViews.setCurrentIndex(0) lst = ["Nothing", "POV", "Label", "Progress", "Compile"] for cmb in self.viewSettingsDatas(): item, part = self.viewSettingsDatas()[cmb] cmb.setCurrentIndex(lst.index(settings.viewSettings[item][part])) cmb.currentIndexChanged.connect(self.viewSettingsChanged) for chk in self.outlineColumnsData(): col = self.outlineColumnsData()[chk] chk.setChecked(col in settings.outlineViewColumns) chk.stateChanged.connect(self.outlineColumnsChanged) self.chkOutlinePOV.setVisible(settings.viewMode != "simple") # Hides checkbox if non-fiction view mode for item, what, value in [ (self.rdoTreeItemCount, "InfoFolder", "Count"), (self.rdoTreeWC, "InfoFolder", "WC"), (self.rdoTreeProgress, "InfoFolder", "Progress"), (self.rdoTreeSummary, "InfoFolder", "Summary"), (self.rdoTreeNothing, "InfoFolder", "Nothing"), (self.rdoTreeTextWC, "InfoText", "WC"), (self.rdoTreeTextProgress, "InfoText", "Progress"), (self.rdoTreeTextSummary, "InfoText", "Summary"), (self.rdoTreeTextNothing, "InfoText", "Nothing"), ]: item.setChecked(settings.viewSettings["Tree"][what] == value) item.toggled.connect(self.treeViewSettignsChanged) self.sldTreeIconSize.valueChanged.connect(self.treeViewSettignsChanged) self.sldTreeIconSize.valueChanged.connect( lambda v: self.lblTreeIconSize.setText("{}x{}".format(v, v))) self.sldTreeIconSize.setValue(settings.viewSettings["Tree"]["iconSize"]) self.rdoCorkOldStyle.setChecked(settings.corkStyle == "old") self.rdoCorkNewStyle.setChecked(settings.corkStyle == "new") self.rdoCorkNewStyle.toggled.connect(self.setCorkStyle) self.rdoCorkOldStyle.toggled.connect(self.setCorkStyle) self.populatesCmbBackgrounds(self.cmbCorkImage) self.setCorkImageDefault() self.updateCorkColor() self.cmbCorkImage.currentIndexChanged.connect(self.setCorkBackground) self.btnCorkColor.clicked.connect(self.setCorkColor) # Text editor opt = settings.textEditor # Font self.setButtonColor(self.btnEditorFontColor, opt["fontColor"]) self.btnEditorFontColor.clicked.connect(self.choseEditorFontColor) self.setButtonColor(self.btnEditorMisspelledColor, opt["misspelled"]) self.btnEditorMisspelledColor.clicked.connect(self.choseEditorMisspelledColor) self.setButtonColor(self.btnEditorBackgroundColor, opt["background"]) self.btnEditorBackgroundColor.clicked.connect(self.choseEditorBackgroundColor) self.chkEditorBackgroundTransparent.setChecked(opt["backgroundTransparent"]) self.chkEditorBackgroundTransparent.stateChanged.connect(self.updateEditorSettings) self.btnEditorColorDefault.clicked.connect(self.restoreEditorColors) f = QFont() f.fromString(opt["font"]) self.cmbEditorFontFamily.setCurrentFont(f) self.cmbEditorFontFamily.currentFontChanged.connect(self.updateEditorSettings) self.spnEditorFontSize.setValue(f.pointSize()) self.spnEditorFontSize.valueChanged.connect(self.updateEditorSettings) # Cursor self.chkEditorCursorWidth.setChecked(opt["cursorWidth"] != 1) self.chkEditorCursorWidth.stateChanged.connect(self.updateEditorSettings) self.spnEditorCursorWidth.setValue(opt["cursorWidth"] if opt["cursorWidth"] != 1 else 9) self.spnEditorCursorWidth.valueChanged.connect(self.updateEditorSettings) self.spnEditorCursorWidth.setEnabled(opt["cursorWidth"] != 1) self.chkEditorNoBlinking.setChecked(opt["cursorNotBlinking"]) self.chkEditorNoBlinking.stateChanged.connect(self.setApplicationCursorBlinking) self.chkEditorTypeWriterMode.setChecked(opt["alwaysCenter"]) self.chkEditorTypeWriterMode.stateChanged.connect(self.updateEditorSettings) self.cmbEditorFocusMode.setCurrentIndex( 0 if not opt["focusMode"] else 1 if opt["focusMode"] == "sentence" else 2 if opt["focusMode"] == "line" else 3) self.cmbEditorFocusMode.currentIndexChanged.connect(self.updateEditorSettings) # Text areas self.chkEditorMaxWidth.setChecked(opt["maxWidth"] != 0) self.chkEditorMaxWidth.stateChanged.connect(self.updateEditorSettings) self.spnEditorMaxWidth.setEnabled(opt["maxWidth"] != 0) self.spnEditorMaxWidth.setValue(500 if opt["maxWidth"] == 0 else opt["maxWidth"]) self.spnEditorMaxWidth.valueChanged.connect(self.updateEditorSettings) self.spnEditorMarginsLR.setValue(opt["marginsLR"]) self.spnEditorMarginsLR.valueChanged.connect(self.updateEditorSettings) self.spnEditorMarginsTB.setValue(opt["marginsTB"]) self.spnEditorMarginsTB.valueChanged.connect(self.updateEditorSettings) # Paragraphs self.cmbEditorAlignment.setCurrentIndex(opt["textAlignment"]) self.cmbEditorAlignment.currentIndexChanged.connect(self.updateEditorSettings) self.cmbEditorLineSpacing.setCurrentIndex( 0 if opt["lineSpacing"] == 100 else 1 if opt["lineSpacing"] == 150 else 2 if opt["lineSpacing"] == 200 else 3) self.cmbEditorLineSpacing.currentIndexChanged.connect(self.updateEditorSettings) self.spnEditorLineSpacing.setValue(opt["lineSpacing"]) self.spnEditorLineSpacing.valueChanged.connect(self.updateEditorSettings) self.spnEditorLineSpacing.setEnabled(opt["lineSpacing"] not in [100, 150, 200]) self.spnEditorLineSpacing.valueChanged.connect(self.updateEditorSettings) self.spnEditorTabWidth.setValue(opt["tabWidth"]) self.spnEditorTabWidth.valueChanged.connect(self.updateEditorSettings) self.chkEditorIndent.setChecked(opt["indent"]) self.chkEditorIndent.stateChanged.connect(self.updateEditorSettings) self.spnEditorParaAbove.setValue(opt["spacingAbove"]) self.spnEditorParaAbove.valueChanged.connect(self.updateEditorSettings) self.spnEditorParaBelow.setValue(opt["spacingBelow"]) self.spnEditorParaBelow.valueChanged.connect(self.updateEditorSettings) self.timerUpdateWidgets = QTimer() self.timerUpdateWidgets.setSingleShot(True) self.timerUpdateWidgets.setInterval(250) self.timerUpdateWidgets.timeout.connect(self.updateAllWidgets) # Labels self.lstLabels.setModel(self.mw.mdlLabels) self.lstLabels.setRowHidden(0, True) self.lstLabels.clicked.connect(self.updateLabelColor) self.btnLabelAdd.clicked.connect(self.addLabel) self.btnLabelRemove.clicked.connect(self.removeLabel) self.btnLabelColor.clicked.connect(self.setLabelColor) # Statuses self.lstStatus.setModel(self.mw.mdlStatus) self.lstStatus.setRowHidden(0, True) self.btnStatusAdd.clicked.connect(self.addStatus) self.btnStatusRemove.clicked.connect(self.removeStatus) # Fullscreen self._editingTheme = None self.btnThemeEditOK.setIcon(qApp.style().standardIcon(QStyle.SP_DialogApplyButton)) self.btnThemeEditOK.clicked.connect(self.saveTheme) self.btnThemeEditCancel.setIcon(qApp.style().standardIcon(QStyle.SP_DialogCancelButton)) self.btnThemeEditCancel.clicked.connect(self.cancelEdit) self.cmbThemeEdit.currentIndexChanged.connect(self.themeEditStack.setCurrentIndex) self.cmbThemeEdit.setCurrentIndex(0) self.cmbThemeEdit.currentIndexChanged.emit(0) self.themeStack.setCurrentIndex(0) self.lstThemes.currentItemChanged.connect(self.themeSelected) self.populatesThemesList() self.btnThemeAdd.clicked.connect(self.newTheme) self.btnThemeEdit.clicked.connect(self.editTheme) self.btnThemeRemove.clicked.connect(self.removeTheme) self.timerUpdateFSPreview = QTimer() self.timerUpdateFSPreview.setSingleShot(True) self.timerUpdateFSPreview.setInterval(250) self.timerUpdateFSPreview.timeout.connect(self.updatePreview)
def __init__(self, parent: QWidget = None): super().__init__(parent) self._size: int = os.cpu_count() if self._size is None: self._size = 2 self._processes_pool = [] self._manager = ImportManager(self._size) self._max_progress: int = 0 self._timer: QTimer = QTimer() self._confuser = ConfuseWindow(self) self._date_start_cache = None self._tesseract_path_cache = None self._poppler_path_cache = None # window settings self.setWindowFlag(Qt.WindowContextHelpButtonHint, False) self.setWindowTitle(self.tr("Import window")) # list widget with files self.list_widget = QListWidget() self.list_widget.setSortingEnabled(True) self.layout_open_folder = QHBoxLayout() self.label_find = QLabel(self.tr("Schedules: ") + "0") self.layout_open_folder.addWidget(self.label_find) self.layout_open_folder.addStretch(1) self.push_button_open_folder = QToolButton() self.layout_open_folder.addWidget(self.push_button_open_folder) self.push_button_open_folder.setText(self.tr("Open folder")) self.push_button_open_folder.setPopupMode(QToolButton.MenuButtonPopup) self.action_open_files = QAction(self.tr("Open files")) self.push_button_open_folder.addAction(self.action_open_files) # main progress self.group_box_main_progress = QGroupBox(self.tr("Main progress")) self.layout_main_progress = QVBoxLayout(self.group_box_main_progress) self.process_bar_main = QProgressBar() self.layout_main_progress.addWidget(self.process_bar_main) self.layout_start_process = QHBoxLayout() self.layout_start_process.addStretch(1) self.push_button_import = QPushButton(self.tr("Import")) self.layout_start_process.addWidget(self.push_button_import) self.push_button_stop = QPushButton(self.tr("Stop")) self.layout_start_process.addWidget(self.push_button_stop) self.push_button_stop.setEnabled(False) self.layout_main_progress.addLayout(self.layout_start_process) # threads process self.group_box_threads = QGroupBox(self.tr("Threads")) self.grid_layout_threads = QGridLayout(self.group_box_threads) self._progresses_bars = [] rows = self._size // 2 columns = 2 for i in range(rows): for j in range(columns): progress_bar = QProgressBar() progress_bar.setTextVisible(True) self._progresses_bars.append(progress_bar) self.grid_layout_threads.addWidget(progress_bar, i, j) # options self.group_box_options = QGroupBox(self.tr("Options")) self.form_layout_options = QFormLayout(self.group_box_options) self.check_box_weekly = QCheckBox(self.tr("Create weekly schedule")) self.form_layout_options.addRow(self.check_box_weekly) self.check_box_full = QCheckBox(self.tr("Create full schedule")) self.form_layout_options.addRow(self.check_box_full) self.check_box_debug_img = QCheckBox(self.tr("Create debug image")) self.form_layout_options.addRow(self.check_box_debug_img) self.spin_box_dpi = QSpinBox() self.form_layout_options.addRow(self.tr("DPI"), self.spin_box_dpi) self.combo_box_tesseract_path = QComboBox() self.form_layout_options.addRow(self.tr("Tesseract path"), self.combo_box_tesseract_path) self.combo_box_poppler_path = QComboBox() self.form_layout_options.addRow(self.tr("Poppler path"), self.combo_box_poppler_path) self.check_box_debug_img.setChecked(True) self.check_box_debug_img.setEnabled(False) self.spin_box_dpi.setRange(200, 800) self.spin_box_dpi.setValue(500) self.combo_box_tesseract_path.addItem( self.tr("<select tesseract path>")) self.combo_box_tesseract_path.addItem("Default", "tesseract") self.combo_box_tesseract_path.setCurrentIndex(1) self._tesseract_path_cache = self.combo_box_tesseract_path.currentText( ) self.combo_box_poppler_path.addItem(self.tr("<select poppler path>")) self.combo_box_poppler_path.addItem("Default", None) self.combo_box_poppler_path.setCurrentIndex(1) self._poppler_path_cache = self.combo_box_poppler_path.currentText() # font edit self.group_box_font = QGroupBox(self.tr("Font settings")) self.form_layout_font = QFormLayout(self.group_box_font) self.label_font = QLabel(self.tr("Font")) self.form_layout_font.setWidget(0, QFormLayout.LabelRole, self.label_font) self.combo_box_font = QComboBox() self.form_layout_font.setWidget(0, QFormLayout.FieldRole, self.combo_box_font) self.label_encoding = QLabel(self.tr("Encoding")) self.form_layout_font.setWidget(1, QFormLayout.LabelRole, self.label_encoding) self.combo_box_encoding = QComboBox() self.form_layout_font.setWidget(1, QFormLayout.FieldRole, self.combo_box_encoding) for font_name, font_path in util.get_fonts(): self.combo_box_font.addItem(font_name, font_path) self.combo_box_font.setCurrentText(qApp.font().family()) self.combo_box_font.setEditable(True) self.combo_box_encoding.addItem("UTF-8") self.combo_box_encoding.addItem("Latin-1") self.combo_box_encoding.addItem("Windows-1252") # date edit self.group_box_date = QGroupBox(self.tr("Date settings")) self.form_layout_date = QFormLayout(self.group_box_date) self.label_date_start = QLabel(self.tr("Start")) self.form_layout_date.setWidget(0, QFormLayout.LabelRole, self.label_date_start) self.date_edit_start = QDateEdit() self.form_layout_date.setWidget(0, QFormLayout.FieldRole, self.date_edit_start) self.label_date_end = QLabel(self.tr("End")) self.form_layout_date.setWidget(1, QFormLayout.LabelRole, self.label_date_end) self.date_edit_end = QDateEdit() self.form_layout_date.setWidget(1, QFormLayout.FieldRole, self.date_edit_end) self.date_edit_start.setCalendarPopup(True) self.date_edit_end.setCalendarPopup(True) if QDate.currentDate().day() < QDate.currentDate().dayOfYear() / 2: date = QDate(QDate.currentDate().year(), 2, 1) else: date = QDate(QDate.currentDate().year(), 9, 1) self._date_start_cache = date.addDays(8 - date.dayOfWeek()) self.date_edit_start.setDate(self._date_start_cache) self.date_edit_end.setMinimumDate(self._date_start_cache.addDays(7)) self.date_edit_end.setDate(self._date_start_cache.addDays(16 * 7)) # subgroup edit self.group_box_subgroup = QGroupBox(self.tr("Subgroup settings")) self.form_layout_subgroup = QFormLayout(self.group_box_subgroup) self.label_color_a = QLabel(self.tr("Color A")) self.form_layout_subgroup.setWidget(0, QFormLayout.LabelRole, self.label_color_a) self.combo_box_color_a = QComboBox() self.form_layout_subgroup.setWidget(0, QFormLayout.FieldRole, self.combo_box_color_a) self.label_color_b = QLabel(self.tr("Color B")) self.form_layout_subgroup.setWidget(1, QFormLayout.LabelRole, self.label_color_b) self.combo_box_color_b = QComboBox() self.form_layout_subgroup.setWidget(1, QFormLayout.FieldRole, self.combo_box_color_b) self.label_pattern_a_b = QLabel(self.tr("Pattern A and B")) self.form_layout_subgroup.setWidget(2, QFormLayout.LabelRole, self.label_pattern_a_b) self.combo_box_pattern_a_b = QComboBox() self.form_layout_subgroup.setWidget(2, QFormLayout.FieldRole, self.combo_box_pattern_a_b) self.add_standard_colors(self.combo_box_color_a) self.add_standard_colors(self.combo_box_color_b) self.combo_box_color_a.setCurrentIndex(9) # lime self.combo_box_color_b.setCurrentIndex(15) # yellow self.combo_box_pattern_a_b.addItem(self.tr("Chess order")) self.combo_box_pattern_a_b.setEnabled(False) # navigate self.layout_navigate = QHBoxLayout() self.layout_navigate.addStretch(1) self.push_button_ok = QPushButton(self.tr("OK")) self.layout_navigate.addWidget(self.push_button_ok) self.push_button_cancel = QPushButton(self.tr("Cancel")) self.layout_navigate.addWidget(self.push_button_cancel) # layout setup self.layout_left = QVBoxLayout() self.layout_left.addWidget(self.list_widget) self.layout_left.addLayout(self.layout_open_folder) self.layout_right = QVBoxLayout() self.layout_right.addWidget(self.group_box_main_progress) self.layout_right.addWidget(self.group_box_threads) self.layout_down = QGridLayout() self.layout_down.addWidget(self.group_box_options, 0, 0) self.layout_down.addWidget(self.group_box_font, 1, 0) self.layout_down.addWidget(self.group_box_date, 0, 1) self.layout_down.addWidget(self.group_box_subgroup, 1, 1) self.layout_right.addLayout(self.layout_down) self.layout_right.addStretch(1) self.layout_right.addLayout(self.layout_navigate) self.layout_main = QHBoxLayout() self.layout_main.addLayout(self.layout_left, 1) self.layout_main.addLayout(self.layout_right, 2) self.setLayout(self.layout_main) # connections self._timer.timeout.connect(self.check_processes) self.push_button_open_folder.clicked.connect(self.open_folder_clicked) self.action_open_files.triggered.connect(self.open_files_clicked) self.push_button_import.clicked.connect( self.push_button_import_clicked) self.push_button_stop.clicked.connect(self.push_button_stop_clicked) self.check_box_weekly.clicked.connect(self.check_box_weekly_clicked) self.combo_box_tesseract_path.activated.connect( self.combo_box_tesseract_path_clicked) self.combo_box_poppler_path.activated.connect( self.combo_box_poppler_path_clicked) self.date_edit_start.dateChanged.connect(self.date_edit_start_changed) self.combo_box_color_a.activated.connect( self.combo_box_color_a_clicked) self.combo_box_color_b.activated.connect( self.combo_box_color_b_clicked) self.push_button_ok.clicked.connect(self.close) self.push_button_cancel.clicked.connect(self.close)
def __init__(self, parent=None, index=None, html=None, spellcheck=None, highlighting=False, dict="", autoResize=False): QTextEdit.__init__(self, parent) self._column = Outline.text self._index = None self._indexes = None self._model = None self._placeholderText = self.placeholderText() self._updating = False self._item = None self._highlighting = highlighting self._textFormat = "text" self.setAcceptRichText(False) # When setting up a theme, this becomes true. self._fromTheme = False self._themeData = None self._highlighterClass = BasicHighlighter if spellcheck is None: spellcheck = settings.spellcheck self.spellcheck = spellcheck self.currentDict = dict if dict else settings.dict self._defaultFontSize = qApp.font().pointSize() self.highlighter = None self.setAutoResize(autoResize) self._defaultBlockFormat = QTextBlockFormat() self._defaultCharFormat = QTextCharFormat() self.highlightWord = "" self.highligtCS = False self._dict = None # self.document().contentsChanged.connect(self.submit, F.AUC) # Submit text changed only after 500ms without modifications self.updateTimer = QTimer() self.updateTimer.setInterval(500) self.updateTimer.setSingleShot(True) self.updateTimer.timeout.connect(self.submit) # self.updateTimer.timeout.connect(lambda: print("Timeout")) self.updateTimer.stop() self.document().contentsChanged.connect(self.updateTimer.start, F.AUC) # self.document().contentsChanged.connect(lambda: print("Document changed")) # self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed")) self.setEnabled(False) if index: self.setCurrentModelIndex(index) elif html: self.document().setHtml(html) self.setReadOnly(True) # Spellchecking if enchant and self.spellcheck: try: self._dict = enchant.Dict(self.currentDict if self.currentDict else self.getDefaultLocale()) except enchant.errors.DictNotFoundError: self.spellcheck = False else: self.spellcheck = False if self._highlighting and not self.highlighter: self.highlighter = self._highlighterClass(self) self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def prepare(tests=False): app = QApplication(sys.argv) app.setOrganizationName("manuskript" + ("_tests" if tests else "")) app.setOrganizationDomain("www.theologeek.ch") app.setApplicationName("manuskript" + ("_tests" if tests else "")) app.setApplicationVersion(getVersion()) print("Running manuskript version {}.".format(getVersion())) icon = QIcon() for i in [16, 32, 64, 128, 256, 512]: icon.addFile(appPath("icons/Manuskript/icon-{}px.png".format(i))) qApp.setWindowIcon(icon) app.setStyle("Fusion") # Load style from QSettings settings = QSettings(app.organizationName(), app.applicationName()) if settings.contains("applicationStyle"): style = settings.value("applicationStyle") app.setStyle(style) # Translation process appTranslator = QTranslator(app) # By default: locale def tryLoadTranslation(translation, source): """Tries to load and activate a given translation for use.""" if appTranslator.load(translation, appPath("i18n")): app.installTranslator(appTranslator) print("Loaded translation: {}".format(translation)) # Note: QTranslator.load() does some fancy heuristics where it simplifies # the given locale until it is 'close enough' if the given filename does # not work out. For example, if given 'i18n/manuskript_en_US.qm', it tries: # * i18n/manuskript_en_US.qm.qm # * i18n/manuskript_en_US.qm # * i18n/manuskript_en_US # * i18n/manuskript_en.qm # * i18n/manuskript_en # * i18n/manuskript.qm # * i18n/manuskript # We have no way to determining what it eventually went with, so mind your # filenames when you observe strange behaviour with the loaded translations. return True else: print("No translation found or loaded. ({})".format(translation)) return False def activateTranslation(translation, source): """Loads the most suitable translation based on the available information.""" using_builtin_translation = True if (translation != ""): # empty string == 'no translation, use builtin' if isinstance(translation, str): if tryLoadTranslation(translation, source): using_builtin_translation = False else: # A list of language codes to try. Once something works, we're done. # This logic is loosely based on the working of QTranslator.load(QLocale, ...); # it allows us to more accurately detect the language used for the user interface. for language_code in translation: lc = language_code.replace('-', '_') if lc.lower() == 'en_US'.lower(): break if tryLoadTranslation("manuskript_{}.qm".format(lc), source): using_builtin_translation = False break if using_builtin_translation: print("Using the builtin translation.") # Load application translation translation = "" source = "default" if settings.contains("applicationTranslation"): # Use the language configured by the user. translation = settings.value("applicationTranslation") source = "user setting" else: # Auto-detect based on system locale. translation = QLocale().uiLanguages() source = "available ui languages" print("Preferred translation: {} (based on {})".format( ("builtin" if translation == "" else translation), source)) activateTranslation(translation, source) def respectSystemDarkThemeSetting(): """Adjusts the Qt theme to match the OS 'dark theme' setting configured by the user.""" if platform.system() is not 'Windows': return # Basic Windows 10 Dark Theme support. # Source: https://forum.qt.io/topic/101391/windows-10-dark-theme/4 themeSettings = QSettings( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings.NativeFormat) if themeSettings.value("AppsUseLightTheme") == 0: darkPalette = QPalette() darkColor = QColor(45, 45, 45) disabledColor = QColor(127, 127, 127) darkPalette.setColor(QPalette.Window, darkColor) darkPalette.setColor(QPalette.WindowText, Qt.GlobalColor.white) darkPalette.setColor(QPalette.Base, QColor(18, 18, 18)) darkPalette.setColor(QPalette.AlternateBase, darkColor) darkPalette.setColor(QPalette.ToolTipBase, Qt.GlobalColor.white) darkPalette.setColor(QPalette.ToolTipText, Qt.GlobalColor.white) darkPalette.setColor(QPalette.Text, Qt.GlobalColor.white) darkPalette.setColor(QPalette.Disabled, QPalette.Text, disabledColor) darkPalette.setColor(QPalette.Button, darkColor) darkPalette.setColor(QPalette.ButtonText, Qt.GlobalColor.white) darkPalette.setColor(QPalette.Disabled, QPalette.ButtonText, disabledColor) darkPalette.setColor(QPalette.BrightText, Qt.GlobalColor.red) darkPalette.setColor(QPalette.Link, QColor(42, 130, 218)) darkPalette.setColor(QPalette.Highlight, QColor(42, 130, 218)) darkPalette.setColor(QPalette.HighlightedText, Qt.GlobalColor.black) darkPalette.setColor(QPalette.Disabled, QPalette.HighlightedText, disabledColor) # Fixes ugly (not to mention hard to read) disabled menu items. # Source: https://bugreports.qt.io/browse/QTBUG-10322?focusedCommentId=371060#comment-371060 darkPalette.setColor(QPalette.Disabled, QPalette.Light, Qt.GlobalColor.transparent) app.setPalette(darkPalette) # This broke the Settings Dialog at one point... and then it stopped breaking it. # TODO: Why'd it break? Check if tooltips look OK... and if not, make them look OK. #app.setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }") respectSystemDarkThemeSetting() QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + [appPath("icons")]) QIcon.setThemeName("NumixMsk") # Font siue if settings.contains("appFontSize"): f = qApp.font() f.setPointSize(settings.value("appFontSize", type=int)) app.setFont(f) # Main window from manuskript.mainWindow import MainWindow MW = MainWindow() # We store the system default cursor flash time to be able to restore it # later if necessary MW._defaultCursorFlashTime = qApp.cursorFlashTime() # Command line project if len(sys.argv) > 1 and sys.argv[1][-4:] == ".msk": if os.path.exists(sys.argv[1]): path = os.path.abspath(sys.argv[1]) MW._autoLoadProject = path return app, MW
def __init__(self, schedule: Schedule, parent: QWidget = None): super().__init__(parent) self._schedule_ref = schedule self._date_start_cache = None # window settings self.setWindowFlag(Qt.WindowContextHelpButtonHint, False) self.setWindowTitle(self.tr("Export window")) self.setMinimumWidth(800) # title, add_date, work mode self.layout_title_date_mode = QHBoxLayout() self.label_title = QLabel(self.tr("Title")) self.layout_title_date_mode.addWidget(self.label_title) self.line_edit_title = QLineEdit() self.layout_title_date_mode.addWidget(self.line_edit_title) self.check_box_add_date = QCheckBox(self.tr("Add date")) self.layout_title_date_mode.addWidget(self.check_box_add_date) self.combo_box_work_mode = QComboBox() self.layout_title_date_mode.addWidget(self.combo_box_work_mode) self.line_edit_title.setPlaceholderText( self.tr("My Group. A subgroup - green color, " "B subgroup - yellow color. ")) self.check_box_add_date.setChecked(True) self.combo_box_work_mode.addItem(self.tr("Weekly")) self.combo_box_work_mode.addItem(self.tr("Full")) # list widget with files self.layout_list_widget = QVBoxLayout() self.check_box_use_current = QCheckBox(self.tr("Use current schedule")) self.layout_list_widget.addWidget(self.check_box_use_current) self.check_box_use_current.setChecked(True) self.list_widget = QListWidget() self.layout_list_widget.addWidget(self.list_widget) self.list_widget.setSortingEnabled(True) self.list_widget.setEnabled(False) self.layout_open_folder = QHBoxLayout() self.layout_list_widget.addLayout(self.layout_open_folder) self.label_find = QLabel(self.tr("Schedules: ") + "0") self.layout_open_folder.addWidget(self.label_find) self.layout_open_folder.addStretch(1) self.push_button_open_folder = QToolButton() self.layout_open_folder.addWidget(self.push_button_open_folder) self.push_button_open_folder.setEnabled(False) self.push_button_open_folder.setText(self.tr("Open folder")) self.push_button_open_folder.setPopupMode(QToolButton.MenuButtonPopup) self.action_open_files = QAction(self.tr("Open files")) self.push_button_open_folder.addAction(self.action_open_files) # font edit self.group_box_font = QGroupBox(self.tr("Font settings")) self.form_layout_font = QFormLayout(self.group_box_font) self.label_font = QLabel(self.tr("Font")) self.form_layout_font.setWidget(0, QFormLayout.LabelRole, self.label_font) self.combo_box_font = QComboBox() self.form_layout_font.setWidget(0, QFormLayout.FieldRole, self.combo_box_font) self.label_encoding = QLabel(self.tr("Encoding")) self.form_layout_font.setWidget(1, QFormLayout.LabelRole, self.label_encoding) self.combo_box_encoding = QComboBox() self.form_layout_font.setWidget(1, QFormLayout.FieldRole, self.combo_box_encoding) for font_name, font_path in util.get_fonts(): self.combo_box_font.addItem(font_name, font_path) self.combo_box_font.setCurrentText(qApp.font().family()) self.combo_box_font.setEditable(True) self.combo_box_encoding.addItem("UTF-8") self.combo_box_encoding.addItem("Latin-1") self.combo_box_encoding.addItem("Windows-1252") # date edit self.group_box_date = QGroupBox(self.tr("Date settings")) self.form_layout_date = QFormLayout(self.group_box_date) self.label_date_start = QLabel(self.tr("Start")) self.form_layout_date.setWidget(0, QFormLayout.LabelRole, self.label_date_start) self.date_edit_start = QDateEdit() self.form_layout_date.setWidget(0, QFormLayout.FieldRole, self.date_edit_start) self.label_date_end = QLabel(self.tr("End")) self.form_layout_date.setWidget(1, QFormLayout.LabelRole, self.label_date_end) self.date_edit_end = QDateEdit() self.form_layout_date.setWidget(1, QFormLayout.FieldRole, self.date_edit_end) self.date_edit_start.setCalendarPopup(True) self.date_edit_end.setCalendarPopup(True) if QDate.currentDate().day() < (QDate.currentDate().dayOfYear() / 2): date = QDate(QDate.currentDate().year(), 2, 1) else: date = QDate(QDate.currentDate().year(), 9, 1) self._date_start_cache = date.addDays(8 - date.dayOfWeek()) self.date_edit_start.setDate(self._date_start_cache) self.date_edit_end.setMinimumDate(self._date_start_cache.addDays(7)) self.date_edit_end.setDate(self._date_start_cache.addDays(16 * 7)) # subgroup edit self.group_box_subgroup = QGroupBox(self.tr("Subgroup settings")) self.form_layout_subgroup = QFormLayout(self.group_box_subgroup) self.label_color_a = QLabel(self.tr("Color A")) self.form_layout_subgroup.setWidget(0, QFormLayout.LabelRole, self.label_color_a) self.combo_box_color_a = QComboBox() self.form_layout_subgroup.setWidget(0, QFormLayout.FieldRole, self.combo_box_color_a) self.label_color_b = QLabel(self.tr("Color B")) self.form_layout_subgroup.setWidget(1, QFormLayout.LabelRole, self.label_color_b) self.combo_box_color_b = QComboBox() self.form_layout_subgroup.setWidget(1, QFormLayout.FieldRole, self.combo_box_color_b) self.label_pattern_a_b = QLabel(self.tr("Pattern A and B")) self.form_layout_subgroup.setWidget(2, QFormLayout.LabelRole, self.label_pattern_a_b) self.combo_box_pattern_a_b = QComboBox() self.form_layout_subgroup.setWidget(2, QFormLayout.FieldRole, self.combo_box_pattern_a_b) self.add_standard_colors(self.combo_box_color_a) self.add_standard_colors(self.combo_box_color_b) self.combo_box_color_a.setCurrentIndex(9) # lime self.combo_box_color_b.setCurrentIndex(15) # yellow self.combo_box_pattern_a_b.addItem(self.tr("Chess order")) self.combo_box_pattern_a_b.setEnabled(False) # navigate buttons self.layout_navigate = QHBoxLayout() self.layout_navigate.addStretch(1) self.push_button_export = QPushButton(self.tr("Export")) self.layout_navigate.addWidget(self.push_button_export) self.push_button_cancel = QPushButton(self.tr("Cancel")) self.layout_navigate.addWidget(self.push_button_cancel) # layout setup self.layout_right_setting = QVBoxLayout() self.layout_right_setting.addWidget(self.group_box_font) self.layout_right_setting.addWidget(self.group_box_date) self.layout_right_setting.addWidget(self.group_box_subgroup) self.layout_right_setting.addStretch(1) self.layout_center = QHBoxLayout() self.layout_center.addLayout(self.layout_list_widget) self.layout_center.addLayout(self.layout_right_setting) self.layout_main = QVBoxLayout() self.layout_main.addLayout(self.layout_title_date_mode) self.layout_main.addLayout(self.layout_center) self.layout_main.addLayout(self.layout_navigate) self.setLayout(self.layout_main) # connection self.check_box_use_current.clicked.connect( self.check_box_use_current_clicked) self.push_button_open_folder.clicked.connect(self.open_folder_clicked) self.action_open_files.triggered.connect(self.open_files_clicked) self.date_edit_start.dateChanged.connect(self.date_edit_start_changed) self.combo_box_color_a.activated.connect( self.combo_box_color_a_clicked) self.combo_box_color_b.activated.connect( self.combo_box_color_b_clicked) self.push_button_export.clicked.connect(self.export_to_pdf) self.push_button_cancel.clicked.connect(self.close)
def __init__(self, installed_plugins, highlighted_plugins=None, parent=None): super().__init__(parent) self.backend_handler = BackendHandler() self.ui = Ui_DialogOptions() self.ui.setupUi(self) self.setWindowFlags(Qt.Window) self.device_options_model = DeviceOptionsTableModel( self.backend_handler, self) self.device_options_model.update() self.ui.tblDevices.setModel(self.device_options_model) self.ui.tblDevices.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) self.ui.tblDevices.setItemDelegateForColumn( 1, ComboBoxDelegate(["native", "GNU Radio"])) self.setAttribute(Qt.WA_DeleteOnClose) layout = QHBoxLayout(self.ui.tab_plugins) self.plugin_controller = PluginFrame(installed_plugins, highlighted_plugins, parent=self) layout.addWidget(self.plugin_controller) self.ui.tab_plugins.setLayout(layout) self.ui.btnViewBuildLog.hide() self.build_log = "" # We use bundled native device backends on windows, so no need to reconfigure them self.ui.groupBoxNativeOptions.setVisible(sys.platform != "win32") self.ui.labelIconTheme.setVisible(sys.platform == "linux") self.ui.comboBoxIconTheme.setVisible(sys.platform == "linux") self.ui.comboBoxTheme.setCurrentIndex( settings.read("theme_index", 0, int)) self.ui.comboBoxIconTheme.setCurrentIndex( settings.read("icon_theme_index", 0, int)) self.ui.checkBoxShowConfirmCloseDialog.setChecked( not settings.read('not_show_close_dialog', False, bool)) self.ui.checkBoxHoldShiftToDrag.setChecked( settings.read('hold_shift_to_drag', True, bool)) self.ui.checkBoxDefaultFuzzingPause.setChecked( settings.read('use_default_fuzzing_pause', True, bool)) self.ui.checkBoxAlignLabels.setChecked( settings.read('align_labels', True, bool)) self.ui.doubleSpinBoxRAMThreshold.setValue( 100 * settings.read('ram_threshold', 0.6, float)) if self.backend_handler.gr_python_interpreter: self.ui.lineEditGRPythonInterpreter.setText( self.backend_handler.gr_python_interpreter) self.ui.doubleSpinBoxFuzzingPause.setValue( settings.read("default_fuzzing_pause", 10**6, int)) self.ui.doubleSpinBoxFuzzingPause.setEnabled( settings.read('use_default_fuzzing_pause', True, bool)) self.ui.checkBoxMultipleModulations.setChecked( settings.read("multiple_modulations", False, bool)) self.ui.radioButtonLowModulationAccuracy.setChecked( Modulator.get_dtype() == np.int8) self.ui.radioButtonMediumModulationAccuracy.setChecked( Modulator.get_dtype() == np.int16) self.ui.radioButtonHighModulationAccuracy.setChecked( Modulator.get_dtype() == np.float32) completer = QCompleter() completer.setModel(QDirModel(completer)) self.ui.lineEditGRPythonInterpreter.setCompleter(completer) self.ui.spinBoxFontSize.setValue(qApp.font().pointSize()) self.refresh_device_tab() self.create_connects() self.old_show_pause_as_time = False self.field_type_table_model = FieldTypeTableModel([], parent=self) self.ui.tblLabeltypes.setModel(self.field_type_table_model) self.ui.tblLabeltypes.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) self.ui.tblLabeltypes.setItemDelegateForColumn( 1, ComboBoxDelegate([f.name for f in FieldType.Function], return_index=False, parent=self)) self.ui.tblLabeltypes.setItemDelegateForColumn( 2, ComboBoxDelegate(ProtocolLabel.DISPLAY_FORMATS, parent=self)) self.read_options() self.old_default_view = self.ui.comboBoxDefaultView.currentIndex() self.old_num_sending_repeats = self.ui.spinBoxNumSendingRepeats.value() self.ui.labelRebuildNativeStatus.setText("") self.show_available_colormaps() try: self.restoreGeometry( settings.read("{}/geometry".format(self.__class__.__name__))) except TypeError: pass
def __init__(self, installed_plugins, highlighted_plugins=None, parent=None): super().__init__(parent) self.backend_handler = BackendHandler() self.backend_handler.set_gnuradio_installed_status() self.ui = Ui_DialogOptions() self.ui.setupUi(self) self.setWindowFlags(Qt.Window) self.device_options_model = DeviceOptionsTableModel(self.backend_handler, self) self.device_options_model.update() self.ui.tblDevices.setModel(self.device_options_model) self.ui.tblDevices.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.ui.tblDevices.setItemDelegateForColumn(1, ComboBoxDelegate(["native", "GNU Radio"])) self.setAttribute(Qt.WA_DeleteOnClose) layout = QHBoxLayout(self.ui.tab_plugins) self.plugin_controller = PluginFrame(installed_plugins, highlighted_plugins, parent=self) layout.addWidget(self.plugin_controller) self.ui.tab_plugins.setLayout(layout) self.ui.btnViewBuildLog.hide() self.build_log = "" # We use bundled native device backends on windows, so no need to reconfigure them self.ui.groupBoxNativeOptions.setVisible(sys.platform != "win32") self.ui.labelIconTheme.setVisible(sys.platform == "linux") self.ui.comboBoxIconTheme.setVisible(sys.platform == "linux") self.ui.comboBoxTheme.setCurrentIndex(constants.SETTINGS.value("theme_index", 0, int)) self.ui.comboBoxIconTheme.setCurrentIndex(constants.SETTINGS.value("icon_theme_index", 0, int)) self.ui.checkBoxShowConfirmCloseDialog.setChecked( not constants.SETTINGS.value('not_show_close_dialog', False, bool)) self.ui.checkBoxHoldShiftToDrag.setChecked(constants.SETTINGS.value('hold_shift_to_drag', True, bool)) self.ui.checkBoxDefaultFuzzingPause.setChecked( constants.SETTINGS.value('use_default_fuzzing_pause', True, bool)) self.ui.checkBoxAlignLabels.setChecked(constants.SETTINGS.value('align_labels', True, bool)) self.ui.doubleSpinBoxRAMThreshold.setValue(100 * constants.SETTINGS.value('ram_threshold', 0.6, float)) self.ui.radioButtonGnuradioDirectory.setChecked(self.backend_handler.use_gnuradio_install_dir) self.ui.radioButtonPython2Interpreter.setChecked(not self.backend_handler.use_gnuradio_install_dir) if self.backend_handler.gnuradio_install_dir: self.ui.lineEditGnuradioDirectory.setText(self.backend_handler.gnuradio_install_dir) if self.backend_handler.python2_exe: self.ui.lineEditPython2Interpreter.setText(self.backend_handler.python2_exe) self.ui.doubleSpinBoxFuzzingPause.setValue(constants.SETTINGS.value("default_fuzzing_pause", 10 ** 6, int)) self.ui.doubleSpinBoxFuzzingPause.setEnabled(constants.SETTINGS.value('use_default_fuzzing_pause', True, bool)) self.ui.checkBoxMultipleModulations.setChecked(constants.SETTINGS.value("multiple_modulations", False, bool)) completer = QCompleter() completer.setModel(QDirModel(completer)) self.ui.lineEditPython2Interpreter.setCompleter(completer) self.ui.lineEditGnuradioDirectory.setCompleter(completer) self.ui.spinBoxFontSize.setValue(qApp.font().pointSize()) self.refresh_device_tab() self.create_connects() self.old_show_pause_as_time = False self.field_type_table_model = FieldTypeTableModel([], parent=self) self.ui.tblLabeltypes.setModel(self.field_type_table_model) self.ui.tblLabeltypes.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.ui.tblLabeltypes.setItemDelegateForColumn(1, ComboBoxDelegate([f.name for f in FieldType.Function], return_index=False, parent=self)) self.ui.tblLabeltypes.setItemDelegateForColumn(2, ComboBoxDelegate(ProtocolLabel.DISPLAY_FORMATS, parent=self)) self.read_options() self.old_default_view = self.ui.comboBoxDefaultView.currentIndex() self.old_num_sending_repeats = self.ui.spinBoxNumSendingRepeats.value() self.ui.labelRebuildNativeStatus.setText("") self.show_available_colormaps() try: self.restoreGeometry(constants.SETTINGS.value("{}/geometry".format(self.__class__.__name__))) except TypeError: pass
def __init__(self, index, parent=None): QWidget.__init__(self, parent) self._background = None self._index = index self._theme = findThemePath(settings.fullScreenTheme) self._themeDatas = loadThemeDatas(self._theme) self.setMouseTracking(True) self._geometries = {} # Text editor self.editor = MDEditView(self, index=index, spellcheck=settings.spellcheck, highlighting=True, dict=settings.dict) self.editor.setFrameStyle(QFrame.NoFrame) self.editor.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.editor.installEventFilter(self) self.editor.setMouseTracking(True) self.editor.setVerticalScrollBar(myScrollBar()) self.scrollBar = self.editor.verticalScrollBar() self.scrollBar.setParent(self) # Top Panel self.topPanel = myPanel(parent=self) # self.topPanel.layout().addStretch(1) # Spell checking if enchant: self.btnSpellCheck = QPushButton(self) self.btnSpellCheck.setFlat(True) self.btnSpellCheck.setIcon(QIcon.fromTheme("tools-check-spelling")) self.btnSpellCheck.setCheckable(True) self.btnSpellCheck.setChecked(self.editor.spellcheck) self.btnSpellCheck.toggled.connect(self.editor.toggleSpellcheck) else: self.btnSpellCheck = None # Navigation Buttons self.btnPrevious = QPushButton(self) self.btnPrevious.setFlat(True) self.btnPrevious.setIcon(QIcon.fromTheme("arrow-left")) self.btnPrevious.clicked.connect(self.switchPreviousItem) self.btnNext = QPushButton(self) self.btnNext.setFlat(True) self.btnNext.setIcon(QIcon.fromTheme("arrow-right")) self.btnNext.clicked.connect(self.switchNextItem) self.btnNew = QPushButton(self) self.btnNew.setFlat(True) self.btnNew.setIcon(QIcon.fromTheme("document-new")) self.btnNew.clicked.connect(self.createNewText) # Path and New Text Buttons self.wPath = myPath(self) # Close self.btnClose = QPushButton(self) self.btnClose.setIcon(qApp.style().standardIcon(QStyle.SP_DialogCloseButton)) self.btnClose.clicked.connect(self.close) self.btnClose.setFlat(True) # Top panel Layout if self.btnSpellCheck: self.topPanel.layout().addWidget(self.btnSpellCheck) self.topPanel.layout().addSpacing(15) self.topPanel.layout().addWidget(self.btnPrevious) self.topPanel.layout().addWidget(self.btnNext) self.topPanel.layout().addWidget(self.btnNew) self.topPanel.layout().addStretch(1) self.topPanel.layout().addWidget(self.wPath) self.topPanel.layout().addStretch(1) self.topPanel.layout().addWidget(self.btnClose) self.updateTopBar() # Left Panel self._locked = False self.leftPanel = myPanel(vertical=True, parent=self) self.locker = locker(self) self.locker.lockChanged.connect(self.setLocked) self.leftPanel.layout().addWidget(self.locker) # Bottom Panel self.bottomPanel = myPanel(parent=self) self.bottomPanel.layout().addSpacing(24) self.lstThemes = QComboBox(self) self.lstThemes.setAttribute(Qt.WA_TranslucentBackground) paths = allPaths("resources/themes") for p in paths: lst = [i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme"] for t in lst: themeIni = os.path.join(p, t) name = loadThemeDatas(themeIni)["Name"] # self.lstThemes.addItem(os.path.splitext(t)[0]) self.lstThemes.addItem(name) self.lstThemes.setItemData(self.lstThemes.count()-1, os.path.splitext(t)[0]) self.lstThemes.setCurrentIndex(self.lstThemes.findData(settings.fullScreenTheme)) # self.lstThemes.setCurrentText(settings.fullScreenTheme) self.lstThemes.currentTextChanged.connect(self.setTheme) self.lstThemes.setMaximumSize(QSize(300, QFontMetrics(qApp.font()).height())) themeLabel = QLabel(self.tr("Theme:"), self) self.bottomPanel.layout().addWidget(themeLabel) self.bottomPanel.layout().addWidget(self.lstThemes) self.bottomPanel.layout().addStretch(1) self.lblProgress = QLabel(self) self.lblProgress.setMaximumSize(QSize(200, 14)) self.lblProgress.setMinimumSize(QSize(100, 14)) self.lblWC = QLabel(self) self.lblClock = myClockLabel(self) self.bottomPanel.layout().addWidget(self.lblWC) self.bottomPanel.layout().addWidget(self.lblProgress) self.bottomPanel.layout().addSpacing(15) self.bottomPanel.layout().addWidget(self.lblClock) self.updateStatusBar() self.bottomPanel.layout().addSpacing(24) # Add Widget Settings if self.btnSpellCheck: self.topPanel.addWidgetSetting(self.tr("Spellcheck"), 'top-spellcheck', (self.btnSpellCheck, )) self.topPanel.addWidgetSetting(self.tr("Navigation"), 'top-navigation', (self.btnPrevious, self.btnNext)) self.topPanel.addWidgetSetting(self.tr("New Text"), 'top-new-doc', (self.btnNew, )) self.topPanel.addWidgetSetting(self.tr("Title"), 'top-title', (self.wPath, )) self.topPanel.addSetting(self.tr("Title: Show Full Path"), 'title-show-full-path', True) self.topPanel.setSettingCallback('title-show-full-path', lambda var, val: self.updateTopBar()) self.bottomPanel.addWidgetSetting(self.tr("Theme selector"), 'bottom-theme', (self.lstThemes, themeLabel)) self.bottomPanel.addWidgetSetting(self.tr("Word count"), 'bottom-wc', (self.lblWC, )) self.bottomPanel.addWidgetSetting(self.tr("Progress"), 'bottom-progress', (self.lblProgress, )) self.bottomPanel.addSetting(self.tr("Progress: Auto Show/Hide"), 'progress-auto-show', True) self.bottomPanel.addWidgetSetting(self.tr("Clock"), 'bottom-clock', (self.lblClock, )) self.bottomPanel.addSetting(self.tr("Clock: Show Seconds"), 'clock-show-seconds', True) self.bottomPanel.setAutoHideVariable('autohide-bottom') self.topPanel.setAutoHideVariable('autohide-top') self.leftPanel.setAutoHideVariable('autohide-left') # Connection self._index.model().dataChanged.connect(self.dataChanged) # self.updateTheme() self.showFullScreen()