Skip to content

Commit

Permalink
make PopupView bg transparency configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sccolbert committed Jun 5, 2013
1 parent 0d92b4c commit 0731314
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 3 additions & 5 deletions enaml/qt/q_popup_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
pyqtSignal
)
from PyQt4.QtGui import (
QApplication, QFrame, QLayout, QPainter, QPainterPath, QRegion, QPen
QApplication, QWidget, QLayout, QPainter, QPainterPath, QRegion, QPen
)

from atom.api import Atom, Typed, Float, Int

from .q_single_widget_layout import QSingleWidgetLayout


class QPopupView(QFrame):
""" A custom QFrame which implements a framless popup widget.
class QPopupView(QWidget):
""" A custom QWidget which implements a framless popup widget.
It is useful for showing transient configuration dialogs as well
as temporary notification windows.
Expand Down Expand Up @@ -115,7 +115,6 @@ def __init__(self, parent=None, flags=Qt.Popup):
"""
super(QPopupView, self).__init__(parent)
self.setWindowFlags(flags | Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setAttribute(Qt.WA_DeleteOnClose)
layout = QSingleWidgetLayout()
layout.setSizeConstraint(QLayout.SetMinAndMaxSize)
Expand Down Expand Up @@ -473,7 +472,6 @@ def paintEvent(self, event):
""" Handle the paint event for the popup view.
"""
super(QPopupView, self).paintEvent(event)
palette = self.palette()
fill_color = palette.window().color()
stroke_color = palette.windowText().color()
Expand Down
5 changes: 4 additions & 1 deletion enaml/qt/qt_popup_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def create_widget(self):
""" Create the QPopupView widget.
"""
flags = WINDOW_TYPES[self.declaration.window_type]
d = self.declaration
flags = WINDOW_TYPES[d.window_type]
self.widget = QPopupView(self.parent_widget(), flags)
if d.translucent_background:
self.widget.setAttribute(Qt.WA_TranslucentBackground)

def init_widget(self):
""" Initialize the widget.
Expand Down
10 changes: 9 additions & 1 deletion enaml/widgets/popup_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from atom.api import (
Coerced, Enum, Float, Event, Int, Typed, ForwardTyped, observe, set_default
Bool, Coerced, Enum, Float, Event, Int, Typed, ForwardTyped, observe,
set_default
)

from enaml.application import deferred_call
Expand Down Expand Up @@ -142,6 +143,13 @@ class PopupView(Widget):
#: or equal to zero means no fade.
fade_out_duration = d_(Int(100))

#: Whether or not the background of the popup view is translucent.
#: This must be True in order to use background colors with alpha
#: and for the fade in and out animation to have effect. This value
#: must be set before the popup view is shown. Changes to this value
#: after the popup is shown will have no effect.
translucent_background = d_(Bool(True))

#: An event emitted when the view is closed. After this event is
#: fired, the view will be destroyed and should not be used.
closed = d_(Event(), writable=False)
Expand Down

0 comments on commit 0731314

Please sign in to comment.