Example #1
0
    def __init__(self):
        super(PiecesBar, self).__init__()
        # Get progress bar styles, in order to keep font consistency
        pb = ProgressBar()
        pb_style = pb.get_style()
        self.text_font = pb_style.font_desc
        self.text_font.set_weight(WEIGHT_BOLD)
        # Done with the ProgressBar styles, don't keep refs of it
        del pb, pb_style

        self.set_size_request(-1, 25)
        self.gtkui_config = ConfigManager('gtkui.conf')

        self.width = self.prev_width = 0
        self.height = self.prev_height = 0
        self.pieces = self.prev_pieces = ()
        self.num_pieces = None
        self.text = self.prev_text = ''
        self.fraction = self.prev_fraction = 0
        self.progress_overlay = self.text_overlay = self.pieces_overlay = None
        self.cr = None

        self.connect('size-allocate', self.do_size_allocate_event)
        self.set_colormap(colormap_get_system())
        self.show()
Example #2
0
  def pick_immediate(self, x, y, magnifier):
    """
    Select the color at the specified pixel

    The coordinates are relative to the screen.
    """

    if self.flags() & gtk.REALIZED == False: return

    if magnifier:
      r,g,b = self.mag.raw_pixbuf.get_pixels_array()[y,x]
    else:
      # grab raw screen data
      self.raw_pixbuf.get_from_drawable(
          gdk.get_default_root_window(),
          gdk.colormap_get_system(),
          x, y,
          0, 0,
          self.raw_width, self.raw_height)

      #pull out rgb value
      #XXX first time this is called generates a warning and doesn't work.
      #    all subsequent times are fine. why?
      r,g,b = self.raw_pixbuf.get_pixels_array()[0,0]

    self.color.set_rgb(r,g,b)
Example #3
0
    def _gc_set_foreground(self, gc, color):
        colormap = gdk.colormap_get_system()

        if color:
            color = colormap.alloc_color(color, True, True)
            gc.set_foreground(color)
        else:
            default_color = gdk.Color(0x0000, 0x0000, 0x0000, 0)
            default_color = colormap.alloc_color(default_color, True, True)
            gc.set_foreground(default_color)
Example #4
0
    def _gc_set_foreground (self, gc, color):
        colormap = gdk.colormap_get_system ()

        if color:
            color = colormap.alloc_color(color, True, True)
            gc.set_foreground(color)
        else:
            default_color = gdk.Color(0x0000, 0x0000, 0x0000, 0)
            default_color = colormap.alloc_color(default_color, True, True)
            gc.set_foreground(default_color)
Example #5
0
def test_set_icon_pixmap_no_warning():
    '''
    Ensure that ``set_icon_pixmap`` can be invoked on a newly
    constructed ``gtk.gdk.DragContext`` without producing GtkWarnings.

    :bug: #539403
    '''
    pix = gdk.Pixmap(None, 100, 100, depth = 32)
    dc = gdk.DragContext()
    cmap = gdk.colormap_get_system()
    dc.set_icon_pixmap(cmap, pix, pix, 0, 0)
Example #6
0
def test_set_icon_pixmap_none_mask():
    '''
    Ensure that ``set_icon_pixmap`` can be invoked successfully with
    ``None`` as the mask.

    :bug: #497781
    '''
    pix = gdk.Pixmap(None, 100, 100, depth = 32)
    dc = gdk.DragContext()
    cmap = gdk.colormap_get_system()
    dc.set_icon_pixmap(cmap, pix, None, 0, 0)
Example #7
0
 def get_pixbuf(self):
     w, h = self.surface.get_width(), self.surface.get_height()
     pixmap = gdk.Pixmap(None, w, h, 24)
     cr = pixmap.cairo_create()
     cr.set_source_surface(self.surface, 0, 0)
     cr.paint ()
     pixbuf = gtk.gdk.Pixbuf (gdk.COLORSPACE_RGB, True, 8, w, h)
     pixbuf = pixbuf.get_from_drawable(pixmap,
                                       gdk.colormap_get_system(), 
                                       0, 0, 0, 0, w, h)
     return pixbuf
