예제 #1
0
    def prepare_stringed (self, rows, cols):
        # We use a Pixmap as offscreen drawing canvas
        cm = Gdk.colormap_get_system()
        pm = Gdk.Pixmap(None, self.width, self.height, cm.get_visual().depth)
        #pangolayout = pm.create_pango_layout("")
        font_size = int(self.width / cols / 4)
        l = Gtk.Label()
        pangolayout = Pango.Layout(l.create_pango_context())
        pangolayout.set_font_description(Pango.FontDescription("sans bold %i" % font_size))
        gc = pm.new_gc()
        gc.set_colormap(Gdk.colormap_get_system())
        color = cm.alloc_color('white')
        gc.set_foreground(color)
        pm.draw_rectangle(gc, True, 0, 0, self.width, self.height)
        color = cm.alloc_color('black')
        gc.set_foreground(color)

        sw, sh = (self.width / cols), (self.height / rows)
        item = iter(self.tlist)
        for r in range(rows):
            for c in range(cols):
                px = sw * c
                py = sh * r
                #if c > 0 and r > 0:
                #    pm.draw_line(gc, px, 0, px, self.height-1)
                #    pm.draw_line(gc, 0, py, self.width-1, py)
                pangolayout.set_text(str(item.next()))
                pe = pangolayout.get_pixel_extents()
                pe = pe[1][2]/2, pe[1][3]/2
                pm.draw_layout(gc, px + (sw / 2) - pe[0],  py + (sh / 2) - pe[1], pangolayout)
        self.get_from_drawable(pm, cm, 0, 0, 0, 0, -1, -1)
예제 #2
0
 def menuitem_response(self, widget, string): 
     if string == "gtk-media-play":
        if self.image.get_stock()[0] == "gtk-media-pause":
            self.player.set_state(gst.State.PAUSED)
            self.image.set_from_stock(gtk.STOCK_MEDIA_PLAY, 3)
        else:
            self.player.set_state(gst.State.PLAYING)
            self.image.set_from_stock(gtk.STOCK_MEDIA_PAUSE,3)
     elif string == "gtk-media-forward":self.durak(True)      
     elif string == "gtk-media-rewind": self.durak(False)      
     elif string == "gtk-media-next": self.sonraki(True)
     elif string == "gtk-media-previous": self.onceki(True)
     elif string == "Ses Dengesi":self.eko()                      
     elif string ==  "Ekran Görüntüsü Al":    
        al = self.movie_window.get_allocation()
        width = al.width
        height = al.height
        screenshot = gdkpixbuf.Pixbuf.get_pixels(
                 gdkpixbuf.Pixbuf( gdk.RGBA, True, 8, width, height),
                 self.movie_window.get_window(),
                 gdk.colormap_get_system(),
                 0, 0, 0, 0, width, height) 
        screenshot.save("%s/%s.%s." %( home,self.window.get_title().replace("/",".") , 
                   self.time.replace("/","-") ) + "png", "png" )
        del screenshot
     elif string == "gtk-about":abou.hakkinda()
예제 #3
0
def colored_cursor(size=64, x=32, y=32):
	#create a custom cursor:
	#first get a colormap and then allocate the colors
	#black and white for drawing on the bitmaps:
	pm = Gdk.Pixmap(None, size, size, 1)
	mask = Gdk.Pixmap(None, size, size, 1)
	colormap = Gdk.colormap_get_system()
	black = colormap.alloc_color('black')
	white = colormap.alloc_color('white')
	# Create two GCs - one each for black and white:
	bgc = pm.new_gc(foreground=black)
	wgc = pm.new_gc(foreground=white)
	# Use the black gc to clear the pixmap and mask:
	mask.draw_rectangle(bgc,True,0,0,size,size)
	pm.draw_rectangle(bgc,True,0,0,size,size)
	# Use the white gc to set the bits in the pixmap and mask:
	pm.draw_arc(wgc,True,0,2,size,size/2,0,360*64)
	mask.draw_rectangle(wgc,True,0,0,size,size)
	# Then create and set the cursor using unallocated colors:
	green = Gdk.color_parse('green')
	red = Gdk.color_parse('red')
	return Gdk.Cursor(pm,mask,green,red, x, y)
예제 #4
0
    def renderer(self, widget_name):
        """
        Rendering thread.

        This function is meant to be run in the various prerendering threads. It
        only uses safe ways to access attributes of the
        :class:`~pympress.pixbufcache.PixbufCache` class (i.e. synchronization
        with :class:`~threading.Lock`\ s). It runs infinitely (until the program
        ends) and does the following steps:

        - fetch the number of a page to render from the jobs
          :class:`~Queue.Queue`
        - check if it is not already available in the cache
        - render it in a new :class:`~GdkPixbuf.Pixbuf` if necessary
        - store it in the cache if it was not added there since the beginning of
          the process

        .. note:: There is a big huge ``print`` in the middle of this function
           which is used to check if everything works fine. It will be removed
           from the code in the next release unless I forget to do it :)

        :param widget_name: name of the widget handled by this thread
        :type  widget_name: string
        """
        # Give the program some time to start
        time.sleep(5)

        while True:
            # Get something to do
            page_nb = self.jobs[widget_name].get()

            # So we have something to do. The main thread may have something to
            # do too: let it acquire this lock first.
            time.sleep(0.1)
            with self.locks[widget_name]:
                if page_nb in self.pixbuf_cache[widget_name]:
                    # Already in cache
                    continue
                ww, wh = self.pixbuf_size[widget_name]
                type = self.pixbuf_type[widget_name]
            with self.doc_lock:
                page = self.doc.page(page_nb)
                pw, ph = page.get_size(type)

            print "Prerendering page %d for widget %s type %d" % (page_nb+1, widget_name, type)

            #with Gdk.lock:
            # Render to a pixmap
            pixmap = Gdk.Pixmap(None, ww, wh, 24) # FIXME: 24 or 32?
            cr = pixmap.cairo_create()
            page.render_cairo(cr, ww, wh, type)

            # Convert pixmap to pixbuf
            pixbuf = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, False, 8, ww, wh)
            pixbuf.get_from_drawable(pixmap, Gdk.colormap_get_system(),
                                     0, 0, 0, 0, ww, wh)

            # Save if possible and necessary
            with self.locks[widget_name]:
                pc = self.pixbuf_cache[widget_name]
                if (ww, wh) == self.pixbuf_size[widget_name] and not page_nb in pc:
                    pc[page_nb] = pixbuf