-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataView Image channel #683
Changes from all commits
093f9cc
f1d915e
9dfc93b
20edfb9
d57301a
44f134b
bf3eafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
The icons are mostly derived work from other icons. As such they are | ||
licensed accordingly to the original license: | ||
|
||
Project License File | ||
------------------ --------------- ----------------------------------------- | ||
FamFamFam Flags Public Domain http://www.famfamfam.com/lab/icons/flags/ | ||
|
||
Unless stated in this file, icons are the work of Enthought, and are | ||
released under a 3 clause BSD license. | ||
|
||
Files and orginal authors: | ||
---------------------------------------------------------------------------- | ||
examples/data_view/images: | ||
gb.png | FamFamFam Flags | ||
us.png | FamFamFam Flags |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
import logging | ||
|
||
from pyface.i_image_resource import IImageResource | ||
from pyface.qt import is_qt5 | ||
from pyface.qt.QtCore import QAbstractItemModel, QModelIndex, Qt | ||
from pyface.data_view.index_manager import Root | ||
|
@@ -148,6 +149,11 @@ def data(self, index, role=Qt.DisplayRole): | |
elif role == Qt.EditRole: | ||
if value_type.has_editor_value(self.model, row, column): | ||
return value_type.get_editor_value(self.model, row, column) | ||
elif role == Qt.DecorationRole: | ||
if value_type.has_image(self.model, row, column): | ||
image = value_type.get_image(self.model, row, column) | ||
if isinstance(image, IImageResource): | ||
return image.create_image() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Observation, not a request change: Here to more untested code, but this entire module is untested and supposed to be rewritten. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of things that don't have issues yet on the dataview roadmap. This is one of them. |
||
elif role == Qt.ToolTipRole: | ||
if value_type.has_tooltip(self.model, row, column): | ||
return value_type.get_tooltip(self.model, row, column) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On naming... I notice that this is the same naming in the TableEditor / ListStrAdapter / etc. (https://github.com/enthought/traitsui/search?q=get_image&unscoped_q=get_image)
This image gets used with the
DecorationRole
, which is for displaying an icon or color (e.g. a color square next to the text).Given the new data view is supposed to be more flexible, e.g. it needs to support alternative editors in the cell such as a spinbox or a combobox, we probably want to differentiate an icon that accompanies the rest of the cell from an image that fills up the entire cell. Since this is new code, could we name this
has_icon
andget_icon
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a distinction in most backends between an image and an icon - an icon is a collection of related images with different styles (ie. versions for enabled/disabled, highlighted, activated, etc.). This is very much not an icon in this sense, and Pyface has no object which corresponds to an icon (
IImageResource
tries to be both an image and an icon and fails at both). So these method as written are very much a "image"-based.Let's leave this as-is for now, since this is currently the only way to display image data; we might revise when it comes time to implement custom editors/renderers and provide a separate channel for icon-like image collections.
Also note that Qt decorations are not limited to icons, and can potentially display thumbnails or even full images (as well as colors).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Just trying to say that as someone reading this method's docstring, it is not obvious that it is used as a decoration rather than an image filling up the whole cell. It was a bit of a surprise that the editable value is used alongside this image.
Qt documentation is very specific about what
DecorationRole
means:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a large image and no text, the decoration will fill up the whole cell (or most of it - I think there may be a border, and you have to take into account how cell sizes are determined).
As someone writing an implementation of this method, you shouldn't care how this image is being displayed; you are providing some image data, and it is up to the view to determine what to do with it.