def _draw_time_scale(self): p_length = int(self._bio[0] * self._scale) e_length = int(self._bio[1] * self._scale) i_length = int(self._bio[2] * self._scale) # Fill background cr = self.window.cairo_create() width = 70 x = self._center_x y = self._center_y cr.set_source_rgba(*style.Color(self._COLOR_WHITE).get_rgba()) cr.rectangle(self._center_x - (width + 30) - 35, (self._center_y - self._scale - 10), 3 * width + 2 * 20 + 20, self._scale * 2 + 20) cr.fill() # Physical cycle cr.set_source_rgba(*style.Color(self._COLOR_P).get_rgba()) cr.rectangle(x - (width + 20) - 35, y, width, p_length) cr.fill() # Emotional cycle cr.set_source_rgba(*style.Color(self._COLOR_E).get_rgba()) cr.rectangle(x - 35, y, width, e_length) cr.fill() # Intellectual cycle cr.set_source_rgba(*style.Color(self._COLOR_I).get_rgba()) cr.rectangle(x - 35 + (width + 20), y, width, i_length) cr.fill()
def _new_face(self, buddy, color): stroke_color, fill_color = buddy.props.color.split(',') stroke_color = style.Color(stroke_color) fill_color = style.Color(fill_color) buddy_face = face.View(fill_color) buddy_face.show_all() inner = CanvasRoundBox( background_color = fill_color.get_int(), ) inner.props.border_color = fill_color.get_int() inner.append(hippo.CanvasWidget(widget=buddy_face), hippo.PACK_EXPAND) inner.props.border = BUDDY_PAD outer = CanvasRoundBox( background_color = stroke_color.get_int(), box_width = BUDDY_SIZE, box_height = BUDDY_SIZE, ) outer.props.border_color = stroke_color.get_int() outer.append(inner, hippo.PACK_EXPAND) outer.props.border = BUDDY_PAD return (buddy_face, outer)
def get_colors(): client = gconf.client_get_default() colors = client.get_string('/desktop/sugar/user/color') colors = colors.split(',') stroke = style.Color(colors[0]).get_rgba() fill = style.Color(colors[1]).get_rgba() return stroke, fill
def draw_label(self, ctx, piece, text, xIni, yIni): stroke_r, stroke_g, stroke_b = 0, 0, 0 alpha = 1 if (piece.player.color != None): xocolor = piece.player.color stroke_r, stroke_g, stroke_b, alpha = style.Color( xocolor.get_stroke_color(), 1.0).get_rgba() ctx.set_source_rgb(stroke_r, stroke_g, stroke_b) xCenter = xIni + (dominoview.SIZE / 2) yCenter = yIni + (dominoview.SIZE / 2) separa = (dominoview.SIZE / 4) radio = 4 # # *1 *2 # *3 *4 *5 # *6 *7 # # 1 if (text == "2") or (text == "3") or (text == "4") or ( text == "5") or (text == "6"): ctx.arc(xCenter - separa, yCenter - separa, radio, 0, 2 * M_PI) ctx.fill() # 2 if (text == "4") or (text == "5") or (text == "6"): ctx.arc(xCenter + separa, yCenter - separa, radio, 0, 2 * M_PI) ctx.fill() # 3 if (text == "6"): ctx.arc(xCenter - separa, yCenter, radio, 0, 2 * M_PI) ctx.fill() #4 if (text == "1") or (text == "3") or (text == "5"): ctx.arc(xCenter, yCenter, radio, 0, 2 * M_PI) ctx.fill() # 5 if (text == "6"): ctx.arc(xCenter + separa, yCenter, radio, 0, 2 * M_PI) ctx.fill() # 6 if (text == "4") or (text == "5") or (text == "6"): ctx.arc(xCenter - separa, yCenter + separa, radio, 0, 2 * M_PI) ctx.fill() # 7 if (text == "2") or (text == "3") or (text == "4") or ( text == "5") or (text == "6"): ctx.arc(xCenter + separa, yCenter + separa, radio, 0, 2 * M_PI) ctx.fill()
def _draw_time(self): markup = _('<markup>\ <span lang="en" font_desc="Sans,Monospace Bold 12">\ <span foreground="#E6000A">%s</span></span></markup>') cr = self.window.cairo_create() cr = pangocairo.CairoContext(cr) cr.set_source_rgba(*style.Color(self._COLOR_E).get_rgba()) pango_layout = cr.create_layout() d = int(self._center_y + self._scale + 20) markup_f = markup % "Physical Emotional Intellectual" pango_layout.set_markup(markup_f) dx, dy = pango_layout.get_pixel_size() pango_layout.set_alignment(pango.ALIGN_CENTER) cr.translate(self._center_x - dx / 2.0, d - dy / 2.0 + 5) cr.show_layout(pango_layout)
def loadToolbar( self, timeout = -1, loadStage = [0,0,0] ): if loadStage[1] == 0: self.toolbarBox = gtk.HBox() scrollbox = HScrolledBox(scroll_policy=gtk.POLICY_NEVER) scrollbox.set_viewport(self.toolbarBox) scrollbox.modify_bg(gtk.STATE_NORMAL, style.Color(Config.PANEL_BCK_COLOR).get_gdk_color()) self.mainVBox.pack_start(scrollbox, False, False) self.firstTbBtn = None self.loadStage[1] = 1 if timeout >= 0 and time.time() > timeout: return False for i in range(loadStage[1]-1, len(Config.CATEGORIES)): category = Config.CATEGORIES[i] if loadStage[2] == 0: self.loadData["btnBox"] = RoundVBox(fillcolor = Config.CATEGORY_BCK_COLOR, bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS) self.loadData["btnBox"].set_border_width(Config.PANEL_SPACING) loadStage[2] = 1 if timeout >= 0 and time.time() > timeout: return False if loadStage[2] == 1: self.loadData["btn"] = ImageRadioButton(self.firstTbBtn, category + '.png', category + 'sel.png', category + 'sel.png') loadStage[2] = 2 if timeout >= 0 and time.time() > timeout: return False if self.firstTbBtn == None: self.firstTbBtn = self.loadData["btn"] self.loadData["btn"].connect('clicked',self.handleToolbarBtnPress,category) self.tooltips.set_tip(self.loadData["btn"],str(category)) self.loadData["btnBox"].add(self.loadData["btn"]) self.toolbarBox.pack_start(self.loadData["btnBox"],True,True) loadStage[2] = 0 loadStage[1] += 1 if timeout >= 0 and time.time() > timeout: return False self.loadData.pop("btn") self.loadData.pop("btnBox") loadStage[1] = 0 return True
def draw_label(self, ctx, piece, text, xIni, yIni): #print "Dibujando ",text stroke_r, stroke_g, stroke_b = 0, 0, 0 alpha = 1 if (piece.player.color != None): xocolor = piece.player.color stroke_r, stroke_g, stroke_b, alpha = style.Color( xocolor.get_stroke_color(), 1.0).get_rgba() ctx.set_source_rgb(stroke_r, stroke_g, stroke_b) ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(20) x_bearing, y_bearing, width, height, x_advance, y_advance = ctx.text_extents( text) x = 0.5 - (width / 2 + x_bearing) y = 0.5 - (height / 2 + y_bearing) ctx.move_to(xIni + x + (dominoview.SIZE / 2), yIni + y + (dominoview.SIZE / 2)) ctx.show_text(text)
def draw(self,ctx,selected): SIZE = dominoview.SIZE #if self.vertical: # width = SIZE + SIZE/8 + 2 # height = SIZE*2 + SIZE/8 + 2 #else: # width = SIZE*2 + SIZE/8 + 2 # height = SIZE + SIZE/8 + 2 ctx.save() ctx.translate(self.x,self.y) ctx.move_to(self.x,self.y) #ctx.translate(1,1) #ctx.move_to(1, 1) r = 10 stroke_r,stroke_g,stroke_b = 0,0,0 fill_r,fill_g,fill_b = 1, 1, 1 alpha = 1 if (self.player.color != None): xocolor = self.player.color stroke_r,stroke_g,stroke_b,alpha = style.Color(xocolor.get_stroke_color(),1.0).get_rgba() fill_r,fill_g,fill_b,alpha = style.Color(xocolor.get_fill_color(),1.0).get_rgba() if self.vertical: cairoutils.draw_round_rect(ctx,-1,-1,SIZE+2,SIZE*2+2,r) ctx.set_source_rgb (stroke_r,stroke_g,stroke_b) ctx.fill() cairoutils.draw_round_rect(ctx,0,0,SIZE,SIZE*2,r) if selected: ctx.set_source_rgb (1, 1, 204.0/255.0) else: ctx.set_source_rgb (fill_r,fill_g,fill_b) ctx.fill() ctx.move_to(SIZE,0) ctx.rel_line_to((SIZE/8),(SIZE/8)) ctx.rel_line_to(0,SIZE*2) ctx.rel_line_to(-(SIZE/8),-(SIZE/8)) ctx.rel_line_to(0,-SIZE*2) ctx.close_path() ctx.fill_preserve() ctx.set_source_rgb (stroke_r,stroke_g,stroke_b) ctx.stroke() ctx.move_to(0,SIZE*2) ctx.rel_line_to((SIZE/8),(SIZE/8)) ctx.rel_line_to(SIZE,0) ctx.rel_line_to(-(SIZE/8),-(SIZE/8)) ctx.rel_line_to(-SIZE,0) ctx.close_path() ctx.set_source_rgb (fill_r,fill_g,fill_b) ctx.fill_preserve() ctx.set_source_rgb (stroke_r,stroke_g,stroke_b) ctx.stroke() #ctx.move_to(SIZE/4,SIZE) #ctx.rel_line_to(SIZE/2,0) #ctx.stroke() if not self.reversed: self._draw_label_a(ctx,0,0) self._draw_label_b(ctx,0,SIZE) else: self._draw_label_b(ctx,0,0) self._draw_label_a(ctx,0,SIZE) else: cairoutils.draw_round_rect(ctx,-1,-1,SIZE*2+2,SIZE+2,r) ctx.set_source_rgb (stroke_r,stroke_g,stroke_b) ctx.fill() cairoutils.draw_round_rect(ctx,0,0,SIZE*2,SIZE,r) if selected: ctx.set_source_rgb (1, 1, 204.0/255.0) else: ctx.set_source_rgb (fill_r,fill_g,fill_b) ctx.fill() ctx.move_to(SIZE*2,0) ctx.rel_line_to((SIZE/8),(SIZE/8)) ctx.rel_line_to(0,SIZE) ctx.rel_line_to(-(SIZE/8),-(SIZE/8)) ctx.rel_line_to(0,-SIZE) ctx.close_path() ctx.fill_preserve() ctx.set_source_rgb (stroke_r,stroke_g,stroke_b) ctx.stroke() ctx.move_to(0,SIZE) ctx.rel_line_to((SIZE/8),(SIZE/8)) ctx.rel_line_to(SIZE*2,0) ctx.rel_line_to(-(SIZE/8),-(SIZE/8)) ctx.rel_line_to(-SIZE*2,0) ctx.close_path() ctx.set_source_rgb (fill_r,fill_g,fill_b) ctx.fill_preserve() ctx.set_source_rgb (stroke_r,stroke_g,stroke_b) ctx.stroke() #ctx.move_to(SIZE/4,0) #ctx.rel_line_to(0,SIZE-SIZE/4) #ctx.stroke() if not self.reversed: self._draw_label_a(ctx,0,0) self._draw_label_b(ctx,SIZE,0) else: self._draw_label_b(ctx,0,0) self._draw_label_a(ctx,SIZE,0) ctx.restore()
def drawGeneration(self): slidersBox = RoundVBox(fillcolor=Config.PANEL_COLOR, bordercolor=Config.PANEL_BCK_COLOR, radius=Config.PANEL_RADIUS) slidersBox.set_border_width(Config.PANEL_SPACING) geneSliderBox = gtk.VBox() self.geneSliderBoxImgTop = gtk.Image() self.geneSliderBoxImgTop.set_from_file(imagefile('complex6.png')) self.geneAdjustment = gtk.Adjustment(value=self.regularity, lower=0, upper=1, step_incr=0.01, page_incr=0, page_size=0) self.geneSlider = ImageVScale('sliderbutbleu.png', self.geneAdjustment, 5) self.geneSlider.set_inverted(False) self.geneAdjustment.connect("value_changed", self.handleGenerationSlider) self.geneSlider.connect("button-release-event", self.handleGenerationSliderRelease) geneSliderBox.pack_start(self.geneSliderBoxImgTop, False, padding=10) geneSliderBox.pack_start(self.geneSlider, True, 20) self.tooltips.set_tip(self.geneSlider, Tooltips.COMPL) beatSliderBox = gtk.VBox() self.beatSliderBoxImgTop = gtk.Image() self.beatSliderBoxImgTop.set_from_file(imagefile('beat3.png')) self.beatAdjustment = gtk.Adjustment(value=self.beat, lower=2, upper=12, step_incr=1, page_incr=0, page_size=0) self.beatSlider = ImageVScale('sliderbutjaune.png', self.beatAdjustment, 5, snap=1) self.beatSlider.set_inverted(True) self.beatAdjustment.connect("value_changed", self.handleBeatSlider) self.beatSlider.connect("button-release-event", self.handleBeatSliderRelease) beatSliderBox.pack_start(self.beatSliderBoxImgTop, False, padding=10) beatSliderBox.pack_start(self.beatSlider, True, 20) self.tooltips.set_tip(self.beatSlider, Tooltips.BEAT) self.delayedTempo = 0 # used to store tempo updates while the slider is active self.tempoSliderActive = False tempoSliderBox = gtk.VBox() self.tempoSliderBoxImgTop = gtk.Image() self.tempoSliderBoxImgTop.set_from_file(imagefile('tempo5.png')) self.tempoAdjustment = gtk.Adjustment(value=self.tempo, lower=Config.PLAYER_TEMPO_LOWER, upper=Config.PLAYER_TEMPO_UPPER, step_incr=1, page_incr=1, page_size=1) tempoSlider = ImageVScale('sliderbutvert.png', self.tempoAdjustment, 5) tempoSlider.set_inverted(True) self.tempoAdjustmentHandler = self.tempoAdjustment.connect( "value_changed", self.handleTempoSliderChange) tempoSlider.connect("button-press-event", self.handleTempoSliderPress) tempoSlider.connect("button-release-event", self.handleTempoSliderRelease) tempoSliderBox.pack_start(self.tempoSliderBoxImgTop, False, padding=10) tempoSliderBox.pack_start(tempoSlider, True) self.tooltips.set_tip(tempoSlider, Tooltips.TEMPO) volumeSliderBox = gtk.VBox() self.volumeSliderBoxImgTop = gtk.Image() self.volumeSliderBoxImgTop.set_from_file(imagefile('volume2.png')) self.volumeAdjustment = gtk.Adjustment(value=self.volume, lower=0, upper=200, step_incr=1, page_incr=1, page_size=1) volumeSlider = ImageVScale('sliderbutbleu.png', self.volumeAdjustment, 5) volumeSlider.set_inverted(True) self.volumeAdjustment.connect("value_changed", self.handleVolumeSlider) #volumeSlider.connect("button-release-event", self.handleVolumeSliderRelease) volumeSliderBox.pack_start(self.volumeSliderBoxImgTop, False, padding=10) volumeSliderBox.pack_start(volumeSlider, True) self.tooltips.set_tip(volumeSlider, Tooltips.VOL) slidersBoxSub = gtk.HBox() slidersBoxSub.pack_start(beatSliderBox) slidersBoxSub.pack_start(geneSliderBox) slidersBoxSub.pack_start(tempoSliderBox) slidersBoxSub.pack_start(volumeSliderBox) slidersBox.pack_start(slidersBoxSub) generateBtnSub = RoundHBox(fillcolor=Config.PANEL_COLOR, bordercolor=Config.PANEL_BCK_COLOR, radius=Config.PANEL_RADIUS) generateBtnSub.set_border_width(Config.PANEL_SPACING) #playImg = gtk.Image() #playImg.set_from_icon_name('media-playback-start', gtk.ICON_SIZE_LARGE_TOOLBAR) self.playButton = ImageToggleButton('miniplay.png', 'stop.png') #self.playButton.set_relief(gtk.RELIEF_NONE) #self.playButton.set_image(playImg) self.playButton.connect('clicked', self.handlePlayButton) generateBtnSub.pack_start(self.playButton) #self.playButton.set_tooltip(_('Play / Stop')) generateBtn = ImageButton('dice.png', clickImg_path='diceblur.png') generateBtn.connect('button-press-event', self.handleGenerateBtn) generateBtnSub.pack_start(generateBtn) self.tooltips.set_tip(generateBtn, Tooltips.GEN) # drums drum_box = RoundVBox(fillcolor=Config.PANEL_COLOR, bordercolor=Config.PANEL_BCK_COLOR, radius=Config.PANEL_RADIUS) drum_scroll = VScrolledBox(scroll_policy=gtk.POLICY_NEVER) drum_scroll.set_viewport(drum_box) drum_scroll.modify_bg( gtk.STATE_NORMAL, style.Color(Config.PANEL_BCK_COLOR).get_gdk_color()) drum_i = 0 drum_group = None for row in range(DRUMCOUNT / 2 + DRUMCOUNT % 2): row_box = gtk.HBox() drum_box.pack_start(row_box, False) for col in range(2): if drum_i >= DRUMCOUNT: break drum = ImageRadioButton( group=drum_group, mainImg_path='drum%dkit.png' % (drum_i + 1), altImg_path='drum%dkitselgen.png' % (drum_i + 1)) drum.connect('clicked', self.handleGenerationDrumBtn, 'drum%dkit' % (drum_i + 1)) row_box.pack_start(drum) drum_name = 'drum%dkit' % (drum_i + 1) hint = self.instrumentDB.instNamed[drum_name].nameTooltip self.tooltips.set_tip(drum, hint) if not drum_group: drum_group = drum drum_i += 1 self.rightBox.pack_start(slidersBox, False) self.rightBox.pack_start(generateBtnSub, False) self.rightBox.pack_start(drum_scroll) drum_size = drum_group.get_size_request() slidersBox.set_size_request(-1, int(drum_size[1] * 2.3)) self.rightBox.set_size_request(int(drum_size[0] * 2.05), -1)
cr.set_line_width(self.border) cr.stroke() if __name__ == '__main__': win = gtk.Window() win.connect('destroy', gtk.main_quit) win.set_default_size(450, 550) vbox = gtk.VBox() box1 = RoundBox() vbox.add(box1) label1 = gtk.Label("Test 1") box1.add(label1) rbox = RoundBox() rbox.background_color = style.Color('#FF0000') vbox.add(rbox) label2 = gtk.Label("Test 2") rbox.add(label2) bbox = RoundBox() bbox.background_color = style.Color('#aaff33') bbox.border_color = style.Color('#ff3300') vbox.add(bbox) win.add(vbox) win.show_all() gtk.main()
def add_text(self, buddy, text, status_message=False): """Display text on screen, with name and colors. buddy -- buddy object or dict {nick: string, color: string} (The dict is for loading the chat log from the journal, when we don't have the buddy object any more.) text -- string, what the buddy said status_message -- boolean False: show what buddy said True: show what buddy did .------------- rb ---------------. | +name_vbox+ +----align-----+ | | | | | | | | | nick: | | +--message---+ | | | | | | | text | | | | +---------+ | +------------+ | | | +----------------+ | `--------------------------------' """ if not buddy: buddy = self.owner if type(buddy) is dict: # dict required for loading chat log from journal nick = buddy['nick'] color = buddy['color'] else: nick = buddy.props.nick color = buddy.props.color try: color_stroke_html, color_fill_html = color.split(',') except ValueError: color_stroke_html, color_fill_html = ('#000000', '#888888') # Select text color based on fill color: color_fill_rgba = style.Color(color_fill_html).get_rgba() color_fill_gray = (color_fill_rgba[0] + color_fill_rgba[1] + color_fill_rgba[2]) / 3 color_stroke = style.Color(color_stroke_html) color_fill = style.Color(color_fill_html) if color_fill_gray < 0.5: text_color = style.COLOR_WHITE else: text_color = style.COLOR_BLACK self._add_log(nick, color, text, status_message) # Check for Right-To-Left languages: if pango.find_base_dir(nick, -1) == pango.DIRECTION_RTL: lang_rtl = True else: lang_rtl = False # Check if new message box or add text to previous: new_msg = True if self._last_msg_sender: if not status_message: if buddy == self._last_msg_sender: # Add text to previous message new_msg = False if not new_msg: message = self._last_msg else: rb = RoundBox() screen_width = gtk.gdk.screen_width() # keep space to the scrollbar rb.set_size_request(screen_width - 50, -1) rb.background_color = color_fill rb.border_color = color_stroke self._last_msg_sender = buddy if not status_message: name = ColorLabel(text=nick + ': ', color=text_color) name_vbox = gtk.VBox() name_vbox.pack_start(name, False, False) rb.pack_start(name_vbox, False, False, padding=5) message = TextBox(text_color, color_fill, lang_rtl) vbox = gtk.VBox() vbox.pack_start(message, True, True, padding=5) rb.pack_start(vbox, True, True, padding=5) self._last_msg = message self._conversation.pack_start(rb, False, False, padding=2) if status_message: self._last_msg_sender = None message.add_text(text) self._conversation.show_all()
def draw_label(self, ctx, piece, text, xIni, yIni): stroke_r, stroke_g, stroke_b = 0, 0, 0 border_r, border_g, border_b = 0.5, 0.5, 0.5 alpha = 1 if (piece.player.color != None): xocolor = piece.player.color stroke_r, stroke_g, stroke_b, alpha = style.Color( xocolor.get_stroke_color(), 1.0).get_rgba() #border_r,border_g,border_b,aplha = style.Color(xocolor.get_fill_color(),1.0).get_rgba() ctx.set_source_rgb(stroke_r, stroke_g, stroke_b) if (text[0] != "G"): #print "Dibujando ",text ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(20) x_bearing, y_bearing, width, height, x_advance, y_advance = ctx.text_extents( text) x = 0.5 - (width / 2 + x_bearing) y = 0.5 - (height / 2 + y_bearing) ctx.move_to(xIni + x + (dominoview.SIZE / 2), yIni + y + (dominoview.SIZE / 2)) ctx.show_text(text) else: text = text[1:] xCenter = xIni + (dominoview.SIZE / 2) yCenter = yIni + (dominoview.SIZE / 2) radio = 22 ctx.set_line_width(2) if ((text == "0") or (text == "1")): ctx.move_to(xCenter + radio, yCenter) ctx.arc(xCenter, yCenter, radio, 0, 2 * M_PI) if (text == "0"): ctx.stroke() if (text == "1"): ctx.fill_preserve() else: numerador = int(text[0]) denominador = int(text[2]) ctx.move_to(xCenter, yCenter) angulo_porcion = 2 * M_PI / denominador angulo_inicial = 0 #print "numerador",numerador,"denominador",denominador,"angulo_porcion",angulo_porcion # relleno las fracciones del numerador for n in range(0, numerador): xIni = math.cos(angulo_inicial) * radio yIni = math.sin(angulo_inicial) * radio #print "N",n,"xIni",xIni,"yIni",yIni ctx.line_to(xCenter + xIni, yCenter + yIni) ctx.arc(xCenter, yCenter, radio, angulo_inicial, angulo_inicial + angulo_porcion) ctx.line_to(xCenter, yCenter) ctx.close_path() ctx.set_source_rgb(stroke_r, stroke_g, stroke_b) ctx.fill() angulo_inicial = angulo_inicial + angulo_porcion # pinto los bordes ctx.move_to(xCenter, yCenter) angulo_porcion = 2 * M_PI / denominador angulo_inicial = 0 #print "numerador",numerador,"denominador",denominador,"angulo_porcion",angulo_porcion ctx.set_source_rgb(border_r, border_g, border_b) for n in range(0, denominador): xIni = math.cos(angulo_inicial) * radio yIni = math.sin(angulo_inicial) * radio #print "N",n,"xIni",xIni,"yIni",yIni ctx.line_to(xCenter + xIni, yCenter + yIni) ctx.arc(xCenter, yCenter, radio, angulo_inicial, angulo_inicial + angulo_porcion) ctx.line_to(xCenter, yCenter) ctx.close_path() ctx.stroke() angulo_inicial = angulo_inicial + angulo_porcion
from sugar.graphics.toolcombobox import ToolComboBox from sugar.graphics import style import logging log = logging.getLogger('measure-activity') log.setLevel(logging.DEBUG) NOTES = [ 'C', 'C♯/D♭', 'D', 'D♯/E♭', 'E', 'F', 'F♯/G♭', 'G', 'G♯/A♭', 'A', 'A♯/B♭', 'B' ] SHARP = '♯' FLAT = '♭' A0 = 27.5 C8 = 4186.01 TWELTHROOT2 = 1.05946309435929 COLOR_RED = style.Color('#FF6060') COLOR_YELLOW = style.Color('#FFFF00') COLOR_GREEN = style.Color('#00FF00') SPAN = '<span foreground="%s"><big><b>%s</b></big></span>' class TuningToolbar(gtk.Toolbar): ''' The toolbar for tuning instruments ''' def __init__(self, activity): gtk.Toolbar.__init__(self) self.activity = activity self._show_tuning_line = False self._updating_note = True self._tuning_tool = None
def add_text(self, buddy, text, status_message=False): if not buddy: buddy = self.owner if buddy == "Computer": nick = "Computer" color = '#000000,#FFF8DC' else: if type(buddy) is dict: # dict required for loading chat log from journal nick = buddy['nick'] color = buddy['color'] else: nick = buddy.props.nick color = buddy.props.color try: color_stroke_html, color_fill_html = color.split(',') except ValueError: color_stroke_html, color_fill_html = ('#000000', '#888888') # Select text color based on fill color: color_fill_rgba = style.Color(color_fill_html).get_rgba() color_fill_gray = (color_fill_rgba[0] + color_fill_rgba[1] + color_fill_rgba[2]) / 3 color_stroke = style.Color(color_stroke_html) color_fill = style.Color(color_fill_html) if color_fill_gray < 0.5: text_color = style.COLOR_WHITE else: text_color = style.COLOR_BLACK self._add_log(nick, text, status_message) # Check for Right-To-Left languages: if pango.find_base_dir(nick, -1) == pango.DIRECTION_RTL: lang_rtl = True else: lang_rtl = False # Check if new message box or add text to previous: new_msg = True if self._last_msg_sender: if not status_message: if buddy == self._last_msg_sender: # Add text to previous message new_msg = True if not new_msg: message = self._last_msg else: rb = RoundBox() screen_width = gtk.gdk.screen_width() # keep space to the scrollbar rb.set_size_request(screen_width - 50, -1) rb.props.border_width = style.DEFAULT_PADDING rb.props.spacing = style.DEFAULT_SPACING rb.background_color = color_fill rb.border_color = color_stroke self._last_msg_sender = buddy if not status_message: name = ColorLabel(text=nick + ':', color=text_color) name_vbox = gtk.VBox() name_vbox.pack_start(name, False, False) rb.pack_start(name_vbox, False, False) message = TextBox(text_color, color_fill, lang_rtl) vbox = gtk.VBox() vbox.pack_start(message, True, True) rb.pack_start(vbox, True, True) self._last_msg = message self._conversation.pack_start(rb, False, False) if status_message: self._last_msg_sender = None message.add_text(text) self._conversation.show_all()