Example #8
0
    def __init__(self):
        gtksheet.Sheet.__init__(self, 20, 20, "Test")
        colormap = gdk.colormap_get_system()

        self.default_bg_color = colormap.alloc_color("light yellow")
        self.default_fg_color = colormap.alloc_color("black")

        self.set_background(self.default_bg_color)
        self.set_grid(colormap.alloc_color("light blue"))


        for column in xrange(self.get_columns_count()):
            name = chr(ord("A") + column)
            self.column_button_add_label(column, name)
            self.set_column_title(column, name)

        self.default_font = self.style.font_desc
Example #9
0
    def grab_immediate(self, x, y, w, h):
        """
    Copy pixels from the region specified by (x,y,w,h) into internal pixbuf

    The coordinates are relative to the screen in units of pixels.

    The grabbed image data is stored in raw_pixbuf.

    This involves copying image data from the server to the client and thus
    is not the quickest of operations.
    Do not call more often than necessary.
    """

        self.screen_rect = gdk.Rectangle(x, y, w, h)
        self.pan_x = 0
        self.pan_y = 0

        # if we're grabbing a different size, create new pixbuf of correct size
        if self.screen_rect.width != self.raw_width or self.screen_rect.height != self.raw_height:
            self.raw_width = self.screen_rect.width
            self.raw_height = self.screen_rect.height
            self.raw_pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, self.raw_width, self.raw_height)

        # grab raw screen data
        self.raw_pixbuf.get_from_drawable(
            gdk.get_default_root_window(),
            gdk.colormap_get_system(),
            self.screen_rect.x,
            self.screen_rect.y,
            0,
            0,
            self.screen_rect.width,
            self.screen_rect.height,
        )

        self.emit("location-changed")
        self.has_data = True

        self.scale()
Example #10
0
    def capture(self, scale_x=None, scale_y=None, quality=75, raw=False):
        """Captures a screenshot and returns in for width, height, data"""

        screenshot = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, self.width, self.height)
        screenshot.get_from_drawable(gdk.get_default_root_window(),
                                    gdk.colormap_get_system(),
                                    0, 0, 0, 0,
                                    self.width, self.height)

        if not scale_x:
            scale_x = self.width
        if not scale_y:
            scale_y = self.height
        if self.width != scale_x or self.height != scale_y:
            screenshot = screenshot.scale_simple(scale_x, scale_y, gdk.INTERP_BILINEAR)

        if raw:
            return scale_x, scale_y, screenshot
        else:
            image=[]
            screenshot.save_to_callback(lambda buf, image: image.append(buf), "jpeg", {"quality": str(quality)}, image)
            return scale_x, scale_y, "".join(image)
Example #11
0
    def grab_immediate(self, x, y, w, h):
        """
    Copy pixels from the region specified by (x,y,w,h) into internal pixbuf

    The coordinates are relative to the screen in units of pixels.

    The grabbed image data is stored in raw_pixbuf.

    This involves copying image data from the server to the client and thus
    is not the quickest of operations.
    Do not call more often than necessary.
    """

        self.screen_rect = gdk.Rectangle(x, y, w, h)
        self.pan_x = 0
        self.pan_y = 0

        # if we're grabbing a different size, create new pixbuf of correct size
        if (self.screen_rect.width != self.raw_width
                or self.screen_rect.height != self.raw_height):
            self.raw_width = self.screen_rect.width
            self.raw_height = self.screen_rect.height
            self.raw_pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8,
                                         self.raw_width, self.raw_height)

        # grab raw screen data
        self.raw_pixbuf.get_from_drawable(gdk.get_default_root_window(),
                                          gdk.colormap_get_system(),
                                          self.screen_rect.x,
                                          self.screen_rect.y, 0, 0,
                                          self.screen_rect.width,
                                          self.screen_rect.height)

        self.emit('location-changed')
        self.has_data = True

        self.scale()
