Permalink
Browse files

Update layout and geometry methods to the latest wpyf implementation.

  • Loading branch information...
1 parent e403c31 commit 58731a966e9ccdb2eb017a271f520da881088cbf @itziakos itziakos committed Mar 19, 2012
Showing with 34 additions and 59 deletions.
  1. +34 −59 enaml/backends/wpf/wpf_widget_component.py
@@ -1,8 +1,5 @@
-import math
-
-from wpyf.visibility import Visibility
-from wpyf.canvas import Canvas as Panel
-
+from wpyf.api import Visibility, Canvas
+from wpyf.api import Size as WPFSize
from .wpf_base_widget_component import WPFBaseWidgetComponent
from ...components.widget_component import AbstractTkWidgetComponent
@@ -18,23 +15,21 @@ def create(self, parent):
"""
print "Create a widget component"
- self.widget = Panel()
+ self.widget = Canvas()
self.add_to_parent(parent)
def enable_updates(self):
""" Enable rendering updates for the underlying WPF widget.
"""
- #self.widget.set_updates_enabled(True)
- raise NotImplementedError
+ pass
def disable_updates(self):
""" Disable rendering updates for the underlying WPF widget.
"""
- #self.widget.set_updates_enabled(False)
- raise NotImplementedError
+ pass
def set_visible(self, visible):
""" Show or hide the widget.
@@ -52,36 +47,26 @@ def size_hint(self):
manager to determine how much space to allocate the widget.
"""
- print "size_hint: ",self
- self.widget.Measure((float('inf'), float('inf')))
- width, height = self.widget.DesiredSize
- # Round to integral values.
- print " returned hint is: ", width, height
- return Size(width=width, height=height)
+ self.widget.Measure(WPFSize(float('inf'), float('inf')))
+ hint = self.widget.DesiredSize
+ return Size(hint.Width, hint.Height)
def layout_geometry(self):
- """ Returns the (x, y, width, height) to of layout geometry
+ """ Returns the (x, y, width, height) tuple of layout geometry
info for the internal toolkit widget. This should ignore any
windowing decorations, and may be different than the value
returned by geometry() if the widget's effective layout rect
is different from its paintable rect.
"""
- widget = self.widget
- pos = self.pos()
- width = widget.ActualWidth
- height = widget.ActualHeight
- rect = Rect(pos.x, pos.y, width, height)
- print "Widget's {} effective geometry is {}".format(self.widget, rect)
- return rect
+ return self.geometry()
def set_layout_geometry(self, rect):
""" Sets the layout geometry of the internal widget to the
given x, y, width, and height values. The parameters passed
are equivalent semantics to layout_geometry().
"""
- print "Setting effective geometry of {} to {}".format(self.widget, rect)
self.set_geometry(rect)
def geometry(self):
@@ -90,19 +75,24 @@ def geometry(self):
decorations.
"""
+ # XXX GetDescendantBounds return negative values (e.g for a
+ # window that has clipped its contents). It is also repotring
+ # that all the elements are at position 0, 0 so it does not
+ # relect the current layout. The reason for this and how it
+ # will effect the layout in enaml needs more
+ # investigation. For now we use the Size and Pos methods.
+ # bounds = VisualTreeHelper.GetDescendantBounds(self.widget).
+ # return Rect(bounds.X, bounds.Y, bounds.Width, bounds.Height)
pos = self.pos()
size = self.size()
- rect = Rect(pos.x, pos.y, size.width, size.height)
- print "The geometry of {} is {}".format(self.widget, rect)
- return rect
+ return Rect(pos.x, pos.y, size.width, size.height)
def set_geometry(self, rect):
""" Sets the geometry of the internal widget to the given
x, y, width, and height values, ignoring any windowing
decorations.
"""
- print "Set geometry of {} to {}".format(self.widget, rect)
self.move(rect.pos)
self.resize(rect.size)
@@ -112,62 +102,49 @@ def min_size(self):
to be resized smaller than this value
"""
- size = Size(self.widget.MinWidth, self.widget.MinHeight)
- print "MinSize of {} is {}".format(self.widget, size)
- return size
+ return Size(self.widget.MinWidth, self.widget.MinHeight)
def set_min_size(self, size):
""" Set the hard minimum width and height of the widget, ignoring
any windowing decorations. A widget will not be able to be resized
smaller than this value.
"""
- print "set_min_size: ", self, size
- size = Size(*size)
- self.widget.MinWidth = size.width
- self.widget.MinHeight = size.height
+ self.widget.MinWidth = size[0]
+ self.widget.MinHeight = size[1]
+
def max_size(self):
""" Returns the hard maximum (width, height) of the widget,
ignoring any windowing decorations. A widget will not be able
to be resized larger than this value
"""
- size = Size(self.widget.MaxWidth, self.widget.MaxHeight)
- print "MaxSize of {} is {}".format(self.widget, size)
- return size
+ return Size(self.widget.MaxWidth, self.widget.MaxHeight)
def set_max_size(self, size):
""" Set the hard maximum width and height of the widget, ignoring
any windowing decorations. A widget will not be able to be resized
larger than this value.
"""
- print "set_max_size: ", self, size
- size = Size(*size)
- self.widget.MaxWidth = size.width
- self.widget.MaxHeight = size.height
+ self.widget.MaxWidth = size[0]
+ self.widget.MaxHeight = size[1]
def size(self):
""" Returns the size of the internal toolkit widget, ignoring any
windowing decorations, as a (width, height) tuple of integers.
"""
- widget = self.widget
- width = -1 if math.isnan(widget.Width) else widget.Width
- height = -1 if math.isnan(widget.Height) else widget.Height
- print "The size of the {} widget is {}".format(widget, (width, height))
- return Size(width, height)
+ return Size(self.widget.ActualWidth, self.widget.ActualHeight)
def resize(self, size):
""" Resizes the internal toolkit widget according the given
width and height integers, ignoring any windowing decorations.
"""
- print "Resize: ",self, size
- size = Size(*size)
- self.widget.Width = size.width
- self.widget.Height = size.height
+ self.widget.Width = size[0]
+ self.widget.Height = size[1]
def pos(self):
""" Returns the position of the internal toolkit widget as an
@@ -176,21 +153,19 @@ def pos(self):
parent, or to the screen if the widget is toplevel.
"""
- left = Panel.GetLeft(self.widget)
- top = Panel.GetTop(self.widget)
- print "Widget is at {}".format((left, top))
- return Pos(left, top)
+ # XXX This will work only when the container is a WPF Canvas panel
+ return Pos(Canvas.GetLeft(self.widget), Canvas.GetTop(self.widget))
def move(self, pos):
""" Moves the internal toolkit widget according to the given
x and y integers which are relative to the origin of the
widget's parent and includes any windowing decorations.
"""
+ # XXX This will work only when the container is a WPF Canvas panel
widget = self.widget
- Panel.SetLeft(widget, pos.x)
- Panel.SetTop(widget, pos.y)
- print "The new position of the {} widget is {}".format(widget, pos)
+ Canvas.SetLeft(widget, pos.x)
+ Canvas.SetTop(widget, pos.y)
def shell_enabled_changed(self, enabled):
""" The change handler for the 'enabled' attribute on the shell

0 comments on commit 58731a9

Please sign in to comment.