TDirectoryOutlineDemo 项目分析¶
项目信息¶
- 项目名称: TDirectoryOutlineDemo
- 下载链接: TDirectoryOutlineDemo.rar
- 分析时间: 2026-03-05
文件结构¶
TDirectoryOutlineDemo/
├── 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.Button2 = Button(self)
self.Button1 = Button(self)
self.Label1 = Label(self)
self.DirectoryOutline1 = DirectoryOutline(self)
self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
self.Button2.OnClick = self.Button2Click
self.Button1.OnClick = self.Button1Click
self.DirectoryOutline1.OnDblClick = self.DirectoryOutline1DblClick
# 创建一个标签用于显示当前选择的目录
self.label = Label(self)
self.label.Parent = self # 设置父控件为当前窗体
self.label.Left = 10 # 设置标签的左侧位置
self.label.Top = 10 # 设置标签的顶部位置
self.label.Caption = 'Selected Directory:' # 标签标题
# 创建一个TDirectoryOutline控件,用于显示目录结构
self.directory_outline = DirectoryOutline(self)
self.directory_outline.Parent = self # 设置父控件为当前窗体
self.directory_outline.Left = 50 # 设置左边距离
self.directory_outline.Top = 50 # 设置顶部距离
self.directory_outline.Width = 200 # 设置宽度
self.directory_outline.Height = 400 # 设置高度
self.directory_outline.OnChange = self.on_change # 注册变化事件处理程序
# 设置初始目录(可以根据需要修改)
self.directory_outline.Directory = 'D:\\' # 设置根目录为D盘
# 处理目录变化事件
def on_change(self, Sender):
# 更新标签以显示当前选定的目录
selected_directory = self.directory_outline.Directory
self.label.Caption = f'Selected Directory: {selected_directory}'
def DirectoryOutline1DblClick(self, Sender):
self.Label1.Caption = self.DirectoryOutline1.Directory
def Button1Click(self, Sender):
# 全部折叠
self.DirectoryOutline1.FullCollapse()
def Button2Click(self, Sender):
# 全部扩展
self.DirectoryOutline1.FullExpand()
设计文件: Unit1.sct¶
def DirectoryOutline1DblClick(Sender):
def Button1Click(Sender):
def Button2Click(Sender):
设计文件: Unit1.sfm¶
object Form1: TForm
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 421
ClientWidth = 544
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Segoe UI'
Font.Style = []
TextHeight = 20
object Label1: TLabel
Left = 288
Top = 8
Width = 44
Height = 20
Caption = 'Label1'
end
object DirectoryOutline1: TDirectoryOutline
Left = 288
Top = 40
Width = 233
Height = 329
ItemHeight = 18
Options = [ooDrawFocusRect]
PictureLeaf.Data = {
46030000424D460300000000000036000000280000000E0000000E0000000100
2000000000001003000000000000000000000000000000000000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080000000000000000000000000000000000000000000000000000000
00000000000000000000000000008000800080008000800080000000000000FF
FF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FF
FF000000000080008000800080008000800000000000FFFFFF0000FFFF00FFFF
FF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF00000000008000
800080008000800080000000000000FFFF00FFFFFF0000FFFF00FFFFFF0000FF
FF00FFFFFF0000FFFF00FFFFFF0000FFFF000000000080008000800080008000
800000000000FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFF
FF0000FFFF00FFFFFF00000000008000800080008000800080000000000000FF
FF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FF
FF000000000080008000800080008000800000000000FFFFFF0000FFFF00FFFF
FF0000FFFF00FFFFFF0000FFFF00FFFFFF0000FFFF00FFFFFF00000000008000
8000800080008000800000000000000000000000000000000000000000000000
0000000000000000000000000000000000008000800080008000800080008000
80008000800000000000FFFFFF0000FFFF00FFFFFF0000FFFF00000000008000
8000800080008000800080008000800080008000800080008000800080008080
8000000000000000000000000000000000008080800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
8000800080008000800080008000800080008000800080008000800080008000
80008000800080008000}
TabOrder = 0
OnDblClick = DirectoryOutline1DblClick
Data = {10}
end
object Button1: TButton
Left = 288
Top = 376
Width = 75
Height = 25
Caption = #25240#21472
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 446
Top = 376
Width = 75
Height = 25
Caption = #25193#23637
TabOrder = 2
OnClick = Button2Click
end
end
其他文件¶
- Extractor_Icon.ico
- Project1.xml
详细分析¶
功能概述¶
GUI组件演示
使用的组件¶
- Form1 (TForm)
- Label1 (TLabel)
- DirectoryOutline1 (TDirectoryOutline)
- Button1 (TButton)
- Button2 (TButton)
技术特点¶
- 包含5个GUI组件
- 定义3个事件处理
窗体属性¶
- caption: #25193#23637
- height: 421
- width: 544
代码分析¶
导入的模块: - import os - from glcl import *
定义的类: - Form1
定义的方法: - init - on_change - DirectoryOutline1DblClick - Button1Click - Button2Click
事件绑定: - self.Button2.OnClick = self.Button2Click - self.Button1.OnClick = self.Button1Click - self.directory_outline.OnChange = self.on_change # 注册变化事件处理程序