mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-01 18:49:38 +12:00
Checkpoint: selecting file working, have to preview and import now.
This commit is contained in:
parent
72b44fe90d
commit
340fceeda3
|
@ -5,19 +5,132 @@ import os
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtGui import QBrush, QColor, QIcon
|
from PyQt5.QtGui import QBrush, QColor, QIcon
|
||||||
from PyQt5.QtWidgets import QWidget
|
from PyQt5.QtWidgets import QWidget, QFileDialog
|
||||||
|
|
||||||
from manuskript import exporter
|
from manuskript import exporter
|
||||||
from manuskript.functions import lightBlue, writablePath
|
from manuskript.functions import lightBlue, writablePath, appPath
|
||||||
from manuskript.ui.importers.importer_ui import Ui_importer
|
from manuskript.ui.importers.importer_ui import Ui_importer
|
||||||
|
|
||||||
|
class importFormat:
|
||||||
|
def __init__(self, name, icon, fileFormat):
|
||||||
|
self.name = name
|
||||||
|
self.icon = icon
|
||||||
|
self.fileFormat = fileFormat
|
||||||
|
|
||||||
class importerDialog(QWidget, Ui_importer):
|
class importerDialog(QWidget, Ui_importer):
|
||||||
|
|
||||||
|
formatsIcon = {
|
||||||
|
".epub": "application-epub+zip",
|
||||||
|
".odt": "application-vnd.oasis.opendocument.text",
|
||||||
|
".docx": "application-vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
".md": "text-x-markdown",
|
||||||
|
".rst": "text-plain",
|
||||||
|
".tex": "text-x-tex",
|
||||||
|
".opml": "text-x-opml+xml",
|
||||||
|
".html": "text-html",
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, parent=None, mw=None):
|
def __init__(self, parent=None, mw=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
# Var
|
# Var
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
|
self.fileName = ""
|
||||||
|
|
||||||
#TODO
|
# Register importFormats:
|
||||||
|
self.formats = []
|
||||||
|
self.formats.append(importFormat("OPML", "text-x-opml+xml",
|
||||||
|
"OPML Files (*.opml)"))
|
||||||
|
self.formats.append(importFormat("Markdown", "text-x-markdown",
|
||||||
|
"Markdown files (*.md; *.txt; *)"))
|
||||||
|
self.formats.append(importFormat("Folder", "folder",
|
||||||
|
"<<folder>>"))
|
||||||
|
|
||||||
|
# Populate combo box with formats
|
||||||
|
self.populateImportList()
|
||||||
|
|
||||||
|
# Connections
|
||||||
|
self.btnChoseFile.clicked.connect(self.selectFile)
|
||||||
|
self.btnClearFileName.clicked.connect(self.setFileName)
|
||||||
|
self.btnPreview.clicked.connect(self.preview)
|
||||||
|
self.setFileName("")
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
# Combobox / Formats
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
def populateImportList(self):
|
||||||
|
|
||||||
|
def addFormat(name, icon):
|
||||||
|
self.cmbImporters.addItem(QIcon.fromTheme(icon), name)
|
||||||
|
|
||||||
|
for f in self.formats:
|
||||||
|
addFormat(f.name, f.icon)
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
# Import file
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
def selectFile(self):
|
||||||
|
|
||||||
|
# We find the current selected format
|
||||||
|
formatName = self.cmbImporters.currentText()
|
||||||
|
F = [F for F in self.formats if F.name == formatName][0]
|
||||||
|
|
||||||
|
options = QFileDialog.Options()
|
||||||
|
options |= QFileDialog.DontUseNativeDialog
|
||||||
|
if F.fileFormat == "<<folder>>":
|
||||||
|
options = QFileDialog.DontUseNativeDialog | QFileDialog.ShowDirsOnly
|
||||||
|
fileName = QFileDialog.getExistingDirectory(self, "Select import folder",
|
||||||
|
"", options=options)
|
||||||
|
else:
|
||||||
|
fileName, _ = QFileDialog.getOpenFileName(self, "Import from file", "",
|
||||||
|
F.fileFormat, options=options)
|
||||||
|
self.setFileName(fileName)
|
||||||
|
|
||||||
|
def setFileName(self, fileName):
|
||||||
|
if fileName:
|
||||||
|
self.fileName = fileName
|
||||||
|
self.btnPreview.setEnabled(True)
|
||||||
|
self.lblFileName.setText(os.path.basename(fileName))
|
||||||
|
self.lblFileName.setToolTip(fileName)
|
||||||
|
self.btnClearFileName.setVisible(True)
|
||||||
|
ext = os.path.splitext(fileName)[1]
|
||||||
|
if ext and ext in self.formatsIcon:
|
||||||
|
self.lblIcon.setVisible(True)
|
||||||
|
h = self.lblFileName.height()
|
||||||
|
self.lblIcon.setPixmap(
|
||||||
|
QIcon.fromTheme(self.formatsIcon[ext]).pixmap(h, h)
|
||||||
|
)
|
||||||
|
elif os.path.isdir(fileName):
|
||||||
|
self.lblIcon.setVisible(True)
|
||||||
|
h = self.lblFileName.height()
|
||||||
|
self.lblIcon.setPixmap(QIcon.fromTheme("folder").pixmap(h, h))
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.fileName = None
|
||||||
|
self.btnPreview.setEnabled(False)
|
||||||
|
self.lblFileName.setText("")
|
||||||
|
self.btnClearFileName.setVisible(False)
|
||||||
|
self.lblIcon.setVisible(False)
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
# Preview
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
def preview(self):
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
def getParentIndex(self):
|
||||||
|
if len(self.mw.treeRedacOutline.selectionModel().
|
||||||
|
selection().indexes()) == 0:
|
||||||
|
idx = QModelIndex()
|
||||||
|
else:
|
||||||
|
idx = self.mw.treeRedacOutline.currentIndex()
|
||||||
|
return idx
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Ui_importer(object):
|
||||||
self.cmbImporters.setObjectName("cmbImporters")
|
self.cmbImporters.setObjectName("cmbImporters")
|
||||||
self.horizontalLayout.addWidget(self.cmbImporters)
|
self.horizontalLayout.addWidget(self.cmbImporters)
|
||||||
self.btnManageImporters = QtWidgets.QPushButton(importer)
|
self.btnManageImporters = QtWidgets.QPushButton(importer)
|
||||||
|
self.btnManageImporters.setText("")
|
||||||
icon = QtGui.QIcon.fromTheme("preferences-system")
|
icon = QtGui.QIcon.fromTheme("preferences-system")
|
||||||
self.btnManageImporters.setIcon(icon)
|
self.btnManageImporters.setIcon(icon)
|
||||||
self.btnManageImporters.setObjectName("btnManageImporters")
|
self.btnManageImporters.setObjectName("btnManageImporters")
|
||||||
|
@ -34,6 +35,27 @@ class Ui_importer(object):
|
||||||
self.btnChoseFile.setIcon(icon)
|
self.btnChoseFile.setIcon(icon)
|
||||||
self.btnChoseFile.setObjectName("btnChoseFile")
|
self.btnChoseFile.setObjectName("btnChoseFile")
|
||||||
self.horizontalLayout.addWidget(self.btnChoseFile)
|
self.horizontalLayout.addWidget(self.btnChoseFile)
|
||||||
|
self.lblIcon = QtWidgets.QLabel(importer)
|
||||||
|
self.lblIcon.setText("")
|
||||||
|
self.lblIcon.setObjectName("lblIcon")
|
||||||
|
self.horizontalLayout.addWidget(self.lblIcon)
|
||||||
|
self.lblFileName = QtWidgets.QLabel(importer)
|
||||||
|
font = QtGui.QFont()
|
||||||
|
font.setBold(True)
|
||||||
|
font.setWeight(75)
|
||||||
|
self.lblFileName.setFont(font)
|
||||||
|
self.lblFileName.setText("")
|
||||||
|
self.lblFileName.setObjectName("lblFileName")
|
||||||
|
self.horizontalLayout.addWidget(self.lblFileName)
|
||||||
|
self.btnClearFileName = QtWidgets.QPushButton(importer)
|
||||||
|
self.btnClearFileName.setText("")
|
||||||
|
icon = QtGui.QIcon.fromTheme("edit-clear")
|
||||||
|
self.btnClearFileName.setIcon(icon)
|
||||||
|
self.btnClearFileName.setFlat(True)
|
||||||
|
self.btnClearFileName.setObjectName("btnClearFileName")
|
||||||
|
self.horizontalLayout.addWidget(self.btnClearFileName)
|
||||||
|
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
||||||
|
self.horizontalLayout.addItem(spacerItem1)
|
||||||
self.btnPreview = QtWidgets.QPushButton(importer)
|
self.btnPreview = QtWidgets.QPushButton(importer)
|
||||||
icon = QtGui.QIcon.fromTheme("document-print-preview")
|
icon = QtGui.QIcon.fromTheme("document-print-preview")
|
||||||
self.btnPreview.setIcon(icon)
|
self.btnPreview.setIcon(icon)
|
||||||
|
@ -63,8 +85,8 @@ class Ui_importer(object):
|
||||||
def retranslateUi(self, importer):
|
def retranslateUi(self, importer):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
importer.setWindowTitle(_translate("importer", "Import"))
|
importer.setWindowTitle(_translate("importer", "Import"))
|
||||||
self.label.setText(_translate("importer", "Import from:"))
|
self.label.setText(_translate("importer", "Format:"))
|
||||||
self.btnManageImporters.setText(_translate("importer", "Manage importers"))
|
self.btnManageImporters.setToolTip(_translate("importer", "Manage importers"))
|
||||||
self.btnChoseFile.setText(_translate("importer", "Chose file"))
|
self.btnChoseFile.setText(_translate("importer", "Chose file"))
|
||||||
self.btnPreview.setText(_translate("importer", "Preview"))
|
self.btnPreview.setText(_translate("importer", "Preview"))
|
||||||
self.grpSettings.setTitle(_translate("importer", "Settings"))
|
self.grpSettings.setTitle(_translate("importer", "Settings"))
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Import from:</string>
|
<string>Format:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -28,9 +28,12 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnManageImporters">
|
<widget class="QPushButton" name="btnManageImporters">
|
||||||
<property name="text">
|
<property name="toolTip">
|
||||||
<string>Manage importers</string>
|
<string>Manage importers</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="preferences-system">
|
<iconset theme="preferences-system">
|
||||||
<normaloff/>
|
<normaloff/>
|
||||||
|
@ -39,7 +42,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -61,6 +64,52 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lblIcon">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lblFileName">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnClearFileName">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="edit-clear"/>
|
||||||
|
</property>
|
||||||
|
<property name="flat">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnPreview">
|
<widget class="QPushButton" name="btnPreview">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
@ -1366,6 +1366,7 @@ class Ui_MainWindow(object):
|
||||||
self.actAbout.setText(_translate("MainWindow", "&About"))
|
self.actAbout.setText(_translate("MainWindow", "&About"))
|
||||||
self.actAbout.setToolTip(_translate("MainWindow", "About Manuskript"))
|
self.actAbout.setToolTip(_translate("MainWindow", "About Manuskript"))
|
||||||
self.actImport.setText(_translate("MainWindow", "Import…"))
|
self.actImport.setText(_translate("MainWindow", "Import…"))
|
||||||
|
self.actImport.setShortcut(_translate("MainWindow", "F7"))
|
||||||
|
|
||||||
from manuskript.ui.cheatSheet import cheatSheet
|
from manuskript.ui.cheatSheet import cheatSheet
|
||||||
from manuskript.ui.editors.mainEditor import mainEditor
|
from manuskript.ui.editors.mainEditor import mainEditor
|
||||||
|
|
|
@ -2490,6 +2490,9 @@ QListView::item:hover {
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Import…</string>
|
<string>Import…</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>F7</string>
|
||||||
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
Loading…
Reference in a new issue