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

Add CloseEvent to DockItem #303

Merged
merged 5 commits into from
Aug 29, 2018

Conversation

bburan
Copy link
Contributor

@bburan bburan commented Aug 20, 2018

This will allow DockItem widgets to perform an action in response to the titlebar close button being clicked (and ignore this event if desired).

This will allow DockItem widgets to perform an action in response to the
titlebar close button being clicked (and ignore this event if desired).
Copy link
Member

@MatthieuDartiailh MatthieuDartiailh left a comment

Choose a reason for hiding this comment

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

LGTM

I will test later. @sccolbert an opinion on this ?

@codecov-io
Copy link

codecov-io commented Aug 20, 2018

Codecov Report

Merging #303 into master will increase coverage by 0.01%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #303      +/-   ##
==========================================
+ Coverage   70.21%   70.23%   +0.01%     
==========================================
  Files         304      305       +1     
  Lines       23625    23642      +17     
==========================================
+ Hits        16589    16604      +15     
- Misses       7036     7038       +2
Impacted Files Coverage Δ
enaml/widgets/window.py 58.04% <100%> (-1.3%) ⬇️
enaml/widgets/dock_item.py 84% <100%> (+0.66%) ⬆️
enaml/qt/qt_dialog.py 75.55% <100%> (ø) ⬆️
enaml/qt/qt_window.py 65.21% <100%> (+0.25%) ⬆️
enaml/qt/qt_main_window.py 60.68% <100%> (ø) ⬆️
enaml/qt/qt_dock_item.py 77.67% <85.71%> (+0.67%) ⬆️
enaml/widgets/close_event.py 88.88% <88.88%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e5cd02...fcd42e6. Read the comment docs.

@sccolbert
Copy link
Member

sccolbert commented Aug 20, 2018 via email

@MatthieuDartiailh
Copy link
Member

Sure @sccolbert . The proxy_ref trick is similar to what you did on the QtWindow (but not at the same place and you used an atomref), hence why it was not really bothering to me (but I will have to check what atomref does...).

@sccolbert
Copy link
Member

sccolbert commented Aug 20, 2018 via email

@bburan
Copy link
Contributor Author

bburan commented Aug 20, 2018

Are you suggesting:

class DockItemEventFilter(QObject):

    def __init__(self, declaration, *args, **kwargs):
        self.declaration = declaration
        QObject.__init__(self, *args, **kwargs)

    def eventFilter(self, object, event):
        if event.type() == QEvent.Close:
            close_event = CloseEvent()
            self.declaration.closing(close_event)
            if not close_event.is_accepted():
                event.ignore()
                return True
        return QObject.eventFilter(self, object, event)

Then doing the following in QtDockItem:

    def create_widget(self):
        """ Create the underlying QDockItem widget.

        """
        self.widget = QCustomDockItem(self.parent_widget())
        self.event_filter = DockItemEventFilter(self.declaration)
        self.widget.installEventFilter(self.event_filter)


@sccolbert
Copy link
Member

sccolbert commented Aug 20, 2018 via email

@bburan
Copy link
Contributor Author

bburan commented Aug 20, 2018

Ok, sounds good. It now parallels what's done in the main window class (with atomref).

@MatthieuDartiailh
Copy link
Member

ping @sccolbert

The implementation now matches the one used for windows. To me this is good to go. Let me know If you think it is worth re-visiting the whole idea using event filters.

Copy link
Member

@sccolbert sccolbert left a comment

Choose a reason for hiding this comment

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

Code looks good. Couple minor cleanup fixes needed before merging.

@@ -10,7 +10,8 @@
from atom.api import Typed, atomref

from enaml.layout.geometry import Pos, Rect, Size
from enaml.widgets.window import ProxyWindow, CloseEvent
from enaml.widgets.window import ProxyWindow
from enaml.widgets.close_event import CloseEvent
Copy link
Member

Choose a reason for hiding this comment

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

close_event should be imported before window to maintain sort order. /pedantry

@@ -0,0 +1,35 @@
from atom.api import Atom, Bool
Copy link
Member

Choose a reason for hiding this comment

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

This file needs a copyright header.

Copy link
Member

Choose a reason for hiding this comment

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

This is always a bit unclear to me but can the copyright mention 2013 when the file was created only in 2018 ?

@@ -15,6 +15,7 @@
from enaml.layout.geometry import Pos, Rect, Size

from .container import Container
from .close_event import CloseEvent
Copy link
Member

Choose a reason for hiding this comment

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

This should be imported before .container to maintain sort order.

@sccolbert
Copy link
Member

sccolbert commented Aug 28, 2018 via email

@sccolbert
Copy link
Member

sccolbert commented Aug 28, 2018 via email

@@ -8,7 +8,7 @@
from atom.api import Typed, atomref

from enaml.widgets.dialog import ProxyDialog
from enaml.widgets.window import CloseEvent
from enaml.widgets.close_event import CloseEvent
Copy link
Member

Choose a reason for hiding this comment

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

Almost there. This is the last one that's out of order.

@sccolbert
Copy link
Member

:shipit:

@MatthieuDartiailh
Copy link
Member

Thanks @bburan this is a welcome addition. Thanks @sccolbert for the reviews.

@MatthieuDartiailh MatthieuDartiailh merged commit 26544b0 into nucleic:master Aug 29, 2018
@bburan
Copy link
Contributor Author

bburan commented Sep 4, 2018

@MatthieuDartiailh My colleague was trying to test out Enaml by cutting-and-pasting examples from readthedocs. He couldn't get the dock_area.enaml to work because I added a closing event to the DockItem (to demo the addition in this PR) and the current conda channels do not yet reflect master (but readthedocs.org does). Do we want to worry about this detail? My coworker was getting a bit frustrated testing it out before he contacted me.

@MatthieuDartiailh
Copy link
Member

I probably should compile the docs for released versions (never had time to set that up). And make sure people notice they are looking at the development version docs. Thanks for reporting.

@MatthieuDartiailh
Copy link
Member

Sadly for the last release the docs are broken ... I will add doc building to the CI and hopefully starting with the next release the stable docs will be available.

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.

4 participants