Skip to content

Commit

Permalink
Merge pull request #260 from NaturalHistoryMuseum/feature/status-bar
Browse files Browse the repository at this point in the history
Feature/status bar
  • Loading branch information
quicklizard99 committed Apr 13, 2016
2 parents 5fd179c + 81cf6a8 commit d8c82d8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version 0.1.26
- Fixed #258 - CTRL / apple key + number to select the active view
- Fixed #256 - Disable template 'Reload' command when default template selected
- Fixed #254 - An Error Occurred: {'Choices with data ...
- Fixed #218 - N boxes / N selected widget to a status bar

Version 0.1.25
-------------
Expand Down
18 changes: 13 additions & 5 deletions inselect/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from PySide import QtGui
from PySide.QtCore import Qt, QEvent, QSettings
from PySide.QtGui import (QMenu, QAction, QMessageBox, QDesktopServices,
QVBoxLayout, QWidget)
from PySide.QtGui import (QAction, QDesktopServices, QHBoxLayout, QMenu,
QMessageBox, QVBoxLayout, QWidget)

# This import is to register our icon resources with QT
import inselect.gui.icons # noqa
Expand Down Expand Up @@ -93,9 +93,19 @@ def __init__(self, app, filename=None):
sidebar = QWidget()
sidebar.setLayout(sidebar_layout)

# Summary view below tabs
summary_and_tabs_layout = QVBoxLayout()
# Remove margins and padding
summary_and_tabs_layout.setContentsMargins(0, 0, 0, 0)
summary_and_tabs_layout.setSpacing(0)
summary_and_tabs_layout.addWidget(self.tabs)
summary_and_tabs_layout.addWidget(self.view_summary.widget)
summary_and_tabs = QWidget()
summary_and_tabs.setLayout(summary_and_tabs_layout)

# Tabs alongside metadata fields
self.splitter = QtGui.QSplitter()
self.splitter.addWidget(self.tabs)
self.splitter.addWidget(summary_and_tabs)
self.splitter.addWidget(sidebar)
self.splitter.setSizes([600, 300])

Expand Down Expand Up @@ -1066,8 +1076,6 @@ def create_toolbar(self):
self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
self.toolbar.addWidget(self.cookie_cutter_widget)

self.toolbar.addSeparator()
self.toolbar.addWidget(self.view_summary.widget)
self.toolbar.addSeparator()
self.toolbar.addWidget(self.view_selector.widget)

Expand Down
22 changes: 18 additions & 4 deletions inselect/gui/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Model(QAbstractItemModel):
# Emitted when modified status changes
modified_changed = Signal()

DISPLAY_TEMPLATE = u'{0} {1}'
LEADING_ZEROES = u'{0:04d}'

def __init__(self, parent=None):
super(Model, self).__init__(parent)
self._modified = False
Expand Down Expand Up @@ -180,8 +183,18 @@ def data(self, index, role=Qt.DisplayRole):
else:
item = self._data[index.row()]
if role in (Qt.DisplayRole, Qt.ToolTipRole):
template = user_template_choice().current
return template.format_label(1 + index.row(), item['fields'])
# Title generated by the metedata template. Title is prefix with
# formatted row index, if title and formatted row index are
# different

title = user_template_choice().current.format_label(
1 + index.row(),
item['fields']
)
formatted_index = self.LEADING_ZEROES.format(1 + index.row())
if formatted_index != title:
title = self.DISPLAY_TEMPLATE.format(formatted_index, title)
return title
elif Qt.WhatsThisRole == role:
return 'Cropped object image'
elif RectRole == role:
Expand All @@ -191,8 +204,9 @@ def data(self, index, role=Qt.DisplayRole):
elif MetadataRole == role:
return item['fields']
elif MetadataValidRole == role:
template = user_template_choice().current
return template.validate_metadata(item['fields'])
return user_template_choice().current.validate_metadata(
item['fields']
)

def setData(self, index, value, role):
"""QAbstractItemModel virtual
Expand Down
13 changes: 3 additions & 10 deletions inselect/gui/views/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class CropDelegate(QAbstractItemDelegate):
# Border around cropped image
BORDER = 25

DISPLAY_TEMPLATE = u'{0} {1}'
LEADING_ZEROES = u'{0:04d}'

@property
def box_rect(self):
"QRect of the complete box"
Expand Down Expand Up @@ -88,13 +85,9 @@ def _paint_title(self, painter, option, index):
painter.setFont(font)
rect = self.title_rect.translated(option.rect.topLeft())

# Textual title in black at top left, prefixed with formatted index,
# if different
title = index.data(Qt.DisplayRole)
formatted_index = self.LEADING_ZEROES.format(1 + index.row())
if formatted_index != title:
title = self.DISPLAY_TEMPLATE.format(formatted_index, title)
painter.drawText(rect, Qt.AlignTop | Qt.AlignLeft, title)
# Textual title in black at top left
painter.drawText(rect, Qt.AlignTop | Qt.AlignLeft,
index.data(Qt.DisplayRole))

def _paint_crop(self, painter, option, index):
"""Paints the crop
Expand Down
54 changes: 33 additions & 21 deletions inselect/gui/views/summary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import locale
from PySide.QtGui import QAbstractItemView, QHBoxLayout, QLabel, QWidget
from PySide import QtCore
from PySide.QtGui import (QAbstractItemView, QHBoxLayout, QLabel, QSizePolicy,
QWidget)

from inselect.lib.utils import debug_print

Expand All @@ -11,36 +13,39 @@ def __init__(self, parent=None):
# This view is not visible
super(SummaryView, self).__init__(None)

layout = QHBoxLayout()

self.n_boxes = QLabel()
layout.addWidget(self.n_boxes)
self.info = QLabel()

# Last item has stretch greater than zero to force all labels to be
# left-aligned
self.n_selected = QLabel()
layout.addWidget(self.n_selected, stretch=1)
layout = QHBoxLayout()

# Smaller margins than the defaults
layout.setContentsMargins(
8, # left
2, # top
0, # right
2 # bottom
)

layout.addWidget(self.info, stretch=1)

self.widget = QWidget(parent)
self.widget.setLayout(layout)

def _n_boxes(self, n):
self.n_boxes.setText(
'{0} boxes'.format(locale.format("%d", n, grouping=True))
)

def _n_selected(self, n):
self.n_selected.setText(
'{0} selected'.format(locale.format("%d", n, grouping=True))
)
def _updated(self, n, selected):
template = u'{0} boxes / {1} selected / {2}'
self.info.setText(template.format(
locale.format("%d", n, grouping=True),
locale.format("%d", len(selected), grouping=True),
selected[0].data(QtCore.Qt.DisplayRole) if 1 == len(selected) else ''
))

def reset(self):
"""QAbstractItemView virtual
"""
debug_print('SummaryView.reset')
super(SummaryView, self).reset()
self._n_boxes(self.model().rowCount())
self._n_selected(0)
self._updated(self.model().rowCount(), [])

def setModel(self, model):
"""QAbstractItemView virtual
Expand All @@ -53,16 +58,23 @@ def dataChanged(self, topLeft, bottomRight):
"""QAbstractItemView virtual
"""
debug_print('SummaryView.dataChanged')
self._n_boxes(self.model().rowCount())
self._updated(
self.model().rowCount(), self.selectionModel().selectedIndexes()
)

def selectionChanged(self, selected, deselected):
"""QAbstractItemView slot
"""
debug_print('SummaryView.selectionChanged')
self._n_selected(len(self.selectionModel().selectedIndexes()))
self._updated(
self.model().rowCount(), self.selectionModel().selectedIndexes()
)

def rowsAboutToBeRemoved(self, parent, start, end):
"""QAbstractItemView slot
"""
debug_print('SummaryView.rowsAboutToBeRemoved')
self._n_boxes(self.model().rowCount() - (end - start))
self._updated(
self.model().rowCount() - (end - start),
self.selectionModel().selectedIndexes()
)

0 comments on commit d8c82d8

Please sign in to comment.