Skip to content

Commit

Permalink
FInal cleanup, UI improvements, and commenting.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMouse92 committed Dec 28, 2019
1 parent d3cfaea commit 1b70ada
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 25 deletions.
2 changes: 2 additions & 0 deletions timecard/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

from timecard import main

if __name__ == "__main__":
Expand Down
8 changes: 8 additions & 0 deletions timecard/data/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Settings [Timecard]
Author(s): Jason C. McDonald
Manages access, storage, and file read/write for application settings.
"""

import functools
import logging
import os
Expand Down Expand Up @@ -48,6 +54,8 @@ def load_from_file(cls):
"""
cls._settings = dict()

logging.debug(f"Loading settings from {str(cls._settings_path)}")

with cls._settings_path.open('r') as file:
for lineno, line in enumerate(file, start=1):
try:
Expand Down
9 changes: 9 additions & 0 deletions timecard/data/timelog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""Time Log [Timecard]
Author(s): Jason C. McDonald
Manages access, storage, and file read/write for the time log.
Also contains the class representing a single time log entry.
"""

from datetime import datetime
import functools
import logging
Expand Down Expand Up @@ -133,6 +140,8 @@ def load(cls, /, force=False):
# Retrieve the path from settings
path = Settings.get_logpath()

logging.debug(f"Loading time log from {path}")

# Initialize an empty log.
cls._log = dict()
# Attempt to open and parse the file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""About View [Timecard]
Author(s): Jason C. McDonald
Displays "about" data for Timecard.
"""

import os
from pathlib import Path
from pkg_resources import resource_filename
Expand All @@ -6,7 +12,7 @@
from PySide2.QtWidgets import QWidget, QVBoxLayout, QTextEdit


class About:
class AboutView:
widget = QWidget()
layout = QVBoxLayout()
lbl_info = QTextEdit()
Expand Down
9 changes: 8 additions & 1 deletion timecard/interface/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""App [Timecard]
Author(s): Jason C. McDonald
The main application classes. Most of the interface modules rely on this,
so it should not rely on any other module in the interface subpackage.
"""

import logging
import os
from pkg_resources import resource_filename
Expand Down Expand Up @@ -45,7 +52,7 @@ def run(cls):
def build(cls):
"""Construct the interface."""
logging.debug("Building main window.")
cls.window.resize(380, 400)
cls.window.resize(400, 400)
cls.window.setWindowTitle(
QApplication.translate("program_name", "Timecard")
)
Expand Down
6 changes: 6 additions & 0 deletions timecard/interface/appcontrols.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""App Controls [Timecard]
Author(s): Jason C. McDonald
Allows switching between major application views.
"""

from PySide2.QtWidgets import QPushButton, QHBoxLayout, QWidget
from PySide2.QtWidgets import QWhatsThis
from PySide2.QtGui import QIcon
Expand Down
6 changes: 6 additions & 0 deletions timecard/interface/editview.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Edit View [Timecard]
Author(s): Jason C. McDonald
Allows editing a single time log entry.
"""

from datetime import datetime

from PySide2.QtWidgets import QWidget, QGridLayout, QHBoxLayout, QVBoxLayout
Expand Down
7 changes: 7 additions & 0 deletions timecard/interface/interface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""Interface [Timecard]
Author(s): Jason C. McDonald
Top-level functions for the interface sub-package. These are the functions
initially called to build and run the interface.
"""

