Skip to content

Commit

Permalink
Merge pull request #1978 from UV-CDAT/vcs_fix_geometry_instantiation
Browse files Browse the repository at this point in the history
Vcs fix geometry instantiation
  • Loading branch information
aashish24 committed May 20, 2016
2 parents 7dbe9cc + e2d407e commit 9593283
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Packages/vcs/vcs/Canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4116,6 +4116,9 @@ def geometry(self, *args):
a.geometry(450,337)
"""
if len(args) == 0:
return self.backend.geometry()

if (args[0] <= 0) or (args[1] <= 0):
raise ValueError(
'Error - The width and height values must be an integer greater than 0.')
Expand Down
28 changes: 19 additions & 9 deletions Packages/vcs/vcs/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, canvas, renWin=None, debug=False, bg=None, geometry=None):
# Initially set to 16x Multi-Sampled Anti-Aliasing
self.antialiasing = 8
self._rasterPropsInVectorFormats = False
self._initialGeometry = geometry
self._geometry = geometry

if renWin is not None:
self.renWin = renWin
Expand Down Expand Up @@ -374,9 +374,9 @@ def createRenWin(self, *args, **kargs):
# turning off antialiasing by default
# mostly so that pngs are same accross platforms
self.renWin.SetMultiSamples(self.antialiasing)
if self._initialGeometry is not None:
width = self._initialGeometry["width"]
height = self._initialGeometry["height"]
if self._geometry is not None:
width = self._geometry["width"]
height = self._geometry["height"]
else:
width = None
height = None
Expand Down Expand Up @@ -435,9 +435,9 @@ def canvasinfo(self):
if (self.bg):
height = self.canvas.bgY
width = self.canvas.bgX
elif (self._initialGeometry):
height = self._initialGeometry['height']
width = self._initialGeometry['width']
elif (self._geometry):
height = self._geometry['height']
width = self._geometry['width']
else:
height = self.canvas.bgY
width = self.canvas.bgX
Expand Down Expand Up @@ -544,8 +544,18 @@ def isopened(self):
else:
return True

def geometry(self, x, y, *args):
self.renWin.SetSize(x, y)
def geometry(self, *args):
if len(args) == 0:
return self._geometry;
if len(args) < 2:
raise TypeError("Function takes zero or two <width, height> " \
"or more than two arguments. Got " + len(*args))
x = args[0]
y = args[1]

if self.renWin is not None:
self.renWin.SetSize(x, y)
self._geometry = {'width': x, 'height': y}
self._lastSize = (x, y)

def flush(self):
Expand Down
4 changes: 4 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ cdat_add_test(test_vcs_missing_colorname
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_missing_colorname.py
"${BASELINE_DIR}/test_vcs_missing_colorname.png"
)
cdat_add_test(test_vcs_geometry
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_geometry.py
)
##############################################################################
#
# These tests perform plotting and need sample data
Expand Down
32 changes: 32 additions & 0 deletions testing/vcs/test_vcs_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys, vcs

# This will check if we can set the geometry
# at the initialization of canvas
canvas = vcs.init(geometry=(600, 400))
canvas.open()

if dict(width=600, height=400) != canvas.geometry():
canvas.close()
sys.exit(1)

canvas.close()

canvas2 = vcs.init()

# This will check if we can safely set the geometry even
# though the canvas window has not been created yet
canvas2.geometry(400, 400)
canvas2.open()
if dict(width=400, height=400) != canvas2.geometry():
canvas2.close()
sys.exit(1)

# This will check if we can dynamically change the geometry
canvas2.geometry(500, 400)
canvas2.geometry(500, 500)
if dict(width=500, height=500) != canvas2.geometry():
canvas2.close()
sys.exit(1)

canvas2.close()
sys.exit(0)

0 comments on commit 9593283

Please sign in to comment.