Browse Source

deletede useless file

dev
Jingxun 8 months ago
parent
commit
8bab61fe78
  1. 313
      frontend/static_gui_tmp/data_import_page.py

313
frontend/static_gui_tmp/data_import_page.py

@ -1,313 +0,0 @@
# -*- coding: utf-8 -*-
import wx
import wx.xrc
import wx.grid
from frontend.components_lib import (
Panel, Frame, FontSize, LayoutParams, FileDirPicker, FileDirPickerParam, GridTable
)
class DataImportBody(Panel):
"""
整个页面的 body 部分
"""
def __init__(self, parent, _id, pos, size, style, page_title):
"""
:param parent:
:param _id:
:param pos:
:param size:
:param style:
:param page_title: 页面的标题
"""
Panel.__init__(self, parent, _id, pos, size, style)
self.__page_title = page_title
self.notebook = None
self.imp_page = None
self.rec_page = None
# 调用初始化 hook
self._OnInit()
def _OnInit(self, *args, **kwargs):
"""
初始化 hook在这个方法中将 body 中所有的组件集合在一起并添加到一个整体的 sizer
:param args:
:param kwargs:
:return:
"""
# 创建 body sizer
self.body_sizer = wx.BoxSizer(wx.VERTICAL)
# 创建标题组件并添加到 body sizer 中
self.body_sizer.Add(
self.title_components(
{
"id": wx.ID_ANY,
"label": f"{self.__page_title}信息录入",
"pos": wx.DefaultPosition,
"size": wx.DefaultSize,
"style": 0
}
), 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5
)
# 创建 content 部分并添加到 body sizer 中
self.body_sizer.Add(
self.content_components(), 0, wx.ALIGN_CENTER_HORIZONTAL, 5
)
# 创建底部按钮组件并添加到 body sizer 中
self.body_sizer.Add(
self.button_components(
"退出", "导入", (80, 0), (0, 5), LayoutParams.VER_LAYOUT
), 0, wx.ALIGN_CENTER_HORIZONTAL, 5
)
def content_components(self):
"""
这是 body 中的 content 部分这个部分是页面的核心部分也是最复杂的部分
:return:
"""
# 创建 content 部分的 sizer
content_sizer = self.flex_sizer_generater(0, 1, 0, 0)
# 创建 notebook 组件,用来实现多标签页切换
self.notebook = wx.Notebook(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
# notebook 组件的基本配置设定
self.notebook.SetFont(wx.Font(**FontSize.CONTENT_SIZE))
self.notebook.SetBackgroundColour(wx.Colour(255, 255, 255))
# 创建数据导入页
self.imp_page = ImportPage(self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
# 创建导入记录页
self.rec_page = RecordPage(self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
# 将两页添加到 notebook 中,默认选中 批量导入 页签
self.notebook.AddPage(self.imp_page, "批量导入", True)
self.notebook.AddPage(self.rec_page, "导入记录", False)
# 将 notebook 组件添加到 content sizer 中
content_sizer.Add(self.notebook, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5)
# 配置 content 部分距离底部按钮之间的空白占位,即 margin
content_sizer.Add((0, 1), 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL | wx.EXPAND, 5)
return content_sizer
class ImportPage(Panel):
def __init__(self, parent, _id, pos, size, style):
"""
这是 批量导入页的组件元素
:param parent:
:param _id:
:param pos:
:param size:
:param style:
"""
Panel.__init__(self, parent, _id, pos, size, style)
self.file = None
# 基本配置
self.SetFont(wx.Font(**FontSize.CONTENT_SIZE))
self.SetMaxSize(wx.Size(700, 270))
# 调用初始化 hook
self._OnInit()
def _OnInit(self, *args, **kwargs):
"""
初始化 hook将页面整合并做相应的页面配置
:param args:
:param kwargs:
:return:
"""
# 创建页面 sizer
self.page_sizer = wx.BoxSizer(wx.VERTICAL)
# 配置大小
self.page_sizer.SetMinSize(wx.Size(700, 270))
# 获取 content 部分并添加到页面 sizer 中
self.page_sizer.Add(self.content_components(), 0, wx.ALIGN_CENTER_HORIZONTAL, 5)
# 设置sizer
self.SetSizer(self.page_sizer)
self.Layout()
# 自适应最小大小
self.page_sizer.Fit(self)
def content_components(self):
"""
创建 content 部分的组件
:return:
"""
# 创建 content sizer
outer_sizer = self.flex_sizer_generater(2, 1, 0, 0)
# 设置占位将元素垂直居中
outer_sizer.Add((0, 100), *LayoutParams.HOR_LAYOUT)
# 创建文件选择器组件的 sizer
comp_sizer = self.flex_sizer_generater(1, 3, 0, 0)
# 创建文件选择器组件
file_pick = (_, _, (self.file, *_)) = FileDirPicker(
self,
{"id": wx.ID_ANY, "label": "选择文件", "pos": wx.DefaultPosition, "size": wx.DefaultSize, "style": 0},
(5, 0), FileDirPickerParam.FILE_OBJ, FontSize.CONTENT_SIZE, LayoutParams.VER_LAYOUT
).get_item
# 设置文件选择器的大小
self.file.SetMinSize(wx.Size(400, -1))
# 将文件选择器组件添加到 sizer 中
comp_sizer.AddMany(file_pick)
outer_sizer.Add(comp_sizer, 1, wx.EXPAND, 5)
return outer_sizer
class RecordPage(ImportPage):
def __init__(self, parent, _id, pos, size, style):
"""
页面框架都一样继承自批量导入页面
:param parent:
:param _id:
:param pos:
:param size:
:param style:
"""
Panel.__init__(self, parent, _id, pos, size, style)
self.SetFont(wx.Font(**FontSize.CONTENT_SIZE))
self.SetMaxSize(wx.Size(700, 270))
# 调用初始化 hook
self._OnInit()
def grid_generater(self, num_rows, num_cols, style):
"""
该方法是一个表格生成器
:param num_rows: 行数
:param num_cols: 列数
:param style: 这个 style 和其他的组件中的 style不一样这是我自定义的 style
{
"col_names": Tuple[Str], 列名
"col_wid": Tuple[Number]/None, 列宽
"edit": Boolean, 表格中数据是否可写
"lines": Boolean, 表格边框线是否可见
"drag_size": Boolean, 是否可以拖拽修改表格大小
"drag_move": Boolean, 是否可以拖拽移动行和列
"drag_rc_size": Boolean, 是否可以拖拽改变行高和列宽
"margins": Tuple[Number], 外边框间隔
"font": Dict, 字体参数
"col_align": Tuple[Number], 表头的对齐方式
"row_align": Tuple[Number], 序号列对齐方式
"cell_align": Tuple[Number], 单元格对齐方式
"size": Tuple[Number] 表格大小
}
:return:
"""
# 创建表格
table = GridTable(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, style)
table.CreateGrid(num_rows, num_cols)
# 设置表格各方面样式及配置
table.set_table(num_cols)
return table
def content_components(self):
# 生成表格
out = self.grid_generater(
15, 5,
{
"col_names": ("导入日期", "导入时间", "操作人", "文件名称", "导入状态"),
"col_wid": (104, 101, 86, 190, 110),
"font": FontSize.CONTENT_SIZE,
"col_align": (wx.ALIGN_CENTER, wx.ALIGN_CENTER),
"row_align": (wx.ALIGN_CENTER, wx.ALIGN_CENTER),
"cell_align": (wx.ALIGN_CENTER, wx.ALIGN_CENTER),
"size": (700, 270)
}
)
self.get_data()
return out
def get_data(self):
pass
class DataImportPage(Frame):
def __init__(self, parent, title, size, page_title):
Frame.__init__(self, parent, title=title, size=size)
self.__size = size
self.__page_title = page_title
# 调用最终汇总 hook
self.show()
def sizer(self, size, orient):
"""
创建最外层 sizer
:param size: 大小
:param orient: 对齐方式
:return:
"""
out_sizer = wx.BoxSizer(orient)
out_sizer.SetMinSize(wx.Size(*size))
return out_sizer
def get_body(self, parent, _id, pos, size, style):
"""
获取页面的 body
:param parent:
:param _id:
:param pos:
:param size:
:param style:
:return:
"""
body_panel = DataImportBody(parent, _id, pos, size, style, self.__page_title)
return body_panel
def show(self):
"""
最终汇总配置 hook
:return:
"""
# 获取 body
self.__body = self.get_body(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL)
# 设置 sizer
self.__body.SetSizer(self.__body.body_sizer)
self.__body.Layout()
# 自适应最小大小
self.__body.body_sizer.Fit(self.__body)
# 创建 frame sizer
frame_sizer = self.sizer(self.__size, wx.VERTICAL)
# 将 body 添加到 frame sizer 中
frame_sizer.Add(self.__body, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)
# 设置 sizer
self.SetSizer(frame_sizer)
self.Layout()
# 将窗口展示到显示器中心
self.Centre(wx.BOTH)
# 事件绑定
self.event_bind()
def exit_onclick(self, event):
self.Destroy()
def login_onclick(self, event):
idx = self.__body.notebook.GetSelection()
op = "导入" if self.__body.notebook.GetPage(idx) == self.__body.imp_page else "导出"
popup = wx.MessageDialog(None, f"您提交了{op}操作", f"{op}操作", wx.YES_DEFAULT)
if popup.ShowModal() == wx.ID_YES:
self.Close()
def change_btn_name(self, event):
idx = self.__body.notebook.GetSelection()
if self.__body.notebook.GetPage(idx) == self.__body.imp_page:
self.__body.submit_btn.SetLabel("导入")
else:
self.__body.submit_btn.SetLabel("导出")
def event_bind(self):
"""
事件绑定
:return:
"""
self.__body.exit_btn.Bind(wx.EVT_LEFT_UP, self.exit_onclick)
self.__body.submit_btn.Bind(wx.EVT_LEFT_UP, self.login_onclick)
# 给 notebook 绑定页签切换事件
self.__body.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.change_btn_name)
if __name__ == '__main__':
app = wx.App()
frame = DataImportPage(None, "数据导入", (800, 510), "积层")
frame.Show()
app.MainLoop()
Loading…
Cancel
Save