Example #12
0
    def pick_immediate(self, x, y, magnifier):
        """
    Select the color at the specified pixel

    The coordinates are relative to the screen.
    """

        if self.flags() & gtk.REALIZED == False: return

        if magnifier:
            r, g, b = self.mag.raw_pixbuf.get_pixels_array()[y, x]
        else:
            # grab raw screen data
            self.raw_pixbuf.get_from_drawable(gdk.get_default_root_window(),
                                              gdk.colormap_get_system(), x, y,
                                              0, 0, self.raw_width,
                                              self.raw_height)

            #pull out rgb value
            #XXX first time this is called generates a warning and doesn't work.
            #    all subsequent times are fine. why?
            r, g, b = self.raw_pixbuf.get_pixels_array()[0, 0]

        self.color.set_rgb(r, g, b)
Example #13
0
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""

import pygtk
pygtk.require("2.0")
from gtk import main_quit, Window, WINDOW_TOPLEVEL, Button, DrawingArea, \
                Label, Table, main, WINDOW_POPUP
from gtk.gdk import colormap_get_system, POINTER_MOTION_MASK, \
                    BUTTON_PRESS_MASK, pointer_ungrab, Pixbuf, \
                    COLORSPACE_RGB, get_default_root_window, pointer_grab, \
                    GRAB_SUCCESS


TITLE = 'Point & Pick' 
SYS_COLORMAP = colormap_get_system()
WHITE_RGB = (255, 255, 255)
GRAB_MASK = POINTER_MOTION_MASK | BUTTON_PRESS_MASK


def rgb_to_string(rgb):
    """Taks an rgb tuple and returns it hex string"""
    return "#" + ''.join('%02x' % c for c in rgb)


class PointAndPick(object):
    def __init__(self, title=TITLE, level=WINDOW_TOPLEVEL, on_exit=None):
        self.title = title
        self.grabbing = False
        self.events = []
        self.rgb = WHITE_RGB
Example #14
0
    def __init__(self):
        gtksheet.Sheet.__init__(self, 1000, 26)
        self.set_background(gdk.color_parse("light yellow"))
        self.set_grid(gdk.color_parse("light blue"))

        for column in xrange(self.get_columns_count()):
            name = chr(ord("A") + column)
            self.column_button_add_label(column, name)
            self.set_column_title(column, name)

        self.row_button_add_label(0, "This is\na multiline\nlabel")
        self.row_button_add_label(1, "This is long label")
        self.row_button_justify(0, gtk.JUSTIFY_RIGHT)

        range = gtksheet.SheetRange(1,1,2,3)
        self.clip_range(range)
        self.range_set_font(range, pango.FontDescription("Arial 28"))
        self.range_set_foreground(range, gdk.color_parse("red"))

        self.set_cell(1,2, gtk.JUSTIFY_CENTER, "Welcome to")
        
        range.row0 = 2
        self.range_set_font(range, pango.FontDescription("Arial 36"))
        self.range_set_foreground(range, gdk.color_parse("blue"))
        self.set_cell(2,2, gtk.JUSTIFY_CENTER, "python-gtksheet")


        range = gtksheet.SheetRange(3,0,3,4)
        self.range_set_background(range, gdk.color_parse("dark gray"))
        self.range_set_foreground(range, gdk.color_parse("green"))

        self.set_cell(3, 2, gtk.JUSTIFY_CENTER, "a Matrix widget for Gtk+")
        
        texts =["GtkSheet is a matrix where you can allocate cells of text.",
                "Cell contents can be edited interactively with an specially designed entry",
                "You can change colors, borders, and many other attributes",
                "Drag & drop or resize the selection clicking the corner or border",
                "Store the selection on the clipboard pressing Ctrl-C",
                "You can add buttons, charts, pixmaps, and other widgets"]
        for i in xrange(len(texts)):
            self.set_cell(i+4, 1, gtk.JUSTIFY_LEFT, texts[i])
        
        colormap = gdk.colormap_get_system()
        pixmap, mask = gdk.pixmap_colormap_create_from_xpm_d(None, colormap, 
                                                             None, bullet_xpm)
        for i in xrange(6):
            image = gtk.image_new_from_pixmap(pixmap, mask)
            image.show()
            self.attach( image,
                         4+i, 0, gtk.EXPAND, gtk.EXPAND, 0, 0)

        pixmap, mask = gdk.pixmap_colormap_create_from_xpm_d(None, colormap, 
                                                             None, smile_xpm)
        self.button_attach( gtk.image_new_from_pixmap(pixmap, mask), -1, 5)

        self.curve = gtk.Curve()
        self.curve.show()
        self.curve.set_range(0, 200, 0, 200)
        
        show_button = gtk.Button("Show me a plot")
        show_button.show()
        show_button.set_size_request(100, 60)
        self.attach(show_button, 12, 2, gtk.FILL, gtk.FILL, 5, 5)

        show_button.connect("clicked", self._show_child_cb)

        self.connect("key_press_event", self._key_press_cb)
