|
@@ -2,12 +2,16 @@ import logging
|
|
|
import tkinter as tk
|
|
import tkinter as tk
|
|
|
from tkinter import ttk
|
|
from tkinter import ttk
|
|
|
|
|
|
|
|
-from plat.base.base_control import BaseControl
|
|
|
|
|
|
|
+from control.base.base_control import BaseControl, UIControl
|
|
|
|
|
|
|
|
|
|
|
|
|
class LeftPanel(tk.LabelFrame):
|
|
class LeftPanel(tk.LabelFrame):
|
|
|
- def __init__(self, master=None):
|
|
|
|
|
|
|
+ def __init__(self, master=None, control: UIControl = None):
|
|
|
super().__init__(master, text="手机列表")
|
|
super().__init__(master, text="手机列表")
|
|
|
|
|
+ self.scrollbar = None
|
|
|
|
|
+ self.canvas = None
|
|
|
|
|
+ self.list_frame = None
|
|
|
|
|
+ self.control = control
|
|
|
self.master = master
|
|
self.master = master
|
|
|
self.phone_items_data = [] # 用于存储每个手机项的数据 (包含 CheckVar)
|
|
self.phone_items_data = [] # 用于存储每个手机项的数据 (包含 CheckVar)
|
|
|
self.create_widgets()
|
|
self.create_widgets()
|
|
@@ -26,7 +30,8 @@ class LeftPanel(tk.LabelFrame):
|
|
|
name_label.grid(row=0, column=1, padx=5, pady=10, sticky="e")
|
|
name_label.grid(row=0, column=1, padx=5, pady=10, sticky="e")
|
|
|
# 选择框
|
|
# 选择框
|
|
|
check_all = tk.BooleanVar()
|
|
check_all = tk.BooleanVar()
|
|
|
- check_button = ttk.Checkbutton(title_label, variable=check_all, command=lambda v=check_all: self.toggle_check(v))
|
|
|
|
|
|
|
+ check_button = ttk.Checkbutton(title_label, variable=check_all,
|
|
|
|
|
+ command=lambda v=check_all: self.toggle_check(v))
|
|
|
check_button.grid(row=0, column=2, padx=5, pady=10, sticky="e")
|
|
check_button.grid(row=0, column=2, padx=5, pady=10, sticky="e")
|
|
|
|
|
|
|
|
# 添加数据按钮
|
|
# 添加数据按钮
|
|
@@ -76,7 +81,6 @@ class LeftPanel(tk.LabelFrame):
|
|
|
item_frame = ttk.Frame(self.list_frame, padding=(5, 5))
|
|
item_frame = ttk.Frame(self.list_frame, padding=(5, 5))
|
|
|
item_frame.pack(fill="x", expand=True)
|
|
item_frame.pack(fill="x", expand=True)
|
|
|
|
|
|
|
|
- name = device['device']
|
|
|
|
|
status = device['status']
|
|
status = device['status']
|
|
|
|
|
|
|
|
# 选择框
|
|
# 选择框
|
|
@@ -101,7 +105,7 @@ class LeftPanel(tk.LabelFrame):
|
|
|
status_button = ttk.Label(item_frame, text="@", width=3, anchor="center", relief="groove")
|
|
status_button = ttk.Label(item_frame, text="@", width=3, anchor="center", relief="groove")
|
|
|
status_button.pack(side="right", padx=5)
|
|
status_button.pack(side="right", padx=5)
|
|
|
|
|
|
|
|
- self.phone_items_data.append((check_var, name, status)) # 存储 CheckVar 和数据
|
|
|
|
|
|
|
+ self.phone_items_data.append((check_var, device["serial"], status)) # 存储 CheckVar 和数据
|
|
|
|
|
|
|
|
def toggle_check(self, check_var):
|
|
def toggle_check(self, check_var):
|
|
|
if check_var.get():
|
|
if check_var.get():
|
|
@@ -116,10 +120,6 @@ class LeftPanel(tk.LabelFrame):
|
|
|
"""
|
|
"""
|
|
|
动态添加数据
|
|
动态添加数据
|
|
|
"""
|
|
"""
|
|
|
- # logging.info(f"==手机信息=>{BaseControl.connect_dict}")
|
|
|
|
|
- # new_index = len(self.phone_data) + 1
|
|
|
|
|
- # new_phone = {"name": f"Tel - {new_index:02d} [New Device]", "status": "pending"}
|
|
|
|
|
- # self.phone_data.append(new_phone)
|
|
|
|
|
self._populate_list() # 重新填充列表以显示新数据
|
|
self._populate_list() # 重新填充列表以显示新数据
|
|
|
self._check_scrollable() # 添加数据后检查是否需要滚动条
|
|
self._check_scrollable() # 添加数据后检查是否需要滚动条
|
|
|
|
|
|
|
@@ -160,8 +160,9 @@ class LeftPanel(tk.LabelFrame):
|
|
|
|
|
|
|
|
|
|
|
|
|
class RightPanel(tk.Frame):
|
|
class RightPanel(tk.Frame):
|
|
|
- def __init__(self, master=None, *args, **kwargs):
|
|
|
|
|
- super().__init__(master)
|
|
|
|
|
|
|
+ def __init__(self, master=None, control: UIControl = None, *args, **kwargs):
|
|
|
|
|
+ super().__init__(master, *args, **kwargs)
|
|
|
|
|
+ self.control = control
|
|
|
self.master = master
|
|
self.master = master
|
|
|
self.create_args()
|
|
self.create_args()
|
|
|
self.create_info_ares()
|
|
self.create_info_ares()
|
|
@@ -182,19 +183,21 @@ class RightPanel(tk.Frame):
|
|
|
fieldset.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
|
|
fieldset.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
|
|
|
# fieldset.grid_columnconfigure(0, weight=1)
|
|
# fieldset.grid_columnconfigure(0, weight=1)
|
|
|
# fieldset.grid_rowconfigure(1, weight=1)
|
|
# fieldset.grid_rowconfigure(1, weight=1)
|
|
|
- name_label = ttk.Label(fieldset, text="币种:", width=5)
|
|
|
|
|
- name_label.grid(row=0, column=0, padx=5, pady=5, sticky="nw")
|
|
|
|
|
-
|
|
|
|
|
- name_val = tk.Text(fieldset, width=20, height=1.2, wrap='word')
|
|
|
|
|
- name_val.grid(row=0, column=1, padx=5, pady=5, sticky="nw")
|
|
|
|
|
- name_val.insert('1.0', 'HMSTR') # 插入文本
|
|
|
|
|
- name_val.config(state='disabled') # 再禁用
|
|
|
|
|
|
|
+ # name_label = ttk.Label(fieldset, text="币种:", width=5)
|
|
|
|
|
+ # name_label.grid(row=0, column=0, padx=5, pady=5, sticky="nw")
|
|
|
|
|
+ #
|
|
|
|
|
+ # name_val = tk.Text(fieldset, width=20, height=1.2, wrap='word')
|
|
|
|
|
+ # name_val.grid(row=0, column=1, padx=5, pady=5, sticky="nw")
|
|
|
|
|
+ # name_val.insert('1.0', 'HMSTR') # 插入文本
|
|
|
|
|
+ # name_val.config(state='disabled') # 再禁用
|
|
|
|
|
|
|
|
cmd_label = ttk.Label(fieldset, text="数量:", width=5)
|
|
cmd_label = ttk.Label(fieldset, text="数量:", width=5)
|
|
|
- cmd_label.grid(row=0, column=2, padx=5, pady=5, sticky="nw")
|
|
|
|
|
|
|
+ cmd_label.grid(row=0, column=1, padx=5, pady=5, sticky="nw")
|
|
|
|
|
|
|
|
cmd_text = tk.Text(fieldset, height=1.2, width=10, wrap='word')
|
|
cmd_text = tk.Text(fieldset, height=1.2, width=10, wrap='word')
|
|
|
- cmd_text.grid(row=0, column=3, padx=5, pady=5, sticky="nw")
|
|
|
|
|
|
|
+ cmd_text.grid(row=0, column=2, padx=5, pady=5, sticky="nw")
|
|
|
|
|
+ button1 = ttk.Button(fieldset, text="设置", command=lambda: print('----'))
|
|
|
|
|
+ button1.grid(row=0, column=3, padx=2, pady=(5, 2), sticky="ew")
|
|
|
|
|
|
|
|
def create_info_ares(self):
|
|
def create_info_ares(self):
|
|
|
# 创建一个 Frame 来模拟 <fieldset>
|
|
# 创建一个 Frame 来模拟 <fieldset>
|
|
@@ -202,14 +205,15 @@ class RightPanel(tk.Frame):
|
|
|
fieldset.grid(row=1, column=0, padx=10, pady=10, sticky="nsew")
|
|
fieldset.grid(row=1, column=0, padx=10, pady=10, sticky="nsew")
|
|
|
|
|
|
|
|
# 设置 fieldset 的网格权重配置
|
|
# 设置 fieldset 的网格权重配置
|
|
|
- fieldset.grid_columnconfigure(0, weight=3) # 让信息区域占据更多水平空间
|
|
|
|
|
- fieldset.grid_columnconfigure(1, weight=1) # 操作区域占据较少水平空间
|
|
|
|
|
|
|
+ fieldset.grid_columnconfigure(1, weight=3) # 让信息区域占据更多水平空间
|
|
|
|
|
+ fieldset.grid_columnconfigure(0, weight=1) # 操作区域占据较少水平空间
|
|
|
fieldset.grid_rowconfigure(0, weight=1) # 让内容区域可以垂直扩展
|
|
fieldset.grid_rowconfigure(0, weight=1) # 让内容区域可以垂直扩展
|
|
|
|
|
|
|
|
fieldset_action = ttk.LabelFrame(fieldset, text="操作")
|
|
fieldset_action = ttk.LabelFrame(fieldset, text="操作")
|
|
|
- fieldset_action.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
|
|
|
|
|
|
|
+ fieldset_action.grid(row=0, column=0, padx=10, pady=10, sticky="new")
|
|
|
|
|
+ # 设置列权重使按钮平分宽度
|
|
|
fieldset_action.grid_columnconfigure(0, weight=1)
|
|
fieldset_action.grid_columnconfigure(0, weight=1)
|
|
|
- fieldset_action.grid_rowconfigure(1, weight=1)
|
|
|
|
|
|
|
+ fieldset_action.grid_columnconfigure(1, weight=1)
|
|
|
|
|
|
|
|
fieldset_log = ttk.LabelFrame(fieldset, text="操作日志")
|
|
fieldset_log = ttk.LabelFrame(fieldset, text="操作日志")
|
|
|
fieldset_log.grid(row=0, column=1, padx=10, pady=10, sticky="nsew")
|
|
fieldset_log.grid(row=0, column=1, padx=10, pady=10, sticky="nsew")
|
|
@@ -241,19 +245,20 @@ class RightPanel(tk.Frame):
|
|
|
|
|
|
|
|
gray_btn_style = ttk.Style()
|
|
gray_btn_style = ttk.Style()
|
|
|
gray_btn_style.configure('Gray.TButton', background='#888888', foreground='#666666')
|
|
gray_btn_style.configure('Gray.TButton', background='#888888', foreground='#666666')
|
|
|
- button1 = ttk.Button(fieldset_action, text="买入/开多", command=lambda: print("买入/开多"), style='Green.TButton')
|
|
|
|
|
- button1.grid(row=0, column=0, padx=5, pady=5, sticky="nw")
|
|
|
|
|
-
|
|
|
|
|
- button2 = ttk.Button(fieldset_action, text="买入/平多", command=lambda: print("买入/平多"), style='Green.TButton')
|
|
|
|
|
- button2.grid(row=0, column=1, padx=5, pady=5, sticky="nw")
|
|
|
|
|
|
|
+ button1 = ttk.Button(fieldset_action, text="买入/开多", command=lambda: self.control.event_2(),
|
|
|
|
|
+ style='Green.TButton')
|
|
|
|
|
+ button1.grid(row=0, column=0, padx=2, pady=(5, 2), sticky="ew")
|
|
|
|
|
+ button2 = ttk.Button(fieldset_action, text="买入/平多", command=lambda: print("买入/平多"),
|
|
|
|
|
+ style='Green.TButton')
|
|
|
|
|
+ button2.grid(row=0, column=1, padx=2, pady=(5, 2), sticky="ew")
|
|
|
button3 = ttk.Button(fieldset_action, text="卖出/开空", command=lambda: print("卖出/开空"), style='Red.TButton')
|
|
button3 = ttk.Button(fieldset_action, text="卖出/开空", command=lambda: print("卖出/开空"), style='Red.TButton')
|
|
|
- button3.grid(row=1, column=0, padx=5, pady=5, sticky="nw")
|
|
|
|
|
|
|
+ button3.grid(row=1, column=0, padx=2, pady=2, sticky="ew")
|
|
|
button4 = ttk.Button(fieldset_action, text="卖出/平空", command=lambda: print("卖出/平空"), style='Red.TButton')
|
|
button4 = ttk.Button(fieldset_action, text="卖出/平空", command=lambda: print("卖出/平空"), style='Red.TButton')
|
|
|
- button4.grid(row=1, column=1, padx=5, pady=5, sticky="nw")
|
|
|
|
|
|
|
+ button4.grid(row=1, column=1, padx=2, pady=2, sticky="ew")
|
|
|
button5 = ttk.Button(fieldset_action, text="撤销委托", command=lambda: print("撤销委托"))
|
|
button5 = ttk.Button(fieldset_action, text="撤销委托", command=lambda: print("撤销委托"))
|
|
|
- button5.grid(row=2, column=0, padx=5, pady=5, sticky="nw")
|
|
|
|
|
|
|
+ button5.grid(row=2, column=0, padx=2, pady=(2, 5), sticky="ew")
|
|
|
button6 = ttk.Button(fieldset_action, text="一键撤单", command=lambda: print("一键撤单"))
|
|
button6 = ttk.Button(fieldset_action, text="一键撤单", command=lambda: print("一键撤单"))
|
|
|
- button6.grid(row=2, column=1, padx=5, pady=5, sticky="nw")
|
|
|
|
|
|
|
+ button6.grid(row=2, column=1, padx=2, pady=(2, 5), sticky="ew")
|
|
|
|
|
|
|
|
|
|
|
|
|
class PhoneListUI(tk.Frame):
|
|
class PhoneListUI(tk.Frame):
|
|
@@ -261,15 +266,15 @@ class PhoneListUI(tk.Frame):
|
|
|
手机列表控制页面
|
|
手机列表控制页面
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
- def __init__(self, control: BaseControl = None, master=None, cnf=None, **kw):
|
|
|
|
|
|
|
+ def __init__(self, control: UIControl = None, master=None, cnf=None, **kw):
|
|
|
super().__init__(master, cnf if cnf is not None else {}, **kw)
|
|
super().__init__(master, cnf if cnf is not None else {}, **kw)
|
|
|
self.control = control
|
|
self.control = control
|
|
|
self.init_ui()
|
|
self.init_ui()
|
|
|
|
|
|
|
|
def init_ui(self):
|
|
def init_ui(self):
|
|
|
- left_panel = LeftPanel(self)
|
|
|
|
|
|
|
+ left_panel = LeftPanel(self, control=self.control)
|
|
|
left_panel.pack(side="left", fill="y")
|
|
left_panel.pack(side="left", fill="y")
|
|
|
|
|
|
|
|
# 为了演示,我们创建一个简单的右侧区域
|
|
# 为了演示,我们创建一个简单的右侧区域
|
|
|
- right_panel = RightPanel(self, width=400, height=400)
|
|
|
|
|
|
|
+ right_panel = RightPanel(self, width=400, height=400, control=self.control)
|
|
|
right_panel.pack(side="left", fill="both", expand=True)
|
|
right_panel.pack(side="left", fill="both", expand=True)
|