from timecard.interface.app import App
from timecard.interface.appcontrols import AppControls
from timecard.interface.notes import Notes
Expand Down
37 changes: 24 additions & 13 deletions timecard/interface/logview.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""Log View [Timecard]
Author(s): Jason C. McDonald
Displays the current log entries and allows deleting or triggering edits
on them.
"""

from PySide2.QtWidgets import QWidget, QTreeWidget, QGridLayout, QPushButton
from PySide2.QtWidgets import QTreeWidgetItem
from PySide2.QtGui import QIcon
Expand Down Expand Up @@ -39,12 +46,15 @@ class LogView:
def build(cls):
"""Build the interface"""
cls.tree_log.setWhatsThis("The time log.")
cls.tree_log.setHeaderLabels(
["Date", "Duration", "Activity"]
)
cls.tree_log.setSortingEnabled(True)
cls.layout.addWidget(cls.tree_log, 0, 0, 3, 3)
cls.refresh()

cls.layout.addWidget(cls.btn_edit, 3, 1, 1, 1)
cls.layout.addWidget(cls.btn_delete, 3, 2, 1, 1)
cls.layout.addWidget(cls.btn_delete, 3, 1, 1, 1)
cls.layout.addWidget(cls.btn_edit, 3, 2, 1, 1)
cls.unselected()
cls._set_mode_default()

Expand All @@ -57,9 +67,6 @@ def build(cls):
def refresh(cls):
"""Reload the data from the log."""
cls.tree_log.clear()
cls.tree_log.setHeaderLabels(
["Date", "Duration", "Activity"]
)
for entry in TimeLog.retrieve_log():
item = LogViewEntry(entry)
cls.tree_log.addTopLevelItem(item)
Expand Down Expand Up @@ -88,26 +95,30 @@ def _disconnect_buttons(cls):
def _set_mode_default(cls):
cls._disconnect_buttons()

cls.btn_edit.setText("Edit")
cls.btn_edit.setIcon(QIcon.fromTheme('document-properties'))
cls.btn_edit.clicked.connect(cls.edit)

cls.btn_delete.setText("Delete")
cls.btn_delete.setIcon(QIcon.fromTheme('edit-delete'))
cls.btn_delete.setWhatsThis("Delete the selected log entry.")
cls.btn_delete.clicked.connect(cls.prompt_delete)

cls.btn_edit.setText("Edit")
cls.btn_edit.setIcon(QIcon.fromTheme('document-properties'))
cls.btn_edit.setWhatsThis("Edit the selected log entry.")
cls.btn_edit.clicked.connect(cls.edit)

@classmethod
def _set_mode_prompt_delete(cls):
cls._disconnect_buttons()

cls.btn_edit.setText("Cancel")
cls.btn_edit.setIcon(QIcon.fromTheme('cancel'))
cls.btn_edit.clicked.connect(cls.cancel)

cls.btn_delete.setText("Confirm Delete")
cls.btn_delete.setIcon(QIcon.fromTheme('edit-delete'))
cls.btn_delete.setWhatsThis("Delete the selected log entry.")
cls.btn_delete.clicked.connect(cls.delete)

cls.btn_edit.setText("Keep")
cls.btn_edit.setIcon(QIcon.fromTheme('edit-undo'))
cls.btn_edit.setWhatsThis("Keep the selected log entry.")
cls.btn_edit.clicked.connect(cls.cancel)

@classmethod
def _selected_entry(cls):
item = cls.tree_log.selectedItems()[0]
Expand Down
6 changes: 6 additions & 0 deletions timecard/interface/notes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Notes [Timecard]
Author(s): Jason C. McDonald
The box for entering session activity notes.
"""

from PySide2.QtWidgets import QLineEdit


