Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
Handle modality on qt windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
sccolbert committed Jan 22, 2013
1 parent e60cdd7 commit 28f2433
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions enaml/qt/qt_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#------------------------------------------------------------------------------
import logging

from .qt.QtCore import QSize, Signal
from .qt.QtCore import Qt, QSize, Signal
from .qt.QtGui import QFrame, QLayout, QIcon, QImage, QPixmap
from .q_deferred_caller import deferredCall
from .q_single_widget_layout import QSingleWidgetLayout
Expand All @@ -15,6 +15,13 @@
logger = logging.getLogger(__name__)


MODALITY = {
'non_modal': Qt.NonModal,
'application_modal': Qt.ApplicationModal,
'window_modal': Qt.WindowModal,
}


class QWindowLayout(QSingleWidgetLayout):
""" A QSingleWidgetLayout subclass which adds support for windows
which explicitly set their minimum and maximum sizes.
Expand Down Expand Up @@ -60,7 +67,7 @@ class QWindow(QFrame):
#: A signal emitted when the window is closed.
closed = Signal()

def __init__(self, *args, **kwargs):
def __init__(self, parent=None):
""" Initialize a QWindow.
Parameters
Expand All @@ -70,7 +77,7 @@ def __init__(self, *args, **kwargs):
a QFrame.
"""
super(QWindow, self).__init__(*args, **kwargs)
super(QWindow, self).__init__(parent, Qt.Window)
self._central_widget = None
self._expl_min_size = QSize()
self._expl_max_size = QSize()
Expand Down Expand Up @@ -203,6 +210,7 @@ def create(self, tree):
super(QtWindow, self).create(tree)
self.set_title(tree['title'])
self.set_initial_size(tree['initial_size'])
self.set_modality(tree['modality'])
self._icon_source = tree['icon_source']
self.widget().closed.connect(self.on_closed)

Expand Down Expand Up @@ -299,11 +307,17 @@ def on_action_set_icon_source(self, content):
self.set_icon_source(content['icon_source'])

def on_action_set_title(self, content):
""" Handle the 'set-title' action from the Enaml widget.
""" Handle the 'set_title' action from the Enaml widget.
"""
self.set_title(content['title'])

def on_action_set_modality(self, content):
""" Handle the 'set_modality' action from the Enaml widget.
"""
self.set_modality(content['modality'])

#--------------------------------------------------------------------------
# Widget Update Methods
#--------------------------------------------------------------------------
Expand Down Expand Up @@ -355,6 +369,12 @@ def set_initial_size(self, size):
return
self.widget().resize(QSize(*size))

def set_modality(self, modality):
""" Set the modality of the window.
"""
self.widget().setWindowModality(MODALITY[modality])

def set_visible(self, visible):
""" Set the visibility on the window.
Expand Down

0 comments on commit 28f2433

Please sign in to comment.