def populateFields(self): # Fill in all the fields in the About dialog iconPic = appPath("icons/Manuskript/icon-64px.png") self.setWindowIcon(QIcon(iconPic)) logoPic = QPixmap(appPath("icons/Manuskript/logo-400x104.png")) self.labelLogo.setPixmap(logoPic) self.labelManuskriptVersion.setText( "<b>" + self.tr("Version") + " " + getVersion() + "</b><br>" + " " * 5 + """<a href="http://www.theologeek.ch/manuskript/"> http://www.theologeek.ch/manuskript/ </a><br>""" + " " * 5 + "Copyright © 2015-2017 Olivier Keshavjee<br>" + " " * 5 + """<a href="https://www.gnu.org/licenses/gpl-3.0.en.html"> GNU General Public License Version 3 </a><br>""") self.labelManuskriptVersion.setOpenExternalLinks(True) self.labelSoftwareVersion.setText( "<b>" + self.tr("Software Versions in Use:") + "</b><br>" + " " * 5 + self.tr("Python") + " " + python_version() + "<br>" + " " * 5 + self.tr("PyQt") + " " + PYQT_VERSION_STR + "<br>" + " " * 5 + self.tr("Qt") + " " + QT_VERSION_STR)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self._updating = False self._fullScreen = None self.mw = mainWindow() # Connections -------------------------------------------------------- self.btnGoUp.clicked.connect(self.goToParentItem) self.sldCorkSizeFactor.valueChanged.connect(self.setCorkSizeFactor, AUC) self.btnRedacFolderCork.toggled.connect( self.sldCorkSizeFactor.setVisible, AUC) self.btnRedacFolderText.clicked.connect( lambda v: self.setFolderView("text"), AUC) self.btnRedacFolderCork.clicked.connect( lambda v: self.setFolderView("cork"), AUC) self.btnRedacFolderOutline.clicked.connect( lambda v: self.setFolderView("outline"), AUC) self.btnRedacFullscreen.clicked.connect(self.showFullScreen, AUC) # self.tab.setDocumentMode(False) # Bug in Qt < 5.5: doesn't always load icons from custom theme. # Cf. https://github.com/qtproject/qtbase/commit/a8621a3f85e64f1252a80ae81a6e22554f7b3f44 # Since those are important, we provide fallback. self.btnRedacFolderCork.setIcon( QIcon.fromTheme( "view-cards", QIcon( appPath("icons/NumixMsk/256x256/actions/view-cards.svg")))) self.btnRedacFolderOutline.setIcon( QIcon.fromTheme( "view-outline", QIcon( appPath( "icons/NumixMsk/256x256/actions/view-outline.svg")))) self.btnRedacFolderText.setIcon( QIcon.fromTheme( "view-text", QIcon( appPath("icons/NumixMsk/256x256/actions/view-text.svg")))) for btn in [ self.btnRedacFolderCork, self.btnRedacFolderText, self.btnRedacFolderOutline ]: btn.setToolTip(btn.text()) btn.setText("")
def run(): app = QApplication(sys.argv) app.setOrganizationName("manuskript") app.setOrganizationDomain("www.theologeek.ch") app.setApplicationName("manuskript") app.setApplicationVersion(_version) icon = QIcon() for i in [16, 31, 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() # By default: locale translation = appPath( os.path.join("i18n", "manuskript_{}.qm".format(locale))) # Load translation from settings if settings.contains("applicationTranslation"): translation = appPath( os.path.join("i18n", settings.value("applicationTranslation"))) print("Found translation in settings:", translation) if appTranslator.load(translation): app.installTranslator(appTranslator) print(app.tr("Loaded translation: {}.").format(translation)) else: print( app.tr("Warning: failed to load translator for locale {}..."). format(locale)) QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + [appPath("icons")]) QIcon.setThemeName("NumixMsk") # qApp.setWindowIcon(QIcon.fromTheme("im-aim")) # Seperating launch to avoid segfault, so it seem. # Cf. http://stackoverflow.com/questions/12433491/is-this-pyqt-4-python-bug-or-wrongly-behaving-code launch()
def MWSampleProject(MW): """ Creates a MainWindow and load a copy of the Acts sample project. """ from manuskript import functions as F import os # Get the path of the first sample project. We assume it is here. spDir = F.appPath("sample-projects") lst = os.listdir(spDir) # We assume it's saved in folder, so there is a `name.msk` file and a # `name` folder. src = [f for f in lst if f[-4:] == ".msk" and f[:-4] in lst][0] src = os.path.join(spDir, src) # Copy to a temp file import tempfile tf = tempfile.NamedTemporaryFile(suffix=".msk") import shutil shutil.copyfile(src, tf.name) shutil.copytree(src[:-4], tf.name[:-4]) MW.closeProject() MW.loadProject(tf.name) assert MW.currentProject is not None return MW
def updateTargetIcon(self, val): icon = QIcon.fromTheme( "set-target", QIcon(appPath("icons/NumixMsk/256x256/actions/set-target.svg"))) if not val: icon = QIcon(icon.pixmap(128, 128, icon.Disabled)) self.btnTarget.setIcon(icon)
def populateTemplates(self): self.tree.clear() self.tree.setIndentation(0) # Add templates item = self.addTopLevelItem(self.tr("Fiction")) templates = [i for i in self.templates() if i[2] == "Fiction"] for t in templates: sub = QTreeWidgetItem(item, [t[0]]) # Add templates: non-fiction item = self.addTopLevelItem(self.tr("Non-fiction")) templates = [i for i in self.templates() if i[2] == "Non-fiction"] for t in templates: sub = QTreeWidgetItem(item, [t[0]]) # Add Demo project item = self.addTopLevelItem(self.tr("Demo projects")) dir = QDir(appPath("sample-projects")) for f in dir.entryList(["*.msk"], filters=QDir.Files): sub = QTreeWidgetItem(item, [f[:-4]]) sub.setData(0, Qt.UserRole, f) self.tree.expandAll()
def run(): app = QApplication(sys.argv) app.setOrganizationName("manuskript") app.setOrganizationDomain("www.theologeek.ch") app.setApplicationName("manuskript") app.setApplicationVersion(_version) icon = QIcon() for i in [16, 31, 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() # By default: locale translation = appPath(os.path.join("i18n", "manuskript_{}.qm".format(locale))) # Load translation from settings if settings.contains("applicationTranslation"): translation = appPath(os.path.join("i18n", settings.value("applicationTranslation"))) print("Found translation in settings:", translation) if appTranslator.load(translation): app.installTranslator(appTranslator) print(app.tr("Loaded translation: {}.").format(translation)) else: print(app.tr("Warning: failed to load translator for locale {}...").format(locale)) QIcon.setThemeSearchPaths(QIcon.themeSearchPaths() + [appPath("icons")]) QIcon.setThemeName("NumixMsk") # qApp.setWindowIcon(QIcon.fromTheme("im-aim")) # Seperating launch to avoid segfault, so it seem. # Cf. http://stackoverflow.com/questions/12433491/is-this-pyqt-4-python-bug-or-wrongly-behaving-code launch()
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
def test_paths(): assert F.appPath() is not None assert F.writablePath is not None assert len(F.allPaths("suffix")) == 2 assert F.tempFile("yop") is not None f = F.findBackground("spacedreams.jpg") assert "resources/backgrounds/spacedreams.jpg" in f assert len(F.customIcons()) > 1
def test_paths(): assert F.appPath() != None assert F.writablePath != None assert len(F.allPaths("suffix")) == 2 assert F.tempFile("yop") != None f = F.findBackground("spacedreams.jpg") assert "resources/backgrounds/spacedreams.jpg" in f assert len(F.customIcons()) > 1
class PDFViewer(QWebEngineView): pdf_viewer_page = "file://"+appPath('libs/pdf.js/web/viewer.html') def __init__(self, parent=None): QWebEngineView.__init__(self, parent) self.settings = QWebEngineSettings.globalSettings() self.settings.setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls, True) def loadPDF(self, pdf): url = QUrl(self.pdf_viewer_page+"?file="+pdf) self.load(url)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self._updating = False self.mw = mainWindow() # Connections -------------------------------------------------------- self.btnGoUp.clicked.connect(self.goToParentItem) self.sldCorkSizeFactor.valueChanged.connect( self.setCorkSizeFactor, AUC) self.btnRedacFolderCork.toggled.connect( self.sldCorkSizeFactor.setVisible, AUC ) self.btnRedacFolderText.clicked.connect( lambda v: self.setFolderView("text"), AUC) self.btnRedacFolderCork.clicked.connect( lambda v: self.setFolderView("cork"), AUC) self.btnRedacFolderOutline.clicked.connect( lambda v: self.setFolderView("outline"), AUC) self.btnRedacFullscreen.clicked.connect( self.showFullScreen, AUC) # self.tab.setDocumentMode(False) # Bug in Qt < 5.5: doesn't always load icons from custom theme. # Cf. https://github.com/qtproject/qtbase/commit/a8621a3f85e64f1252a80ae81a6e22554f7b3f44 # Since those are important, we provide fallback. self.btnRedacFolderCork.setIcon(QIcon.fromTheme("view-cards", QIcon(appPath("icons/NumixMsk/256x256/actions/view-cards.svg")))) self.btnRedacFolderOutline.setIcon(QIcon.fromTheme("view-outline", QIcon(appPath("icons/NumixMsk/256x256/actions/view-outline.svg")))) self.btnRedacFolderText.setIcon(QIcon.fromTheme("view-text", QIcon(appPath("icons/NumixMsk/256x256/actions/view-text.svg")))) for btn in [self.btnRedacFolderCork, self.btnRedacFolderText, self.btnRedacFolderOutline]: btn.setToolTip(btn.text()) btn.setText("")
def addThemePreviewText(pixmap, themeDatas, screenRect): # Text previewText = MDEditView(highlighting=True) previewText.setFrameStyle(QFrame.NoFrame) previewText.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) previewText.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) f = QFile(appPath("resources/themes/preview.txt")) f.open(QIODevice.ReadOnly) previewText.setPlainText(QTextStream(f).readAll()) setThemeEditorDatas(previewText, themeDatas, pixmap, screenRect) previewText.render(pixmap, previewText.pos())
def addThemePreviewText(pixmap, themeDatas, screenRect): # Text previewText = textEditView(highlighting=True) previewText.setFrameStyle(QFrame.NoFrame) previewText.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) previewText.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) f = QFile(appPath("resources/themes/preview.txt")) f.open(QIODevice.ReadOnly) previewText.setPlainText(QTextStream(f).readAll()) setThemeEditorDatas(previewText, themeDatas, pixmap, screenRect) previewText.render(pixmap, previewText.pos())
def populatesThemesList(self): paths = allPaths("resources/themes") current = settings.fullScreenTheme self.lstThemes.clear() for p in paths: lst = [ i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme" ] for t in lst: theme = os.path.join(p, t) editable = not appPath() in theme n = getThemeName(theme) item = QListWidgetItem(n) item.setData(Qt.UserRole, theme) item.setData(Qt.UserRole + 1, editable) item.setToolTip("{}{}".format( n, self.tr(" (read-only)") if not editable else "")) thumb = os.path.join(p, t.replace(".theme", ".jpg")) px = QPixmap(200, 120) px.fill(Qt.white) if not os.path.exists(thumb): currentScreen = qApp.desktop().screenNumber(self) screenRect = qApp.desktop().screenGeometry(currentScreen) thumb = createThemePreview(theme, screenRect) icon = QPixmap(thumb).scaled(200, 120, Qt.KeepAspectRatio) painter = QPainter(px) painter.drawPixmap(px.rect().center() - icon.rect().center(), icon) painter.end() item.setIcon(QIcon(px)) self.lstThemes.addItem(item) if current and current in t: self.lstThemes.setCurrentItem(item) current = None self.lstThemes.setIconSize(QSize(200, 120)) if current: # the theme from settings wasn't found # select the last from the list self.lstThemes.setCurrentRow(self.lstThemes.count() - 1)
class manuskriptExporter(basicExporter): name = "Manuskript" description = qApp.translate( "Export", "Default exporter, provides basic formats used by other exporters.") exportTo = [ plainText(), markdown(), HTML(), basicFormat("OPML", icon="text-x-opml+xml") ] icon = appPath("icons/Manuskript/icon-256px.png") @classmethod def isValid(cls): return True
def populatesThemesList(self): paths = allPaths("resources/themes") current = settings.fullScreenTheme self.lstThemes.clear() for p in paths: lst = [i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme"] for t in lst: theme = os.path.join(p, t) editable = not appPath() in theme n = getThemeName(theme) item = QListWidgetItem(n) item.setData(Qt.UserRole, theme) item.setData(Qt.UserRole + 1, editable) item.setToolTip("{}{}".format( n, self.tr(" (read-only)") if not editable else "")) thumb = os.path.join(p, t.replace(".theme", ".jpg")) px = QPixmap(200, 120) px.fill(Qt.white) if not os.path.exists(thumb): currentScreen = qApp.desktop().screenNumber(self) screenRect = qApp.desktop().screenGeometry(currentScreen) thumb = createThemePreview(theme, screenRect) icon = QPixmap(thumb).scaled(200, 120, Qt.KeepAspectRatio) painter = QPainter(px) painter.drawPixmap(px.rect().center() - icon.rect().center(), icon) painter.end() item.setIcon(QIcon(px)) self.lstThemes.addItem(item) if current and current in t: self.lstThemes.setCurrentItem(item) current = None self.lstThemes.setIconSize(QSize(200, 120)) if current: # the theme from settings wasn't found # select the last from the list self.lstThemes.setCurrentRow(self.lstThemes.count() - 1)
def changeTemplate(self, item, column): template = [i for i in self._templates if i[0] == item.text(0)] self.btnCreate.setText(self.btnCreateText) # Selected item is a template if len(template): self.template = template[0] self.updateTemplate() # Selected item is a sample project elif item.data(0, Qt.UserRole): name = item.data(0, Qt.UserRole) # Clear templates self.template = self._templates[0] self.updateTemplate() # Change button text self.btnCreate.setText("Open {}".format(name)) # Load project self.mw.loadProject(appPath("sample-projects/{}".format(name)))
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 MWSampleProject(MW): """ Creates a MainWindow and load a copy of the Acts sample project. """ from manuskript import functions as F import os # Get the path of the first sample project. We assume it is here. spDir = F.appPath("sample-projects") lst = os.listdir(spDir) # We assume it's saved in folder, so there is a `name.msk` file and a # `name` folder. src = [f for f in lst if f[-4:] == ".msk" and f[:-4] in lst][0] src = os.path.join(spDir, src) # Copy to a temp file import tempfile tf = tempfile.NamedTemporaryFile(suffix=".msk") import shutil shutil.copyfile(src, tf.name) shutil.copytree(src[:-4], tf.name[:-4]) MW.loadProject(tf.name) assert MW.currentProject is not None return MW
def updateTargetIcon(self, val): icon = QIcon.fromTheme("set-target", QIcon(appPath("icons/NumixMsk/256x256/actions/set-target.svg"))) if not val: icon = QIcon(icon.pixmap(128, 128, icon.Disabled)) self.btnTarget.setIcon(icon)
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 setupMoreUi(self): # Tool bar on the right self.toolbar = collapsibleDockWidgets(Qt.RightDockWidgetArea, self) self.toolbar.addCustomWidget(self.tr("Book summary"), self.grpPlotSummary, self.TabPlots) self.toolbar.addCustomWidget(self.tr("Project tree"), self.treeRedacWidget, self.TabRedac) self.toolbar.addCustomWidget(self.tr("Metadata"), self.redacMetadata, self.TabRedac) self.toolbar.addCustomWidget(self.tr("Story line"), self.storylineView, self.TabRedac) if self._toolbarState: self.toolbar.restoreState(self._toolbarState) # Custom "tab" bar on the left self.lstTabs.setIconSize(QSize(48, 48)) for i in range(self.tabMain.count()): icons = [ "general-128px.png", "summary-128px.png", "characters-128px.png", "plot-128px.png", "world-128px.png", "outline-128px.png", "redaction-128px.png", "" ] self.tabMain.setTabIcon( i, QIcon(appPath("icons/Custom/Tabs/{}".format(icons[i])))) item = QListWidgetItem(self.tabMain.tabIcon(i), self.tabMain.tabText(i)) item.setSizeHint(QSize(item.sizeHint().width(), 64)) item.setTextAlignment(Qt.AlignCenter) self.lstTabs.addItem(item) self.tabMain.tabBar().hide() self.lstTabs.currentRowChanged.connect(self.tabMain.setCurrentIndex) self.tabMain.currentChanged.connect(self.lstTabs.setCurrentRow) # Splitters self.splitterPersos.setStretchFactor(0, 25) self.splitterPersos.setStretchFactor(1, 75) self.splitterPlot.setStretchFactor(0, 20) self.splitterPlot.setStretchFactor(1, 60) self.splitterPlot.setStretchFactor(2, 30) self.splitterWorld.setStretchFactor(0, 25) self.splitterWorld.setStretchFactor(1, 75) self.splitterOutlineH.setStretchFactor(0, 25) self.splitterOutlineH.setStretchFactor(1, 75) self.splitterOutlineV.setStretchFactor(0, 75) self.splitterOutlineV.setStretchFactor(1, 25) self.splitterRedacV.setStretchFactor(0, 75) self.splitterRedacV.setStretchFactor(1, 25) self.splitterRedacH.setStretchFactor(0, 30) self.splitterRedacH.setStretchFactor(1, 40) self.splitterRedacH.setStretchFactor(2, 30) # QFormLayout stretch for w in [ self.txtWorldDescription, self.txtWorldPassion, self.txtWorldConflict ]: s = w.sizePolicy() s.setVerticalStretch(1) w.setSizePolicy(s) # Help box references = [ (self.lytTabOverview, self.tr("Enter infos about your book, and yourself."), 0), (self.lytSituation, self. tr("""The basic situation, in the form of a 'What if...?' question. Ex: 'What if the most dangerous evil wizard could wasn't abled to kill a baby?' (Harry Potter)""" ), 1), (self.lytSummary, self. tr("""Take time to think about a one sentence (~50 words) summary of your book. Then expand it to a paragraph, then to a page, then to a full summary."""), 1), (self.lytTabPersos, self.tr("Create your characters."), 0), (self.lytTabPlot, self.tr("Develop plots."), 0), (self.lytTabOutline, self.tr("Create the outline of your masterpiece."), 0), (self.lytTabRedac, self.tr("Write."), 0), (self.lytTabDebug, self.tr("Debug infos. Sometimes useful."), 0) ] for widget, text, pos in references: label = helpLabel(text, self) self.actShowHelp.toggled.connect(label.setVisible, AUC) widget.layout().insertWidget(pos, label) self.actShowHelp.setChecked(False) # Spellcheck if enchant: self.menuDict = QMenu(self.tr("Dictionary")) self.menuDictGroup = QActionGroup(self) self.updateMenuDict() self.menuTools.addMenu(self.menuDict) self.actSpellcheck.toggled.connect(self.toggleSpellcheck, AUC) self.dictChanged.connect(self.mainEditor.setDict, AUC) self.dictChanged.connect(self.redacMetadata.setDict, AUC) self.dictChanged.connect(self.outlineItemEditor.setDict, AUC) else: # No Spell check support self.actSpellcheck.setVisible(False) a = QAction(self.tr("Install PyEnchant to use spellcheck"), self) a.setIcon(self.style().standardIcon(QStyle.SP_MessageBoxWarning)) a.triggered.connect(self.openPyEnchantWebPage, AUC) self.menuTools.addAction(a)
def setupMoreUi(self): # Tool bar on the right self.toolbar = collapsibleDockWidgets(Qt.RightDockWidgetArea, self) self.toolbar.addCustomWidget(self.tr("Book summary"), self.grpPlotSummary, self.TabPlots) self.toolbar.addCustomWidget(self.tr("Project tree"), self.treeRedacWidget, self.TabRedac) self.toolbar.addCustomWidget(self.tr("Metadata"), self.redacMetadata, self.TabRedac) self.toolbar.addCustomWidget(self.tr("Story line"), self.storylineView, self.TabRedac) if self._toolbarState: self.toolbar.restoreState(self._toolbarState) # Custom "tab" bar on the left self.lstTabs.setIconSize(QSize(48, 48)) for i in range(self.tabMain.count()): icons = ["general-128px.png", "summary-128px.png", "characters-128px.png", "plot-128px.png", "world-128px.png", "outline-128px.png", "redaction-128px.png", "" ] self.tabMain.setTabIcon(i, QIcon(appPath("icons/Custom/Tabs/{}".format(icons[i])))) item = QListWidgetItem(self.tabMain.tabIcon(i), self.tabMain.tabText(i)) item.setSizeHint(QSize(item.sizeHint().width(), 64)) item.setTextAlignment(Qt.AlignCenter) self.lstTabs.addItem(item) self.tabMain.tabBar().hide() self.lstTabs.currentRowChanged.connect(self.tabMain.setCurrentIndex) self.tabMain.currentChanged.connect(self.lstTabs.setCurrentRow) # Splitters self.splitterPersos.setStretchFactor(0, 25) self.splitterPersos.setStretchFactor(1, 75) self.splitterPlot.setStretchFactor(0, 20) self.splitterPlot.setStretchFactor(1, 60) self.splitterPlot.setStretchFactor(2, 30) self.splitterWorld.setStretchFactor(0, 25) self.splitterWorld.setStretchFactor(1, 75) self.splitterOutlineH.setStretchFactor(0, 25) self.splitterOutlineH.setStretchFactor(1, 75) self.splitterOutlineV.setStretchFactor(0, 75) self.splitterOutlineV.setStretchFactor(1, 25) self.splitterRedacV.setStretchFactor(0, 75) self.splitterRedacV.setStretchFactor(1, 25) self.splitterRedacH.setStretchFactor(0, 30) self.splitterRedacH.setStretchFactor(1, 40) self.splitterRedacH.setStretchFactor(2, 30) # QFormLayout stretch for w in [self.txtWorldDescription, self.txtWorldPassion, self.txtWorldConflict]: s = w.sizePolicy() s.setVerticalStretch(1) w.setSizePolicy(s) # Help box references = [ (self.lytTabOverview, self.tr("Enter infos about your book, and yourself."), 0), (self.lytSituation, self.tr( """The basic situation, in the form of a 'What if...?' question. Ex: 'What if the most dangerous evil wizard could wasn't abled to kill a baby?' (Harry Potter)"""), 1), (self.lytSummary, self.tr( """Take time to think about a one sentence (~50 words) summary of your book. Then expand it to a paragraph, then to a page, then to a full summary."""), 1), (self.lytTabPersos, self.tr("Create your characters."), 0), (self.lytTabPlot, self.tr("Develop plots."), 0), (self.lytTabOutline, self.tr("Create the outline of your masterpiece."), 0), (self.lytTabRedac, self.tr("Write."), 0), (self.lytTabDebug, self.tr("Debug infos. Sometimes useful."), 0) ] for widget, text, pos in references: label = helpLabel(text, self) self.actShowHelp.toggled.connect(label.setVisible, AUC) widget.layout().insertWidget(pos, label) self.actShowHelp.setChecked(False) # Spellcheck if enchant: self.menuDict = QMenu(self.tr("Dictionary")) self.menuDictGroup = QActionGroup(self) self.updateMenuDict() self.menuTools.addMenu(self.menuDict) self.actSpellcheck.toggled.connect(self.toggleSpellcheck, AUC) self.dictChanged.connect(self.mainEditor.setDict, AUC) self.dictChanged.connect(self.redacMetadata.setDict, AUC) self.dictChanged.connect(self.outlineItemEditor.setDict, AUC) else: # No Spell check support self.actSpellcheck.setVisible(False) a = QAction(self.tr("Install PyEnchant to use spellcheck"), self) a.setIcon(self.style().standardIcon(QStyle.SP_MessageBoxWarning)) a.triggered.connect(self.openPyEnchantWebPage, AUC) self.menuTools.addAction(a)
#!/usr/bin/env python # --!-- coding: utf8 --!-- import os import sys from PyQt5.QtGui import QTextDocument from libs.odf.opendocument import OpenDocumentText from libs.odf.text import H, P from manuskript.exporter.basic import basicExporter from manuskript.functions import appPath from manuskript.functions import mainWindow sys.path.append(os.path.join(appPath(), "libs")) class odtExporter(basicExporter): requires = ["filename"] def __init__(self): pass def doCompile(self, filename): mw = mainWindow() root = mw.mdlOutline.rootItem doc = OpenDocumentText() def appendItem(item): if item.isFolder():
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