Package dtk :: Package ui :: Module tooltip_test

Source Code for Module dtk.ui.tooltip_test

  1  #! /usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3   
  4  # Copyright (C) 2011 ~ 2012 Deepin, Inc. 
  5  #               2011 ~ 2012 Xia Bin 
  6  #  
  7  # Author:     Xia Bin <xiabin@gmail.com> 
  8  # Maintainer: Xia Bin <xiabin@gmail.com> 
  9  #  
 10  # This program is free software: you can redistribute it and/or modify 
 11  # it under the terms of the GNU General Public License as published by 
 12  # the Free Software Foundation, either version 3 of the License, or 
 13  # any later version. 
 14  #  
 15  # This program is distributed in the hope that it will be useful, 
 16  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 18  # GNU General Public License for more details. 
 19  #  
 20  # You should have received a copy of the GNU General Public License 
 21  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 22   
 23  import gtk 
 24  from color_selection import ColorButton 
 25  from gtk import gdk 
 26  import pseudo_skin 
 27  import tooltip as TT 
 28   
 29  __all__ = [] 
 30   
31 -def customTooltip_cb():
32 box = gtk.VBox() 33 #box.set_size_request(800, 400) 34 b = gtk.Button("abcdsdf") 35 l = gtk.Label("huhuhuhuhuhulabellooooooooooooooooooooooooooooooooooooooooooooA") 36 #b.connect('destroy', show_d) 37 #l.connect('destroy', show_d) 38 box.add(b) 39 box.add(l) 40 return box
41
42 -def show_d(w, e):
43 print "destroing..", type(w), id(w)
44
45 -def gen_control(widget):
46 box = gtk.VBox() 47 t = gtk.CheckButton("NeedShadow") 48 t.set_active(True) 49 t.connect('toggled', lambda w: TT.has_shadow(widget, w.get_active())) 50 box.pack_start(t, False, False) 51 TT.text(t, "toggle the shadow") 52 53 winfo = TT.WidgetInfo.get_info(widget) 54 t1 = gtk.Entry() 55 t1.set_text(winfo.text or "") 56 t1.connect('activate', lambda w: TT.text(widget, w.get_text())) 57 box.pack_start(t1, False, False) 58 59 t2 = gtk.SpinButton() 60 t2.set_range(0, 10) 61 t2.set_value((winfo.show_delay / 1000)) 62 t2.connect('value-changed', lambda w: TT.show_delay(widget, w.get_value_as_int() * 1000 + 100)) 63 box.pack_start(t2, False, False) 64 65 t3 = ColorButton() 66 t3.set_color(str(winfo.background)) 67 t3.connect('color-select', lambda w, e: TT.background(widget, gtk.gdk.Color(w.get_color()))) 68 box.pack_start(t3) 69 70 t4 = gtk.SpinButton() 71 t4.set_range(0, 100) 72 t4.set_value(winfo.padding_r) 73 t4.connect('value-changed', lambda w: TT.padding(widget, -1, -1, -1, w.get_value())) 74 box.pack_start(t4, False, False) 75 76 t5 = gtk.CheckButton("disable") 77 t5.set_active(False) 78 t5.connect('toggled', lambda w: TT.disable(widget, w.get_active())) 79 box.pack_start(t5, False, False) 80 81 #----------------------------------------------------------------------# 82 TT.text(t1, "The text value if tooltip didn't has custom property")\ 83 (t2, "The show delay value")\ 84 (t3, "The background color")\ 85 (t4, "The pading right value")\ 86 (t5, "tmp disable tooltip")\ 87 .show_delay([t1,t2,t3,t4,t5], 200)\ 88 .background([t1,t2], gdk.Color("red"))\ 89 .set_value([t1,t2,t3,t4,t5], {'text_kargs': {"text_size":15}}) 90 #_____________________________________________________________________# 91 return box
92 93 94 w = gtk.Window() 95 w.set_size_request(500, 500) 96 box = gtk.VBox() 97 98 b1 = gtk.Button("button") 99 b2 = gtk.Button("button1") 100 101 ls = gtk.HBox() 102 l1 = gtk.Label("label1") 103 l2 = gtk.Label("label2") 104 ls.add(l1) 105 ls.add(l2) 106 107 #----------------------how to use tooltip api-------------------------# 108 TT.show_delay([b1,b2,l1,l2], 1000)\ 109 .background(b1, gdk.Color("yellow"))(b2, gdk.Color("#95BE0D"))(l1,gdk.Color("blue"))\ 110 .custom(b1, customTooltip_cb)\ 111 .text([l1, l2], "tooliiiiit")(b2, "button2222", enable_gaussian=True)\ 112 .padding(l1, -1, -1, -1, 50)(b2, -1, -1, -1, 0)(b1, 0, 50, 50, 50) 113 #_____________________________________________________________________# 114 115 116 117 b1c = gen_control(b1) 118 b = gtk.HBox() 119 b.add(b1) 120 b.pack_start(b1c, False) 121 box.pack_start(b) 122 123 b2c = gen_control(b2) 124 b = gtk.HBox() 125 b.add(b2) 126 b.pack_start(b2c, False) 127 box.pack_start(b) 128 129 lc = gen_control(l1) 130 b = gtk.HBox() 131 b.add(ls) 132 b.pack_start(lc, False) 133 box.pack_start(b) 134 135 w.add(box) 136 w.connect('destroy', gtk.main_quit) 137 w.show_all() 138 gtk.main() 139 #run_with_profile(gtk.main, '/dev/shm/ttt') 140