1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#------------------------------------------------------------------------------
#
# Copyright (c) 2012, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Author: Pietro Berkes
# Date: Feb 2012
#
#------------------------------------------------------------------------------
"""
Test the layout of elements is consistent with the layout parameters.
"""
from traits.has_traits import HasTraits
from traits.trait_types import Str
from traitsui.item import Item
from traitsui.view import View
from traitsui.group import HGroup, VGroup
from traitsui.tests._tools import *
_DIALOG_WIDTH = 500
_DIALOG_HEIGHT = 500
_TXT_WIDTH = 100
class VResizeDialog(HasTraits):
txt = Str('hallo')
traits_view = View(
VGroup(
Item('txt', width=_TXT_WIDTH, resizable=True),
),
width = _DIALOG_WIDTH,
height = _DIALOG_HEIGHT,
resizable=True
)
class HResizeDialog(HasTraits):
txt = Str('hallo')
traits_view = View(
HGroup(
Item('txt', width=_TXT_WIDTH, resizable=True),
),
width = _DIALOG_WIDTH,
height = _DIALOG_HEIGHT,
resizable=True
)
@skip_if_not_qt4
def test_qt_resizable_in_vgroup():
# Behavior: Item.resizable controls whether a component can resize along
# the non-layout axis of its group. In a VGroup, resizing should work
# only in the horizontal direction.
from pyface import qt
with store_exceptions_on_all_threads():
dialog = VResizeDialog()
ui = dialog.edit_traits()
text = ui.control.findChild(qt.QtGui.QLineEdit)
# horizontal size should be large
nose.tools.assert_greater(text.width(), _DIALOG_WIDTH-100)
# vertical size should be unchanged
nose.tools.assert_less(text.height(), 100)
@skip_if_not_qt4
def test_qt_resizable_in_hgroup():
# Behavior: Item.resizable controls whether a component can resize along
# the non-layout axis of its group. In a HGroup, resizing should work
# only in the vertical direction.
from pyface import qt
with store_exceptions_on_all_threads():
dialog = HResizeDialog()
ui = dialog.edit_traits()
text = ui.control.findChild(qt.QtGui.QLineEdit)
# vertical size should be large
nose.tools.assert_greater(text.height(), _DIALOG_HEIGHT-100)
# horizontal size should be unchanged
# ??? maybe not: some elements (e.g., the text field) have
# 'Expanding' as their default behavior
#nose.tools.assert_less(text.width(), _TXT_WIDTH+100)
if __name__ == "__main__":
# Execute from command line for manual testing
vw = VResizeDialog()
vw.configure_traits()
|