Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
Comment thread
BlayW marked this conversation as resolved.
Outdated
3 changes: 2 additions & 1 deletion novelwriter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class Config:
"narratorDialog", "altDialogOpen", "altDialogClose", "highlightEmph", "stopWhenIdle",
"userIdleTime", "incNotesWCount", "fmtApostrophe", "fmtSQuoteOpen", "fmtSQuoteClose",
"fmtDQuoteOpen", "fmtDQuoteClose", "fmtPadBefore", "fmtPadAfter", "fmtPadThin",
"spellLanguage", "showViewerPanel", "showEditToolBar", "showSessionTime", "showSessionGoal", "showProjectGoal", "viewComments",
"spellLanguage", "showViewerPanel", "showEditToolBar", "showSessionTime",
"showSessionGoal", "showProjectGoal", "viewComments",
"viewSynopsis", "searchCase", "searchWord", "searchRegEx", "searchLoop", "searchNextFile",
"searchMatchCap", "searchProjCase", "searchProjWord", "searchProjRegEx", "verQtString",
"verQtValue", "verPyQtString", "verPyQtValue", "verPyString", "osType", "osLinux",
Expand Down
21 changes: 11 additions & 10 deletions novelwriter/core/projectdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import logging
import uuid


from datetime import date
from typing import TYPE_CHECKING, Any
from PyQt6.QtCore import QDate

