Skip to content

Commit

Permalink
Merge pull request #363 from NaturalHistoryMuseum/feature/362-report-…
Browse files Browse the repository at this point in the history
…elapsed-time

[#362] Command-line option to print elapsed time for which document w…
  • Loading branch information
quicklizard99 authored Oct 14, 2016
2 parents 4c9516e + 4cef0fd commit cc84318
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Version 0.1.35
- #273 Inselect as a package
- #83 Architecture and code organisation

Version 0.1.34
-------------
- #362 Command-line option to print elapsed time for which document was open

Version 0.1.34
-------------
- #353 Error 5
Expand Down
9 changes: 7 additions & 2 deletions inselect/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ def main(args=None):
parser.add_argument(
'-q', '--quit', action='store_true',
help='Exit immediately after showing the main window; intended for dev '
'purposes only'
'purposes only'
)
parser.add_argument(
'-s', '--stylesheet', action='store', type=Path,
help='Use stylesheet; intended for dev purposes only'
)
parser.add_argument(
'-t', '--print-time', action='store_true',
help='Will print, when a document is closed, the elapsed time for '
'which the document was open'
)
parser.add_argument(
'-v', '--version', action='version',
version='%(prog)s ' + inselect.__version__
Expand Down Expand Up @@ -89,7 +94,7 @@ def main(args=None):
# Stylesheet
app.setStyleSheet(_stylesheet(parsed.stylesheet))

window = MainWindow(app)
window = MainWindow(app, parsed.print_time)
if parsed.window_size:
window.show_with_size(parsed.window_size)
else:
Expand Down
18 changes: 17 additions & 1 deletion inselect/gui/main_window.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import print_function
import sys

from datetime import datetime
from functools import partial
from itertools import count, izip
from pathlib import Path
Expand Down Expand Up @@ -58,10 +60,16 @@ class MainWindow(QtGui.QMainWindow):

IMAGE_FILE_FILTER = u'Images ({0})'.format(u' '.join(IMAGE_PATTERNS))

def __init__(self, app):
def __init__(self, app, print_time=False):
"""if print_time is True, will print, when a document is closed, the
elapsed time for which the document was open.
"""
super(MainWindow, self).__init__()
self.app = app

self.print_time = print_time
self.time_doc_opened = None

# self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint)

# Plugins
Expand Down Expand Up @@ -415,6 +423,8 @@ def open_document(self, path=None, document=None):
self.document_path = path
self.model.from_document(self.document)

self.time_doc_opened = datetime.utcnow()

self.setWindowTitle('')
self.setWindowFilePath(str(self.document_path))
self.info_widget.set_document(self.document)
Expand Down Expand Up @@ -695,6 +705,12 @@ def empty_document(self):
"""Creates an empty document
"""
debug_print('MainWindow.empty_document')

if self.time_doc_opened and self.print_time:
elapsed = datetime.utcnow() - self.time_doc_opened
self.time_doc_opened = None
print(u'{0},{1}s'.format(self.document_path, elapsed.total_seconds()))

# Clear selection before closing for performance reasons
self.select_none()
self.document = None
Expand Down

0 comments on commit cc84318

Please sign in to comment.