Example #15
0
    def activate():
        screen = gdk.screen_get_default()

        screenWidth  = screen.get_width()
        screenHeight = screen.get_height()

        pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, screenWidth, screenHeight)
        screenshot = gdk.Pixbuf.get_from_drawable(pixbuf, gdk.get_default_root_window(), gdk.colormap_get_system(), 0, 0, 0, 0, screenWidth, screenHeight)
        screenshot.save(os.path.join(tempfile.gettempdir(), 'perdyselection.png'), 'png')

        areaWindow = AreaWindow(screenWidth, screenHeight)
        areaWindow.move(0, 0)
        areaWindow.setFixedSize(screenWidth, screenHeight)
        areaWindow.show()
Example #16
0
def main(argSource):
    cwd = os.getcwd()

    version = 'Perdyshot ' + open(os.path.join(dirname, os.path.pardir, '.version'), 'r').read()

    parser = argparse.ArgumentParser(description = 'Takes a perdy screenshot of the active window.')

    parser.add_argument('-b', '--background', help = 'overrides setting in perdyshot.conf', default = '')

    parser.add_argument('--delay', help = 'the delay in seconds before capturing the active window (default: 1)', default = 1, type = float)

    parser.add_argument('-f', '--file', help = 'overrides setting in perdyshot.conf', default = None)

    parser.add_argument('--round-top', help = "overrides setting in perdyshot.conf", default = None, action = 'store_true')
    parser.add_argument('--no-round-top', help = "overrides setting in perdyshot.conf", dest = 'round_top', action = 'store_false')

    parser.add_argument('--round-bottom', help = "overrides setting in perdyshot.conf", type = int, choices = [0, 1, 2], default = None)

    parser.add_argument('--shadow', help = "overrides setting in perdyshot.conf", default = None)

    parser.add_argument('--size-bugged', help = "overrides setting in perdyshot.conf", type = int, default = None, choices = [0, 1, 2])

    parser.add_argument('-v', '--version', action = 'version', version = version)

    args = vars(parser.parse_args(argSource))

    config = ConfigObj(os.path.join(dirname, os.path.pardir, 'perdyshot.conf'), encoding = 'UTF8', configspec = os.path.join(dirname, os.path.pardir, 'perdyshot.conf.spec'))
    validator = Validator()
    if not config.validate(validator):
        wireutils.color_print("Invalid configuration file", color = wireutils.ansi_colors.DARKRED)
        sys.exit(1)



    wireutils.color_print("Please select the window to be captured\n")
    time.sleep(args['delay'])

    startTime = time.time()

    # https://gist.github.com/mozbugbox/10cd35b2872628246140
    def pixbuf2image(pix):
        """Convert gdkpixbuf to PIL image"""
        data = pix.get_pixels()
        w = pix.props.width
        h = pix.props.height
        stride = pix.props.rowstride
        mode = "RGB"
        if pix.props.has_alpha == True:
            mode = "RGBA"
        im = Image.frombytes(mode, (w, h), data, "raw", mode, stride)
        return im

    # Get the root window
    root = gdk.screen_get_default()

    # And its size
    screenSize = (root.get_width(), root.get_height())

    # Get the active window
    window = root.get_active_window()

    if window == None:
        wireutils.color_print("Failed to capture window, exiting.", color = wireutils.ansi_colors.DARKRED)
        sys.exit(1)

    # And its geometry
    x, y = window.get_origin()
    x -= 1
    y -= 1
    width, height = window.get_size()

    # Fix something that may just be specific to my f****d up left monitor
    if x < 0:
        x = 0
        window.move(x, y)
        time.sleep(.5)

    # Get the position of the window decorations
    decoX, decoY = window.get_root_origin()
    decoY += 1

    # Check if the window has a custom titlebar
    hascustomtitlebar = (y + 2 == decoY)

    # Add the dimensions of the decorations to window dimensions
    width  += x - decoX + 1
    height += y - decoY - 1

    windowType = window.get_type_hint()

    # Get its WM_CLASS
    WM_CLASS = window.property_get('WM_CLASS')[2].split('\x00')[0]

    # Read the config file and figure out the settings
    settings = {}

    if config['Settings']['background'] == "False":
        settings['background'] = False
    else:
        settings['background'] = config['Settings']['background']

    settings['shadow'] = config['Settings']['shadowColour']

    settings['filename'] = config['Settings']['filename']

    if config['Settings']['cornerImage'] == '':
        settings['cornerImage'] = None
    else:
        settings['cornerImage'] = Image.open(os.path.join(dirname, config['Settings']['cornerImage']))

    if config['Settings']['cornerImageDM'] == '':
        settings['cornerImageDM'] = None
    else:
        settings['cornerImageDM'] = Image.open(os.path.join(dirname, config['Settings']['cornerImageDM']))

    if config['Settings']['borderImage'] == '':
        settings['borderImage'] = None
    else:
        settings['borderImage'] = Image.open(os.path.join(dirname, config['Settings']['borderImage']))

    if config['Settings']['borderImageDM'] == '':
        settings['borderImageDM'] = None
    else:
        settings['borderImageDM'] = Image.open(os.path.join(dirname, config['Settings']['borderImageDM']))


    if WM_CLASS in config['Applications']:
        app = config['Applications'][WM_CLASS]

        settings['sizeBugged'] = app['sizeBugged']

        settings['roundTop'] = app['roundTop']
        if settings['roundTop'] == None:
            settings['roundTop'] = not hascustomtitlebar

        settings['roundBottom'] = app['roundBottom']
        if settings['roundBottom'] == None:
            if hascustomtitlebar:
                settings['roundBottom'] = 0
            else:
                settings['roundBottom'] = 2
    else:
        settings['sizeBugged'] = False

        settings['roundTop'] = not hascustomtitlebar

        if hascustomtitlebar:
            settings['roundBottom'] = 0
        else:
            settings['roundBottom'] = 2

    # Add the border size
    width  += settings['borderImage'].size[0]
    height += settings['borderImage'].size[1]

    # Get pixbuf
    pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, width, height)

    # Screenshot the window (and its decorations)
    screenshot = gdk.Pixbuf.get_from_drawable(pixbuf, gdk.get_default_root_window(), gdk.colormap_get_system(), decoX, decoY, 0, 0, width, height)

    # Convert it to a PIL image
    image = pixbuf2image(screenshot)

    # Find out how long it took
    partialTime = time.time()

    # Get the geometry of the window's monitor
    monitorid = root.get_monitor_at_window(window)
    monitor = root.get_monitor_geometry(monitorid)

    geometry = window.get_geometry()
    bounds = window.get_frame_extents()


    # This is an estimate by a long-shot, but it's usually about right
    # At least on Pantheon, the gtk.gdk.WINDOW_STATE_MAXIMIZED state isn't set, so we resort to this
    maximized = height + 31 >= monitor.height and bounds.y - monitor.y + bounds.height == monitor.height

    sizeBugged = args['size_bugged'] if args['size_bugged'] != None else settings['sizeBugged']
    if sizeBugged == 1 or (sizeBugged == 2 and not(windowType & gdk.WINDOW_TYPE_HINT_DIALOG)):
        if not maximized:
            if windowType & gdk.WINDOW_TYPE_HINT_DIALOG:
                image = image.crop((37, 27, width - 38, height - 48))
                width -= 38 + 37
                height -= 48 + 27
            else:
                image = image.crop((50, 38, width - 51, height - 62))
                width -= 51 + 50
                height -= 62 + 38

    # Fix borders
    pixels = image.load()

    roundTop = args['round_top'] if args['round_top'] != None else settings['roundTop']

    roundBottom = args['round_bottom'] if args['round_bottom'] != None else settings['roundBottom']
    roundBottom = (roundBottom == 1 or (roundBottom == 2 and (maximized or windowType & gdk.WINDOW_TYPE_HINT_DIALOG)))

    # Apply deletion maps
    cornerDeleteMapSize = (0, 0)
    if settings['cornerImageDM'] != None:
        cornerDeleteMap = settings['cornerImageDM'].load()
        cornerDeleteMapSize = settings['cornerImageDM'].size
        for deleteColumn in xrange(0, cornerDeleteMapSize[0]):
            for deleteRow in xrange(0, cornerDeleteMapSize[1]):
                if cornerDeleteMap[deleteColumn, deleteRow][3] > 0:
                    if roundTop:
                        # Top left
                        pixels[deleteColumn, deleteRow] = (0, 0, 0, 0)
                        # Top right
                        pixels[width - deleteColumn - 1, deleteRow] = (0, 0, 0, 0)
                    if roundBottom:
                        # Bottom left
                        pixels[deleteColumn, height - deleteRow - 1] = (0, 0, 0, 0)
                        # Bottom right
                        pixels[width - deleteColumn - 1, height - deleteRow - 1] = (0, 0, 0, 0)

        if settings['borderImageDM'] != None:
            borderDeleteMap = settings['borderImageDM'].load()
            borderDeleteMapSize = settings['borderImageDM'].size
            for imx in xrange(0, width, borderDeleteMapSize[0]):
                for deleteColumn in xrange(0, borderDeleteMapSize[0]):
                    for deleteRow in xrange(0, borderDeleteMapSize[1]):
                        if borderDeleteMap[deleteColumn, deleteRow][3] > 0:
                            # Top
                            if not (roundTop and imx in xrange(cornerDeleteMapSize[0] - 1, width - cornerDeleteMapSize[0] - 1)):
                                pixels[imx + deleteColumn, deleteRow] = (0, 0, 0, 0)
                            # Bottom
                            if not (roundBottom and imx in xrange(cornerDeleteMapSize[0] - 1, width - cornerDeleteMapSize[0] - 1)):
                                pixels[imx + deleteColumn, height - deleteRow - 1] = (0, 0, 0, 0)

            for imy in xrange(0, height, borderDeleteMapSize[1]):
                # TODO: Rotate the image
                for deleteColumn in xrange(0, borderDeleteMapSize[0]):
                    for deleteRow in xrange(0, borderDeleteMapSize[1]):
                        if borderDeleteMap[deleteColumn, deleteRow][3] > 0:
                            # Left
                            if not ((roundTop and imy < cornerDeleteMapSize[1] - 1) or (roundBottom and imy > height - cornerDeleteMapSize[1] - 1)):
                                pixels[deleteColumn, imy + deleteRow] = (0, 0, 0, 0)
                            # Right
                            if not ((roundTop and imy < cornerDeleteMapSize[1] - 1) or (roundBottom and imy > height - cornerDeleteMapSize[1] - 1)):
                                pixels[width - deleteColumn - 1, imy + deleteRow] = (0, 0, 0, 0)

    # Apply overlay images
    cornerImageSize = (0, 0)
    if settings['cornerImage'] != None:
        cornerImage = settings['cornerImage']
        cornerImageSize = cornerImage.size

        if roundTop:
            imageTopLeft = cornerImage.copy()
            image.paste(imageTopLeft, (0, 0), imageTopLeft)

            imageTopRight = ImageOps.mirror(cornerImage)
            image.paste(imageTopRight, (width - cornerImageSize[0], 0), imageTopRight)

        if roundBottom:
            imageBottomLeft = ImageOps.flip(cornerImage)
            image.paste(imageBottomLeft, (0, height - cornerImageSize[1]), imageBottomLeft)

            imageBottomRight = ImageOps.flip(ImageOps.mirror(cornerImage))
            image.paste(imageBottomRight, (width - cornerImageSize[0], height - cornerImageSize[1]), imageBottomRight)

    if settings['borderImage'] != None:
        borderImage = settings['borderImage']
        borderImageSize = borderImage.size

        for imx in xrange(1, width, borderImageSize[0]):
            # Top
            if not roundTop or imx in xrange(cornerImageSize[0], width - cornerImageSize[0]):
                borderImageCopy = borderImage.copy()
                image.paste(borderImageCopy, (imx, 0), borderImageCopy)

            # Bottom
            if not roundBottom or imx in xrange(cornerImageSize[0], width - cornerImageSize[0]):
                borderImageCopy = ImageOps.flip(borderImage)
                image.paste(borderImageCopy, (imx, height - 1), borderImageCopy)


        rangeStartY = 1
        if roundTop:
            rangeStartY = cornerImageSize[1] - 1

        rangeEndY = height - 1
        if roundBottom:
            rangeEndY = height - cornerImageSize[1]

        for imy in xrange(rangeStartY, rangeEndY, borderImageSize[0]):
            # Left
            borderImageCopy = borderImage.rotate(90)
            image.paste(borderImageCopy, (0, imy), borderImageCopy)

            # Right
            borderImageCopy = borderImage.rotate(270)
            image.paste(borderImageCopy, (width - 1, imy), borderImageCopy)



    # Save the image with PIL for modification with ImageMagick
    image.save(os.path.join(tempfile.gettempdir(), 'perdywindow.png'), 'png')

    # Apply a shadow
    shadowColour = args['shadow'] if args['shadow'] != None else settings['shadow']
    command  = "convert " + os.path.join(tempfile.gettempdir(), 'perdywindow.png') + " -bordercolor none -border 64x64 -repage +48+48 \( +clone -background \"" + shadowColour + "\" -shadow 100x24+0+32 \) +swap -background none -mosaic"

    # Change the background if necessary
    background = args['background'] if args['background'] != '' else settings['background']
    if background != '' and background != False:
        command += " -background \"" + background + "\" -alpha remove"

    # Apply our magick to our image and save it to a file
    filename = args['file'] if args['file'] != None else settings['filename']
    filename = time.strftime(filename)
    subprocess.check_output(command + " " + filename, shell = True)

    totalTime = time.time()
    print # An empty line.
    wireutils.color_print("Screenshot time: %.2f seconds" % (partialTime - startTime))
    wireutils.color_print("Post-processing time: %.2f seconds" % (totalTime - partialTime))
    wireutils.color_print("Total time: %.2f seconds" % (totalTime - startTime))
    print
    wireutils.color_print("Saved as {name}.", name = filename)
