PyGobject(一百零九)CSS系列——在UI文件中使用style属性

  • 例子

例子

PyGobject(一百零九)CSS系列——在UI文件中使用style属性_第1张图片
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/18
# section 159
# 
# author: xiaosanyu
# website: yuxiaosan.tk \
#          http://blog.csdn.net/a87b01c14
# created: 16/7/18

TITLE = "Style Classes"
DESCRIPTION = """
use 'style' tag on the ui file
"""
import gi

gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio
import os


def main():
    window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
    window.set_title("Style Classes")
    window.set_resizable(False)
    window.set_border_width(12)
    window.connect("destroy", Gtk.main_quit)

    builder = Gtk.Builder.new_from_file(os.path.join(os.path.dirname(__file__), "../Data/theming.glade"))

    grid = builder.get_object("grid")
    window.add(grid)
    window.show_all()
    Gtk.main()


if __name__ == "__main__":
    main()

布局文件theming.glade

version="1.0" encoding="UTF-8"?>

  class="GtkGrid" id="grid">
    <property name="row-spacing">10property>
    <property name="orientation">verticalproperty>
    
      class="GtkToolbar">
        <property name="visible">1property>
        <property name="hexpand">1property>
        <property name="show-arrow">0property>
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="use_action_appearance">0property>
            <property name="label" translatable="yes">Normalproperty>
            <property name="use_underline">1property>
            <property name="is_important">1property>
            <property name="icon_name">edit-findproperty>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="use_action_appearance">0property>
            <property name="label" translatable="yes">Activeproperty>
            <property name="use_underline">1property>
            <property name="is_important">1property>
            <property name="icon_name">edit-findproperty>
            <property name="active">1property>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="sensitive">0property>
            <property name="label" translatable="yes">Insensitiveproperty>
            <property name="use_underline">1property>
            <property name="is_important">1property>
            <property name="icon_name">edit-findproperty>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="label" translatable="yes">Raisedproperty>
            <property name="use_underline">1property>
            <property name="is_important">1property>
            <property name="icon_name">edit-find-symbolicproperty>
            
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="label" translatable="yes">Raised Activeproperty>
            <property name="use_underline">1property>
            <property name="is_important">1property>
            <property name="icon_name">edit-find-symbolicproperty>
            <property name="active">1property>
            
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="sensitive">0property>
            <property name="label" translatable="yes">Insensitive Activeproperty>
            <property name="use_underline">1property>
            <property name="icon_name">edit-findproperty>
            <property name="is_important">1property>
            <property name="active">1property>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToolItem">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            
              class="GtkEntry" id="entry1">
                <property name="visible">1property>
                <property name="can_focus">1property>
                <property name="invisible_char">•property>
                <property name="placeholder-text" translatable="yes">Search...property>
                <property name="secondary-icon-name">edit-find-symbolicproperty>
              
            
          
        
        
          class="GtkToolItem">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            
              class="GtkSwitch" id="switch1">
                <property name="visible">1property>
                <property name="can_focus">1property>
              
            
          
        
      
    
    
      class="GtkBox">
        <property name="visible">1property>
        <property name="valign">centerproperty>
        <property name="halign">centerproperty>
        
        
          class="GtkButton">
            <property name="label" translatable="yes">Hi, I am a buttonproperty>
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="can_focus">1property>
            <property name="receives_default">1property>
            <property name="use_action_appearance">0property>
          
        
        
          class="GtkButton">
            <property name="label" translatable="yes">And I'm another buttonproperty>
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="can_focus">1property>
            <property name="receives_default">1property>
            <property name="use_action_appearance">0property>
          
          
            <property name="position">1property>
          
        
        
          class="GtkButton">
            <property name="label" translatable="yes">This is a button party!property>
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="can_focus">1property>
            <property name="receives_default">1property>
            <property name="use_action_appearance">0property>
          
          
            <property name="position">2property>
          
        
      
    
    
      class="GtkToolbar">
        <property name="visible">1property>
        <property name="hexpand">1property>
        <property name="icon_size">1property>
        <property name="toolbar-style">iconsproperty>
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="use_action_appearance">0property>
            <property name="label" translatable="yes">Normalproperty>
            <property name="use_underline">1property>
            <property name="icon_name">list-add-symbolicproperty>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="use_action_appearance">0property>
            <property name="label" translatable="yes">Normalproperty>
            <property name="use_underline">1property>
            <property name="icon_name">list-add-symbolicproperty>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="use_action_appearance">0property>
            <property name="label" translatable="yes">Activeproperty>
            <property name="use_underline">1property>
            <property name="icon_name">list-remove-symbolicproperty>
            <property name="active">1property>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="use_action_appearance">0property>
            <property name="label" translatable="yes">Activeproperty>
            <property name="use_underline">1property>
            <property name="icon_name">list-remove-symbolicproperty>
            <property name="active">1property>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="sensitive">0property>
            <property name="use_action_appearance">0property>
            <property name="label" translatable="yes">Insensitiveproperty>
            <property name="use_underline">1property>
            <property name="icon_name">edit-find-symbolicproperty>
          
          
            <property name="homogeneous">1property>
          
        
        
          class="GtkToggleToolButton">
            <property name="use_action_appearance">0property>
            <property name="visible">1property>
            <property name="sensitive">0property>
            <property name="use_action_appearance">0property>
            <property name="label" translatable="yes">Insensitive Activeproperty>
            <property name="use_underline">1property>
            <property name="icon_name">go-up-symbolicproperty>
            <property name="active">1property>
          
          
            <property name="homogeneous">1property>
          
        
      
    
    
      class="GtkBox">
        <property name="visible">1property>
        <property name="spacing">10property>
        <property name="orientation">horizontalproperty>
        
          class="GtkButton">
            <property name="visible">1property>
            <property name="label">Plainproperty>
            <property name="halign">endproperty>
          
          
            <property name="expand">1property>
          
        
        
          class="GtkButton">
            <property name="visible">1property>
            <property name="label">Destructiveproperty>
            
          
        
        
          class="GtkButton">
            <property name="visible">1property>
            <property name="label">Suggestedproperty>
            
          
        
      
    
  





代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728

你可能感兴趣的:(PyGObject,PyGobject详解)