def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip): artist = "Artist" title = "Title" if self.current_bean: if self.current_bean.artist and self.current_bean.title: artist = self.current_bean.artist #artist = string.join(["&" if x == '&' else x for x in artist], '') artist = artist.replace('&', '&') title = self.current_bean.title else: artist = "Unknown artist" title = self.current_bean.text max_str_len = 40 if len(title) > max_str_len: title = split_string(title, max_str_len) alabel = Gtk.Label.new(None) alabel.set_markup("<b>%s</b>" % artist) hbox1 = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) hbox1.pack_start(alabel, False, False, 0) hbox2 = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) hbox2.pack_start(Gtk.Label.new(title), False, False, 0) vbox = VBoxDecorator(Gtk.Label.new(None), hbox1, Gtk.Label.new(None), hbox2) """if self.tooltip_image.size == 150: alignment = Gtk.Alignment(0, 0.4) else: alignment = Gtk.Alignment() alignment.set_padding(padding_top=0, padding_bottom=0, padding_left=10, padding_right=10) alignment.add(vbox)""" vbox.set_halign(Gtk.Align.CENTER) tooltip.set_icon(self.tooltip_image.get_pixbuf()) tooltip.set_custom(vbox) return True
def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip): artist = "Artist" title = "Title" if self.current_bean: if self.current_bean.artist and self.current_bean.title: artist = self.current_bean.artist #artist = string.join(["&" if x == '&' else x for x in artist], '') artist = artist.replace('&', '&') title = self.current_bean.title else: artist = "Unknown artist" title = self.current_bean.text max_str_len = 40 if len(title) > max_str_len: title = split_string(title, max_str_len) alabel = Gtk.Label() alabel.set_markup("<b>%s</b>" % artist) hbox1 = Gtk.HBox() hbox1.pack_start(alabel, False, False) hbox2 = Gtk.HBox() hbox2.pack_start(Gtk.Label(title), False, False) vbox = VBoxDecorator(Gtk.Label(), hbox1, Gtk.Label(), hbox2) if self.tooltip_image.size == 150: alignment = Gtk.Alignment(0, 0.4) else: alignment = Gtk.Alignment() alignment.set_padding(padding_top=0, padding_bottom=0, padding_left=10, padding_right=10) alignment.add(vbox) tooltip.set_icon(self.tooltip_image.get_pixbuf()) tooltip.set_custom(alignment) return True
def __init__(self, title, type=Gtk.MessageType.INFO, text=None, parent=None, buttons=None, flags=0, func=None, args=(), func1=None, args1=()): text = split_string(text, 40) Gtk.MessageDialog.__init__(self, parent, flags, type, buttons, text) self.set_title(title) self.show_all() id = self.run() if id != Gtk.ResponseType.NONE: if func and id in [ Gtk.ResponseType.OK, Gtk.ResponseType.APPLY, Gtk.ResponseType.ACCEPT, Gtk.ResponseType.YES ]: func(args) if args else func() if func1 and id in [ Gtk.ResponseType.NO, Gtk.ResponseType.CLOSE, Gtk.ResponseType.CANCEL, Gtk.ResponseType.REJECT ]: func1(args1) if args else func1() time.sleep(0.2) #otherwise can be freezes self.destroy()
def __init__(self, title, type=Gtk.MessageType.INFO, text=None, parent=None, buttons=None, flags=0, func=None, args=(), func1=None, args1=()): text = split_string(text, 40) Gtk.MessageDialog.__init__(self, parent, flags, type, buttons, text) self.set_title(title) self.show_all() id = self.run() if id != Gtk.ResponseType.NONE: if func and id in [Gtk.ResponseType.OK, Gtk.ResponseType.APPLY, Gtk.ResponseType.ACCEPT, Gtk.ResponseType.YES]: func(args) if args else func() if func1 and id in [Gtk.ResponseType.NO, Gtk.ResponseType.CLOSE, Gtk.ResponseType.CANCEL, Gtk.ResponseType.REJECT]: func1(args1) if args else func1() time.sleep(0.2) #otherwise can be freezes self.destroy()
def __init__(self, title, type=gtk.MESSAGE_INFO, text=None, parent=None, buttons=None, flags=0, func=None, args=(), func1=None, args1=()): text = split_string(text, 40) gtk.MessageDialog.__init__(self, parent, flags, type, buttons, text) self.set_title(title) self.show_all() id = self.run() if id != gtk.RESPONSE_NONE: if func and id in [gtk.RESPONSE_OK, gtk.RESPONSE_APPLY, gtk.RESPONSE_ACCEPT, gtk.RESPONSE_YES]: func(args) if args else func() if func1 and id in [gtk.RESPONSE_NO, gtk.RESPONSE_CLOSE, gtk.RESPONSE_CANCEL, gtk.RESPONSE_REJECT]: func1(args1) if args else func1() time.sleep(0.2) #otherwise can be freezes self.destroy()
def test_good_splitter1(self): result = split_string(self.input, 19) self.assertEquals("abcde,1234 w2\ne3fdfd", result)
def test_empty_len(self): result = split_string("100", 3) self.assertEquals("100\n", result)
def test_empty_string(self): result = split_string("", 3) self.assertEquals("", result)