Improved the alert to user interface, and added an enum class for severity flags.
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ from PyQt5.QtCore import Qt, QTimer
|
||||
|
||||
from nw.gui.dochighlight import GuiDocHighlighter
|
||||
from nw.gui.wordcounter import WordCounter
|
||||
from nw.enum import nwDocAction
|
||||
from nw.enum import nwDocAction, nwAlert
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
+5
-4
@@ -21,6 +21,7 @@ from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView, QIn
|
||||
from nw.project.item import NWItem
|
||||
from nw.enum import nwItemType, nwItemClass
|
||||
from nw.constants import nwLabels
|
||||
from nw.enum import nwAlert
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -93,13 +94,13 @@ class GuiDocTree(QTreeWidget):
|
||||
|
||||
pHandle = self.getSelectedHandle()
|
||||
if pHandle is None:
|
||||
self.makeAlert("No valid parent item selected", 2)
|
||||
self.makeAlert("No valid parent item selected", nwAlert.ERROR)
|
||||
return False
|
||||
|
||||
if itemClass is None:
|
||||
itemClass = self.theProject.getItem(pHandle).itemClass
|
||||
if itemClass is None:
|
||||
self.makeAlert("Failed to find an appropriate item class for item %s" % pHandle, 2)
|
||||
self.makeAlert("Failed to find an appropriate item class for item %s" % pHandle, nwAlert.BUG)
|
||||
return False
|
||||
|
||||
logger.verbose("Adding new item of type %s and class %s to handle %s" % (
|
||||
@@ -234,7 +235,7 @@ class GuiDocTree(QTreeWidget):
|
||||
trItemP.setSelected(True)
|
||||
self.theProject.setProjectChanged(True)
|
||||
else:
|
||||
self.theParent.makeAlert(["Cannot delete folder.","It is not empty."],2)
|
||||
self.makeAlert(["Cannot delete folder.","It is not empty."], nwAlert.ERROR)
|
||||
return
|
||||
|
||||
elif nwItemS.itemType == nwItemType.ROOT:
|
||||
@@ -245,7 +246,7 @@ class GuiDocTree(QTreeWidget):
|
||||
self.theParent.mainMenu.setAvailableRoot()
|
||||
self.theProject.setProjectChanged(True)
|
||||
else:
|
||||
self.theParent.makeAlert(["Cannot delete root folder.","It is not empty."],2)
|
||||
self.makeAlert(["Cannot delete root folder.","It is not empty."], nwAlert.ERROR)
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
+10
-5
@@ -31,7 +31,7 @@ from nw.project.document import NWDoc
|
||||
from nw.project.item import NWItem
|
||||
from nw.convert.tokenizer import Tokenizer
|
||||
from nw.convert.tohtml import ToHtml
|
||||
from nw.enum import nwItemType
|
||||
from nw.enum import nwItemType, nwAlert
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -124,7 +124,7 @@ class GuiMain(QMainWindow):
|
||||
|
||||
return
|
||||
|
||||
def makeAlert(self, theMessage, theLevel):
|
||||
def makeAlert(self, theMessage, theLevel=nwAlert.INFO):
|
||||
"""Alert both the user and the logger at the same time. Message can be either a string or an
|
||||
array of strings. Severity level is 0 = info, 1 = warning, and 2 = error.
|
||||
"""
|
||||
@@ -137,18 +137,23 @@ class GuiMain(QMainWindow):
|
||||
logMsg = [theMessage]
|
||||
|
||||
msgBox = QMessageBox()
|
||||
if theLevel == 0:
|
||||
if theLevel == nwAlert.INFO:
|
||||
for msgLine in logMsg:
|
||||
logger.info(msgLine)
|
||||
msgBox.information(self, "Information", popMsg)
|
||||
elif theLevel == 1:
|
||||
elif theLevel == nwAlert.WARN:
|
||||
for msgLine in logMsg:
|
||||
logger.warning(msgLine)
|
||||
msgBox.warning(self, "Warning", popMsg)
|
||||
elif theLevel == 2:
|
||||
elif theLevel == nwAlert.ERROR:
|
||||
for msgLine in logMsg:
|
||||
logger.error(msgLine)
|
||||
msgBox.critical(self, "Error", popMsg)
|
||||
elif theLevel == nwAlert.BUG:
|
||||
for msgLine in logMsg:
|
||||
logger.error(msgLine)
|
||||
popMsg += "<br>This is a bug!"
|
||||
msgBox.critical(self, "Internal Error", popMsg)
|
||||
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user