1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
| #!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
'''Text Widget/Hypertext
Usually, tags modify the appearance of text in the view, e.g. making it
bold or colored or underlined. But tags are not restricted to appearance.
They can also affect the behavior of mouse and key presses, as this demo
shows.'''
# pygtk version: Maik Hertha <maik.hertha@berlin.de>
import gtk
import pango
import gobject
import shelve
import os
class stock_buffer(object):
def __init__(self,buffer):
self.buffer = buffer
class HypertextDemo(gtk.Window):
hovering_over_link = False
hand_cursor = gtk.gdk.Cursor(gtk.gdk.HAND2)
regular_cursor = gtk.gdk.Cursor(gtk.gdk.XTERM)
def save(self,buffer):
save_file = os.path.abspath("D:\sphinx" + os.sep + 'essai.tvw')
db = shelve.open(save_file)
instance_buffer = stock_buffer(buffer)
db['cle']=instance_buffer
db.close()
print('sauvegarde ok')
def load(self):
save_file = os.path.abspath("D:\sphinx" + os.sep + 'essai.tvw')
db = shelve.open(save_file)
print
print "liste des clé enregistrée",db.keys
print
conteneur = db['cle']
db.close()
window = gtk.Window()
window.connect('destroy', lambda *w: gtk.main_quit())
window.set_title(self.__class__.__name__+' clone')
window.set_default_size(450, 450)
window.set_border_width(0)
view = gtk.TextView(conteneur.buffer)
view.set_wrap_mode(gtk.WRAP_WORD) #c'est utile car il y a en permanence une partie cachée pas top pour une aide
view.connect("key-press-event", self.key_press_event)
view.connect("event-after", self.event_after)
view.connect("motion-notify-event", self.motion_notify_event)
view.connect("visibility-notify-event", self.visibility_notify_event)
#buffer = view.get_buffer()
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
window.add(sw)
sw.add(view)
window.show_page(buffer, 1)
window.show_all()
def __init__(self, parent=None):
livre_xpm_red = [
"16 16 6 1",
" c None s None",
". c black",
"X c red",
"o c yellow",
"O c #808080",
"# c white",
" ",
" .. ",
" ..XX. ",
" ..XXXXX. ",
" ..XXXXXXXX. ",
".ooXXXXXXXXX. ",
"..ooXXXXXXXXX. ",
".X.ooXXXXXXXXX. ",
".XX.ooXXXXXX.. ",
" .XX.ooXXX..#O ",
" .XX.oo..##OO. ",
" .XX..##OO.. ",
" .X.#OO.. ",
" ..O.. ",
" .. ",
" "]
self.pixbuf_red = gtk.gdk.pixbuf_new_from_xpm_data(livre_xpm_red)
livre_xpm_blue = [
"16 16 6 1",
" c None s None",
". c black",
"X c blue",
"o c yellow",
"O c #808080",
"# c white",
" ",
" .. ",
" ..XX. ",
" ..XXXXX. ",
" ..XXXXXXXX. ",
".ooXXXXXXXXX. ",
"..ooXXXXXXXXX. ",
".X.ooXXXXXXXXX. ",
".XX.ooXXXXXX.. ",
" .XX.ooXXX..#O ",
" .XX.oo..##OO. ",
" .XX..##OO.. ",
" .X.#OO.. ",
" ..O.. ",
" .. ",
" "]
self.pixbuf_blue = gtk.gdk.pixbuf_new_from_xpm_data(livre_xpm_blue)
livre_xpm_green = [
"16 16 6 1",
" c None s None",
". c black",
"X c green",
"o c yellow",
"O c #808080",
"# c white",
" ",
" .. ",
" ..XX. ",
" ..XXXXX. ",
" ..XXXXXXXX. ",
".ooXXXXXXXXX. ",
"..ooXXXXXXXXX. ",
".X.ooXXXXXXXXX. ",
".XX.ooXXXXXX.. ",
" .XX.ooXXX..#O ",
" .XX.oo..##OO. ",
" .XX..##OO.. ",
" .X.#OO.. ",
" ..O.. ",
" .. ",
" "]
self.pixbuf_green = gtk.gdk.pixbuf_new_from_xpm_data(livre_xpm_green)
livre_xpm_pink = [
"16 16 6 1",
" c None s None",
". c black",
"X c pink",
"o c yellow",
"O c #808080",
"# c white",
" ",
" .. ",
" ..XX. ",
" ..XXXXX. ",
" ..XXXXXXXX. ",
".ooXXXXXXXXX. ",
"..ooXXXXXXXXX. ",
".X.ooXXXXXXXXX. ",
".XX.ooXXXXXX.. ",
" .XX.ooXXX..#O ",
" .XX.oo..##OO. ",
" .XX..##OO.. ",
" .X.#OO.. ",
" ..O.. ",
" .. ",
" "]
self.pixbuf_pink = gtk.gdk.pixbuf_new_from_xpm_data(livre_xpm_pink)
livre_xpm_yel = [
"16 16 6 1",
" c None s None",
". c black",
"X c yellow",
"o c red",
"O c #808080",
"# c white",
"a c darkblue",
" ",
" .. ",
" ..XX. ",
" ..XXXXX. ",
" ..XXXXXXXX. ",
".XXXXXXXXXXX. ",
"..XXXXXXXXXXX. ",
".a.XXXXXXXXXXX. ",
".aa.XXXXXXXX.. ",
" .aa.XXXXX..#O ",
" .aa.XX..##OO. ",
" .aa..##OO.. ",
" .a.#OO.. ",
" ..O.. ",
" .. ",
" "]
self.pixbuf_yel = gtk.gdk.pixbuf_new_from_xpm_data(livre_xpm_yel)
livre_xpm_yel_b = [
"48 36 6 1",
" c None s None",
". c black",
"X c yellow",
"o c red",
"O c #808080",
"# c white",
"a c #A69996589658",
" ",
" .. ",
" ..XX. ",
" ..XXXXX. ",
" ..XXXXXXXX. ",
" ..XXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" ..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" ...XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" .aaa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" .aaaa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" .aaaa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX..#. ",
" .aaaa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX..##O. ",
" .aaaa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXX..##OOO. ",
" .aaaa.XXXXXXXXXXXXXXXXXXXXXXXXXX..##OOOO.. ",
" .aaaa.XXXXXXXXXXXXXXXXXXXXXXX..##OOOO.. ",
" .aaaa.XXXXXXXXXXXXXXXXXXXX..##OOOO.. ",
" .aaaa.XXXXXXXXXXXXXXXXX..##OOOO.. ",
" .aaaa.XXXXXXXXXXXXXX..##OOOO.. ",
" .aaaa.XXXXXXXXXXX..##OOOO.. ",
" .aaaa.XXXXXXXX..##OOOO.. ",
" .aaaa.XXXXX..##OOOO.. ",
" .aaaa.XX..##OOOO.. ",
" .aaaa..##OOOO.. ",
" .aa.##OOOO.. ",
" .a.#OOO.. ",
" ..... ",
" ... ",
" "]
self.pixbuf_yel_b = gtk.gdk.pixbuf_new_from_xpm_data(livre_xpm_yel_b)
BrouettePleine_xpm = [
"48 48 64 1",
" c None",
". c #DF7DCF3CC71B",
"X c #965875D669A6",
"o c #71C671C671C6",
"O c #A699A289A699",
"+ c #965892489658",
"@ c #8E38410330C2",
"# c #D75C7DF769A6",
"$ c #F7DECF3CC71B",
"% c #96588A288E38",
"& c #A69992489E79",
"* c #8E3886178E38",
"= c #104008200820",
"- c #596510401040",
"; c #C71B30C230C2",
": c #C71B9A699658",
"> c #618561856185",
", c #20811C712081",
"< c #104000000000",
"1 c #861720812081",
"2 c #DF7D4D344103",
"3 c #79E769A671C6",
"4 c #861782078617",
"5 c #41033CF34103",
"6 c #000000000000",
"7 c #49241C711040",
"8 c #492445144924",
"9 c #082008200820",
"0 c #69A618611861",
"q c #B6DA71C65144",
"w c #410330C238E3",
"e c #CF3CBAEAB6DA",
"r c #71C6451430C2",
"t c #EFBEDB6CD75C",
"y c #28A208200820",
"u c #186110401040",
"i c #596528A21861",
"p c #71C661855965",
"a c #A69996589658",
"s c #30C228A230C2",
"d c #BEFBA289AEBA",
"f c #596545145144",
"g c #30C230C230C2",
"h c #8E3882078617",
"j c #208118612081",
"k c #38E30C300820",
"l c #30C2208128A2",
"z c #38E328A238E3",
"x c #514438E34924",
"c c #618555555965",
"v c #30C2208130C2",
"b c #38E328A230C2",
"n c #28A228A228A2",
"m c #41032CB228A2",
"M c #104010401040",
"N c #492438E34103",
"B c #28A2208128A2",
"V c #A699596538E3",
"C c #30C21C711040",
"Z c #30C218611040",
"A c #965865955965",
"S c #618534D32081",
"D c #38E31C711040",
"F c #082000000820",
" ",
" .XoO ",
" +@#$%o& ",
" *=-;#::o+ ",
" >,<12#:34 ",
" 45671#:X3 ",
" +89<02qwo ",
"e* >,67;ro ",
"ty> 459@>+&& ",
"$2u+ ><ipas8* ",
"%$;=* *3:.Xa.dfg> ",
"Oh$;ya *3d.a8j,Xe.d3g8+ ",
" Oh$;ka *3d$a8lz,,xxc:.e3g54 ",
" Oh$;kO *pd$%svbzz,sxxxxfX..&wn> ",
" Oh$@mO *3dthwlsslszjzxxxxxxx3:td8M4 ",
" Oh$@g& *3d$XNlvvvlllm,mNwxxxxxxxfa.:,B* ",
" Oh$@,Od.czlllllzlmmqV@V#V@fxxxxxxxf:%j5& ",
" Oh$1hd5lllslllCCZrV#r#:#2AxxxxxxxxxcdwM* ",
" OXq6c.%8vvvllZZiqqApA:mq:Xxcpcxxxxxfdc9* ",
" 2r<6gde3bllZZrVi7S@SV77A::qApxxxxxxfdcM ",
" :,q-6MN.dfmZZrrSS:#riirDSAX@Af5xxxxxfevo",
" +A26jguXtAZZZC7iDiCCrVVii7Cmmmxxxxxx%3g",
" *#16jszN..3DZZZZrCVSA2rZrV7Dmmwxxxx&en",
" p2yFvzssXe:fCZZCiiD7iiZDiDSSZwwxx8e*>",
" OA1<jzxwwc:$d%NDZZZZCCCZCCZZCmxxfd.B ",
" 3206Bwxxszx%et.eaAp77m77mmmf3&eeeg* ",
" @26MvzxNzvlbwfpdettttttttttt.c,n& ",
" *;16=lsNwwNwgsvslbwwvccc3pcfu<o ",
" p;<69BvwwsszslllbBlllllllu<5+ ",
" OS0y6FBlvvvzvzss,u=Blllj=54 ",
" c1-699Blvlllllu7k96MMMg4 ",
" *10y8n6FjvllllB<166668 ",
" S-kg+>666<M<996-y6n<8* ",
" p71=4 m69996kD8Z-66698&& ",
" &i0ycm6n4 ogk17,0<6666g ",
" N-k-<> >=01-kuu666> ",
" ,6ky& &46-10ul,66, ",
" Ou0<> o66y<ulw<66& ",
" *kk5 >66By7=xu664 ",
" <<M4 466lj<Mxu66o ",
" *>> +66uv,zN666* ",
" 566,xxj669 ",
" 4666FF666> ",
" >966666M ",
" oM6668+ ",
" *4 ",
" ",
" "
]
self.pixbuf_bro = gtk.gdk.pixbuf_new_from_xpm_data(BrouettePleine_xpm)
gtk.Window.__init__(self)
try:
self.set_screen(parent.get_screen())
except AttributeError:
self.connect('destroy', lambda *w: gtk.main_quit())
self.set_title(self.__class__.__name__)
self.set_default_size(450, 450)
self.set_border_width(0)
view = gtk.TextView()
view.set_wrap_mode(gtk.WRAP_WORD) #c'est utile car il y a en permanence une partie cachée pas top pour une aide
view.connect("key-press-event", self.key_press_event)
view.connect("event-after", self.event_after)
view.connect("motion-notify-event", self.motion_notify_event)
view.connect("visibility-notify-event", self.visibility_notify_event)
buffer = view.get_buffer()
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.add(sw)
sw.add(view)
self.show_page(buffer, 1)
self.show_all()
self.save(buffer)
#self.load()
# Links can be activated by pressing Enter.
def key_press_event(self, text_view, event):
if (event.keyval == gtk.gdk.Return or
event.keyval == gtk.gdk.KP_Enter):
buffer = text_view.get_buffer()
iter = buffer.get_iter_at_mark(buffer.get_insert())
self.follow_if_link(text_view, iter)
return False
# Links can also be activated by clicking.
def event_after(self, text_view, event):
if event.type != gtk.gdk.BUTTON_RELEASE:
return False
if event.button != 1:
return False
buffer = text_view.get_buffer()
# we shouldn't follow a link if the user has selected something
try:
start, end = buffer.get_selection_bounds()
except ValueError:
# If there is nothing selected, None is return
pass
else:
if start.get_offset() != end.get_offset():
return False
x, y = text_view.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET,
int(event.x), int(event.y))
iter = text_view.get_iter_at_location(x, y)
self.follow_if_link(text_view, iter)
return False
# Looks at all tags covering the position (x, y) in the text view,
# and if one of them is a link, change the cursor to the "hands" cursor
# typically used by web browsers.
def set_cursor_if_appropriate(self, text_view, x, y):
hovering = False
buffer = text_view.get_buffer()
iter = text_view.get_iter_at_location(x, y)
tags = iter.get_tags()
for tag in tags:
page = tag.get_data("page")
if page != 0:
hovering = True
break
if hovering != self.hovering_over_link:
self.hovering_over_link = hovering
if self.hovering_over_link:
text_view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(self.hand_cursor)
else:
text_view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(self.regular_cursor)
# Update the cursor image if the pointer moved.
def motion_notify_event(self, text_view, event):
x, y = text_view.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET,
int(event.x), int(event.y))
self.set_cursor_if_appropriate(text_view, x, y)
text_view.window.get_pointer()
return False
# Also update the cursor image if the window becomes visible
# (e.g. when a window covering it got iconified).
def visibility_notify_event(self, text_view, event):
wx, wy, mod = text_view.window.get_pointer()
bx, by = text_view.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET, wx, wy)
self.set_cursor_if_appropriate (text_view, bx, by)
return False
def insert_link(self, buffer, iter, text, page):
''' Inserts a piece of text into the buffer, giving it the usual
appearance of a hyperlink in a web browser: blue and underlined.
Additionally, attaches some data on the tag, to make it recognizable
as a link.
'''
tag = buffer.create_tag(None,
foreground="blue", underline=pango.UNDERLINE_SINGLE)
tag.set_data("page", page)
buffer.insert_with_tags(iter, text, tag)
def show_page(self, buffer, page):
''' Fills the buffer with text and interspersed links. In any real
hypertext app, this method would parse a file to identify the links.
'''
buffer.set_text("", 0)
iter = buffer.get_iter_at_offset(0)
if page == 1:
buffer.insert_pixbuf(iter, self.pixbuf_red)
buffer.insert(iter, "Some text to show that simple ")
self.insert_link(buffer, iter, "hypertext", 3)
buffer.insert(iter, " can easily be realized with ")
self.insert_link(buffer, iter, "tags", 2)
buffer.insert(iter, ".")
buffer.insert(iter, "\n")
buffer.insert_pixbuf(iter, self.pixbuf_yel)
buffer.insert(iter, 'Inserts a piece of text into the buffer, giving it the usual'
'appearance of a hyperlink in a web browser: blue and underlined.'
'Additionally, attaches some data on the tag, to make it recognizable'
'as a link')
buffer.insert(iter, "\n")
buffer.insert_pixbuf(iter, self.pixbuf_bro)
buffer.insert(iter, 'Inserts a piece of text into the buffer, giving it the usual'
'appearance of a hyperlink in a web browser: blue and underlined.'
'Additionally, attaches some data on the tag, to make it recognizable'
'as a link')
buffer.insert(iter, "\n")
buffer.insert_pixbuf(iter, self.pixbuf_yel_b)
buffer.insert(iter, 'Inserts a piece of text into the buffer, giving it the usual'
'appearance of a hyperlink in a web browser: blue and underlined.'
'Additionally, attaches some data on the tag, to make it recognizable'
'as a link')
buffer.insert(iter, "\n")
buffer.insert_pixbuf(iter, self.pixbuf_blue)
buffer.insert(iter, 'Inserts a piece of text into the buffer, giving it the usual'
'appearance of a hyperlink in a web browser: blue and underlined.'
'Additionally, attaches some data on the tag, to make it recognizable'
'as a link')
buffer.insert(iter, "\n")
buffer.insert_pixbuf(iter, self.pixbuf_green)
buffer.insert(iter, 'Inserts a piece of text into the buffer, giving it the usual'
'appearance of a hyperlink in a web browser: blue and underlined.'
'Additionally, attaches some data on the tag, to make it recognizable'
'as a link')
buffer.insert(iter, "\n")
buffer.insert_pixbuf(iter, self.pixbuf_pink)
buffer.insert(iter, 'Inserts a piece of text into the buffer, giving it the usual'
'appearance of a hyperlink in a web browser: blue and underlined.'
'Additionally, attaches some data on the tag, to make it recognizable'
'as a link')
elif page == 2:
buffer.insert_pixbuf(iter, self.pixbuf_red)
buffer.insert(iter,
"A tag is an attribute that can be applied to some range of text. "
"For example, a tag might be called \"bold\" and make the text inside "
"the tag bold. However, the tag concept is more general than that "
"tags don't have to affect appearance. They can instead affect the "
"behavior of mouse and key presses, \"lock\" a range of text so the "
"user can't edit it, or countless other things.\n", -1)
self.insert_link(buffer, iter, "Go back", 1)
elif page == 3:
tag = buffer.create_tag(None, weight=pango.WEIGHT_BOLD)
buffer.insert_pixbuf(iter, self.pixbuf_red)
buffer.insert_with_tags(iter, "hypertext:\n", tag)
buffer.insert(iter,
"machine-readable text that is not sequential but is organized "
"so that related items of information are connected.\n")
self.insert_link(buffer, iter, "Go back", 1)
def follow_if_link(self, text_view, iter):
''' Looks at all tags covering the position of iter in the text view,
and if one of them is a link, follow it by showing the page identified
by the data attached to it.
'''
tags = iter.get_tags()
for tag in tags:
page = tag.get_data("page")
if page != 0:
self.show_page(text_view.get_buffer(), page)
break
def create_tags(self, text_buffer):
'''
Create a bunch of tags. Note that it's also possible to
create tags with gtk.text_tag_new() then add them to the
tag table for the buffer, text_buffer.create_tag() is
just a convenience function. Also note that you don't have
to give tags a name; pass None for the name to create an
anonymous tag.
In any real app, another useful optimization would be to create
a GtkTextTagTable in advance, and reuse the same tag table for
all the buffers with the same tag set, instead of creating
new copies of the same tags for every buffer.
Tags are assigned default priorities in order of addition to the
tag table. That is, tags created later that affect the same text
property affected by an earlier tag will override the earlier
tag. You can modify tag priorities with
gtk.text_tag_set_priority().
'''
text_buffer.create_tag("heading",
weight=pango.WEIGHT_BOLD,
size=15 * pango.SCALE)
text_buffer.create_tag("italic", style=pango.STYLE_ITALIC)
text_buffer.create_tag("bold", weight=pango.WEIGHT_BOLD)
text_buffer.create_tag("heading",weight=pango.WEIGHT_BOLD,size=15 * pango.SCALE)
text_buffer.create_tag("big", size=20 * pango.SCALE)# points times the pango.SCALE factor
text_buffer.create_tag("huge", size=40 * pango.SCALE)
text_buffer.create_tag("xx-small", scale=pango.SCALE_XX_SMALL)
text_buffer.create_tag("x-large", scale=pango.SCALE_X_LARGE)
text_buffer.create_tag("monospace", family="monospace")
text_buffer.create_tag("blue_foreground", foreground="blue")
text_buffer.create_tag("brown_foreground", foreground="brown")
text_buffer.create_tag("cyan_foreground", foreground="cyan")
text_buffer.create_tag("green_foreground", foreground="green")
text_buffer.create_tag("magenta_foreground", foreground="magenta")
text_buffer.create_tag("orange_foreground", foreground="orange")
text_buffer.create_tag("pink_foreground", foreground="pink")
text_buffer.create_tag("purple_foreground", foreground="purple")
text_buffer.create_tag("red_foreground", foreground="red")
text_buffer.create_tag("yellow_foreground", foreground="yellow")
text_buffer.create_tag("darkblue_foreground", foreground="darkblue")
text_buffer.create_tag("darkgreen_foreground", foreground="darkgreen")
text_buffer.create_tag("darkred_foreground", foreground="darkred")
text_buffer.create_tag("blue_background", background="blue")
text_buffer.create_tag("brown_background", background="brown")
text_buffer.create_tag("cyan_background", background="cyan")
text_buffer.create_tag("green_background", background="green")
text_buffer.create_tag("magenta_background", background="magenta")
text_buffer.create_tag("orange_background", background="orange")
text_buffer.create_tag("pink_background", background="pink")
text_buffer.create_tag("purple_background", background="purple")
text_buffer.create_tag("gray_background", background="gray")
text_buffer.create_tag("red_background", background="red")
text_buffer.create_tag("yellow_background", background="yellow")
text_buffer.create_tag("white_background", background="white")
text_buffer.create_tag("darkgray_background", background="darkgray")
text_buffer.create_tag("light_blue_background", background="light blue")
text_buffer.create_tag("light_cyan_background", background="light cyan")
text_buffer.create_tag("light_green_background", background="light green")
text_buffer.create_tag("light_magenta_background", background="light magenta")
text_buffer.create_tag("light_orange_background", background="light orange")
text_buffer.create_tag("light_pink_background", background="light pink")
text_buffer.create_tag("light_red_background", background="light red")
text_buffer.create_tag("light_yellow_background", background="light yellow")
stipple = gtk.gdk.bitmap_create_from_data(None,
gray50_bits, gray50_width, gray50_height)
text_buffer.create_tag("background_stipple", background_stipple=stipple)
text_buffer.create_tag("foreground_stipple", foreground_stipple=stipple)
text_buffer.create_tag("big_gap_before_line", pixels_above_lines=30)
text_buffer.create_tag("big_gap_after_line", pixels_below_lines=30)
text_buffer.create_tag("double_spaced_line", pixels_inside_wrap=10)
text_buffer.create_tag("not_editable", editable=False)
text_buffer.create_tag(None, invisible=True)
text_buffer.create_tag(editable=False, foreground="purple") #balise_non_editable
text_buffer.create_tag("word_wrap", wrap_mode=gtk.WRAP_WORD)
text_buffer.create_tag("char_wrap", wrap_mode=gtk.WRAP_CHAR)
text_buffer.create_tag("no_wrap", wrap_mode=gtk.WRAP_NONE)
text_buffer.create_tag("center", justification=gtk.JUSTIFY_CENTER)
text_buffer.create_tag("right_justify", justification=gtk.JUSTIFY_RIGHT)
text_buffer.create_tag("left_justify", justification=gtk.JUSTIFY_LEFT)
text_buffer.create_tag("fill_justify", justification=gtk.GTK_JUSTIFY_FILL)
text_buffer.create_tag("wide_margins",left_margin=50, right_margin=50)
text_buffer.create_tag("strikethrough", strikethrough=True) #barre
text_buffer.create_tag("underline",underline=pango.UNDERLINE_SINGLE)
text_buffer.create_tag("double_underline", underline=pango.UNDERLINE_DOUBLE)
text_buffer.create_tag("superscript", # exposant
rise=10 * pango.SCALE, # 10 pixels
size=8 * pango.SCALE) # 8 points
text_buffer.create_tag("subscript", # subexposant
rise=-10 * pango.SCALE, # 10 pixels
size=8 * pango.SCALE) # 8 points
text_buffer.create_tag("rtl_quote",
wrap_mode=gtk.WRAP_WORD, direction=gtk.TEXT_DIR_RTL,
indent=30, left_margin=20, right_margin=20)
'''
NBRE_COULEURS = 16
ECHELLE_PANGO = 1024
tabledesbalises = self.get_tag_table()
self.comptref = 0
self.nomfichier = None
self.sanstitre_num = -1
self.balises_couleurs = []
self.marqueur_cycle_couleurs = 0
self.teinte_depart = 0.0
for i in range(Buffer.NBRE_COULEURS):
balise = self.create_tag()
self.balises_couleurs.append(balise)
'''
def main():
HypertextDemo()
gtk.main()
if __name__ == '__main__':
main() |
Partager