diff --git a/Packages/vcs/Lib/Canvas.py b/Packages/vcs/Lib/Canvas.py index 91ea3921a1..4fca9f07ca 100644 --- a/Packages/vcs/Lib/Canvas.py +++ b/Packages/vcs/Lib/Canvas.py @@ -18,7 +18,7 @@ # landscape (width exceeding height), portrait (height exceeding# # width), or full-screen mode. # # # -# Version: 4.0 # +# Version: 2.4 # # # ############################################################################### @@ -4462,13 +4462,13 @@ def landscape(self, width=-99, height=-99, x=-99, y=-99, clear=0): if (self.orientation() == 'landscape'): return - if (((not isinstance(width, IntType))) or ((not isinstance(height, IntType))) or - ((not isinstance(x, IntType))) or ((not isinstance(y, IntType))) or + if (((not isinstance(width, int))) or ((not isinstance(height, int))) or + ((not isinstance(x, int))) or ((not isinstance(y, int))) or ((width != -99) and (width < 0)) or ((height != -99) and (height < 0)) or ((x != -99) and (x < 0)) or ((y != -99) and (y < 0))): raise ValueError( 'If specified, width, height, x, and y must be integer values greater than or equal to 0.') - if (((not isinstance(clear, IntType))) and (clear not in [0, 1])): + if (((not isinstance(clear, int))) and (clear not in [0, 1])): raise ValueError( "clear must be: 0 - 'the default value for not clearing the canvas' or 1 - 'for clearing the canvas'.") @@ -4476,7 +4476,7 @@ def landscape(self, width=-99, height=-99, x=-99, y=-99, clear=0): and (x == -99) and (y == -99) and (clear == 0)): cargs = () try: - dict = self.canvas.canvasinfo(*cargs) + dict = self.canvasinfo(*cargs) except: dict = {} height = dict.get('width', -99) @@ -4486,7 +4486,7 @@ def landscape(self, width=-99, height=-99, x=-99, y=-99, clear=0): self.flush() # update the canvas by processing all the X events args = (width, height, x, y, clear) - l = self.canvas.landscape(*args) + l = self.backend.landscape(*args) return l @@ -4657,7 +4657,7 @@ def portrait(self, width=-99, height=-99, x=-99, y=-99, clear=0): and (x == -99) and (y == -99) and (clear == 0)): cargs = () try: - dict = self.canvas.canvasinfo(*cargs) + dict = self.canvasinfo(*cargs) except: dict = {} height = dict.get('width', -99) diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py index e9150a2002..e01598e782 100644 --- a/Packages/vcs/Lib/VTKPlots.py +++ b/Packages/vcs/Lib/VTKPlots.py @@ -383,15 +383,18 @@ def canvasinfo(self): return info def orientation(self, *args, **kargs): - if self.renWin is None: - return "landscape" - w, h = self.renWin.GetSize() + canvas_info = self.canvasinfo() + w = canvas_info["width"] + h = canvas_info["height"] if w > h: return "landscape" else: return "portrait" - def portrait(self, W, H, x, y, clear): + def resize_or_rotate_window(self, W=-99, H=-99, x=-99, y=-99, clear=0): + # Resize and position window to the provided arguments except when the + # values are default and negative. In the latter case, it should just + # rotate the window. if clear: self.clear() if self.renWin is None: @@ -404,6 +407,14 @@ def portrait(self, W, H, x, y, clear): self.canvas.bgY = W else: self.renWin.SetSize(W, H) + self.canvas.bgX = W + self.canvas.bgY = H + + def portrait(self, W=-99, H=-99, x=-99, y=-99, clear=0): + self.resize_or_rotate_window(W, H, x, y, clear) + + def landscape(self, W=-99, H=-99, x=-99, y=-99, clear=0): + self.resize_or_rotate_window(W, H, x, y, clear) def initialSize(self): # Gets user physical screen dimensions diff --git a/testing/vcs/CMakeLists.txt b/testing/vcs/CMakeLists.txt index 34f7eb1e4e..6f93a2de7b 100644 --- a/testing/vcs/CMakeLists.txt +++ b/testing/vcs/CMakeLists.txt @@ -136,6 +136,10 @@ cdat_add_test(vcs_test_dump_json ${cdat_SOURCE_DIR}/testing/vcs/test_dump_json.py ${cdat_SOURCE_DIR}/testing/vcs/test_vcs_dump_json.json ) +cdat_add_test(vcs_test_background_mode_rotate + "${PYTHON_EXECUTABLE}" + ${cdat_SOURCE_DIR}/testing/vcs/test_background_mode_rotate.py + ) # Some vector plot testing FOREACH(angle -180 -135 -90 -45 0 45 135 90 135 ) diff --git a/testing/vcs/test_background_mode_rotate.py b/testing/vcs/test_background_mode_rotate.py new file mode 100644 index 0000000000..028c044b93 --- /dev/null +++ b/testing/vcs/test_background_mode_rotate.py @@ -0,0 +1,44 @@ +import vcs +import numpy + +data = numpy.sin(numpy.arange(100)) +data = numpy.reshape(data, (10, 10)) + +x = vcs.init() +x.plot(data, bg=1) +assert x.orientation() == "landscape", "Default canvas orientation failed" +c = x.canvasinfo() +assert c['width'] == 814, "Default canvas width failed" +assert c['height'] == 606, "Default canvas height failed" + +x.clear() +x.portrait() +x.plot(data, bg=1) +assert x.orientation() == "portrait", "Portrait canvas orientation failed" +c = x.canvasinfo() +assert c['width'] == 606, "Portrait canvas width failed" +assert c['height'] == 814, "Portrait canvas height failed" + +x.clear() +x.landscape() +x.plot(data, bg=1) +assert x.orientation() == "landscape", "Landscape canvas orientation failed" +c = x.canvasinfo() +assert c['width'] == 814, "Landscape canvas width failed" +assert c['height'] == 606, "Landscape canvas height failed" + +x.clear() +x.landscape() +x.plot(data, bg=1) +assert x.orientation() == "landscape", "Landscape canvas orientation failed" +c = x.canvasinfo() +assert c['width'] == 814, "Landscape canvas width failed" +assert c['height'] == 606, "Landscape canvas height failed" + +x.clear() +x.portrait() +x.plot(data, bg=1) +assert x.orientation() == "portrait", "Portrait canvas orientation failed" +c = x.canvasinfo() +assert c['width'] == 606, "Portrait canvas width failed" +assert c['height'] == 814, "Portrait canvas height failed"