Skip to content
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

Refactor fields #1234

Merged
merged 26 commits into from
Apr 6, 2023
Merged

Refactor fields #1234

merged 26 commits into from
Apr 6, 2023

Conversation

corranwebster
Copy link
Contributor

@corranwebster corranwebster commented Apr 2, 2023

This is a refactor of the Field class to split it into display and editable variants: base Fields may not be editable, EditaleFields add editability (ie. the value can be changed by the user). Includes tests and documentation, including fixes to make the documentation actually compile.

Adds a LabelField and ImageField to demonstrate the non-editable Fields.

@corranwebster corranwebster marked this pull request as ready for review April 4, 2023 08:30
Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with a (not very thorough) review. Amongst other comments, there are some copy-paste errors, and a typo in pyface.fields.api that breaks from pyface.fields.api import EditableField.

@@ -14,6 +14,8 @@

- :class:`~.CheckBoxField`
- :class:`~.ComboField`
- :class:`~.ImageField`
- :class:`~.LabelField`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Field and EditableField be added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

pyface/fields/api.py Outdated Show resolved Hide resolved
pyface/fields/i_editable_field.py Outdated Show resolved Hide resolved
pyface/fields/i_field.py Outdated Show resolved Hide resolved
raise NotImplementedError()
def _get_control_alignment(self):
""" Toolkit specific method to get the control's read_only state. """
raise NotImplementedError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency nit:

Suggested change
raise NotImplementedError
raise NotImplementedError()



def alignment_to_qalignment(alignment):
return ALIGNMENT_TO_QALIGNMENT[alignment]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have docstrings (or maybe just type annotations) here.

pyface/ui/wx/fields/editable_field.py Outdated Show resolved Hide resolved
pyface/ui/wx/fields/image_field.py Outdated Show resolved Hide resolved
pyface/ui/wx/fields/image_field.py Outdated Show resolved Hide resolved
import wx


class ImageControl(wx.Window):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I wanted to see this code in action, what's the easiest way for me to exercise this code manually? Are there examples that make use of this?

Copy link
Contributor Author

@corranwebster corranwebster Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No examples currently, but this was copied and simplified from the wx TraitsUI ImageEditor's ImageControl: https://github.com/enthought/traitsui/blob/main/traitsui/wx/image_control.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could exercise it with something like:

import wx
from pyface.api import ImageResource
from pyface.wx.image_control import ImageControl

window = wx.Frame()
# hack to get a wx bitmap - could also get it through wx api and an image file
bitmap = ImageResource('splash').create_bitmap()
control = ImageControl(window, bitmap)
window.Show()

I think (my wx is rusty)

corranwebster and others added 2 commits April 6, 2023 11:16
Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
@corranwebster
Copy link
Contributor Author

corranwebster commented Apr 6, 2023

This is probably going to fail because of PySide 6.5 and Numpy issues discussed in #1238

@corranwebster corranwebster merged commit 0328089 into main Apr 6, 2023
@corranwebster corranwebster deleted the enh/more-refactor-features branch April 6, 2023 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants