Skip to content

TGridPanelDemo 项目分析

项目信息

文件结构

TGridPanelDemo/
├── 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.GridPanel1 = GridPanel(self)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))

        # 设置列宽百分比
        self.GridPanel1.ColumnCollection[0].Value = 25
        self.GridPanel1.ColumnCollection[1].Value = 30
        self.GridPanel1.ColumnCollection[2].Value = 45

        # 设置行宽百分比
        self.GridPanel1.RowCollection[0].Value = 25
        self.GridPanel1.RowCollection[1].Value = 25
        self.GridPanel1.RowCollection[2].Value = 25
        self.GridPanel1.RowCollection[3].Value = 25

        # 循环创建12个Button
        for i in range(12):
            btn = Button(self)
            btn.Name = "btn" + str(i)
            btn.Parent = self.GridPanel1    # 设置父控件为GridPanel1
            btn.Caption = "aaa" +str(i)
            btn.Align = alClient            # 对齐方式填充客户区域

        # 下面两行分别是列和行的合并,可以分别取消注释看下效果
        #self.GridPanel1.ControlCollection[0].ColumnSpan = 2
        #self.GridPanel1.ControlCollection[0].RowSpan = 2

设计文件: Unit1.sct


设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 509
  ClientWidth = 537
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object GridPanel1: TGridPanel
    Left = 16
    Top = 16
    Width = 505
    Height = 481
    ColumnCollection = <
      item
        Value = 34.37806072477960000
      end
      item
        Value = 39.17727717923603000
      end
      item
        Value = 26.44466209598437000
      end>
    ControlCollection = <>
    RowCollection = <
      item
        Value = 28.27140549273020000
      end
      item
        Value = 31.01777059773827000
      end
      item
        Value = 18.09369951534735000
      end
      item
        Value = 22.61712439418421000
      end>
    TabOrder = 0
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

网格组件演示

使用的组件

  • Form1 (TForm)
  • GridPanel1 (TGridPanel)

技术特点

  • 包含2个GUI组件
  • 定义0个事件处理

窗体属性

  • caption: Form1
  • height: 509
  • width: 537

代码分析

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

定义的类: - Form1

定义的方法: - init