Guest User

Untitled

a guest
Feb 23rd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. from gi.repository import Gtk, Gdk
  2. class Monelio:
  3. def __init__(self):
  4. # load CSS
  5. style_provider = Gtk.CssProvider()
  6. css = open('monelio.css')
  7. css_data = css.read()
  8. css.close()
  9. style_provider.load_from_data(css_data)
  10. Gtk.StyleContext.add_provider_for_screen(
  11. Gdk.Screen.get_default(),
  12. style_provider,
  13. Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
  14. )
  15. # load CSS
  16. style_provider = Gtk.CssProvider()
  17. css = open('monelio.css')
  18. css_data = css.read()
  19. css.close()
  20. style_provider.load_from_data(css_data)
  21. Gtk.StyleContext.add_provider_for_screen(
  22. Gdk.Screen.get_default(),
  23. style_provider,
  24. Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
  25. )
  26. button1 = Gtk.Button()
  27. button1.set_label(" - ")
  28. button1.set_name("btn_moins_" + str(x+1))
  29. button1.set_size_request(80, 70)
  30. button1.get_style_context().add_class("btn_moins")
  31. button1.connect("clicked", self.on_btn_moins_clicked)
  32. button1.show()
  33.  
  34. .btn_moins {
  35. background-color: orange;
  36. background: orange;
  37. color: white;
  38. font-weight: bold;
  39. font-size: 25;
  40. padding: 0 20px 0 20px;
  41. }
  42.  
  43. from gi.repository import Gtk
  44.  
  45. class LabelWindow(Gtk.Window):
  46.  
  47. def __init__(self):
  48. Gtk.Window.__init__(self, title="Label Example")
  49.  
  50. hbox = Gtk.Box(spacing=10)
  51. hbox.set_homogeneous(False)
  52. vbox_left = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
  53. vbox_left.set_homogeneous(False)
  54. vbox_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
  55. vbox_right.set_homogeneous(False)
  56.  
  57. hbox.pack_start(vbox_left, True, True, 0)
  58. hbox.pack_start(vbox_right, True, True, 0)
  59.  
  60. label = Gtk.Label("This is a normal label")
  61. vbox_left.pack_start(label, True, True, 0)
  62.  
  63. label = Gtk.Label()
  64. label.set_text("This is a left-justified label.nWith multiple lines.")
  65. label.set_justify(Gtk.Justification.LEFT)
  66. vbox_left.pack_start(label, True, True, 0)
  67.  
  68. label = Gtk.Label(
  69. "This is a right-justified label.nWith multiple lines.")
  70. label.set_justify(Gtk.Justification.RIGHT)
  71. vbox_left.pack_start(label, True, True, 0)
  72.  
  73. label = Gtk.Label("This is an example of a line-wrapped label. It "
  74. "should not be taking up the entire "
  75. "width allocated to it, but automatically "
  76. "wraps the words to fit.n"
  77. " It supports multiple paragraphs correctly, "
  78. "and correctly adds "
  79. "many extra spaces. ")
  80. label.set_line_wrap(True)
  81. vbox_right.pack_start(label, True, True, 0)
  82.  
  83. label = Gtk.Label("This is an example of a line-wrapped, filled label. "
  84. "It should be taking "
  85. "up the entire width allocated to it. "
  86. "Here is a sentence to prove "
  87. "my point. Here is another sentence. "
  88. "Here comes the sun, do de do de do.n"
  89. " This is a new paragraph.n"
  90. " This is another newer, longer, better "
  91. "paragraph. It is coming to an end, "
  92. "unfortunately.")
  93. label.set_line_wrap(True)
  94. label.set_justify(Gtk.Justification.FILL)
  95. vbox_right.pack_start(label, True, True, 0)
  96.  
  97. label = Gtk.Label()
  98. label.set_markup("Text can be <small>small</small>, <big>big</big>, "
  99. "<b>bold</b>, <i>italic</i> and even point to "
  100. "somewhere in the <a href="http://www.gtk.org" "
  101. "title="Click to find out more">internets</a>.")
  102. label.set_line_wrap(True)
  103. vbox_left.pack_start(label, True, True, 0)
  104.  
  105. label = Gtk.Label.new_with_mnemonic(
  106. "_Press Alt + P to select button to the right")
  107. vbox_left.pack_start(label, True, True, 0)
  108. label.set_selectable(True)
  109.  
  110. button = Gtk.Button(label="Click at your own risk")
  111. label.set_mnemonic_widget(button)
  112. vbox_right.pack_start(button, True, True, 0)
  113.  
  114. self.add(hbox)
  115.  
  116. window = LabelWindow()
  117. window.connect("delete-event", Gtk.main_quit)
  118. window.show_all()
  119. Gtk.main()
  120.  
  121. screen = Gdk.Screen.get_default()
  122. gtk_provider = Gtk.CssProvider()
  123. gtk_context = Gtk.StyleContext()
  124. gtk_context.add_provider_for_screen(screen, gtk_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
  125. #css = """#styled_button { font-weight: bold; font-size: 22; }""" #also valid
  126. css = """#styled_button { font: bold 16}""" #bold is not necessary
  127. gtk_provider.load_from_data(css)
  128.  
  129. button.set_name("styled_button")
  130.  
  131. ...
  132. css = "GtkButton { font: 16}"
  133. ...
  134.  
  135. def on_button_clicked(self, widget, valid):
  136. style_context = widget.get_style_context()
  137. if valid:
  138. style_context.add_class("bigger")
  139. else:
  140. style_context.remove_class("bigger")
Add Comment
Please, Sign In to add comment