-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage_setting.py
More file actions
96 lines (66 loc) · 3.5 KB
/
page_setting.py
File metadata and controls
96 lines (66 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from tkinter import *
from tkinter import ttk
import pickle
class PageSettigs(Toplevel):
"""
The PageSettigs class represents a settings page in the additional application's user interface of the main application. Contains methods to configure the relationships of the data received from serial communication with the execution of keyboard events.
Attributes:
- parent: (Parent object) The parent object that the settings page belongs to.
- labels: (list) A list to hold the labels for the settings.
- entrys: (list) A list to hold the entry fields for the settings.
- settings: (dictionary) A dictionary to hold the key settings.
Methods:
- __init__(self, parent): Initializes the settings page.
- get_settings_len(self) -> int: Returns the length of the settings.
- save_settings(self): Saves the settings to a file and updates the parent object with the new settings.
"""
def __init__(self, parent):
"""Initializes the settings page."""
super().__init__(parent)
self.title("Keyboard Settings")
self.configure(padx=20, pady=10)
self.parent = parent
self.labels:list = []
self.entrys:list = []
self.settings:dir = parent.key_Settings
# UI construction
ttk.Label(self, text="Keyboard Settings", font=("Arial", 16)).grid(row=0, column=0,columnspan=4, pady=10, padx=60)
# Settings Area
for event in list(range(1,11)):
label = ttk.Label(self,text=f"Message Received - {event}:")
label.grid(row=event, column=1, padx=10, pady=5)
self.labels.append(label)
entry = ttk.Entry(self,justify='center', width=15)
entry.insert(0,self.settings[event])
entry.grid(row=event, column=2, padx=10, pady=5)
self.entrys.append(entry)
#Save botton
ttk.Button(self,text="Save",width=50, command= self.save_settings).grid(row= 12, column=1, columnspan=2, padx=20, pady= 10)
# ttk.Button(self,text="Save",width=50, command= self.save_settings).pack(padx=20)
def on_key_edit(self,event):
selected_item = self.table.selection()[0]
self.table.item(selected_item, values=(self.table.item(selected_item, 'values')[0], event.char.upper()))
def get_settings_len(self) -> int:
"""Returns the length of the settings."""
return len(self.entrys) + 1
def save_settings(self):
"""Saves the settings to a file and updates the parent object with the new settings."""
# code save
count_settings = self.get_settings_len()
events = list(range(1,count_settings))
for event, entry in zip(events, self.entrys):
self.settings[event] = entry.get()
self.parent.key_Settings = dict(self.settings)
self.parent.rc.set_commands_event(self.settings)
with open('microlinkdata.pkl', 'wb') as file:
pickle.dump(self.parent.key_Settings, file)
self.parent.logbar.config(text="Saved keayboard actions")
self.destroy()
def edit_cell(self,event):
# Obtén el índice de la columna seleccionada
column = self.table.identify_column(event.x)
if column != '#0':
# Obtén el índice del item seleccionado
item = self.table.identify_row(event.y)
# Inicia la edición de la celda
self.table.edit_item(item, column)