def do_init_new_backing_instance(self): w, h = self.size self._backing = None assert w < 32768 and h < 32768, "dimensions too big: %sx%s" % (w, h) if w == 0 or h == 0: #this can happen during cleanup return if w < 0 or h < 0: log.warn("Warning: invalid backing dimensions %ix%i", w, h) w = max(1, w) h = max(1, h) try: if self._alpha_enabled: self._backing = gdk.Pixmap(None, w, h, 32) screen = self._backing.get_screen() rgba = screen.get_rgba_colormap() if rgba is not None: self._backing.set_colormap(rgba) else: #cannot use transparency log.warn( "Warning: cannot display transparency, no RGBA colormap" ) self._alpha_enabled = False self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) else: self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) except RuntimeError as e: log("do_init_new_backing_instance()", exc_info=True) log.error("Error creating pixmap backing of size %ix%i", w, h) log.error(" %s", e) self._backing = None
def init(self, ww, wh, bw, bh): #use window size as backing size: self.render_size = ww, wh self.size = bw, bh w, h = bw, bh old_backing = self._backing self._backing = None assert w < 32768 and h < 32768, "dimensions too big: %sx%s" % (w, h) if w == 0 or h == 0: #this can happen during cleanup return if self._alpha_enabled: self._backing = gdk.Pixmap(None, w, h, 32) screen = self._backing.get_screen() rgba = screen.get_rgba_colormap() if rgba is not None: self._backing.set_colormap(rgba) else: #cannot use transparency log.warn("cannot use transparency: no RGBA colormap!") self._alpha_enabled = False self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) else: self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) cr = self._backing.cairo_create() cr.set_source_rgb(1, 1, 1) if old_backing is not None: # Really we should respect bit-gravity here but... meh. old_w, old_h = old_backing.get_size() if w > old_w and h > old_h: #both width and height are bigger: cr.rectangle(old_w, 0, w - old_w, h) cr.fill() cr.new_path() cr.rectangle(0, old_h, old_w, h - old_h) cr.fill() elif w > old_w: #enlarged in width only cr.rectangle(old_w, 0, w - old_w, h) cr.fill() if h > old_h: #enlarged in height only cr.rectangle(0, old_h, w, h - old_h) cr.fill() cr.set_operator(cairo.OPERATOR_SOURCE) cr.set_source_pixmap(old_backing, 0, 0) cr.paint() else: cr.rectangle(0, 0, w, h) cr.fill()
def init_colors(self): self._pixmap = gdk.Pixmap(self.parent.window, self.width, self.height, -1) self.set_from_pixmap(self._pixmap, None) self._colormap = self._pixmap.get_colormap() #self._colormap = gtk.gdk.colormap_get_system() #gtk.gdk.screen_get_default().get_default_colormap() self._gc = self._pixmap.new_gc() self._context = self.get_pango_context() self._fontdesc = pango.FontDescription("sans bold 10") if isinstance(self.fg_color, tuple): self.fg_color = self._colormap.alloc_color(*self.fg_color) elif self.fg_color is None: self.fg_color = self._colormap.alloc_color( self.get_style().text[gtk.STATE_NORMAL]) if isinstance(self.bg_color, tuple): self.bg_color = self._colormap.alloc_color(*self.bg_color) elif self.bg_color is None: self.bg_color = self._colormap.alloc_color( self.get_style().bg[gtk.STATE_NORMAL]) self._border_color = self._colormap.alloc_color(0, 0, 0) self.refresh()
def __init__(self): self.statusicon = gtk.StatusIcon() self.counter = 0 self.statusicon.connect("activate", self.quit_cb) self.statusicon.connect("popup-menu", self.quit_cb) self.statusicon.set_tooltip("StatusIcon Example") #generate tray image: s = 64 w, h = s * 2, s * 2 pixmap = gdk.Pixmap(gdk.get_default_root_window(), w, h) cr = pixmap.cairo_create() cr.set_operator(cairo.OPERATOR_CLEAR) cr.fill() cr.set_operator(cairo.OPERATOR_SOURCE) for i, color in enumerate([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)]): cr.set_source_rgba(*color) cr.new_path() x = (i % 2) * s y = (i / 2) * s cr.move_to(x, y) cr.line_to(x + s, y) cr.line_to(x + s, y + s) cr.line_to(x, y + s) cr.close_path() cr.fill() pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h) pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, w, h) self.statusicon.set_from_pixbuf(pixbuf)
def _create_background_pixmap(self): """ Draw the gridlines for the plot """ back_surf = gdk.Pixmap(self.window, self._tick_size, self._tick_size) cr = back_surf.cairo_create() cr.set_source_rgb(0, 0, 0) cr.paint() cr.set_line_width(self._BACKGROUND_LINE_THICKNESS) cr.set_source_rgb(0.2, 0.2, 0.2) x = 0 y = 0 for j in range(0, 2): cr.move_to(x, y) cr.rel_line_to(0, self._tick_size) x = x + self._tick_size x = 0 y = (self.allocation.height % self._tick_size) / 2 - self._tick_size for j in range(0, 3): cr.move_to(x, y) cr.rel_line_to(self._tick_size, 0) y = y + self._tick_size cr.set_line_width(self._BACKGROUND_LINE_THICKNESS) cr.stroke() del cr self.window.set_back_pixmap(back_surf, False) return
def set_icon(): #generate window icon image: if not self.rotate: return True s = 64 w, h = s * 2, s * 2 pixmap = gdk.Pixmap(gdk.get_default_root_window(), w, h) cr = pixmap.cairo_create() cr.set_operator(cairo.OPERATOR_CLEAR) cr.fill() cr.set_operator(cairo.OPERATOR_SOURCE) v = (self.counter % 256 / 255.0) self.counter += 10 for i, color in enumerate([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1), (v, v, v, v)]): cr.set_source_rgba(*color) cr.new_path() x = (i % 2) * s y = (i / 2) * s cr.move_to(x, y) cr.line_to(x + s, y) cr.line_to(x + s, y + s) cr.line_to(x, y + s) cr.close_path() cr.fill() pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h) pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, w, h) self.set_icon(pixbuf) print("set icon to %s" % int(255 * v)) return True
def _generate_image(self, num): w = 55 h = w pixmap = gdk.Pixmap(self.get_window(), w, h, -1) ctx = pixmap.cairo_create() ctx.rectangle(0, 0, w, h) ctx.set_source_rgb(0, 0, 0) ctx.fill() x = 0 y = 4 ctx.translate(x, y) circle_path = os.path.join(constants.GFX_PATH, 'media-circle.png') surface = cairo.ImageSurface.create_from_png(circle_path) ctx.set_source_surface(surface, 0, 0) ctx.paint() ctx.translate(-x, -y) ctx.set_source_rgb(255, 255, 255) pctx = pangocairo.CairoContext(ctx) play = pctx.create_layout() font = pango.FontDescription("sans 30") play.set_font_description(font) play.set_text(str(num)) dim = play.get_pixel_extents() ctx.translate(-dim[0][0], -dim[0][1]) xoff = (w - dim[0][2]) / 2 yoff = (h - dim[0][3]) / 2 ctx.translate(xoff, yoff) ctx.translate(-3, 0) pctx.show_layout(play) return pixmap
def init(self, w, h): old_backing = self._backing self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) cr = self._backing.cairo_create() cr.set_source_rgb(1, 1, 1) if CRASH and old_backing is not None: cr.set_operator(cairo.OPERATOR_SOURCE) cr.set_source_pixmap(old_backing, 0, 0) cr.paint() old_w, old_h = old_backing.get_size() if w > old_w: cr.new_path() cr.move_to(old_w, 0) cr.line_to(w, 0) cr.line_to(w, h) cr.line_to(old_w, h) cr.close_path() cr.fill() if h > old_h: cr.new_path() cr.move_to(0, old_h) cr.line_to(0, h) cr.line_to(w, h) cr.line_to(w, old_h) cr.close_path() cr.fill() else: cr.rectangle(0, 0, w, h) cr.fill()
def _handle_net_wm_icon_change(self): iconlog("_NET_WM_ICON changed on %#x, re-reading", self.xid) surf = self.prop_get("_NET_WM_ICON", "icon") if surf is not None: # FIXME: There is no Pixmap.new_for_display(), so this isn't # actually display-clean. Oh well. pixmap = gdk.Pixmap(None, surf.get_width(), surf.get_height(), 32) screen = get_display_for(pixmap).get_default_screen() colormap = screen.get_rgba_colormap() if not colormap: colormap = screen.get_rgb_colormap() if not colormap: iconlog.warn( "Warning: cannot find colormap for default screen") pixmap = None else: pixmap.set_colormap(colormap) cr = pixmap.cairo_create() cr.set_source_surface(surf) # Important to use SOURCE, because a newly created Pixmap can have # random trash as its contents, and otherwise that will show # through any alpha in the icon: cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() else: pixmap = None #FIXME: it would be more efficient to notify first, #then get the icon pixels on demand and cache them.. self._internal_set_property("icon", surf) self._internal_set_property("icon-pixmap", pixmap) iconlog("icon is now %r, pixmap=%s", surf, pixmap)
def init(self, w, h): old_backing = self._backing assert w < 32768 and h < 32768, "dimensions too big: %sx%s" % (w, h) if self._has_alpha and HAS_RGBA: self._backing = gdk.Pixmap(None, w, h, 32) screen = self._backing.get_screen() rgba = screen.get_rgba_colormap() if rgba is not None: self._backing.set_colormap(rgba) else: #cannot use transparency self._has_alpha = False self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) else: self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) cr = self._backing.cairo_create() cr.set_source_rgb(1, 1, 1) if old_backing is not None: # Really we should respect bit-gravity here but... meh. old_w, old_h = old_backing.get_size() #note: we may paint the rectangle (old_w, old_h) to (w, h) twice - no big deal if w > old_w: cr.new_path() cr.move_to(old_w, 0) cr.line_to(w, 0) cr.line_to(w, h) cr.line_to(old_w, h) cr.close_path() cr.fill() if h > old_h: cr.new_path() cr.move_to(0, old_h) cr.line_to(0, h) cr.line_to(w, h) cr.line_to(w, old_h) cr.close_path() cr.fill() cr.new_path() cr.move_to(0, 0) cr.set_operator(cairo.OPERATOR_SOURCE) cr.set_source_pixmap(old_backing, 0, 0) cr.paint() else: cr.rectangle(0, 0, w, h) cr.fill()
def __init__(self, pixmap_path, resizee): gtk.Widget.__init__(self) #self.set_size_request(-1, 100) self.button_down = False self.pixmap = gdk.Pixmap(None, 10, 10, 24) self.pixmap_path = pixmap_path self.resizee = resizee
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
def do_init_new_backing_instance(self): w, h = self.size self._backing = None assert w<32768 and h<32768, "dimensions too big: %sx%s" % (w, h) if w==0 or h==0: #this can happen during cleanup return if self._alpha_enabled: self._backing = gdk.Pixmap(None, w, h, 32) screen = self._backing.get_screen() rgba = screen.get_rgba_colormap() if rgba is not None: self._backing.set_colormap(rgba) else: #cannot use transparency log.warn("cannot use transparency: no RGBA colormap!") self._alpha_enabled = False self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) else: self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h)
def init(self, w, h): old_backing = self._backing assert w<32768 and h<32768, "dimensions too big: %sx%s" % (w, h) if self._has_alpha and HAS_ALPHA: self._backing = gdk.Pixmap(None, w, h, 32) screen = self._backing.get_screen() rgba = screen.get_rgba_colormap() if rgba is not None: self._backing.set_colormap(rgba) else: #cannot use transparency self._has_alpha = False self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) else: self._backing = gdk.Pixmap(gdk.get_default_root_window(), w, h) cr = self._backing.cairo_create() cr.set_source_rgb(1, 1, 1) if old_backing is not None: # Really we should respect bit-gravity here but... meh. old_w, old_h = old_backing.get_size() if w>old_w and h>old_h: #both width and height are bigger: cr.rectangle(old_w, 0, w-old_w, h) cr.fill() cr.new_path() cr.rectangle(0, old_h, old_w, h-old_h) cr.fill() elif w>old_w: #enlarged in width only cr.rectangle(old_w, 0, w-old_w, h) cr.fill() if h>old_h: #enlarged in height only cr.rectangle(0, old_h, w, h-old_h) cr.fill() cr.set_operator(cairo.OPERATOR_SOURCE) cr.set_source_pixmap(old_backing, 0, 0) cr.paint() else: cr.rectangle(0, 0, w, h) cr.fill()
def _drawDefaultBackground(self): # allocate the slate background self.bg = gdk.pixbuf_new_from_file(fs.background) # create a pixmap to put a tile into _pixmap = gdk.Pixmap(self.gw_viewport1.window, self.bg.get_width(), self.bg.get_height()) gc = _pixmap.new_gc() _pixmap.draw_pixbuf(gc, self.bg, 0, 0, 0, 0) # a kludge to make gw_viewport1 generate a new style object: self.gw_viewport1.modify_bg(gtk.STATE_NORMAL, gdk.Color(0xff0000)) # now modify the new style object self.gw_viewport1.style.bg_pixmap[gtk.STATE_NORMAL] = _pixmap
def main(args): global pixmap width = 544 height = 100 screen = gdk.screen_get_default( ) win = gtk.Window( ) win.set_title( 'Spectrumize' ) win.set_default_size( width, height ) win.stick( ) win.set_keep_below( True ) win.set_decorated( False ) win.set_skip_taskbar_hint( True ) #win.set_gravity( gdk.GRAVITY_CENTER ) win.connect( 'delete-event', gtk.main_quit ) win.connect( 'expose-event', expose ) win.connect( 'screen-changed', screenChanged ) # initialize for the current display screenChanged( win ) # Run the program win.show_all( ) pixmap = gdk.Pixmap( win.window, width, height, -1 ) # Tell GTK+ that we want to draw the windows background ourself. win.set_app_paintable( True ) win.set_double_buffered( False ) screen_rect = screen.get_monitor_geometry( 0 ) win.move( screen_rect.width / 2 - width / 2 + screen_rect.x, screen_rect.height / 2 - height / 2 + screen_rect.y ) gobject.timeout_add( 33, timerExecFrame, win ) try: gtk.main( ) except KeyboardInterrupt: pass print total_peak_heights return True
def _create_shape(self, width, height): black = gdk.Color(red=0, green=0, blue=0, pixel=1) white = gdk.Color(red=255, green=255, blue=255, pixel=0) pm = gdk.Pixmap(self.window, width, height, 1) gc = gdk.GC(pm) gc.set_background(white) gc.set_foreground(white) pm.draw_rectangle(gc, True, 0, 0, width, height) gc.set_foreground(black) pm.draw_rectangle(gc, False, 0, 0, width - 1, height - 1) pm.draw_rectangle(gc, False, 1, 1, width - 3, height - 3) self.shape_combine_mask(pm, 0, 0)
def do_size_allocate(self, allocation): """ The do_size_allocate is called when the actual size is known and the widget is told how much space could actually be allocated.""" self.allocation = allocation self.width = self.allocation.width self.height = self.allocation.height if self.flags() & gtk.REALIZED: self.window.move_resize(*allocation) self._pixmap = gdk.Pixmap(self.window, self.width, self.height) self.draw()
def cache_graphs(self): if self.window != None: print "caching" space = self.get_allocation() self.graph_cache_width = space.width self.graph_cache_height = space.height self.graph_cache = [] for n in range(0, self.graph_cache_images): print n rotation = 2.0 * math.pi * float(n) / float( self.graph_cache_images) pixmap = gdk.Pixmap(self.window, space.width, space.height) #pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, space.width, space.height) context = pixmap.cairo_create() self.draw_fan(context, space, rotation) self.graph_cache.append(pixmap) print "done"
def _draw_color(self, pixbuf, color, x, y, width, height): """Draws a color cell""" border_color = "#000000" # create pixmap pixmap = gdk.Pixmap(None, width, height, 24) cmap = pixmap.get_colormap() gc = pixmap.new_gc() color1 = cmap.alloc_color(color) color2 = cmap.alloc_color(border_color) # draw fill gc.foreground = color1 #gtk.gdk.Color(* color) pixmap.draw_rectangle(gc, True, 0, 0, width, height) # draw border gc.foreground = color2 #gtk.gdk.Color(* border_color) pixmap.draw_rectangle(gc, False, 0, 0, width - 1, height - 1) pixbuf.get_from_drawable(pixmap, cmap, 0, 0, 0, 0, width, height)
def do_expose_event(self, event): """ This is where the widget must draw itself. """ retval = False if self.flags() & gtk.REALIZED and not self._pixmap: self._pixmap = gdk.Pixmap(self.window, self.allocation.width, self.allocation.height) self._adjust_adjustments() self.draw() if self._pixmap: self.window.draw_drawable(self.style.fg_gc[self.state], self._pixmap, event.area.x, event.area.y, event.area.x, event.area.y, event.area.width, event.area.height) return retval
def paint(self, widget, x, y): x = int(x) y = int(y) rect = (x - 5, y - 5, 10, 10) white = widget.get_style().white_gc if self.last_brush is not None: gc2 = widget.window.new_gc() gc2.copy(white) gc2.set_line_attributes(10, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_BEVEL) self.scraped.draw_lines(gc2, [(x, y), self.last_brush]) # paint the same thing to a duplicate so we can get the # drawn pixels without the background if self.duplicate is None: # delay creating the duplicate until here so it's easy to # check if it's been modified x, y, ww, hh = widget.get_allocation() self.duplicate = gdk.Pixmap(widget.window, ww, hh) self.duplicate.draw_lines(gc2, [(x, y), self.last_brush]) widget.queue_draw() self.last_brush = x, y
def scrape(self, canvas): x, y, ww, hh = canvas.get_allocation() self.scraped = gdk.Pixmap(canvas.window, ww, hh) self.scraped.draw_drawable(self.scraped.new_gc(), canvas.window, 0, 0, 0, 0, ww, hh)
def __init__(self, width, height): gdk_root = gdk.get_default_root_window() self._gdk_pixmap = gdk.Pixmap(gdk_root, width, height)
def check_support(min_texture_size=0, force_enable=False): #tricks to get py2exe to include what we need / load it from its unusual path: opengl_icon = os.path.join(os.getcwd(), "icons", "opengl.png") if sys.platform.startswith("win"): log("is frozen: %s", hasattr(sys, "frozen")) if hasattr(sys, "frozen"): log("found frozen path: %s", sys.frozen) if sys.frozen in ("windows_exe", "console_exe"): main_dir = os.path.dirname( unicode(sys.executable, sys.getfilesystemencoding())) log("main_dir=%s", main_dir) sys.path.insert(0, main_dir) os.chdir(main_dir) opengl_icon = os.path.join(main_dir, "icons", "opengl.png") else: sys.path.insert(0, ".") #This is supposed to help py2exe (after we setup the path): from OpenGL.platform import win32 #@UnusedImport props = {} from gtk import gdk import gtk.gdkgl, gtk.gtkgl assert gtk.gdkgl is not None and gtk.gtkgl is not None log("pygdkglext version=%s", gtk.gdkgl.pygdkglext_version) props["pygdkglext_version"] = gtk.gdkgl.pygdkglext_version log("pygdkglext OpenGL version=%s", gtk.gdkgl.query_version()) props["gdkgl_version"] = gtk.gdkgl.query_version() display_mode = get_DISPLAY_MODE() try: glconfig = gtk.gdkgl.Config(mode=display_mode) except gtk.gdkgl.NoMatches: display_mode &= ~gtk.gdkgl.MODE_DOUBLE glconfig = gtk.gdkgl.Config(mode=display_mode) friendly_mode_names = { gtk.gdkgl.MODE_RGB: "RGB", gtk.gdkgl.MODE_DEPTH: "DEPTH", gtk.gdkgl.MODE_DOUBLE: "DOUBLE", gtk.gdkgl.MODE_SINGLE: "SINGLE" } friendly_modes = [ v for k, v in friendly_mode_names.items() if (k & display_mode) == k ] log("using display mode: %s", friendly_modes) props["display_mode"] = friendly_modes props["glconfig"] = glconfig assert gtk.gdkgl.query_extension() glcontext, gldrawable, glext, w = None, None, None, None try: if sys.platform.startswith("win"): #FIXME: ugly win32 hack for getting a drawable and context, we must use a window... #maybe using a gl.drawable would work too? w = gtk.Window() w.set_decorated(False) vbox = gtk.VBox() if opengl_icon and os.path.exists(opengl_icon): pixbuf = gtk.gdk.pixbuf_new_from_file(opengl_icon) image = gtk.image_new_from_pixbuf(pixbuf) vbox.add(image) w.set_default_size(pixbuf.get_width(), pixbuf.get_height()) w.set_resizable(False) glarea = gtk.gtkgl.DrawingArea(glconfig) vbox.add(glarea) w.add(vbox) w.show_all() gtk.gdk.window_process_all_updates() gldrawable = glarea.get_gl_drawable() glcontext = glarea.get_gl_context() else: glext = gtk.gdkgl.ext( gdk.Pixmap(gdk.get_default_root_window(), 1, 1)) gldrawable = glext.set_gl_capability(glconfig) glcontext = gtk.gdkgl.Context(gldrawable, direct=True) gl_props = check_GL_support(gldrawable, glcontext, min_texture_size, force_enable) finally: if w: w.destroy() del glcontext, gldrawable, glext, glconfig props.update(gl_props) return props
def event_configure(self, *args): x, y, self.width, self.height = self.area.get_allocation() self.pixmap = gdk.Pixmap(self.area.window, self.width, self.height) return True
glEnableClientState, glDisable, glGenTextures, \ glBindTexture, glPixelStorei, glEnable, glBegin, \ glTexParameteri, glVertexPointeri, glTexCoordPointeri, \ glTexImage2D, glTexSubImage2D, \ glDrawArrays, glMultiTexCoord2i, \ glVertex2i, glEnd from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glBindProgramARB, glProgramStringARB from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB from xpra.gl_colorspace_conversions import GL_COLORSPACE_CONVERSIONS #sanity checks: OpenGL version try: from gtk import gdk glconfig = gtk.gdkgl.Config(mode=gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_SINGLE) glext = gtk.gdkgl.ext(gdk.Pixmap(gdk.get_default_root_window(), 1, 1)) gldrawable = glext.set_gl_capability(glconfig) glcontext = gtk.gdkgl.Context(gldrawable, direct=True) if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) try: gl_major = int(glGetString(GL_VERSION)[0]) gl_minor = int(glGetString(GL_VERSION)[2]) if gl_major <= 1 and gl_minor < 1: raise ImportError( "** OpenGL output requires OpenGL version 1.1 or greater, not %s.%s" % (gl_major, gl_minor)) log.info("found valid OpenGL: %s.%s", gl_major, gl_minor) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt
def event_configure(self, *args): """ Called when the window is resized and created. """ x, y, self.width, self.height = self.area.get_allocation() self.pixmap = gdk.Pixmap(self.area.window, self.width, self.height) return True
def _from_nothing(cls): cursor = cls.__new__(cls) pixmap = gdk.Pixmap(None, 1, 1, 1) color = gdk.Color() cursor._gtk_cursor = gdk.Cursor(pixmap, pixmap, color, color, 0, 0) return cursor
def osd(text, bgcolor, fgcolor, fontdesc, use_markup=False, alignment=pango.ALIGN_CENTER, fake_translucent_bg=False, drop_shadow=False, max_width=None, debug_frame=False, ellipsize=pango.ELLIPSIZE_NONE): assert isinstance(fontdesc, pango.FontDescription) win = gtk.Window(gtk.WINDOW_POPUP) win.add_events(gtk.gdk.ENTER_NOTIFY_MASK) darea = gtk.DrawingArea() win.add(darea) darea.show() if use_markup: layout = win.create_pango_layout('') layout.set_markup(text) else: layout = win.create_pango_layout(text) try: layout.set_ellipsize(ellipsize) except AttributeError: print "ellipsize attribute not supported, ignored" layout.set_justify(False) layout.set_alignment(alignment) layout.set_font_description(fontdesc) if max_width is None: MAX_WIDTH = gdk.screen_width() - 8 else: MAX_WIDTH = max_width - 8 layout.set_width(pango.SCALE * MAX_WIDTH) if ellipsize != pango.ELLIPSIZE_NONE: layout.set_wrap(pango.WRAP_WORD) width, height = layout.get_pixel_size() off_x = BORDER_WIDTH * 2 off_y = BORDER_WIDTH * 2 if alignment == pango.ALIGN_CENTER: off_x -= MAX_WIDTH / 2 - width / 2 elif alignment == pango.ALIGN_RIGHT: off_x -= MAX_WIDTH - width width += BORDER_WIDTH * 4 height += BORDER_WIDTH * 4 if drop_shadow: drop_shadow_distance = max( 2, int(fontdesc.get_size() / pango.SCALE * 0.1)) width += drop_shadow_distance height += drop_shadow_distance darea.set_size_request(width, height) darea.realize() pixmap = gtk.gdk.Pixmap(darea.window, width, height) pixmap.set_colormap(darea.window.get_colormap()) fg_gc = gdk.GC(pixmap) fg_gc.copy(darea.style.fg_gc[gtk.STATE_NORMAL]) bg_gc = gdk.GC(pixmap) bg_gc.copy(darea.style.fg_gc[gtk.STATE_NORMAL]) fg_gc.set_foreground(darea.get_colormap().alloc_color(fgcolor)) bg_gc.set_background(darea.get_colormap().alloc_color(bgcolor)) pixmap.draw_rectangle(bg_gc, True, 0, 0, width, height) pixmap.draw_layout(fg_gc, off_x, off_y, layout) if debug_frame: pixmap.draw_rectangle(fg_gc, False, 0, 0, width - 1, height - 1) bitmap = gtk.gdk.Pixmap(darea.window, width, height, 1) bitmap.set_colormap(darea.window.get_colormap()) fg_gc = gdk.GC(bitmap) bg_gc = gdk.GC(bitmap) fg_gc.set_foreground(gdk.Color(pixel=-1)) bg_gc.set_background(gdk.Color(pixel=0)) if fake_translucent_bg: w, h = 2, 2 stipple = gtk.gdk.Pixmap(None, w, h, 1) stipple.draw_rectangle(bg_gc, True, 0, 0, w, h) stipple.draw_point(fg_gc, 0, 0) stipple.draw_point(fg_gc, 1, 1) fg_gc.set_stipple(stipple) bitmap.draw_rectangle(bg_gc, True, 0, 0, width, height) fg_gc.set_fill(gtk.gdk.STIPPLED) bitmap.draw_rectangle(fg_gc, True, 0, 0, width, height) fg_gc.set_fill(gtk.gdk.SOLID) # draw corners corner_size = int(fontdesc.get_size() / pango.SCALE * 0.5) fg_gc.set_function(gtk.gdk.AND) gc = gdk.GC(bitmap) corner = gtk.gdk.Pixmap(bitmap, corner_size, corner_size) def draw_corner(angle1, x, y, arc_x0, arc_y0): gc.set_foreground(gdk.Color(pixel=0)) corner.draw_rectangle(gc, True, 0, 0, corner_size, corner_size) gc.set_foreground(gdk.Color(pixel=1)) corner.draw_arc(gc, True, arc_x0, arc_y0, corner_size * 2, corner_size * 2, angle1 * 64, 90 * 64) bitmap.draw_drawable(fg_gc, corner, 0, 0, x, y, corner_size, corner_size) # top-left draw_corner(90, 0, 0, 0, 0) # bottom-left draw_corner(180, 0, height - corner_size, 0, -corner_size) # bottom-right draw_corner(270, width - corner_size, height - corner_size, -corner_size, -corner_size) # top-right draw_corner(0, width - corner_size, 0, -corner_size, 0) fg_gc.set_function(gtk.gdk.SET) else: bitmap.draw_rectangle(bg_gc, True, 0, 0, width, height) bitmap.draw_layout(fg_gc, off_x, off_y, layout) bitmap.draw_layout(fg_gc, off_x + BORDER_WIDTH, off_y, layout) bitmap.draw_layout(fg_gc, off_x + BORDER_WIDTH, off_y + BORDER_WIDTH, layout) bitmap.draw_layout(fg_gc, off_x, off_y + BORDER_WIDTH, layout) bitmap.draw_layout(fg_gc, off_x - BORDER_WIDTH, off_y + BORDER_WIDTH, layout) bitmap.draw_layout(fg_gc, off_x - BORDER_WIDTH, off_y, layout) bitmap.draw_layout(fg_gc, off_x - BORDER_WIDTH, off_y - BORDER_WIDTH, layout) bitmap.draw_layout(fg_gc, off_x, off_y - BORDER_WIDTH, layout) bitmap.draw_layout(fg_gc, off_x + BORDER_WIDTH, off_y - BORDER_WIDTH, layout) if drop_shadow: bitmap.draw_layout(fg_gc, off_x + drop_shadow_distance, off_y + drop_shadow_distance, layout) if debug_frame: bitmap.draw_rectangle(fg_gc, False, 0, 0, width - 1, height - 1) darea.window.set_back_pixmap(pixmap, False) win.window.shape_combine_mask(bitmap, 0, 0) win.width = width win.height = height # Set the overlay mode of the window pixmap = gdk.Pixmap(None, width, height, 1) win.input_shape_combine_mask(pixmap, 0, 0) return win