Skip to content

TCategoryPanelGroupDemo 项目分析

项目信息

文件结构

TCategoryPanelGroupDemo/
├── Extractor_Icon.ico
├── Project1.py
├── Project1.xml
├── Unit1.py
├── Unit1.pydfm
├── Unit1.sct
├── Unit1.sfm

主程序文件: Project1.py

from glcl import *
from Unit1 import *

def main():
    Application.Initialize()
    Application.Title = 'Project1'
    Application.MainFormOnTaskbar = True
    Application.Icon.LoadFromFile(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Extractor_Icon.ico"))
    MainForm = Form1(Application)
    MainForm.Show()
    FreeConsole()
    Application.Run()
    MainForm.Free()

if __name__ == '__main__':
    main()

单元文件: Unit1.py

import os
from glcl import *

class Form1(Form):

    def __init__(self, owner):
        self.Button4 = Button(self)
        self.Button3 = Button(self)
        self.Button2 = Button(self)
        self.Button1 = Button(self)
        self.CategoryPanelGroup1 = CategoryPanelGroup(self)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
        self.Button4.OnClick = self.Button4Click
        self.Button3.OnClick = self.Button3Click
        self.Button2.OnClick = self.Button2Click
        self.Button1.OnClick = self.Button1Click


    def Button1Click(self, Sender):
        # 折叠所有面板
        self.CategoryPanelGroup1.CollapseAll()

    def Button2Click(self, Sender):
        # 展开所有面板
        self.CategoryPanelGroup1.ExpandAll()

    def Button3Click(self, Sender):
        # 不显示 第二个面板
        self.CategoryPanelGroup1.Controls[1].Visible = False

    def Button4Click(self, Sender):
        # 显示 第二个面板
        self.CategoryPanelGroup1.Controls[1].Visible = True

设计文件: Unit1.sct

def Button1Click(Sender): 
def Button2Click(Sender): 
def Button3Click(Sender): 
def Button4Click(Sender): 

设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 522
  ClientWidth = 681
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object CategoryPanelGroup1: TCategoryPanelGroup
    Left = 0
    Top = 0
    Height = 522
    VertScrollBar.Tracking = True
    HeaderFont.Charset = DEFAULT_CHARSET
    HeaderFont.Color = clWindowText
    HeaderFont.Height = -15
    HeaderFont.Name = 'Segoe UI'
    HeaderFont.Style = []
    TabOrder = 0
    ExplicitLeft = 88
    ExplicitTop = 48
    ExplicitHeight = 350
    object CategoryPanel3: TCategoryPanel
      Top = 400
      Caption = 'CategoryPanel3'
      TabOrder = 0
      ExplicitWidth = 196
    end
    object CategoryPanel2: TCategoryPanel
      Top = 200
      Caption = 'CategoryPanel2'
      TabOrder = 1
      ExplicitWidth = 196
    end
    object CategoryPanel1: TCategoryPanel
      Top = 0
      Caption = 'CategoryPanel1'
      TabOrder = 2
      ExplicitWidth = 196
    end
  end
  object Button1: TButton
    Left = 224
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 224
    Top = 64
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 2
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 224
    Top = 120
    Width = 75
    Height = 25
    Caption = 'Button3'
    TabOrder = 3
    OnClick = Button3Click
  end
  object Button4: TButton
    Left = 224
    Top = 176
    Width = 75
    Height = 25
    Caption = 'Button4'
    TabOrder = 4
    OnClick = Button4Click
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • CategoryPanelGroup1 (TCategoryPanelGroup)
  • CategoryPanel3 (TCategoryPanel)
  • CategoryPanel2 (TCategoryPanel)
  • CategoryPanel1 (TCategoryPanel)
  • Button1 (TButton)
  • Button2 (TButton)
  • Button3 (TButton)
  • Button4 (TButton)

技术特点

  • 包含9个GUI组件
  • 定义4个事件处理

窗体属性

  • caption: Button4
  • height: 522
  • width: 681

代码分析

导入的模块: - import os - from glcl import *

定义的类: - Form1

定义的方法: - init - Button1Click - Button2Click - Button3Click - Button4Click

事件绑定: - self.Button4.OnClick = self.Button4Click - self.Button3.OnClick = self.Button3Click - self.Button2.OnClick = self.Button2Click - self.Button1.OnClick = self.Button1Click