Expand Down
6 changes: 6 additions & 0 deletions timecard/interface/quitview.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Quit View [Timecard]
Author(s): Jason C. McDonald
Prompts the user whether they want to quit or not.
"""

from PySide2.QtCore import Qt
from PySide2.QtWidgets import QWidget, QGridLayout, QLabel, QPushButton
from PySide2.QtGui import QIcon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
"""Settings View [Timecard]
Author(s): Jason C. McDonald
Allows viewing and editing application settings.
"""

from datetime import datetime

from PySide2.QtWidgets import QWidget, QGridLayout, QHBoxLayout, QVBoxLayout
from PySide2.QtWidgets import QLabel, QCheckBox, QLineEdit, QPushButton
from PySide2.QtGui import QIcon

from timecard.data.timelog import TimeLog
from timecard.data.settings import Settings


class SettingsPanel:
class SettingsView:
widget = QWidget()
layout = QVBoxLayout()
grid_widget = QWidget()
Expand All @@ -28,13 +35,17 @@ class SettingsPanel:
btn_revert = QPushButton(QIcon.fromTheme('edit-undo'), "Revert")
btn_save = QPushButton(QIcon.fromTheme('document-save'), "Save")

reload_log = False

@classmethod
def build(cls):
"""Build the interface."""
cls.txt_logdir.textEdited.connect(cls.edited)
cls.txt_logdir.textEdited.connect(cls.logpath_edited)
cls.lbl_logdir.setWhatsThis("The directory where the logs are saved.")
cls.txt_logdir.setWhatsThis("The directory where the logs are saved.")
cls.txt_logname.textEdited.connect(cls.edited)
cls.txt_logname.textEdited.connect(cls.logpath_edited)
cls.lbl_logname.setWhatsThis("The filename for the log.")
cls.txt_logname.setWhatsThis("The filename for the log.")

Expand Down Expand Up @@ -84,6 +95,11 @@ def build(cls):
cls.refresh()
return cls.widget

@classmethod
def logpath_edited(cls):
"""Schedule reload of log."""
cls.reload_log = True

@classmethod
def datefmt_edited(cls):
"""Update the preview for the timestamp format."""
Expand All @@ -105,11 +121,17 @@ def not_edited(cls):
@classmethod
def refresh(cls):
"""Load and display current settings."""
# Cancel any scheduled log reloads.
cls.reload_log = False

# Load settings into interface.
cls.txt_logdir.setText(Settings.get_logdir_str())
cls.txt_logname.setText(Settings.get_logname())
cls.chk_persist.setChecked(Settings.get_persist())
cls.txt_datefmt.setText(Settings.get_datefmt())
cls.chk_decdur.setChecked(Settings.get_decdur())

# Update interface controls.
cls.datefmt_edited()
cls.not_edited()

Expand All @@ -122,3 +144,9 @@ def save(cls):
Settings.set_datefmt(cls.txt_datefmt.text())
Settings.set_decdur(cls.chk_decdur.isChecked())
cls.not_edited()

# If we're scheduled to reload the time logs...
if cls.reload_log:
# We must do so AFTER updating the path (earlier)
TimeLog.load(force=True)
cls.reload_log = False
6 changes: 6 additions & 0 deletions timecard/interface/systray.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""System Tray [Timecard]
Author(s): Jason C. McDonald
The application system tray and its menu.
"""

from PySide2.QtWidgets import QAction, QMenu, QSystemTrayIcon
from PySide2.QtGui import QIcon

Expand Down
6 changes: 6 additions & 0 deletions timecard/interface/timecontrols.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Time Controls [Timecard]
Author(s): Jason C. McDonald
Controls the timer and saves the time entries to the log.
"""

from PySide2.QtWidgets import QPushButton, QHBoxLayout, QWidget
from PySide2.QtGui import QIcon

Expand Down
9 changes: 8 additions & 1 deletion timecard/interface/timedisplay.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""Time Display [Timecard]
Author(s): Jason C. McDonald
Displays and stores the current timer duration, including its start timestamp
and state.
"""

from datetime import datetime

from PySide2.QtCore import Qt, QDateTime, QTime, QTimer
from PySide2.QtCore import QDateTime, QTime, QTimer
from PySide2.QtWidgets import QLCDNumber


Expand Down
14 changes: 10 additions & 4 deletions timecard/interface/workspace.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"""Workspace [Timecard]
Author(s): Jason C. McDonald
Switches between Views in the application.
"""

from PySide2.QtWidgets import QWidget, QStackedLayout

from timecard.interface.about import About
from timecard.interface.aboutview import AboutView
from timecard.interface.editview import EditView
from timecard.interface.logview import LogView
from timecard.interface.settingspanel import SettingsPanel
from timecard.interface.settingsview import SettingsView
from timecard.interface.quitview import QuitView


Expand All @@ -17,8 +23,8 @@ class Workspace:
def build(cls):
cls.widget.setLayout(cls.layout)
cls.layout.addWidget(LogView.build())
cls.layout.addWidget(About.build())
cls.layout.addWidget(SettingsPanel.build())
cls.layout.addWidget(AboutView.build())
cls.layout.addWidget(SettingsView.build())
cls.layout.addWidget(QuitView.build())
cls.layout.addWidget(EditView.build())

Expand Down
10 changes: 6 additions & 4 deletions timecard/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""
[Timecard]
Version: 2.0
#!/usr/bin/env python3

"""Timecard
Author(s): Jason C. McDonald
Track time spent.
"""

import logging

from timecard.interface import interface

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)


def startUI():
Expand Down

0 comments on commit 1b70ada

Please sign in to comment.