Package arcmap :: Module resizewidget
[hide private]
[frames] | no frames]

Source Code for Module arcmap.resizewidget

  1  ################################################################################ 
  2  # Authors: Brian Schott (Sir Alaran) 
  3  # Copyright: Brian Schott (Sir Alaran) 
  4  # Date: Sep 29 2009 
  5  # License: 
  6  # 
  7  # This program is free software: you can redistribute it and/or modify 
  8  # it under the terms of the GNU General Public License as published by 
  9  # the Free Software Foundation, either version 3 of the License, or 
 10  # (at your option) any later version. 
 11  # 
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 15  # GNU General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  ################################################################################ 
 20   
 21   
 22  """ 
 23  Contains a custom widget for previewing a resize operation 
 24  """ 
 25   
 26  import cairo 
 27  import gtk 
 28   
 29  import graphics 
 30   
 31   
32 -class ResizeView(gtk.DrawingArea):
33 """ 34 Widget for previewing a resize operation. 35 """ 36 37 __gsignals__ = {"expose-event" : "override"} 38
39 - def __init__(self, tileWidth, tileHeight , thumb):
40 """ 41 @type tileWidth: int 42 @param tileWidth: current width of map in tiles 43 @type tileHeight: int 44 @param tileHeight: current height of map in tiles 45 @type thumb: cairo.ImageSurface 46 @param thumb: thumbnail image of the map 47 """ 48 gtk.DrawingArea.__init__(self) 49 self.__tWidth = thumb.get_width() 50 self.__tHeight = thumb.get_height() 51 self.__pixelSize = int(max(thumb.get_width(), thumb.get_height())) 52 self.__oldWidth = tileWidth 53 self.__oldHeight = tileHeight 54 self.__thumb = thumb 55 self.__newWidth = tileWidth 56 self.__newHeight = tileHeight 57 self.__scaleFactor = 1.0 58 self.__top = 0 59 self.__bottom = 0 60 self.__left = 0 61 self.__right = 0 62 self.__checkerBoard = graphics.getCheckerPattern(16) 63 self.set_size_request(thumb.get_width(), thumb.get_height())
64
65 - def setTop(self, top):
66 self.__top = top 67 self.__newHeight = self.__oldHeight + self.__top + self.__bottom 68 self.__setDimentions()
69
70 - def setBottom(self, bottom):
71 self.__bottom = bottom 72 self.__newHeight = self.__oldHeight + self.__top + self.__bottom 73 self.__setDimentions()
74
75 - def setLeft(self, left):
76 self.__left = left 77 self.__newWidth = self.__oldWidth + self.__left + self.__right 78 self.__setDimentions()
79
80 - def setRight(self, right):
81 self.__right = right 82 self.__newWidth = self.__oldWidth + self.__left + self.__right 83 self.__setDimentions()
84
85 - def do_expose_event(self, event):
86 """ 87 Redraws the widget 88 """ 89 context = self.window.cairo_create() 90 context.set_source(self.__checkerBoard) 91 context.paint() 92 context.scale(self.__scaleFactor, self.__scaleFactor) 93 tileWidth = float(self.__tHeight) / float(self.__oldHeight) 94 context.set_source_surface(self.__thumb, self.__left * tileWidth, 95 self.__top * tileWidth) 96 context.rectangle(self.__left * tileWidth, 97 self.__top * tileWidth, self.__tWidth, self.__tHeight) 98 context.fill()
99
100 - def __setDimentions(self):
101 # Sets the dimentions of the widget and causes a redraw with the proper 102 # scaling applied. The math here is magical. Don't mess with it 103 w = self.__pixelSize 104 h = self.__pixelSize 105 # gd = greater dimention 106 gd = max(self.__oldWidth, self.__oldHeight) 107 if self.__newWidth > self.__newHeight: 108 h = self.__pixelSize * (float(self.__newHeight) / float(self.__newWidth)) 109 self.__scaleFactor = gd / float(self.__newWidth) 110 else: 111 w = self.__pixelSize * (float(self.__newWidth) / float(self.__newHeight)) 112 self.__scaleFactor = gd / float(self.__newHeight) 113 self.set_size_request(int(w), int(h)) 114 self.queue_draw()
115