-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtabModSelection.py
More file actions
180 lines (151 loc) · 7 KB
/
tabModSelection.py
File metadata and controls
180 lines (151 loc) · 7 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"""
Tab that lists car and track folders. User selects and adds them to a list
which is written to a data file for ModMaker.bat
"""
# Python 3
import os
import tkinter as tk
from tkinter import ttk
from data.rFactoryConfig import rF2root
from data.utils import getListOfFiles
_main = False # True if this is running standalone
#########################
# The tab's public class:
#########################
class Tab:
def __init__(self, parentFrame):
""" Put this into the parent frame """
self.settings = {}
self.vars = {}
xPadding = 10
#############################################
vehicles_path = os.path.join(rF2root, 'Installed', 'Vehicles')
vehicles = getListOfFiles(vehicles_path, pattern='*')
tkFrame_vehicles = tk.LabelFrame(
parentFrame, text='Vehicles', padx=xPadding)
tkFrame_vehicles.grid(column=0, row=0, sticky='ew')
# find the widest
v = [x[1] for x in vehicles]
w = max(v, key=len)
self.tkVehicleListbox = tk.Listbox(tkFrame_vehicles,
selectmode=tk.EXTENDED,
width=len(w) - 2,
height=min(20, len(vehicles))
)
self.tkVehicleListbox.grid(rowspan=2)
#
tkVehicleScrollbar = tk.Scrollbar(tkFrame_vehicles, orient="vertical")
tkVehicleScrollbar.config(command=self.tkVehicleListbox.yview)
tkVehicleScrollbar.grid(column=1, row=0, sticky='ns', rowspan=2)
for __, _v in vehicles:
self.tkVehicleListbox.insert(tk.END, _v)
self.tkVehicleListbox.activate(1)
if _main:
# Double click selects the server
self.tkVehicleListbox.bind("<Double-Button-1>", self.copy_vehicles)
############################################
tk.Button(tkFrame_vehicles, text="=>", command=self.copy_vehicles).\
grid(column=2, row=0, pady=20, padx=xPadding)
tk.Button(tkFrame_vehicles, text="<=", command=self.uncopy_vehicles).\
grid(column=2, row=1, pady=20, padx=xPadding)
#############################################
self.tkSelectedVehicleListbox = tk.Listbox(tkFrame_vehicles,
selectmode=tk.EXTENDED,
width=20,
height=min(
20, len(vehicles))
)
self.tkSelectedVehicleListbox.grid(column=3, row=0, rowspan=2)
#############################################
#############################################
locations_path = os.path.join(rF2root, 'Installed', 'Locations')
locations = getListOfFiles(locations_path, pattern='*')
tkFrame_locations = tk.LabelFrame(
parentFrame, text='Locations', padx=xPadding)
tkFrame_locations.grid(column=2, row=0, sticky='ew')
# find the widest
l = [x[1] for x in locations]
w = max(l, key=len)
self.tkLocationListbox = tk.Listbox(tkFrame_locations,
selectmode=tk.EXTENDED,
width=len(w) - 2,
height=min(20, len(locations))
)
self.tkLocationListbox.grid(rowspan=2)
#
tkLocationScrollbar = tk.Scrollbar(
tkFrame_locations, orient="vertical")
tkLocationScrollbar.config(command=self.tkLocationListbox.yview)
tkLocationScrollbar.grid(column=1, row=0, sticky='ns', rowspan=2)
for __, _v in locations:
self.tkLocationListbox.insert(tk.END, _v)
self.tkLocationListbox.activate(1)
if _main:
# Double click selects the server
self.tkLocationListbox.bind(
"<Double-Button-1>", self.copy_locations)
############################################
tk.Button(tkFrame_locations, text="=>", command=self.copy_locations).\
grid(column=2, row=0, pady=20, padx=xPadding)
tk.Button(
tkFrame_locations,
text="<=",
command=self.uncopy_locations). grid(
column=2,
row=1,
pady=20,
padx=xPadding)
#############################################
self.tkSelectedLocationListbox = tk.Listbox(tkFrame_locations,
selectmode=tk.EXTENDED,
width=20,
height=min(
20, len(locations))
)
self.tkSelectedLocationListbox.grid(column=3, row=0, rowspan=2)
def copy_vehicles(self, __=None):
""" Copy selected to selection window """
vehicles = [self.tkVehicleListbox.get(
i) for i in self.tkVehicleListbox.curselection()]
for _v in vehicles:
self.tkSelectedVehicleListbox.insert(tk.END, _v)
def uncopy_vehicles(self, __=None):
""" Remove selected from selection window """
[self.tkSelectedVehicleListbox.delete(i) for i in reversed(
self.tkSelectedVehicleListbox.curselection())]
def copy_locations(self, __=None):
""" Copy selected to selection window """
locations = [self.tkLocationListbox.get(
i) for i in self.tkLocationListbox.curselection()]
for _v in locations:
self.tkSelectedLocationListbox.insert(tk.END, _v)
def uncopy_locations(self, __=None):
""" Remove selected from selection window """
[self.tkSelectedLocationListbox.delete(i) for i in reversed(
self.tkSelectedLocationListbox.curselection())]
def getSettings(self):
""" Return the settings for this tab """
modSelection = dict()
modSelection['cars'] = self.tkSelectedVehicleListbox.get(0, tk.END)
modSelection['tracks'] = self.tkSelectedLocationListbox.get(0, tk.END)
return modSelection
def setSettings(self, settings):
""" Set the settings for this tab """
# Clear the list boxes
self.tkSelectedVehicleListbox.delete(0, tk.END)
self.tkSelectedLocationListbox.delete(0, tk.END)
# Then load them
for car in settings['cars']:
self.tkSelectedVehicleListbox.insert(tk.END, car)
for track in settings['tracks']:
self.tkSelectedLocationListbox.insert(tk.END, track)
if __name__ == '__main__':
# To run this tab by itself for development
_main = True
root = tk.Tk()
tabModSelection = ttk.Frame(
root, width=1200, height=1200, relief='sunken', borderwidth=5)
tabModSelection.grid()
o_tab = Tab(tabModSelection)
root.mainloop()
o_tab.getSettings()