Added an import file to document feature
This commit is contained in:
@@ -47,6 +47,7 @@ class Config:
|
|||||||
self.confPath = None
|
self.confPath = None
|
||||||
self.confFile = None
|
self.confFile = None
|
||||||
self.homePath = None
|
self.homePath = None
|
||||||
|
self.lastPath = None
|
||||||
self.appPath = None
|
self.appPath = None
|
||||||
self.appRoot = None
|
self.appRoot = None
|
||||||
self.appIcon = None
|
self.appIcon = None
|
||||||
@@ -129,6 +130,7 @@ class Config:
|
|||||||
|
|
||||||
self.confFile = self.appHandle+".conf"
|
self.confFile = self.appHandle+".conf"
|
||||||
self.homePath = path.expanduser("~")
|
self.homePath = path.expanduser("~")
|
||||||
|
self.lastPath = self.homePath
|
||||||
self.appPath = path.dirname(__file__)
|
self.appPath = path.dirname(__file__)
|
||||||
self.appRoot = path.join(self.appPath,path.pardir)
|
self.appRoot = path.join(self.appPath,path.pardir)
|
||||||
self.helpPath = path.join(self.appRoot,"help","en_GB")
|
self.helpPath = path.join(self.appRoot,"help","en_GB")
|
||||||
@@ -212,6 +214,7 @@ class Config:
|
|||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
|
self.lastPath = self._parseLine(cnfParse, cnfSec, "lastpath", self.CNF_STR, self.lastPath)
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
self.recentList[i] = self._parseLine(cnfParse, cnfSec, "recent%d" % i,self.CNF_STR, self.recentList[i])
|
self.recentList[i] = self._parseLine(cnfParse, cnfSec, "recent%d" % i,self.CNF_STR, self.recentList[i])
|
||||||
|
|
||||||
@@ -278,6 +281,7 @@ class Config:
|
|||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
cnfParse.add_section(cnfSec)
|
cnfParse.add_section(cnfSec)
|
||||||
|
cnfParse.set(cnfSec,"lastpath", str(self.lastPath))
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
cnfParse.set(cnfSec,"recent%d" % i, str(self.recentList[i]))
|
cnfParse.set(cnfSec,"recent%d" % i, str(self.recentList[i]))
|
||||||
|
|
||||||
@@ -312,6 +316,10 @@ class Config:
|
|||||||
self.confFile = path.basename(newPath)
|
self.confFile = path.basename(newPath)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def setLastPath(self, lastPath):
|
||||||
|
self.lastPath = path.dirname(lastPath)
|
||||||
|
return True
|
||||||
|
|
||||||
def setWinSize(self, newWidth, newHeight):
|
def setWinSize(self, newWidth, newHeight):
|
||||||
if abs(self.winGeometry[0] - newWidth) > 5:
|
if abs(self.winGeometry[0] - newWidth) > 5:
|
||||||
self.winGeometry[0] = newWidth
|
self.winGeometry[0] = newWidth
|
||||||
|
|||||||
@@ -289,6 +289,9 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def isEmpty(self):
|
||||||
|
return self.qDocument.isEmpty()
|
||||||
|
|
||||||
##
|
##
|
||||||
# Document Events and Maintenance
|
# Document Events and Maintenance
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class GuiItemEditor(QDialog):
|
|||||||
if itemLayout in self.validLayouts:
|
if itemLayout in self.validLayouts:
|
||||||
self.editLayout.addItem(nwLabels.LAYOUT_NAME[itemLayout],itemLayout)
|
self.editLayout.addItem(nwLabels.LAYOUT_NAME[itemLayout],itemLayout)
|
||||||
|
|
||||||
self.mainForm.addRow("Name", self.editName)
|
self.mainForm.addRow("Label", self.editName)
|
||||||
self.mainForm.addRow("Status", self.editStatus)
|
self.mainForm.addRow("Status", self.editStatus)
|
||||||
self.mainForm.addRow("Layout", self.editLayout)
|
self.mainForm.addRow("Layout", self.editLayout)
|
||||||
|
|
||||||
|
|||||||
+9
-2
@@ -312,8 +312,15 @@ class GuiMainMenu(QMenuBar):
|
|||||||
menuItem.triggered.connect(self.theParent.closeDocViewer)
|
menuItem.triggered.connect(self.theParent.closeDocViewer)
|
||||||
self.docuMenu.addAction(menuItem)
|
self.docuMenu.addAction(menuItem)
|
||||||
|
|
||||||
# # Document > Separator
|
# Document > Separator
|
||||||
# self.docuMenu.addSeparator()
|
self.docuMenu.addSeparator()
|
||||||
|
|
||||||
|
# Document > Close Preview
|
||||||
|
menuItem = QAction("Import from File", self)
|
||||||
|
menuItem.setStatusTip("Import document from a text or markdown file")
|
||||||
|
menuItem.setShortcut("Ctrl+Shift+I")
|
||||||
|
menuItem.triggered.connect(self.theParent.importDocument)
|
||||||
|
self.docuMenu.addAction(menuItem)
|
||||||
|
|
||||||
# # Document > Split
|
# # Document > Split
|
||||||
# menuItem = QAction("Split Document", self)
|
# menuItem = QAction("Split Document", self)
|
||||||
|
|||||||
@@ -366,6 +366,54 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def importDocument(self):
|
||||||
|
|
||||||
|
lastPath = self.mainConf.lastPath
|
||||||
|
|
||||||
|
extFilter = [
|
||||||
|
"Text files (*.txt)",
|
||||||
|
"Markdown files (*.md)",
|
||||||
|
"All files (*.*)",
|
||||||
|
]
|
||||||
|
dlgOpt = QFileDialog.Options()
|
||||||
|
dlgOpt |= QFileDialog.DontUseNativeDialog
|
||||||
|
inPath = QFileDialog.getOpenFileName(
|
||||||
|
self,"Import File",lastPath,options=dlgOpt,filter=";;".join(extFilter)
|
||||||
|
)
|
||||||
|
if inPath:
|
||||||
|
loadFile = inPath[0]
|
||||||
|
self.mainConf.setLastPath(loadFile)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
theText = None
|
||||||
|
try:
|
||||||
|
with open(loadFile,mode="r") as inFile:
|
||||||
|
theText = inFile.read()
|
||||||
|
except Exception as e:
|
||||||
|
self.makeAlert(["Could not read file. The file cannot be a binary file.",str(e)], nwAlert.ERROR)
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self.docEditor.theHandle is None:
|
||||||
|
self.makeAlert(["Please open a document to import the text file into."], nwAlert.ERROR)
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not self.docEditor.isEmpty():
|
||||||
|
if self.mainConf.showGUI:
|
||||||
|
msgBox = QMessageBox()
|
||||||
|
msgRes = msgBox.question(
|
||||||
|
self, "Import Document",
|
||||||
|
"Importing the file will overwrite the current content of the document. Do you want to proceed?"
|
||||||
|
)
|
||||||
|
if msgRes != QMessageBox.Yes:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.docEditor.setText(theText)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Tree Item Actions
|
# Tree Item Actions
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user