def __expose(self, widget, event): """ Dibuja el estado de la barra de progreso. """ x, y, w, h = self.get_allocation() ancho, borde = (self.ancho, self.borde) gc = gtk.gdk.Drawable.new_gc(self.window) gc.set_rgb_fg_color(gdk.color_parse("#ffffff")) self.window.draw_rectangle(gc, True, x, y, w, h) gc.set_rgb_fg_color(gdk.Color(0, 0, 0)) ww = w - borde * 2 xx = x + w / 2 - ww / 2 hh = ancho yy = y + h / 2 - ancho / 2 self.window.draw_rectangle(gc, True, xx, yy, ww, hh) ximage = int(self.ajuste.get_value() * ww / 100) gc.set_rgb_fg_color(gdk.Color(65000, 26000, 0)) self.window.draw_rectangle(gc, True, xx, yy, ximage, hh) # La Imagen imgw, imgh = (self.pixbuf.get_width(), self.pixbuf.get_height()) yimage = yy + hh / 2 - imgh / 2 self.window.draw_pixbuf(gc, self.pixbuf, 0, 0, ximage, yimage, imgw, imgh, gtk.gdk.RGB_DITHER_NORMAL, 0, 0) return True
def __init__(self, tagtable=None): VView.__init__(self) self.textview = gtk.TextView() self.textview.connect("populate_popup", self.vwGetPopup) self.add(self.textview) if tagtable == None: tagtable = gtk.TextTagTable() self.vwSetTagTable(tagtable) style = gtk.Style() style.base[gtk.STATE_NORMAL] = gdk.Color(0, 0, 0) style.text[gtk.STATE_NORMAL] = gdk.Color(0, 0, 0xff) style.base[gtk.STATE_INSENSITIVE] = gdk.Color(0, 0, 0) style.text[gtk.STATE_INSENSITIVE] = gdk.Color(20, 20, 20) self.textview.set_style(style) self.tagcfg = ConfigParser() self.curtag = None # Is a current tag selected? #self.deftag = self.vwInitTag(VTextTag("default")) start, end = self.textbuf.get_bounds() self.textbuf.create_mark("insertend", end)
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)
def __init__(self): BaseWidget.__init__(self) self._sep = gtk.HSeparator() self.add(self._sep) self._size = None self._sep.modify_bg(gtk.STATE_NORMAL, gdk.Color(* DEFAULT_HR_COLOR)) self._sep.modify_fg(gtk.STATE_NORMAL, gdk.Color(* DEFAULT_HR_COLOR)) self._sep.connect("size-request", self._on_resize)
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 _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)
def gfx_get_color_gc(self, color): r = color[0] g = color[1] b = color[2] if (r, g, b) not in self.color_memo: rgb = (int(r * 65535), int(g * 65535), int(b * 65535)) gc = self.area.window.new_gc() gc.set_rgb_fg_color(gdk.Color(rgb[0], rgb[1], rgb[2])) self.color_memo[(r, g, b)] = gc return self.color_memo[(r, g, b)]
def __init__(self, red, green, blue, alpha = 1.0, image = False, im = ''): self._rgba = (red, green, blue, alpha) self.image = image if image: self.image = im._gdk_pixbuf else: gdk_color = gdk.Color() gdk_color.red = int(red * 65535) gdk_color.green = int(green * 65535) gdk_color.blue = int(blue * 65535) self._gdk_color = gdk_color self._alpha = alpha
def gen_control(widget): box = gtk.VBox() t = gtk.CheckButton("NeedShadow") t.set_active(True) t.connect('toggled', lambda w: TT.has_shadow(widget, w.get_active())) box.pack_start(t, False, False) TT.text(t, "toggle the shadow") winfo = TT.WidgetInfo.get_info(widget) t1 = gtk.Entry() t1.set_text(winfo.text or "") t1.connect('activate', lambda w: TT.text(widget, w.get_text())) box.pack_start(t1, False, False) t2 = gtk.SpinButton() t2.set_range(0, 10) t2.set_value((winfo.show_delay / 1000)) t2.connect( 'value-changed', lambda w: TT.show_delay(widget, w.get_value_as_int() * 1000 + 100)) box.pack_start(t2, False, False) t3 = ColorButton() t3.set_color(str(winfo.background)) t3.connect( 'color-select', lambda w, e: TT.background(widget, gtk.gdk.Color(w.get_color()))) box.pack_start(t3) t4 = gtk.SpinButton() t4.set_range(0, 100) t4.set_value(winfo.padding_r) t4.connect('value-changed', lambda w: TT.padding(widget, -1, -1, -1, w.get_value())) box.pack_start(t4, False, False) t5 = gtk.CheckButton("disable") t5.set_active(False) t5.connect('toggled', lambda w: TT.disable(widget, w.get_active())) box.pack_start(t5, False, False) #----------------------------------------------------------------------# TT.text(t1, "The text value if tooltip didn't has custom property")\ (t2, "The show delay value")\ (t3, "The background color")\ (t4, "The pading right value")\ (t5, "tmp disable tooltip")\ .show_delay([t1,t2,t3,t4,t5], 200)\ .background([t1,t2], gdk.Color("red"))\ .set_value([t1,t2,t3,t4,t5], {'text_kargs': {"text_size":15}}) #_____________________________________________________________________# return box
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 update(self, objeto, estado): if "PAUSED" in estado: self.btn_stop.set_sensitive(False) self.btn_foto.set_sensitive(False) self.btn_play.set_sensitive(True) elif "PLAYING" in estado: self.btn_stop.set_sensitive(True) self.btn_foto.set_sensitive(True) self.btn_play.set_sensitive(False) elif "NULL" in estado: self.btn_stop.set_sensitive(False) self.btn_foto.set_sensitive(False) self.btn_play.set_sensitive(True) self.visor.modify_bg(0, gdk.Color(0, 0, 0))
def get_color(color): """ Devuelve Colores predefinidos. """ from gtk import gdk colors = { "GRIS": gdk.Color(60156, 60156, 60156), "AMARILLO": gdk.Color(65000, 65000, 40275), "NARANJA": gdk.Color(65000, 26000, 0), "BLANCO": gdk.Color(65535, 65535, 65535), "NEGRO": gdk.Color(0, 0, 0), "ROJO": gdk.Color(65000, 0, 0), "VERDE": gdk.Color(0, 65000, 0), "AZUL": gdk.Color(0, 0, 65000), } return colors.get(color, None)
def set_background_color(self, r, g, b): """ Set background color. @type r: int @param r: red @type g: int @param g: green @type b: int @param b: blue """ self._background_color = (r, g, b) if self._background_gc: # This part can only be called after the widget is visible color = gdk.Color(red=r, green=g, blue=b) self._background_gc = gdk.GC(self.window) self._gc_set_foreground(self._background_gc, color) self.refresh(force_draw=True)
def _init_gc(self): if not self._handwriting_line_gc: color = gdk.Color(red=0x0000, blue=0x0000, green=0x0000) self._handwriting_line_gc = gdk.GC(self.window) self._gc_set_foreground(self._handwriting_line_gc, color) self._handwriting_line_gc.set_line_attributes( 4, gdk.LINE_SOLID, gdk.CAP_ROUND, gdk.JOIN_ROUND) if not self._stroke_gc: color = gdk.Color(red=0xff00, blue=0x0000, green=0x0000) self._stroke_gc = gdk.GC(self.window) self._gc_set_foreground(self._stroke_gc, color) self._stroke_gc.set_line_attributes(4, gdk.LINE_SOLID, gdk.CAP_ROUND, gdk.JOIN_ROUND) if not self._background_writing_gc: color = gdk.Color(red=0xcccc, blue=0xcccc, green=0xcccc) self._background_writing_gc = gdk.GC(self.window) self._gc_set_foreground(self._background_writing_gc, color) self._background_writing_gc.set_line_attributes( 4, gdk.LINE_SOLID, gdk.CAP_ROUND, gdk.JOIN_ROUND) if not self._annotation_gc: color = gdk.Color(red=0x8000, blue=0x0000, green=0x0000) self._annotation_gc = gdk.GC(self.window) self._gc_set_foreground(self._annotation_gc, color) if not self._axis_gc: color = gdk.Color(red=0x8000, blue=0x8000, green=0x8000) self._axis_gc = gdk.GC(self.window) self._gc_set_foreground(self._axis_gc, color) self._axis_gc.set_line_attributes(1, gdk.LINE_ON_OFF_DASH, gdk.CAP_BUTT, gdk.JOIN_ROUND) if not self._background_gc: color = gdk.Color(*self._background_color) self._background_gc = gdk.GC(self.window) self._gc_set_foreground(self._background_gc, color)
# -*- coding: utf-8 -*- from gtk import gdk ## r, g, b in range(256) rgbToGdkColor = lambda r, g, b, a=None: gdk.Color(int(r * 257), int(g * 257), int(b * 257)) gdkColorToRgb = lambda gc: (gc.red // 257, gc.green // 257, gc.blue // 257) #htmlColorToGdk = lambda hc: gdk.color_parse(hc)
w = gtk.Window() w.set_size_request(500, 500) box = gtk.VBox() b1 = gtk.Button("button") b2 = gtk.Button("button1") ls = gtk.HBox() l1 = gtk.Label("label1") l2 = gtk.Label("label2") ls.add(l1) ls.add(l2) #----------------------how to use tooltip api-------------------------# TT.show_delay([b1,b2,l1,l2], 1000)\ .background(b1, gdk.Color("yellow"))(b2, gdk.Color("#95BE0D"))(l1,gdk.Color("blue"))\ .custom(b1, customTooltip_cb)\ .text([l1, l2], "tooliiiiit")(b2, "button2222", enable_gaussian=True)\ .padding(l1, -1, -1, -1, 50)(b2, -1, -1, -1, 0)(b1, 0, 50, 50, 50) #_____________________________________________________________________# b1c = gen_control(b1) b = gtk.HBox() b.add(b1) b.pack_start(b1c, False) box.pack_start(b) b2c = gen_control(b2) b = gtk.HBox() b.add(b2) b.pack_start(b2c, False)
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 create_window(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.destroy) self.window.set_default_size(400, 300) self.window.set_border_width(20) self.window.set_title("Xpra Launcher") self.window.modify_bg(gtk.STATE_NORMAL, gdk.Color(red=65535, green=65535, blue=65535)) icon_pixbuf = self.get_icon("xpra.png") if icon_pixbuf: self.window.set_icon(icon_pixbuf) self.window.set_position(gtk.WIN_POS_CENTER) vbox = gtk.VBox(False, 0) vbox.set_spacing(15) # Title hbox = gtk.HBox(False, 0) if icon_pixbuf: logo_button = gtk.Button("") settings = logo_button.get_settings() settings.set_property('gtk-button-images', True) logo_button.connect("clicked", about) set_tooltip_text(logo_button, "About") image = gtk.Image() image.set_from_pixbuf(icon_pixbuf) logo_button.set_image(image) hbox.pack_start(logo_button, expand=False, fill=False) label = gtk.Label("Connect to xpra server") label.modify_font(pango.FontDescription("sans 14")) hbox.pack_start(label, expand=True, fill=True) vbox.pack_start(hbox) # Mode: hbox = gtk.HBox(False, 20) hbox.set_spacing(20) hbox.pack_start(gtk.Label("Mode: ")) self.mode_combo = gtk.combo_box_new_text() self.mode_combo.get_model().clear() self.mode_combo.append_text("TCP") self.mode_combo.append_text("TCP + AES") self.mode_combo.append_text("SSH") self.mode_combo.connect("changed", self.mode_changed) hbox.pack_start(self.mode_combo) vbox.pack_start(hbox) # Encoding: hbox = gtk.HBox(False, 20) hbox.set_spacing(20) hbox.pack_start(gtk.Label("Encoding: ")) self.encoding_combo = gtk.OptionMenu() def get_current_encoding(): return self.config.encoding def set_new_encoding(e): self.config.encoding = e encodings = [ x for x in PREFERED_ENCODING_ORDER if x in self.client.get_encodings() ] server_encodings = encodings es = make_encodingsmenu(get_current_encoding, set_new_encoding, encodings, server_encodings) self.encoding_combo.set_menu(es) set_history_from_active(self.encoding_combo) hbox.pack_start(self.encoding_combo) vbox.pack_start(hbox) self.encoding_combo.connect("changed", self.encoding_changed) # Quality hbox = gtk.HBox(False, 20) hbox.set_spacing(20) self.quality_label = gtk.Label("Quality: ") hbox.pack_start(self.quality_label) self.quality_combo = gtk.OptionMenu() def set_min_quality(q): self.config.min_quality = q def set_quality(q): self.config.quality = q def get_min_quality(): return self.config.min_quality def get_quality(): return self.config.quality sq = make_min_auto_menu("Quality", MIN_QUALITY_OPTIONS, QUALITY_OPTIONS, get_min_quality, get_quality, set_min_quality, set_quality) self.quality_combo.set_menu(sq) set_history_from_active(self.quality_combo) hbox.pack_start(self.quality_combo) vbox.pack_start(hbox) # Speed hbox = gtk.HBox(False, 20) hbox.set_spacing(20) self.speed_label = gtk.Label("Speed: ") hbox.pack_start(self.speed_label) self.speed_combo = gtk.OptionMenu() def set_min_speed(s): self.config.min_speed = s def set_speed(s): self.config.speed = s def get_min_speed(): return self.config.min_speed def get_speed(): return self.config.speed ss = make_min_auto_menu("Speed", MIN_SPEED_OPTIONS, SPEED_OPTIONS, get_min_speed, get_speed, set_min_speed, set_speed) self.speed_combo.set_menu(ss) set_history_from_active(self.speed_combo) hbox.pack_start(self.speed_combo) vbox.pack_start(hbox) # Username@Host:Port hbox = gtk.HBox(False, 0) hbox.set_spacing(5) self.username_entry = gtk.Entry(max=128) self.username_entry.set_width_chars(16) self.username_entry.connect("changed", self.validate) set_tooltip_text(self.username_entry, "SSH username") self.username_label = gtk.Label("@") self.host_entry = gtk.Entry(max=128) self.host_entry.set_width_chars(24) self.host_entry.connect("changed", self.validate) set_tooltip_text(self.host_entry, "hostname") self.port_entry = gtk.Entry(max=5) self.port_entry.set_width_chars(5) self.port_entry.connect("changed", self.validate) hbox.pack_start(self.username_entry) hbox.pack_start(self.username_label) hbox.pack_start(self.host_entry) hbox.pack_start(gtk.Label(":")) hbox.pack_start(self.port_entry) vbox.pack_start(hbox) # Password hbox = gtk.HBox(False, 0) hbox.set_spacing(20) self.password_entry = gtk.Entry(max=128) self.password_entry.set_width_chars(30) self.password_entry.set_text("") self.password_entry.set_visibility(False) self.password_entry.connect("changed", self.password_ok) self.password_entry.connect("changed", self.validate) self.password_label = gtk.Label("Password: "******"Save") set_tooltip_text(self.save_btn, "Save settings to a session file") self.save_btn.connect("clicked", self.save_clicked) hbox.pack_start(self.save_btn) #Load: self.load_btn = gtk.Button("Load") set_tooltip_text(self.load_btn, "Load settings from a session file") self.load_btn.connect("clicked", self.load_clicked) hbox.pack_start(self.load_btn) # Connect button: self.button = gtk.Button("Connect") self.button.connect("clicked", self.connect_clicked) connect_icon = self.get_icon("retry.png") if connect_icon: self.button.set_image(scaled_image(connect_icon, 24)) hbox.pack_start(self.button) def accel_close(*args): gtk.main_quit() add_close_accel(self.window, accel_close) vbox.show_all() self.window.vbox = vbox self.window.add(vbox)
def __init__(self): gtk.Window.__init__(self) self.set_title("Espectrómetro") #self.set_icon_from_file(os.path.join(BASE_PATH, # "Iconos", "...")) self.set_resizable(False) self.set_default_size(640, 480) self.set_border_width(4) self.set_position(gtk.WIN_POS_CENTER) self.processor = ImgProcessor() self.camara = False hbox = gtk.HBox() vbox = gtk.VBox() hbox.pack_start(vbox, True, True, 4) self.add(hbox) ''' Descripcion de la interfaz --------- | 1 | 2 | | 3 | 4 | --------- 1 - vista de la camara 2 - fotografia a analizar 3 - botones, play, stop, foto 4 - datos del analisis ''' # 1 self.visor = Visor() self.visor.set_size_request(320, 240) vbox.pack_start(self.visor, True, True, 4) # 2 vbox2 = gtk.VBox() self.image = gtk.Image() self.image.set_size_request(160, 120) self.image.modify_bg(0, gdk.Color(0, 0, 0)) hbox.pack_start(vbox2, False, False, 0) vbox2.pack_start(self.image, False, False, 0) # 3 hbox = gtk.HBox() self.btn_play = gtk.Button("PLAY") self.btn_play.modify_bg(0, gdk.Color(0, 0, 255)) self.btn_stop = gtk.Button("STOP") self.btn_stop.modify_bg(0, gdk.Color(0, 0, 255)) self.btn_foto = gtk.Button("FOTO") self.btn_foto.modify_bg(0, gdk.Color(0, 0, 255)) hbox.pack_start(self.btn_play, False, False, 0) hbox.pack_start(self.btn_stop, False, False, 0) hbox.pack_end(self.btn_foto, False, False, 0) vbox.pack_start(hbox, False, False, 0) # 4 # ... self.connect("delete-event", self.__salir) self.visor.connect("realize", self.run) self.show_all() self.realize() print "process pid:", os.getpid()
def __init__(self): self.isBanner_mode = True self.final = None self.design = 7 self.color = None #Initialize systems objects if TEST_MODE: self.vid = cv2.VideoCapture(os.path.join(tests, "demo.avi")) self.v = Video() #----------------testing purpose--------------# self.back = RemoveBackground() self.norm = NormalizedRGB() self.replace = Replace() #print self.replace self.tshirt = DetectShirt() self.p_mat = np.array( np.mat([[0, 0], [100, 0], [100, 100], [0, 100]], np.float32)) self.design_template = cv2.imread(templates + "Green.png") #----------------------------------------------------- self.__glade__ = gtk.Builder() self.__ui__ = self.__glade__.add_from_file( os.path.join(assets, "main_ui.glade")) self.__main_win__ = self.__glade__.get_object("vdr_main") self.drawing_area = self.__glade__.get_object("da1") self.about = self.__glade__.get_object("abt") self.about.connect("clicked", self.show_abt) self.about_dia = self.__glade__.get_object("about_dia") #init Drawing Area self.drawing_area.realize() self.drawing_area.set_size_request(800, 600) #get canvas self.canvas = self.drawing_area.window #get GC self.gc = self.canvas.new_gc() #draw rectnagle #print self.canvas,self.gc self.gc.set_background(gdk.Color(0, 0, 0, 0)) self.gc.set_foreground(gdk.Color(255, 0, 0, 0)) #print dir(self.canvas) self.canvas.draw_rectangle(self.gc, False, 10, 10, 100, 200) self.canvas.draw_line(self.gc, 10, 10, 100, 100) #decorate Mainwindows self.__main_win__.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0, 0)) self.__main_win__.modify_fg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 255, 0, 0)) self.tview1 = self.__glade__.get_object("tv1") self.lstore1 = self.__glade__.get_object("ls1") self.tview2 = self.__glade__.get_object("tv2") self.lstore2 = self.__glade__.get_object("ls2") self.apply_btn = self.__glade__.get_object("apply") self.apply_btn.connect("clicked", self.change_avtar) self.lstore1.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Red.png'), red]) self.lstore1.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Green.png'), green]) self.lstore1.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Blue.png'), blue]) self.lstore1.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Yellow.png'), yellow]) self.lstore1.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Pink.png'), pink]) self.lstore1.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Brown.png'), brown]) self.lstore2.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Blue.png'), plain]) self.lstore2.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Nike.png'), temp1]) self.lstore2.append( [gtk.gdk.pixbuf_new_from_file(templates + 'Reebok.png'), temp2]) #treeview = gtk.TreeView(self.lstore1) self.tview1.set_model(self.lstore1) self.tview2.set_model(self.lstore2) self.tview1.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0, 0)) self.tview2.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0, 0)) cell = gtk.CellRendererPixbuf() column = gtk.TreeViewColumn("Pixbuf", cell) column.add_attribute(cell, "pixbuf", 0) self.tview1.append_column(column) cell.set_padding(30, 50) cell2 = gtk.CellRendererPixbuf() column2 = gtk.TreeViewColumn("Pixbuf", cell2) column2.add_attribute(cell2, "pixbuf", 0) self.tview2.append_column(column2) cell2.set_padding(30, 50) #self.canvas.draw_ self.drawing_area.set_app_paintable(True) self.drawing_area.connect("expose-event", self.display_frame) selection_color = self.tview1.get_selection() selection_color.connect("changed", self.change_cloth_plain) selection_design = self.tview2.get_selection() selection_design.connect("changed", self.change_cloth_design) self.canvas.set_background(gtk.gdk.Color(0, 0, 0, 0)) self.__main_win__.connect("delete-event", gtk.mainquit) self.img = cv2.cv.LoadImage(os.path.join(assets, "Banner.png")) # self.__main_win__.show() self.__main_win__.maximize()
def to_gdk_color(self): return gdk.Color(*self.get_rgb_float())
def __init__(self): gtk.EventBox.__init__(self) # TODO: will this be configurable? # set to white background self.modify_bg(gtk.STATE_NORMAL, gdk.Color(*DEFAULT_BGCOLOR))
def __init__(self): gtk.DrawingArea.__init__(self) self.modify_bg(0, gdk.Color(0, 0, 0)) self.show_all()
def gfx_get_color_gc(self, r, g, b): rgb = (int(r * 65535), int(g * 65535), int(b * 65535)) gc = self.area.window.new_gc() gc.set_rgb_fg_color(gdk.Color(rgb[0], rgb[1], rgb[2])) return gc
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