from novelwriter.common import (
checkBool, checkInt, checkStringNone, checkUuid, isHandle,
Expand Down Expand Up @@ -63,7 +64,7 @@ def __init__(self, project: NWProject) -> None:
# Project Settings
self._doBackup = True
self._projGoal = 1
self._projDeadline = QDate.currentDate()
self._projDeadline = date.today()
self._sessGoal = 1
self._sessGoalAuto = False
self._language = None
Expand Down Expand Up @@ -136,22 +137,22 @@ def editTime(self) -> int:
def doBackup(self) -> bool:
"""Return the backup setting."""
return self._doBackup

@property
def projGoal(self) -> int:
"""Return the project goal."""
return self._projGoal

@property
def projDeadline(self) -> QDate | None:
def projDeadline(self) -> date | None:
"""Return the project deadline."""
return self._projDeadline

@property
def sessGoal(self) -> int:
"""Return the session goal."""
return self._sessGoal

@property
def sessGoalAuto(self) -> bool:
"""Return the automatic session goal setting."""
Expand Down Expand Up @@ -291,21 +292,21 @@ def setProjGoal(self, value: Any) -> None:
self._projGoal = checkInt(value, self._projGoal)
self._project.setProjectChanged(True)
return

def setProjDeadline(self, value: Any) -> None:
"""Set the project deadline."""
if value != self._projDeadline and isinstance(value, QDate):
if value != self._projDeadline and isinstance(value, date):
self._projDeadline = value
self._project.setProjectChanged(True)
return

def setSessGoal(self, value: Any) -> None:
"""Set the session goal."""
if value != self._sessGoal:
self._sessGoal = checkInt(value, self._sessGoal)
self._project.setProjectChanged(True)
return

def setSessGoalAuto(self, value: Any) -> None:
"""Set the session goal."""
if value != self._sessGoalAuto:
Expand Down
6 changes: 3 additions & 3 deletions novelwriter/core/projectxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import logging
import xml.etree.ElementTree as ET

import datetime
from enum import Enum
from pathlib import Path
from time import time
from typing import TYPE_CHECKING
from PyQt6.QtCore import QDate

from novelwriter import __hexversion__, __version__
from novelwriter.common import (
Expand Down Expand Up @@ -263,7 +263,7 @@ def _parseProjectSettings(self, xSection: ET.Element, data: NWProjectData) -> No
elif xItem.tag == "projGoal":
data.setProjGoal(xItem.text)
elif xItem.tag == "projDeadline":
date = QDate.fromString(xItem.text, "yyyy-MM-dd")
date = datetime.date.fromisoformat(xItem.text)
data.setProjDeadline(date)
elif xItem.tag == "sessGoalAuto":
data.setSessGoalAuto(xItem.text)
Expand Down Expand Up @@ -521,7 +521,7 @@ def write(self, data: NWProjectData, content: list, saveTime: float, editTime: i
xSettings = ET.SubElement(xRoot, "settings")
self._packSingleValue(xSettings, "doBackup", yesNo(data.doBackup))
self._packSingleValue(xSettings, "projGoal", data.projGoal)
self._packSingleValue(xSettings, "projDeadline", data.projDeadline.toString("yyyy-MM-dd"))
self._packSingleValue(xSettings, "projDeadline", data.projDeadline.isoformat())
self._packSingleValue(xSettings, "sessGoalAuto", yesNo(data.sessGoalAuto))
self._packSingleValue(xSettings, "sessGoal", data.sessGoal)
self._packSingleValue(xSettings, "language", data.language)
Expand Down
14 changes: 8 additions & 6 deletions novelwriter/dialogs/projectsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import csv
import logging

from datetime import date
from pathlib import Path

from PyQt6.QtCore import Qt, pyqtSignal, pyqtSlot, QDate
from PyQt6.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt6.QtGui import QCloseEvent, QColor
from PyQt6.QtWidgets import (
QAbstractItemView, QApplication, QColorDialog, QDialogButtonBox,
Expand Down Expand Up @@ -186,10 +187,10 @@ def _doSave(self) -> None:
spellLang = self.settingsPage.spellLang.currentData()
doBackup = not self.settingsPage.noBackup.isChecked()
projGoal = int(self.goalsPage.projGoal.text())
projDeadline = self.goalsPage.projDeadline.date()
projDeadline = self.goalsPage.projDeadline.date().toPyDate()
sessGoalAuto = self.goalsPage.sessGoalAuto.isChecked()
if sessGoalAuto:
days_remaining = QDate.currentDate().daysTo(projDeadline)
days_remaining = (projDeadline - date.today()).days
if days_remaining == 0:
days_remaining == 1
sessGoal = projGoal // days_remaining
Expand All @@ -208,7 +209,6 @@ def _doSave(self) -> None:

SHARED.mainGui.mainStatus.setGoals(projGoal, sessGoal)


if self.statusPage.changed:
logger.debug("Updating status labels")
project.updateStatus("s", self.statusPage.getNewList())
Expand Down Expand Up @@ -319,6 +319,7 @@ def __init__(self, parent: QWidget) -> None:

return


class _GoalsPage(NScrollableForm):

def __init__(self, parent: QWidget) -> None:
Expand Down Expand Up @@ -353,7 +354,8 @@ def __init__(self, parent: QWidget) -> None:
self.sessGoalAuto.setChecked(data.sessGoalAuto)
self.addRow(
self.tr("Auto populate session goal?"), self.sessGoalAuto,
self.tr("Calculate Session goal based on target date assuming daily sessions. Overrides configured session goal below.")
self.tr("Calculate Session goal based on target date assuming daily sessions. \
Overrides configured session goal below.")
Comment thread
BlayW marked this conversation as resolved.
Outdated
)

# Session Goal
Expand All @@ -367,11 +369,11 @@ def __init__(self, parent: QWidget) -> None:
stretch=(3, 2)
)


self.finalise()

return


class _StatusPage(NFixedPage):

C_DATA = 0
Expand Down
90 changes: 90 additions & 0 deletions novelwriter/extensions/progressbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"""
from __future__ import annotations

import logging

from math import ceil

from PyQt6.QtCore import QRect
Expand All @@ -35,6 +37,8 @@
QtTransparent
)

logger = logging.getLogger(__name__)


class NProgressCircle(QProgressBar):
"""Extension: Circular Progress Widget
Expand Down Expand Up @@ -126,3 +130,89 @@ def paintEvent(self, event: QPaintEvent) -> None:
painter.setBrush(self.palette().highlight())
painter.drawRect(0, 0, progress, self.height())
return


class NProgressGoal(QProgressBar):
"""Extension: Goal Progress Widget

A custom widget that paints a progress bar with custom styling and text.
"""

__slots__ = (
"_text", "_point", "_dRect", "_cRect", "_dPen", "_dBrush",
"_cPen", "_bPen", "_tColor"
)

def __init__(self, parent: QWidget, width: int, height: int, point: int) -> None:
super().__init__(parent=parent)
logger.debug(self.palette())
self._text = None
self._point = point
self._dRect = QRect(0, 0, width, height)
self._cRect = QRect(2 * point, 2 * point, width - 2 * point, height - 2 * point)
self._dPen = QPen(QtTransparent)
self._dBrush = QBrush(QtTransparent)
self.setColors(
track=self.palette().base().color().darker(300),
bar=self.palette().highlight().color(),
text=self.palette().text().color(),
back=self.palette().base().color().darker(300)
)
self.setSizePolicy(QtSizeFixed, QtSizeFixed)
self.setFixedWidth(width)
self.setFixedHeight(height)
return

def resetColors(self) -> None:
"""Reset the colours to the default values."""
self.setColors(
track=self.palette().base().color().darker(300),
bar=self.palette().highlight().color(),
text=self.palette().text().color(),
back=self.palette().base().color().darker(300)
)
return

def setColors(
self, back: QColor | None = None, track: QColor | None = None,
bar: QColor | None = None, text: QColor | None = None
) -> None:
"""Set the colours of the widget."""
if isinstance(back, QColor):
self._dPen = QPen(back)
self._dBrush = QBrush(back)
if isinstance(bar, QColor):
logger.debug(f"Setting bar colour: {bar}")
self._cPen = QPen(QBrush(bar), 2 * self._point, QtSolidLine)
self._cBrush = QBrush(bar)
if isinstance(track, QColor):
logger.debug(f"Setting track colour: {track}")
self._bPen = QPen(QBrush(track), 2 * self._point, QtSolidLine, QtRoundCap)
if isinstance(text, QColor):
self._tColor = text
return

def setCentreText(self, text: str | None) -> None:
"""Replace the progress text with a custom string."""
self._text = text
self.setValue(self.value()) # Triggers a redraw
return

def paintEvent(self, event: QPaintEvent) -> None:
"""Custom painter for the progress bar."""
progress = self.value()/self.maximum()
painter = QPainter(self)
painter.setRenderHint(QtPaintAntiAlias, True)

painter.setPen(self._bPen)
painter.setBrush(self._dBrush)
painter.drawRect(self._dRect)

painter.setPen(self._cPen)
painter.setBrush(self._cBrush)
x, y = self._cRect.topLeft().x(), self._cRect.topLeft().y()
painter.drawRect(x, y, ceil(self._cRect.width() * progress), self._cRect.height())

painter.setPen(self._tColor)
painter.drawText(self._cRect, QtAlignCenter, self._text or f"{(progress*100):.1f} %")
return
Loading