Example #17
0
    def __init__(self):
        gtk.Window.__init__(self)

        status_box = gtk.HBox(spacing=1)
        status_box.set_border_width(0)

        self.location = gtk.Label("")
        (width, height) = self.location.size_request()
        self.location.set_size_request(160, height)
        status_box.pack_start(self.location, False)

        self.entry = gtk.Entry()
        self.entry.connect("changed", self._show_sheet_entry_cb)
        status_box.pack_start(self.entry)
        
        t = gtk.Toolbar()
        ttips = gtk.Tooltips()
        def add_widget_to_toolbar(widget, separator=True, tooltip=None):
            ti = gtk.ToolItem()
            ti.add(widget)
            if tooltip is not None:                
                ti.set_tooltip(ttips, tooltip)
            t.insert(ti, -1)
            if separator:
                t.insert(gtk.SeparatorToolItem(), -1)       
         
        fontbutton = gtk.FontButton()
        fontbutton.connect("font-set", self._font_changed_cb)
        add_widget_to_toolbar(fontbutton,
            tooltip="Change the font of the selected cells");
        self.fontbutton = fontbutton

        items = \
            (("justleft",  None,                  
              "Justify selected cells to the left",
              gtk.STOCK_JUSTIFY_LEFT, self._justification_cb, 
              gtk.JUSTIFY_LEFT), 
             ("justcenter", None,                  
              "Justify selected cells to the center",
              gtk.STOCK_JUSTIFY_CENTER, self._justification_cb, 
              gtk.JUSTIFY_CENTER),
             ("justright", None,                  
              "Justify selected cells to the right",
              gtk.STOCK_JUSTIFY_RIGHT, self._justification_cb, 
              gtk.JUSTIFY_RIGHT))
        for name, label, tooltip, stock_id, cb, cb_params in items:
            ti = gtk.Action(name, label, tooltip, stock_id)
            ti.connect("activate", cb, cb_params)
            t.insert(ti.create_tool_item(), -1)
        
        bordercombo = BorderCombo()
        bordercombo.connect("changed", self._border_changed_cb)
        add_widget_to_toolbar(bordercombo,
            tooltip="Change the border of the selected cells")
        
        colormap = gdk.colormap_get_system()
        colorbtn = gtk.ColorButton(colormap.alloc_color("black"))
        colorbtn.connect("color-set", self._color_changed_cb, "f")
        add_widget_to_toolbar(colorbtn, separator=False,
            tooltip="Change the foreground color of the selected cells")
        self.fgcolorbtn = colorbtn

        colorbtn = gtk.ColorButton(colormap.alloc_color("light yellow"))
        colorbtn.connect("color-set", self._color_changed_cb, "b")
        add_widget_to_toolbar(colorbtn, 
            tooltip="Change the background color of the selected cells");
        self.bgcolorbtn = colorbtn

        self.sheet = TestSheet()
        self.sheet.connect("activate", self._activate_sheet_cell_cb)
        self.sheet.get_entry().connect("changed", self._show_entry_cb)
        self.sheet.connect("changed", self._sheet_changed_cb)
        ws = gtk.ScrolledWindow()
        ws.add(self.sheet)

        fd = self.sheet.default_font
        fontbutton.set_font_name(fd.to_string())

        vbox = gtk.VBox()
        vbox.pack_start(t, False, False, 0)
        vbox.pack_start(status_box, False, False, 0)
        vbox.pack_start(ws, True, True, 0)

        self.add(vbox)
        self.set_size_request(500,400)
        self.show_all()
Example #18
0
import gtk.gdk as gdk
import time

w = gdk.screen_width()
h = gdk.screen_height()

sg = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, w, h)

start = time.clock()

pb = sg.get_from_drawable(gdk.get_default_root_window(),
                          gdk.colormap_get_system(), 0, 0, 0, 0, w, h)

print(time.clock() - start)