Advertisement
Guest User

Untitled

a guest
Jun 4th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 43.64 KB | None | 0 0
  1. diff -aur lovesnow-deepin-scrot-46375e8/src/mainscrot.py lovesnow-deepin-scrot-46375e8.edited/src/mainscrot.py
  2. --- lovesnow-deepin-scrot-46375e8/src/mainscrot.py  2012-01-28 18:57:41.000000000 -0800
  3. +++ lovesnow-deepin-scrot-46375e8.edited/src/mainscrot.py   2012-06-04 13:56:52.042071266 -0700
  4. @@ -47,7 +47,7 @@
  5.  
  6.  class MainScrot:
  7.      '''Main scrot.'''
  8. -  
  9. +
  10.      def __init__(self):
  11.          '''Init Main scrot.'''
  12.  
  13. @@ -56,37 +56,37 @@
  14.          self.width = self.height = 0
  15.          self.x = self.y = self.rectWidth = self.rectHeight = 0
  16.          self.buttonToggle = None
  17. -        
  18. -        self.frameColor = "#00AEFF"# "#FFFF0"
  19. +
  20. +        self.frameColor = "#00AEFF"# "#FFFF0"
  21.          self.frameLineWidth = 2
  22.          self.dragPosition = None
  23.          self.dragStartX = self.dragStartY = self.dragStartOffsetX = self.drawStartOffsetY = 0
  24.          self.dragPointRadius = 4
  25. -        
  26. +
  27.          self.dragFlag = False
  28.          self.showToolbarFlag = False
  29. -        self.showColorbarFlag = False
  30. +        self.showColorbarFlag = False
  31.          self.showTextWindowFlag = False
  32.          self.textDragOffsetX = self.textDragOffsetY = 0
  33.          self.saveFiletype = 'png'
  34. -        
  35. +
  36.          self.toolbarOffsetX = 10
  37.          self.toolbarOffsetY = 10
  38.          #self.toolbarHeight = 50
  39. -        
  40. +
  41.          self.actionSize = 2
  42.          self.actionColor = "#FF0000"
  43.          self.fontName = "Sans 10"
  44. -        
  45.  
  46. -        
  47. -        # default window
  48. +
  49. +
  50. +        # default window
  51.          self.scrotWindowInfo = getScrotWindowInfo()
  52.          self.windowFlag = True
  53.  
  54.          # keybinding map
  55.          self.keyBindings = {}
  56. -        
  57. +
  58.          # Init action list.
  59.          self.currentAction = None
  60.          self.actionList = []
  61. @@ -97,16 +97,16 @@
  62.          self.textModifyFlag = False
  63.          self.drawTextLayoutFlag = False
  64.  
  65. -        
  66. +
  67.          # Get desktop background.
  68. -        self.desktopBackground = self.getDesktopSnapshot()
  69. -        
  70. +        self.desktopBackground = self.getDesktopSnapshot()
  71. +
  72.          # Init window.
  73.          self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  74.          self.window.fullscreen()
  75.          self.window.set_icon_from_file("../theme/logo/deepin-scrot.ico")
  76.          self.window.set_keep_above(True)
  77. -        
  78. +
  79.          # Init event handle.
  80.          self.window.add_events(gtk.gdk.KEY_RELEASE_MASK)
  81.          self.window.add_events(gtk.gdk.POINTER_MOTION_MASK)
  82. @@ -116,34 +116,34 @@
  83.          self.window.connect("expose-event", lambda w, e: self.getCurrentCoord(w))
  84.          self.window.connect("expose-event", self.redraw)
  85.          self.window.connect("button-press-event", self.buttonPress)
  86. -        
  87. +
  88.          self.window.connect("button-press-event", self.doubleClickRect)
  89.          self.window.connect("button-release-event", self.buttonRelease)
  90.          self.window.connect("motion-notify-event", self.motionNotify)
  91.          self.window.connect("key-press-event", self.keyPress)
  92. -        
  93. +
  94.          # Register key binding.
  95.          self.registerKeyBinding("Escape", lambda : self.destroy(self.window))
  96.          self.registerKeyBinding("C-s", self.saveSnapshotToFile)
  97.          self.registerKeyBinding("Return", self.saveSnapshot)
  98.          self.registerKeyBinding("C-z", self.undo)
  99. -        
  100. +
  101.          # Init toolbar window.
  102.          self.initToolbar()
  103. -        
  104. +
  105.          # Init text window.
  106.          self.initTextWindow()
  107. -        
  108. +
  109.          # Init color window.
  110.          self.initColorWindow()
  111. -        
  112. -      
  113. +
  114. +
  115.          # Show.
  116.          self.window.show_all()
  117. -        
  118. +
  119.          gtk.main()
  120. -        
  121. -    
  122. +
  123. +
  124.      def initColorWindow(self):
  125.          ''' init ColorWindow'''
  126.          paddingX = 5
  127. @@ -151,12 +151,12 @@
  128.          iconWidth = iconHeight = 28
  129.          self.colorNum = 9
  130.          self.iconIndex = 2
  131. -        
  132. +
  133.          self.colorbarWindow = gtk.Window(gtk.WINDOW_POPUP)
  134.          self.colorbarWindow.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
  135.          self.colorbarWindow.set_keep_above(True)
  136.          self.colorbarWindow.set_transient_for(self.window)
  137. -        
  138. +
  139.          self.colorbarWindow.set_decorated(False)
  140.          self.colorbarWindow.set_resizable(False)
  141.          self.colorbarWindow.set_default_size(100, 24)
  142. @@ -178,8 +178,8 @@
  143.  
  144.          self.colorbarWindow.connect("size-allocate", lambda w, a: updateShape(w, a, 2))
  145.          self.colorbarWindow.connect('expose-event', lambda w,e: exposeBackground(w, e, appTheme.getDynamicPixbuf("color_bg.png")))
  146. -        
  147. -    
  148. +
  149. +
  150.          self.smallSizeButton = self.createSizeButton('small', 2)
  151.          self.smallSizeButton.connect('button-press-event', lambda w, e: self.setIconIndex(2))
  152.  
  153. @@ -189,26 +189,26 @@
  154.          self.bigSizeButton = self.createSizeButton('big', 5)
  155.          self.bigSizeButton.connect('button-press-event', lambda w, e: self.setIconIndex(5))
  156.  
  157. -        
  158. +
  159.          self.sizeAlign = gtk.Alignment()
  160.          self.sizeAlign.set(0.5,0.5,0,0)
  161.          self.sizeAlign.set_padding(2, 1, 0, 0)
  162.          self.sizeAlign.add(self.sizeBox)
  163.          self.dynamicBox.pack_start(self.sizeAlign)
  164.          self.colorbarBox.pack_start(self.dynamicBox)
  165. -        
  166. +
  167.          self.fontLabel = gtk.Label("Sans 10")
  168.          self.fontEvent = gtk.EventBox()
  169.          self.fontEvent.add(self.fontLabel)
  170.          self.fontEvent.set_visible_window(False)
  171. -        self.fontEvent.connect("button-press-event", lambda w, e: self.openFontDialog())
  172. +        self.fontEvent.connect("button-press-event", lambda w, e: self.openFontDialog())
  173.          setClickableCursor(self.fontEvent)
  174.          self.fontEvent.set_size_request(100, -1)
  175.  
  176.          separatorLabel = gtk.Label()
  177.          drawSeparator(separatorLabel, 'sep')
  178.          self.colorbarBox.pack_start(separatorLabel)
  179. -        
  180. +
  181.          self.colorBox = gtk.EventBox()
  182.  
  183.          self.colorbarBox.pack_start(self.colorBox)
  184. @@ -219,9 +219,9 @@
  185.          self.colorBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FF0000"))
  186.          self.colorBox.connect('expose-event', lambda w, e:self.setColorboxBorder(w))
  187.          self.colorBox.connect('button-press-event', self.colorSetEvent)
  188. -        
  189. -            
  190. -        
  191. +
  192. +
  193. +
  194.  
  195.          self.vbox = gtk.VBox(False, 2)
  196.          self.aboveHbox = gtk.HBox(False, 2)
  197. @@ -289,14 +289,14 @@
  198.  
  199.          pinkButton = self.createColorButton('pink', False)
  200.          pinkButton.connect('button-press-event', lambda w,e: self.setButtonColor('pink'))
  201. -        
  202. +
  203.          wathetButton = self.createColorButton('wathet', False)
  204.          wathetButton.connect('button-press-event', lambda w,e: self.setButtonColor('wathet'))
  205.  
  206.  
  207.          self.vbox.pack_start(self.belowHbox)
  208.          self.colorbarBox.pack_start(self.vbox)
  209. -        
  210. +
  211.      def openFontDialog(self):
  212.          '''open font dialog.'''
  213.          self.fontDialog = gtk.FontSelectionDialog("font select")
  214. @@ -311,13 +311,13 @@
  215.          if response == gtk.RESPONSE_OK:
  216.              self.fontName = self.fontDialog.get_font_name()
  217.              self.fontLabel.set_label(self.fontDialog.get_font_name())
  218. -        
  219. +
  220.          self.adjustToolbar()
  221.          self.showToolbar()
  222.          self.showColorbar()
  223.          self.fontDialog.destroy()
  224. -        
  225. -      
  226. +
  227. +
  228.      def colorSetEvent(self, widget, event):
  229.          '''colorBox button_press event'''
  230.          self.colorDialog = gtk.ColorSelectionDialog('Select color')
  231. @@ -340,10 +340,10 @@
  232.          self.showToolbar()
  233.          self.showColorbar()
  234.          self.colorDialog.destroy()
  235. -    
  236. +
  237.      def setColorboxBorder(self, widget):
  238.          '''set colorBox border '''
  239. -        (x, y, width, height, depth) = widget.window.get_geometry()
  240. +        (x, y, width, height, depth) = widget.window.get_geometry()
  241.          cr = widget.window.cairo_create()
  242.          cr.set_line_width(2)
  243.          cr.rectangle(0,0,width, height)
  244. @@ -353,13 +353,7 @@
  245.          cr.set_line_width(1)
  246.          cr.set_source_rgb(*colorHexToCairo("#FFFFFF"))
  247.          cr.stroke()
  248. -        
  249. -        
  250. -        
  251. -        
  252. -        
  253.  
  254. -        
  255.      def initToolbar(self):
  256.          '''Init toolbar.'''
  257.          # Init window.
  258. @@ -381,7 +375,7 @@
  259.          self.toolbarWindow.set_size_request(
  260.              self.toolbarIconWidth * self.toolbarIconNum + self.toolbarPaddingX * 2,
  261.              self.toolbarIconHeight + self.toolbarPaddingY * 2)
  262. -        
  263. +
  264.          # Add action button.
  265.          self.toolBox = gtk.HBox(False, 2)
  266.          self.toolAlign = gtk.Alignment()
  267. @@ -389,25 +383,25 @@
  268.          self.toolAlign.set_padding(self.toolbarPaddingY + 2, self.toolbarPaddingY, self.toolbarPaddingX, self.toolbarPaddingX)
  269.          self.toolAlign.add(self.toolBox)
  270.          self.toolbarWindow.add(self.toolAlign)
  271. -        
  272. +
  273.          self.actionRectangleButton = self.createActionButton("rect", __("Tip draw rectangle"))
  274.          self.actionRectangleButton.connect("button-press-event", lambda w, e: self.setOtherInactive(w))
  275.          self.actionRectangleButton.connect('toggled', lambda w: self.buttonToggled(w))
  276.          self.actionRectangleButton.connect("button-release-event", lambda w, e: self.toggleReleaseEvent())
  277. -        
  278.  
  279. -        
  280. +
  281. +
  282.          self.actionEllipseButton = self.createActionButton("ellipse", __("Tip draw ellipse"))
  283.          self.actionEllipseButton.connect("button-press-event", lambda w, e: self.setOtherInactive(w))
  284.          self.actionEllipseButton.connect('toggled', lambda w: self.buttonToggled(w))
  285.          self.actionEllipseButton.connect("button-release-event", lambda w, e: self.toggleReleaseEvent())
  286. -        
  287. +
  288.          self.actionArrowButton = self.createActionButton("arrow", __("Tip draw arrow"))
  289.          self.actionArrowButton.connect("button-press-event", lambda w, e: self.setOtherInactive(w))
  290.          self.actionArrowButton.connect('toggled', lambda w: self.buttonToggled(w))
  291.          self.actionArrowButton.connect("button-release-event", lambda w, e: self.toggleReleaseEvent())
  292. -      
  293. -        
  294. +
  295. +
  296.          self.actionLineButton = self.createActionButton("line", __("Tip draw line"))
  297.          self.actionLineButton.connect("button-press-event", lambda w, e: self.setOtherInactive(w))
  298.          self.actionLineButton.connect('toggled', lambda w: self.buttonToggled(w))
  299. @@ -423,11 +417,11 @@
  300.  
  301.          self.actionUndoButton = self.createOtherButton("undo", __("Tip undo"))
  302.          self.actionUndoButton.connect("button-press-event", lambda w, e: self.undo())
  303. -        
  304. -        
  305. +
  306. +
  307.          self.actionSaveButton = self.createOtherButton("save", __("Tip save"))
  308.          self.actionSaveButton.connect("button-press-event", lambda w, e: self.saveSnapshotToFile())
  309. -        
  310. +
  311.          separatorLabel = gtk.Button()
  312.          drawSeparator(separatorLabel, 'sep')
  313.          self.toolBox.pack_start(separatorLabel)
  314. @@ -437,44 +431,44 @@
  315.  
  316.          self.actionFinishButton = self.createOtherButton("finish",__("Tip finish"))
  317.          self.actionFinishButton.connect("button-press-event", lambda w, e: self.saveSnapshot())
  318. -      
  319. -      
  320. +
  321. +
  322.      def setOtherInactive(self, button):
  323.          buttonList = [self.actionRectangleButton, self.actionEllipseButton, self.actionArrowButton, self.actionLineButton,
  324.                        self.actionTextButton]
  325. -        
  326. +
  327.          for eachButton in buttonList:
  328.              if eachButton == button:
  329.                  continue
  330.              eachButton.set_active(False)
  331. -    
  332. +
  333.      def setAllInactive(self):
  334.          buttonList = [self.actionRectangleButton, self.actionEllipseButton, self.actionArrowButton, self.actionLineButton,
  335.                        self.actionTextButton]
  336. -        
  337. +
  338.          for eachButton in buttonList:
  339.              eachButton.set_active(False)
  340. -        
  341. +
  342.      def isHaveOneToggled(self):
  343.          buttonList = [self.actionRectangleButton, self.actionEllipseButton, self.actionArrowButton, self.actionLineButton,
  344.                        self.actionTextButton]
  345. -        
  346. +
  347.          for eachButton in buttonList:
  348.              if eachButton.get_active():
  349.                  return True
  350.          return False
  351. -    
  352. +
  353.      def toggleReleaseEvent(self):
  354.          buttonList = [self.actionRectangleButton, self.actionEllipseButton, self.actionArrowButton, self.actionLineButton,
  355.                        self.actionTextButton]
  356.          self.isToggled = False
  357. -        
  358. +
  359.          for eachButton in buttonList:
  360.              if eachButton.get_active():
  361.                  self.isToggled = True
  362. -        
  363. -        
  364. -    
  365. +
  366. +
  367. +
  368.      def buttonToggled(self, widget):
  369.          '''the button toggled'''
  370.          if widget.get_active():
  371. @@ -488,7 +482,7 @@
  372.                  self.setActionType(ACTION_LINE)
  373.              elif widget == self.actionTextButton:
  374.                  self.setActionType(ACTION_TEXT)
  375. -            
  376. +
  377.              self.showColorbar()
  378.  
  379.          else:
  380. @@ -497,19 +491,19 @@
  381.                  self.setActionType(ACTION_SELECT)
  382.              elif self.actionList and self.isToggled or self.textActionList:
  383.                  self.setActionType(None)
  384. -            
  385. -        
  386. +
  387. +
  388.      def setIconIndex(self, index):
  389.          '''Set icon index.'''
  390.          self.iconIndex = index
  391.          self.actionSize = index
  392.          self.colorbarWindow.queue_draw()
  393. -        
  394. -        
  395. +
  396. +
  397.      def getIconIndex(self):
  398.          '''Get icon index.'''
  399.          return self.iconIndex
  400. -        
  401. +
  402.      def initTextWindow(self):
  403.          '''Init text window.'''
  404.          # Init window.
  405. @@ -528,37 +522,37 @@
  406.          self.textAlign.set(0.5, 0.5, 0, 0)
  407.          self.textAlign.set_padding(10, 10, 10, 10)
  408.          self.textVbox = gtk.VBox()
  409. -        
  410. +
  411.  
  412.          scrollWindow = gtk.ScrolledWindow()
  413.          scrollWindow.set_shadow_type(gtk.SHADOW_ETCHED_IN)
  414. -        scrollWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  415. +        scrollWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  416.  
  417.          self.textView = gtk.TextView()
  418.  
  419.          textBuffer = self.textView.get_buffer()
  420.          self.textView.connect("expose-event", self.exposeTextViewTag)
  421. -        
  422. +
  423.          self.textTag = textBuffer.create_tag("first",
  424.                                          foreground_gdk=gtk.gdk.color_parse(self.actionColor),
  425.                                          font=self.fontName)
  426.          textBuffer.apply_tag(self.textTag, textBuffer.get_start_iter(), textBuffer.get_end_iter())
  427. -        
  428. +
  429.          self.textView.set_cursor_visible(True)
  430.          self.textView.set_wrap_mode(gtk.WRAP_WORD)
  431.          self.textView.set_size_request(300, 60)
  432. -        
  433. +
  434.          #textLabel = gtk.Label("按Enter可保存,按Shift+Enter可输入多行内容")
  435. -        
  436. +
  437.          scrollWindow.add(self.textView)
  438.          self.textVbox.pack_start(scrollWindow)
  439.          #self.textVbox.pack_start(textLabel)
  440.          self.textAlign.add(self.textVbox)
  441.          self.textWindow.add(self.textAlign)
  442.  
  443. -        
  444. +
  445.          self.textWindow.set_focus(self.textView)
  446. -    
  447. +
  448.      def exposeTextViewTag(self, widget, event):
  449.          ''' expose of textView'''
  450.          textBuffer = widget.get_buffer()
  451. @@ -586,73 +580,73 @@
  452.          #     self.y + self.rectHeight - ey - offset,
  453.          #     -1, 10, 10, 10
  454.          #     )
  455. -        
  456. +
  457.          # self.textWindow.grab_focus()
  458. -        
  459. +
  460.      def hideTextWindow(self):
  461.          '''Hide text window.'''
  462.          self.showTextWindowFlag = False
  463.          self.textView.get_buffer().set_text("")
  464.          self.textWindow.hide_all()
  465. -        
  466. -    
  467. +
  468. +
  469.      def getInputText(self):
  470.          '''Get input text.'''
  471.          textBuffer = self.textView.get_buffer()
  472.          return (textBuffer.get_text(textBuffer.get_start_iter(), textBuffer.get_end_iter())).rstrip(" ")
  473. -        
  474. +
  475.      def setActionType(self, aType):
  476.          '''Set action. type'''
  477. -        self.action = aType    
  478. +        self.action = aType
  479.          self.currentAction = None
  480. -        
  481. +
  482.      def createActionButton(self, iconName, helpText):
  483.          '''Create action button.'''
  484.          #actionButton = gtk.Button()
  485.          actionButton = gtk.ToggleButton()
  486.          drawSimpleButton(actionButton, iconName, helpText)
  487.          self.toolBox.pack_start(actionButton)
  488. -        
  489. +
  490.          return actionButton
  491. -    
  492. +
  493.      def createOtherButton(self, iconName, helpText):
  494.          ''' no toggle button'''
  495.          Button = gtk.Button()
  496.          drawSimpleButton(Button, iconName, helpText)
  497.          self.toolBox.pack_start(Button)
  498.          return Button
  499. -    
  500. +
  501.      def createSizeButton(self, iconName, index):
  502.          ''' size button'''
  503.          Button = gtk.Button()
  504.          drawSizeButton(Button, iconName, index, self.getIconIndex)
  505.          self.sizeBox.pack_start(Button)
  506.          return Button
  507. -    
  508. +
  509.      def createColorButton(self, iconName, above = True):
  510.          button = gtk.Button()
  511.          drawColorButton(button, iconName)
  512. -        
  513. +
  514.          if above:
  515.              self.aboveHbox.pack_start(button)
  516.          else:
  517.              self.belowHbox.pack_start(button)
  518.          return button
  519. -    
  520. +
  521.      def setButtonColor(self, colorName):
  522.          modifyBackground(self.colorBox, self.colorMap[colorName])
  523.          self.actionColor = self.colorMap[colorName]
  524. -        
  525. +
  526.      def showToolbar(self):
  527.          '''Show toolbar.'''
  528.          self.showToolbarFlag = True
  529.          self.toolbarWindow.show_all()
  530. -        
  531. +
  532.      def hideToolbar(self):
  533.          '''Hide toolbar.'''
  534.          self.showToolbarFlag = False
  535.          self.toolbarWindow.hide_all()
  536. -    
  537. +
  538.      def showColorbar(self):
  539.          '''show colorbar '''
  540.          if self.action == ACTION_TEXT:
  541. @@ -664,49 +658,49 @@
  542.          self.showColorbarFlag = True
  543.          self.adjustColorbar()
  544.          self.colorbarWindow.show_all()
  545. -        
  546. -      
  547. -    
  548. +
  549. +
  550. +
  551.      def hideColorbar(self):
  552.          '''hide colorbar'''
  553.          self.showColorbarFlag = False
  554.          self.colorbarWindow.hide_all()
  555. -      
  556. -  
  557. +
  558. +
  559.      def adjustToolbar(self):
  560.          '''Adjust toolbar position.'''
  561.          (x, y, self.toolbarWidth, self.toolbarHeight, depth) = self.toolbarWindow.window.get_geometry()
  562.          colorbarHeight = 32
  563. -        
  564. -        
  565. +
  566. +
  567.          self.toolbarX = (self.x + self.rectWidth - self.toolbarWidth, self.toolbarOffsetX)[self.x + self.rectWidth - self.toolbarWidth < self.toolbarOffsetX]
  568. -        
  569. +
  570.          if self.y + self.rectHeight + self.toolbarOffsetY + self.toolbarHeight + colorbarHeight + 5 < self.height:
  571.              self.toolbarY = self.y + self.rectHeight + self.toolbarOffsetY
  572.          elif self.y - self.toolbarOffsetY - self.toolbarHeight -colorbarHeight - 5 > 0:
  573.              self.toolbarY = self.y - self.toolbarOffsetY - self.toolbarHeight
  574.          else:
  575.              self.toolbarY = self.y + self.toolbarOffsetY
  576. -    
  577. -          
  578. +
  579. +
  580.          self.toolbarWindow.move(int(self.toolbarX), int(self.toolbarY))
  581. -    
  582. +
  583.      def adjustColorbar(self):
  584.          '''Adjust Colorbar position '''
  585.          if self.toolbarY < self.y:
  586.              colorbarY =  self.toolbarY - self.toolbarHeight - 8
  587.          else:
  588.              colorbarY = self.toolbarY + self.toolbarHeight + 5
  589. -        
  590. +
  591.          colorbarX = self.toolbarX
  592. -        
  593. +
  594.          self.colorbarWindow.move(int(colorbarX), int(colorbarY))
  595. -        
  596. +
  597.      def getEventCoord(self, event):
  598.          '''Get event coord.'''
  599.          (rx, ry) = event.get_root_coords()
  600.          return (int(rx), int(ry))
  601. -        
  602. +
  603.      def buttonPress(self, widget, event):
  604.          '''Button press.'''
  605.          self.dragFlag = True
  606. @@ -714,17 +708,17 @@
  607.          # print "buttonPress: %s" % (str(event.get_root_coords()))
  608.          if self.action == ACTION_WINDOW:
  609.                  self.windowFlag = False
  610. -            
  611. +
  612.          elif self.action == ACTION_INIT:
  613.              (self.x, self.y) = self.getEventCoord(event)
  614. -            
  615. +
  616.          elif self.action == ACTION_SELECT:
  617.              # Init drag position.
  618.              self.dragPosition = self.getPosition(event)
  619. -            
  620. +
  621.              # Set cursor.
  622.              self.setCursor(self.dragPosition)
  623. -            
  624. +
  625.              # Get drag coord and offset.
  626.              (self.dragStartX, self.dragStartY) = self.getEventCoord(event)
  627.              self.dragStartOffsetX = self.dragStartX - self.x
  628. @@ -750,7 +744,7 @@
  629.                  self.currentAction = LineAction(ACTION_LINE, self.actionSize, self.actionColor)
  630.                  self.currentAction.startDraw(self.getEventCoord(event))
  631.          elif self.action == ACTION_TEXT:
  632. -            
  633. +
  634.              if self.textWindow.get_visible():
  635.                  content = self.getInputText()
  636.                  if content != "":
  637. @@ -764,7 +758,7 @@
  638.                          self.actionList.append(textAction)
  639.                      self.hideTextWindow()
  640.                      self.setAllInactive()
  641. -                    
  642. +
  643.                      self.window.queue_draw()
  644.                  else:
  645.                      self.hideTextWindow()
  646. @@ -772,40 +766,40 @@
  647.  
  648.              else:
  649.                  self.showTextWindow(self.getEventCoord(event))
  650. -        
  651. +
  652.          if self.action in [ACTION_RECTANGLE, ACTION_ELLIPSE, ACTION_ARROW, ACTION_LINE] and self.showToolbarFlag and self.y < self.toolbarY < self.y + self.rectHeight:
  653.              self.hideToolbar()
  654.              self.hideColorbar()
  655.  
  656. -        
  657. +
  658.  
  659.          if self.currentTextAction and self.action == None:
  660.              currentX, currentY = self.getEventCoord(event)
  661.              drawTextX,drawTextY = self.currentTextAction.getLayoutInfo()[:2]
  662.              self.textDragOffsetX = currentX - drawTextX
  663.              self.testDragOffsetY = currentY - drawTextY
  664. -            self.textDragFlag = True
  665. -            
  666. -    
  667. +            self.textDragFlag = True
  668. +
  669. +
  670.      def motionNotify(self, widget, event):
  671.          '''Motion notify.'''
  672.          if self.dragFlag:
  673.              # print "motionNotify: %s" % (str(event.get_root_coords()))
  674.              (ex, ey) = self.getEventCoord(event)
  675. -            
  676. -            
  677. -            if self.action == ACTION_WINDOW and not self.windowFlag:
  678. -                
  679. +
  680. +
  681. +            if self.action == ACTION_WINDOW and not self.windowFlag:
  682. +
  683.                  self.action = ACTION_INIT
  684.                  (self.x, self.y) = self.getEventCoord(event)
  685.                  self.window.queue_draw()
  686. -                
  687. -                
  688. +
  689. +
  690.              elif self.action == ACTION_INIT:
  691.                  (self.rectWidth, self.rectHeight) = (ex - self.x, ey - self.y)
  692.                  self.window.queue_draw()
  693.              elif self.action == ACTION_SELECT:
  694. -                
  695. +
  696.                  if self.dragPosition == DRAG_INSIDE:
  697.                      self.x = min(max(ex - self.dragStartOffsetX, 0), self.width - self.rectWidth)
  698.                      self.y = min(max(ey - self.dragStartOffsetY, 0), self.height - self.rectHeight)
  699. @@ -828,43 +822,43 @@
  700.                      self.dragFrameLeft(ex, ey)
  701.                  elif self.dragPosition == DRAG_BOTTOM_RIGHT_CORNER:
  702.                      self.dragFrameBottom(ex, ey)
  703. -                    self.dragFrameRight(ex, ey)                      
  704. +                    self.dragFrameRight(ex, ey)
  705.                  self.window.queue_draw()
  706. -                
  707. +
  708.              elif self.action == ACTION_RECTANGLE:
  709.                  self.currentAction.drawing((ex, ey), (self.x, self.y, self.rectWidth, self.rectHeight))
  710. -                
  711. +
  712.                  self.window.queue_draw()
  713.              elif self.action == ACTION_ELLIPSE:
  714.                  self.currentAction.drawing((ex, ey), (self.x, self.y, self.rectWidth, self.rectHeight))
  715. -                
  716. +
  717.                  self.window.queue_draw()
  718.              elif self.action == ACTION_ARROW:
  719.                  self.currentAction.drawing((ex, ey), (self.x, self.y, self.rectWidth, self.rectHeight))
  720. -                
  721. +
  722.                  self.window.queue_draw()
  723.              elif self.action == ACTION_LINE:
  724.                  self.currentAction.drawing((ex, ey), (self.x, self.y, self.rectWidth, self.rectHeight))
  725. -                
  726. +
  727.                  self.window.queue_draw()
  728.          else:
  729.              if self.action == ACTION_SELECT:
  730.                  self.setCursor(self.getPosition(event))
  731. -          
  732. +
  733.              elif self.action == ACTION_WINDOW:
  734.                  setPixbufCursor(self.window, "start_cursor.png")
  735. -            
  736. +
  737.              elif self.action in (ACTION_RECTANGLE, ACTION_ELLIPSE):
  738.                  setCursor(self.window, gtk.gdk.TCROSS)
  739. -            
  740. +
  741.              elif self.action == ACTION_LINE:
  742.                  setCursor(self.window, gtk.gdk.PENCIL)
  743.              elif self.action == ACTION_TEXT:
  744.                  setCursor(self.window, gtk.gdk.XTERM)
  745.              else:
  746.                  self.window.window.set_cursor(None)
  747. -                
  748. -                
  749. +
  750. +
  751.              if self.windowFlag:
  752.                  self.hideToolbar()
  753.                  (wx, wy) = self.getEventCoord(event)
  754. @@ -874,28 +868,28 @@
  755.                          self.y = eachCoord.y
  756.                          self.rectWidth = eachCoord.width
  757.                          self.rectHeight = eachCoord.height
  758. -                
  759. +
  760.                  self.window.queue_draw()
  761. -                
  762. -        
  763. -                
  764. +
  765. +
  766. +
  767.          if self.action == None:
  768.  
  769. -            (tx, ty) = self.getEventCoord(event)      
  770. +            (tx, ty) = self.getEventCoord(event)
  771. +
  772.  
  773. -            
  774.              if self.textDragFlag:
  775.                  self.currentTextAction.updateCoord(tx - self.textDragOffsetX, ty - self.textDragOffsetY - 10)
  776.                  self.drawTextLayoutFlag = True
  777.                  self.window.queue_draw()
  778. -                
  779. +
  780.              else:
  781.                  for eachAction, info in self.textActionInfo.items():
  782.                      if info[0] < tx < info[0]+info[2] and info[1] < ty < info[1]+info[3]:
  783.                          self.currentTextAction = eachAction
  784.  
  785.  
  786. -                        
  787. +
  788.              if self.currentTextAction:
  789.                  drawTextX, drawTextY, drawTextWidth, drawTextHeight = self.currentTextAction.getLayoutInfo()
  790.                  if drawTextX < tx < drawTextX + drawTextWidth and drawTextY < ty < drawTextY + drawTextHeight:
  791. @@ -903,11 +897,11 @@
  792.                      setCursor(self.window, gtk.gdk.FLEUR)
  793.                      self.window.queue_draw()
  794.                  else:
  795. -                    self.drawTextLayoutFlag = False    
  796. +                    self.drawTextLayoutFlag = False
  797.                      self.currentTextAction = None
  798.                      self.window.window.set_cursor(None)
  799.                      self.window.queue_draw()
  800. -                            
  801. +
  802.      def buttonRelease(self, widget, event):
  803.          '''Button release.'''
  804.          self.textDragFlag = False
  805. @@ -920,27 +914,27 @@
  806.                  self.window.queue_draw()
  807.              else:
  808.                  self.windowFlag = True
  809. -                
  810. -            
  811. +
  812. +
  813.          elif self.action == ACTION_INIT:
  814.              self.action = ACTION_SELECT
  815.              (ex, ey) = self.getEventCoord(event)
  816. -            
  817. +
  818.              # Adjust value when button release.
  819.              if ex > self.x:
  820.                  self.rectWidth = ex - self.x
  821.              else:
  822.                  self.rectWidth = fabs(ex - self.x)
  823.                  self.x = ex
  824. -                
  825. +
  826.              if ey > self.y:
  827.                  self.rectHeight = ey - self.y
  828.              else:
  829.                  self.rectHeight = fabs(ey - self.y)
  830.                  self.y = ey
  831. -                
  832. +
  833.              self.window.queue_draw()
  834. -            
  835. +
  836.              self.showToolbar()
  837.          elif self.action == ACTION_SELECT:
  838.              pass
  839. @@ -948,27 +942,27 @@
  840.              self.currentAction.endDraw(self.getEventCoord(event), (self.x, self.y, self.rectWidth, self.rectHeight))
  841.              self.actionList.append(self.currentAction)
  842.              self.currentAction = None
  843. -            
  844. +
  845.              self.window.queue_draw()
  846.          elif self.action == ACTION_ELLIPSE:
  847.              self.currentAction.endDraw(self.getEventCoord(event), (self.x, self.y, self.rectWidth, self.rectHeight))
  848.              self.actionList.append(self.currentAction)
  849.              self.currentAction = None
  850. -            
  851. +
  852.              self.window.queue_draw()
  853.          elif self.action == ACTION_ARROW:
  854.              self.currentAction.endDraw(self.getEventCoord(event), (self.x, self.y, self.rectWidth, self.rectHeight))
  855.              self.actionList.append(self.currentAction)
  856.              self.currentAction = None
  857. -            
  858. +
  859.              self.window.queue_draw()
  860.          elif self.action == ACTION_LINE:
  861.              self.currentAction.endDraw(self.getEventCoord(event), (self.x, self.y, self.rectWidth, self.rectHeight))
  862.              self.actionList.append(self.currentAction)
  863.              self.currentAction = None
  864. -            
  865. +
  866.              self.window.queue_draw()
  867. -        
  868. +
  869.          if self.action in [ACTION_RECTANGLE, ACTION_ELLIPSE, ACTION_ARROW, ACTION_LINE, ACTION_TEXT] and not self.showToolbarFlag and self.y < self.toolbarY < self.y + self.rectHeight:
  870.              self.adjustToolbar()
  871.              self.showToolbar()
  872. @@ -985,15 +979,15 @@
  873.              self.fontName = self.currentTextAction.getFontname()
  874.              modifyBackground(self.colorBox, self.actionColor)
  875.              self.fontLabel.set_label(self.fontName)
  876. -            
  877. +
  878.              self.actionTextButton.set_active(True)
  879.              self.showTextWindow(self.getEventCoord(event))
  880.              self.textModifyFlag = True
  881. -      
  882. +
  883.          if isDoubleClick(event) and self.action == ACTION_SELECT and self.x < ex < self.x + self.rectWidth and self.y < ey < self.y + self.rectHeight:
  884.              self.saveSnapshot()
  885.              self.buttonRelease(widget, event)
  886. -        
  887. +
  888.  
  889.      def registerKeyBinding(self, keyEventName, callback):
  890.          '''Register a keybinding'''
  891. @@ -1003,105 +997,110 @@
  892.          '''Unregister a keybinding'''
  893.          if self.keyBindings.has_key(keyEventName):
  894.              del self.keyBindings[keyEventName]
  895. -            
  896. +
  897.      def keyPress(self, widget, event):
  898.          '''process key press event'''
  899.          keyEventName = getKeyEventName(event)
  900.          if self.keyBindings.has_key(keyEventName):
  901.              self.keyBindings[keyEventName]()
  902.  
  903. +    def getSnapBuf(self):
  904. +        # Init cairo.
  905. +        pixbuf = None
  906. +        cr = self.window.window.cairo_create()
  907. +
  908. +        # Draw desktop background.
  909. +        self.drawDesktopBackground(cr)
  910. +
  911. +        # Draw action list.
  912. +        for action in self.actionList:
  913. +            action.expose(cr)
  914. +            # Draw text Action list.
  915. +        for eachTextAction in self.textActionList:
  916. +            eachTextAction.expose(cr)
  917. +
  918. +        # Get snapshot.
  919. +        pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, int(self.rectWidth), int(self.rectHeight))
  920. +        pixbuf.get_from_drawable(
  921. +            self.window.get_window(), self.window.get_window().get_colormap(),
  922. +            self.x, self.y,
  923. +            0, 0,
  924. +            int(self.rectWidth), int(self.rectHeight))
  925. +
  926. +        return pixbuf
  927. +
  928.      def saveSnapshotToFile(self):
  929.          '''Save file to file.'''
  930. +        pixbuf = self.getSnapBuf()
  931.          dialog = gtk.FileChooserDialog(
  932.              "Save..",
  933.              self.window,
  934.              gtk.FILE_CHOOSER_ACTION_SAVE,
  935.              (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
  936.               gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT))
  937. -        
  938. +
  939.          dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)
  940.          dialog.set_default_response(gtk.RESPONSE_ACCEPT)
  941.          dialog.set_position(gtk.WIN_POS_MOUSE)
  942.          dialog.set_local_only(True)
  943.          dialog.set_current_folder(os.environ['HOME'])
  944.          dialog.set_current_name("%s%s.%s" % (DEFAULT_FILENAME, getFormatTime(), self.saveFiletype))
  945. -        
  946. +
  947.          optionMenu = gtk.OptionMenu()
  948.          optionMenu.set_size_request(155, -1)
  949.          menu = gtk.Menu()
  950.          menu.set_size_request(155, -1)
  951. -        
  952. +
  953.          pngItem = makeMenuItem('PNG (*.png)',
  954.                       lambda item, data: self.setSaveFiletype(dialog, 'png'))
  955. -        
  956. +
  957.          jpgItem = makeMenuItem('JPEG (*.jpeg)',
  958.                       lambda item, data: self.setSaveFiletype(dialog, 'jpeg'))
  959. -        
  960. +
  961.          bmpItem = makeMenuItem('BMP (*.bmp)',
  962.                       lambda item, data: self.setSaveFiletype(dialog, 'bmp'))
  963. -        
  964. -        
  965. -        
  966. -        
  967. +
  968. +
  969.          menu.append(pngItem)
  970.          menu.append(jpgItem)
  971.          menu.append(bmpItem)
  972.          optionMenu.set_menu(menu)
  973. -        
  974. -        
  975. +
  976. +
  977.          hbox = gtk.HBox()
  978.          hbox.pack_end(optionMenu, False, False)
  979.          dialog.vbox.pack_start(hbox, False, False)
  980. -        hbox.show_all()                          
  981. -        
  982. -        
  983. +        hbox.show_all()
  984. +
  985. +
  986.          self.hideToolbar()
  987.          if self.showColorbarFlag:
  988.              self.hideColorbar()
  989. -            
  990. +
  991.          response = dialog.run()
  992.          if response == gtk.RESPONSE_ACCEPT:
  993.              filename = dialog.get_filename()
  994. -            self.saveSnapshot(filename, self.saveFiletype)
  995. +            self.saveSnapshot(pixbuf=pixbuf, filename=filename, filetype=self.saveFiletype)
  996.              print "Save snapshot to %s" % (filename)
  997.          elif response == gtk.RESPONSE_REJECT:
  998.              self.adjustToolbar()
  999.              self.showToolbar()
  1000. -            
  1001. +
  1002.              if self.isHaveOneToggled():
  1003.                  self.showColorbar()
  1004.              print 'Closed, no files selected'
  1005.          dialog.destroy()
  1006.  
  1007. -        
  1008. +
  1009.      def setSaveFiletype(self, dialog, filetype):
  1010.          ''' save filetype '''
  1011.          dialog.set_current_name("%s%s.%s" % (DEFAULT_FILENAME, getFormatTime(), filetype))
  1012.          self.saveFiletype = filetype
  1013. -      
  1014. -    def saveSnapshot(self, filename=None, filetype='png'):
  1015. +
  1016. +    def saveSnapshot(self, pixbuf=None, filename=None, filetype='png'):
  1017.          '''Save snapshot.'''
  1018. -        # Init cairo.
  1019. -        cr = self.window.window.cairo_create()
  1020. -        
  1021. -        # Draw desktop background.
  1022. -        self.drawDesktopBackground(cr)
  1023. -        
  1024. -        # Draw action list.
  1025. -        for action in self.actionList:
  1026. -            action.expose(cr)
  1027. -        # Draw text Action list.
  1028. -        for eachTextAction in self.textActionList:
  1029. -            eachTextAction.expose(cr)
  1030. -            
  1031. -        # Get snapshot.
  1032. -        pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, int(self.rectWidth), int(self.rectHeight))
  1033. -        pixbuf.get_from_drawable(
  1034. -            self.window.get_window(), self.window.get_window().get_colormap(),
  1035. -            self.x, self.y,
  1036. -            0, 0,
  1037. -            int(self.rectWidth), int(self.rectHeight))
  1038. -        
  1039. +        if pixbuf is None:
  1040. +            pixbuf = self.getSnapBuf()
  1041.          # Save snapshot.
  1042.          if filename == None:
  1043.              # Save snapshot to clipboard if filename is None.
  1044. @@ -1113,40 +1112,38 @@
  1045.              # Otherwise save to local file.
  1046.              pixbuf.save(filename, filetype)
  1047.              tipContent = __("Tip save to file")
  1048. -            
  1049. -        
  1050.  
  1051. -        
  1052. +
  1053.          # Exit
  1054.          self.window.window.set_cursor(None)
  1055.          self.destroy(self.window)
  1056. -        
  1057. +
  1058.           # tipWindow
  1059.          cmd = ('python', 'tipswindow.py', tipContent)
  1060.          subprocess.Popen(cmd)
  1061.  
  1062. -        
  1063. +
  1064.      def redraw(self, widget, event):
  1065.          '''Redraw.'''
  1066.          # Init cairo.
  1067.          cr = widget.window.cairo_create()
  1068. -        
  1069. +
  1070.          # Draw desktop background.
  1071.          self.drawDesktopBackground(cr)
  1072. -        
  1073. +
  1074.          # Draw mask.
  1075.          self.drawMask(cr)
  1076. -        
  1077. +
  1078.          # Draw toolbar.
  1079.          if self.showToolbarFlag:
  1080.              self.adjustToolbar()
  1081.              self.adjustColorbar()
  1082. -            
  1083. +
  1084.          # Draw action list.
  1085.          for action in self.actionList:
  1086.              if action != None:
  1087.                  action.expose(cr)
  1088. -        
  1089. +
  1090.          # Draw Text Action list.
  1091.          for eachTextAction in self.textActionList:
  1092.              eachTextAction.expose(cr)
  1093. @@ -1155,13 +1152,13 @@
  1094.          # Draw current action.
  1095.          if self.currentAction != None:
  1096.              self.currentAction.expose(cr)
  1097. -        
  1098. +
  1099.  
  1100.          # draw currentText layout
  1101.          if self.drawTextLayoutFlag:
  1102.              drawAlphaRectangle(cr, *self.currentTextAction.getLayoutInfo())
  1103. -    
  1104. -    
  1105. +
  1106. +
  1107.          #draw magnifier
  1108.          if self.action == ACTION_WINDOW and self.rectWidth:
  1109.              drawMagnifier(cr, self.window, self.currentX, self.currentY,
  1110. @@ -1177,17 +1174,17 @@
  1111.                  drawRoundTextRectangle(cr, self.x + 5, self.y - 35, 85, 30, 7,'%d x %d' % (fabs(self.rectWidth), fabs(self.rectHeight)), 0.7)
  1112.              elif self.action in [None, ACTION_SELECT, ACTION_WINDOW, ACTION_INIT]:
  1113.                  drawRoundTextRectangle(cr, self.x + 5 , self.y + 5 , 85, 30, 7,'%d x %d' % (fabs(self.rectWidth), fabs(self.rectHeight)), 0.7)
  1114. -            
  1115. -        
  1116. +
  1117. +
  1118.          if widget.get_child() != None:
  1119.              widget.propagate_expose(widget.get_child(), event)
  1120. -    
  1121. +
  1122.          return True
  1123. -    
  1124. +
  1125.      def drawDesktopBackground(self, cr):
  1126.          '''Draw desktop.'''
  1127. -        drawPixbuf(cr, self.desktopBackground)    
  1128. -        
  1129. +        drawPixbuf(cr, self.desktopBackground)
  1130. +
  1131.      def drawMask(self, cr):
  1132.          '''Draw mask.'''
  1133.          # Adjust value when create selection area.
  1134. @@ -1204,7 +1201,7 @@
  1135.          else:
  1136.              y = self.y + self.rectHeight
  1137.              rectHeight = fabs(self.rectHeight)
  1138. -        
  1139. +
  1140.          # Draw top.
  1141.          cr.set_source_rgba(0, 0, 0, 0.5)
  1142.          cr.rectangle(0, 0, self.width, y)
  1143. @@ -1224,68 +1221,68 @@
  1144.          cr.set_source_rgba(0, 0, 0, 0.5)
  1145.          cr.rectangle(x + rectWidth, y, self.width - x - rectWidth, rectHeight)
  1146.          cr.fill()
  1147. -        
  1148. +
  1149.      def drawFrame(self, cr):
  1150.          '''Draw frame.'''
  1151.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1152.          cr.set_line_width(self.frameLineWidth)
  1153.          cr.rectangle(self.x, self.y, self.rectWidth, self.rectHeight)
  1154.          cr.stroke()
  1155. -        
  1156. +
  1157.      def drawDragPoint(self, cr):
  1158.          '''Draw drag point.'''
  1159.          # Draw left top corner.
  1160.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1161.          cr.arc(self.x, self.y, self.dragPointRadius, 0, 2 * pi)
  1162.          cr.fill()
  1163. -        
  1164. +
  1165.          # Draw right top corner.
  1166.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1167.          cr.arc(self.x + self.rectWidth, self.y, self.dragPointRadius, 0, 2 * pi)
  1168.          cr.fill()
  1169. -        
  1170. +
  1171.          # Draw left bottom corner.
  1172.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1173.          cr.arc(self.x, self.y + self.rectHeight, self.dragPointRadius, 0, 2 * pi)
  1174.          cr.fill()
  1175. -        
  1176. +
  1177.          # Draw right bottom corner.
  1178.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1179.          cr.arc(self.x + self.rectWidth, self.y + self.rectHeight, self.dragPointRadius, 0, 2 * pi)
  1180.          cr.fill()
  1181. -        
  1182. +
  1183.          # Draw top side.
  1184.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1185.          cr.arc(self.x + self.rectWidth / 2, self.y, self.dragPointRadius, 0, 2 * pi)
  1186.          cr.fill()
  1187. -        
  1188. +
  1189.          # Draw bottom side.
  1190.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1191.          cr.arc(self.x + self.rectWidth / 2, self.y + self.rectHeight, self.dragPointRadius, 0, 2 * pi)
  1192.          cr.fill()
  1193. -        
  1194. +
  1195.          # Draw left side.
  1196.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1197.          cr.arc(self.x, self.y + self.rectHeight / 2, self.dragPointRadius, 0, 2 * pi)
  1198.          cr.fill()
  1199. -        
  1200. +
  1201.          # Draw right side.
  1202.          cr.set_source_rgb(*colorHexToCairo(self.frameColor))
  1203.          cr.arc(self.x + self.rectWidth, self.y + self.rectHeight / 2, self.dragPointRadius, 0, 2 * pi)
  1204.          cr.fill()
  1205. -        
  1206. +
  1207.      def getDesktopSnapshot(self):
  1208.          '''Get desktop snapshot.'''
  1209. -        rootWindow = gtk.gdk.get_default_root_window()
  1210. -        [self.width, self.height] = rootWindow.get_size()
  1211. +        rootWindow = gtk.gdk.get_default_root_window()
  1212. +        [self.width, self.height] = rootWindow.get_size()
  1213.          pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, self.width, self.height)
  1214. -        return pixbuf.get_from_drawable(rootWindow, rootWindow.get_colormap(), 0, 0, 0, 0, self.width, self.height)
  1215. -        
  1216. +        return pixbuf.get_from_drawable(rootWindow, rootWindow.get_colormap(), 0, 0, 0, 0, self.width, self.height)
  1217. +
  1218.      def destroy(self, widget, data=None):
  1219.          '''Destroy main window.'''
  1220.          self.window.window.set_cursor(None)
  1221.          gtk.main_quit()
  1222. -        
  1223. +
  1224.      def getDragPointCoords(self):
  1225.          '''Get drag point coords.'''
  1226.          return (
  1227. @@ -1306,16 +1303,16 @@
  1228.              # Right side.
  1229.              (self.x + self.rectWidth - self.dragPointRadius, self.y + self.rectHeight / 2 - self.dragPointRadius),
  1230.              )
  1231. -        
  1232. +
  1233.      def getPosition(self, event):
  1234.          '''Get drag position.'''
  1235.          # Get event position.
  1236.          (ex, ey) = self.getEventCoord(event)
  1237. -        
  1238. +
  1239.          # Get drag point coords.
  1240.          pWidth = pHeight = self.dragPointRadius * 2
  1241.          ((tlX, tlY), (trX, trY), (blX, blY), (brX, brY), (tX, tY), (bX, bY), (lX, lY), (rX, rY)) = self.getDragPointCoords()
  1242. -        
  1243. +
  1244.          # Calcuate drag position.
  1245.          if isInRect((ex, ey), (self.x, self.y, self.rectWidth, self.rectHeight)):
  1246.              return DRAG_INSIDE
  1247. @@ -1337,7 +1334,7 @@
  1248.              return DRAG_RIGHT_SIDE
  1249.          else:
  1250.              return DRAG_OUTSIDE
  1251. -        
  1252. +
  1253.      def setCursor(self, position):
  1254.          '''Set cursor.'''
  1255.          if position == DRAG_INSIDE:
  1256. @@ -1360,38 +1357,38 @@
  1257.              setCursor(self.window, gtk.gdk.LEFT_SIDE)
  1258.          elif position == DRAG_RIGHT_SIDE:
  1259.              setCursor(self.window, gtk.gdk.RIGHT_SIDE)
  1260. -            
  1261. +
  1262.      def dragFrameTop(self, ex, ey):
  1263.          '''Drag frame top.'''
  1264.          maxY = self.y + self.rectHeight
  1265.          self.rectHeight = self.rectHeight - min(self.rectHeight, (ey - self.y))
  1266. -        self.y = min(ey, maxY)
  1267. -    
  1268. +        self.y = min(ey, maxY)
  1269. +
  1270.      def dragFrameBottom(self, ex, ey):
  1271.          '''Drag frame bottom.'''
  1272.          self.rectHeight = max(0, ey - self.y)
  1273. -    
  1274. +
  1275.      def dragFrameLeft(self, ex, ey):
  1276.          '''Drag frame left.'''
  1277.          maxX = self.x + self.rectWidth
  1278.          self.rectWidth = self.rectWidth - min(self.rectWidth, (ex - self.x))
  1279.          self.x = min(ex, maxX)
  1280. -    
  1281. +
  1282.      def dragFrameRight(self, ex, ey):
  1283.          '''Drag frame right.'''
  1284.          self.rectWidth = max(0, ex - self.x)
  1285. -        
  1286. +
  1287.      def undo(self):
  1288.          '''Undo'''
  1289.          if self.textWindow.get_visible():
  1290.              self.hideTextWindow()
  1291. -            
  1292. +
  1293.          if self.actionList:
  1294.              tempAction = self.actionList.pop()
  1295.              if tempAction.getActionType() == ACTION_TEXT:
  1296.                  self.textActionList.pop()
  1297.                  del self.textActionInfo[tempAction]
  1298. -                
  1299. +
  1300.          else:
  1301.              self.window.window.set_cursor(None)
  1302.              self.action = ACTION_WINDOW
  1303. @@ -1401,10 +1398,10 @@
  1304.              self.hideToolbar()
  1305.              if self.showColorbarFlag:
  1306.                  self.setAllInactive()
  1307. -        
  1308. +
  1309.          self.window.queue_draw()
  1310. -        
  1311. -        
  1312. +
  1313. +
  1314.      def drawWindowRectangle(self, cr):
  1315.          '''Draw frame.'''
  1316.          cr.set_line_width(4.5)
  1317. @@ -1413,8 +1410,8 @@
  1318.          cr.stroke()
  1319.      def getCurrentCoord(self, widget):
  1320.          '''get Current Coord '''
  1321. -        (self.currentX, self.currentY) = widget.window.get_pointer()[:2]
  1322. +        (self.currentX, self.currentY) = widget.window.get_pointer()[:2]
  1323. +
  1324.  
  1325. -    
  1326.  if __name__ == "__main__":
  1327.      MainScrot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement