Skip to content

Commit c210381

Browse files
committed
add basic properties editor and fix minor problems and syntax
1 parent 67755d0 commit c210381

File tree

7 files changed

+234
-121
lines changed

7 files changed

+234
-121
lines changed

readme.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ WNDEdit/
5050

5151
7. **window/line_iterator.py**: Allows line-by-line iteration through the WND file, including a line counter and filename.
5252

53-
8. **window/window.py**: Processes a single window structure from the WND file, creating objects with window properties (Config).
53+
8. **window/window.py**: Processes a single window structure from the WND file, creating objects with window properties (WindowProperties).
5454

5555
9. **window/wnd_parser.py**: A processing file that parses a WND file and returns an object representing the window hierarchy.
5656

@@ -62,11 +62,11 @@ A WND file is a simple text file containing UI settings for the game. Here's an
6262
WINDOW
6363
WINDOWTYPE = USER
6464
NAME = "dummy"
65-
... rest of window options
65+
... rest of window properties
6666
CHILD
6767
WINDOW ; child
6868
WINDOWTYPE = CHECKBOX
69-
... rest of window child options
69+
... rest of window child properties
7070
END
7171
ENDALLCHILDREN
7272
END
@@ -87,25 +87,25 @@ parser = {
8787
'windows': [
8888
Window(
8989
key=uuid1, # Random UUID for each window
90-
options={'OPTION1': 'value1', 'OPTION2': 'value2'},
90+
properties={'OPTION1': 'value1', 'OPTION2': 'value2'},
9191
children=[
9292
Window(
9393
key=uuid2,
94-
options={'OPTION1': 'value1', 'OPTION2': 'value2'},
94+
properties={'OPTION1': 'value1', 'OPTION2': 'value2'},
9595
children=[]
9696
),
9797
Window(
9898
key=uuid3,
99-
options={'OPTION3': 'value3'},
99+
properties={'OPTION3': 'value3'},
100100
children=[]
101101
),
102102
Window(
103103
key=uuid4,
104-
options={'OPTION4': 'value4'},
104+
properties={'OPTION4': 'value4'},
105105
children=[
106106
Window(
107107
key=uuid5,
108-
options={'OPTION5': 'value5'},
108+
properties={'OPTION5': 'value5'},
109109
children=[]
110110
)
111111
]

resources/hierarchy.txt

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
WINDOW
22
WINDOWTYPE = USER
33
NAME = "dummy"
4-
... rest of window options
4+
... rest of window properties
55
CHILD
66
WINDOW ; child
77
WINDOWTYPE = CHEAKBOX;
8-
... rest of window child options
8+
... rest of window child properties
99
END
1010
ENDALLCHILDREN
1111
END
@@ -21,33 +21,60 @@ NAME
2121

2222

2323

24-
Window Key: uud
25-
Options: {'OPTION1': 'value1', 'OPTION2': 'value2'}
26-
Children: [
27-
Window Key: uud
28-
Options: {'OPTION1': 'value1', 'OPTION2': 'value2'}
29-
Children: []
30-
31-
Window Key: uud
32-
Options: {'OPTION3': 'value3'}
33-
Children: []
34-
35-
Window Key: uud
36-
Options: {'OPTION4': 'value4'}
37-
Children: [
38-
Window Key: uud
39-
Options: {'OPTION5': 'value5'}
40-
Children: []
24+
parser = {
25+
'file_metadata': {
26+
'FILE_VERSION': 'num',
27+
'LAYOUTBLOCK': {
28+
'LAYOUTINIT': 'value',
29+
'LAYOUTSHUTDOWN': 'value',
30+
'LAYOUTUPDATE': 'value'
31+
}
32+
},
33+
'windows': [
34+
Window(
35+
KEY=uuid1,
36+
properties=WindowProperties(
37+
WINDOWTYPE="BUTTON",
38+
SCREENRECT={"x": 100, "y": 150, "width": 200, "height": 50},
39+
NAME="Button1",
40+
STATUS=["ENABLED"],
41+
STYLE=["MOUSETRACK"],
42+
SYSTEMCALLBACK="OnClick",
43+
INPUTCALLBACK="OnKeyPress",
44+
TOOLTIPCALLBACK="OnTooltip",
45+
DRAWCALLBACK="OnDraw",
46+
FONT={"name": "Arial", "size": 12, "bold": 1},
47+
HEADERTEMPLATE="Header1",
48+
TOOLTIPTEXT="Click me",
49+
TOOLTIPDELAY=1000,
50+
TEXT="Click me",
51+
TEXTCOLOR={"r": 255, "g": 255, "b": 255},
52+
ENABLEDDRAWDATA=["data1", "data2"],
53+
DISABLEDDRAWDATA=["data3", "data4"],
54+
HILITEDRAWDATA={"color": "red"},
55+
properties_fields={}
56+
),
57+
CHILDREN=[
58+
Window(
59+
KEY=uuid2,
60+
properties=WindowProperties(
61+
WINDOWTYPE="TEXTBOX",
62+
SCREENRECT={"x": 120, "y": 200, "width": 300, "height": 40},
63+
# rest of properties
64+
),
65+
CHILDREN=[]
66+
)
67+
]
68+
)
4169
]
42-
]
4370

4471

4572
# # Example usage:
4673
# # Assuming 'parser' is an instance of ConfigParser
47-
# # and has already parsed your config string
74+
# # and has already parsed your window_properties string
4875
# # Example usage:
4976
# # Assuming 'parser' is an instance of ConfigParser
50-
# # and has already parsed your config string
77+
# # and has already parsed your window_properties string
5178
# config_string = """
5279
# WINDOW
5380
# WINDOWTYPE = USER
@@ -71,12 +98,12 @@ Children: [
7198
# WINDOW
7299
# WINDOWTYPE = USER
73100
# NAME = "dummy"
74-
# ... rest of window options
101+
# ... rest of window properties
75102
# CHILD
76103
# WINDOW ; child
77104
# WINDOWTYPE = CHEAKBOX;
78105
# NAME = "checkbox2"
79-
# ... rest of window child options
106+
# ... rest of window child properties
80107
# END
81108
# ENDALLCHILDREN
82109
# END
@@ -85,33 +112,52 @@ Children: [
85112
# config_string_3 = """
86113
# WINDOW
87114
# NAME = "root"
88-
# Options: {'OPTION1': 'value1', 'OPTION2': 'value2'}
115+
# properties: {'OPTION1': 'value1', 'OPTION2': 'value2'}
89116
# CHILD
90117
# WINDOW
91118
# NAME = "child1"
92-
# Options: {'OPTION1': 'value1', 'OPTION2': 'value2'}
119+
# properties: {'OPTION1': 'value1', 'OPTION2': 'value2'}
93120
# CHILD
94121
# WINDOW
95122
# NAME = "child1child1"
96-
# Options: {'OPTION5': 'value5'}
123+
# properties: {'OPTION5': 'value5'}
97124
# END
98125
# ENDALLCHILDREN
99126
#
100127
# WINDOW
101128
# NAME = "child2"
102-
# Options: {'OPTION3': 'value3'}
129+
# properties: {'OPTION3': 'value3'}
103130
# END
104131
# CHILD
105132
# WINDOW
106133
# NAME = "child3"
107-
# Options: {'OPTION4': 'value4'}
134+
# properties: {'OPTION4': 'value4'}
108135
# CHILD
109136
# WINDOW
110137
# NAME = "child3child1"
111-
# Options: {'OPTION5': 'value5'}
138+
# properties: {'OPTION5': 'value5'}
112139
# END
113140
# END
114141
# ENDALLCHILDREN
115142
# END
116143
# """
117144

145+
146+
מבנה תיקיות וקבצים
147+
148+
WNDEdit\logs\log_current.log
149+
WNDEdit\logs\log_current_old.log
150+
WNDEdit\resources\window_properties.py
151+
WNDEdit\resources\example.wnd
152+
WNDEdit\resources\styles.qss
153+
WNDEdit\src\error_handler.py
154+
WNDEdit\src\file_tree.py
155+
WNDEdit\src\log_manager.py
156+
WNDEdit\src\main.py
157+
WNDEdit\src\object_tree.py
158+
WNDEdit\src\property_editor.py
159+
WNDEdit\src\window\line_iterator.py
160+
WNDEdit\src\window\window.py
161+
WNDEdit\src\window\wnd_parser.py
162+
163+

src/main.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from object_tree import ObjectTree
1010
from file_tree import FileTree
11+
from property_editor import PropertyEditor
1112
from src.window.wnd_parser import WndParser
1213
from log_manager import LogManager
1314

@@ -79,8 +80,8 @@ def __init__(self):
7980
# Connect the object selected signal to the update function
8081
self.object_tree.object_selected_signal.connect(self.select_object)
8182

82-
# Property Editor (for window details)
83-
self.property_editor = QTableView()
83+
# Property Editor (for object details)
84+
self.property_editor = PropertyEditor(self)
8485
self.property_editor.setMinimumWidth(300)
8586

8687
# Toggle Buttons for object tree and property editor
@@ -124,18 +125,19 @@ def __init__(self):
124125

125126
# Enable drag and drop
126127
self.setAcceptDrops(True)
127-
def select_object(self, obj_name):
128+
def select_object(self, window_object):
128129
"""Handles selection of an object from the object tree"""
129-
self.selected_object = obj_name
130+
self.selected_object = window_object
130131
self.update_status_bar() # Update status bar with selected object
131-
132+
self.load_object_property()
132133
# Log the selected object
133-
self.log_manager.log(f"Object selected: {obj_name}", level="INFO")
134+
if self.selected_object:
135+
self.log_manager.log(f"Object selected: {window_object.properties.get('WINDOWTYPE')} - {window_object.properties.get('NAME', 'Unnamed')}", level="INFO")
134136

135137
def select_file(self, file_path):
136138
"""Handles selection of a file from the file tree"""
137139
self.selected_file = file_path
138-
self.selected_object = None # Reset the selected object when a new file is selected
140+
# self.selected_object = None # Reset the selected object when a new file is selected
139141
self.update_status_bar() # Update status bar with selected file
140142

141143
# Log the selected file
@@ -204,8 +206,11 @@ def update_status_bar(self):
204206
file_name = "Folder selected"
205207

206208
if hasattr(self, 'selected_object') and self.selected_object:
207-
object_name = f"Object: {self.selected_object}"
208-
209+
# Show the name of the selected object in the status bar
210+
try:
211+
object_name = f"Object: {self.selected_object.properties.get('WINDOWTYPE')} - {self.selected_object.properties.get('NAME', 'Unnamed')}"
212+
except AttributeError:
213+
object_name = f"{str(self.selected_object)}"
209214
# Combine all information
210215
status_text = f"{root_path_info} | {file_name} | {object_name}"
211216

@@ -271,9 +276,22 @@ def load_wnd_file(self, file_path):
271276
error_message = f"Error loading file: {e}"
272277
self.log_manager.log(error_message, level="ERROR")
273278
self.object_tree.display_error(error_message)
279+
self.selected_object = error_message
280+
self.update_status_bar()
274281

275282

283+
def load_object_property(self):
284+
"""Loads and parses the WND file, and displays the object tree."""
285+
if self.selected_object:
286+
try:
287+
# Load the windows into the object tree
288+
self.property_editor.load_property(self.selected_object.properties)
289+
self.log_manager.log(f"Loaded properties from object {self.selected_object.properties.get('WINDOWTYPE')} - {self.selected_object.properties.get('NAME', 'Unnamed')}", level="INFO")
276290

291+
except ValueError as e:
292+
error_message = f"Error loading object: {e}"
293+
self.log_manager.log(error_message, level="ERROR")
294+
self.property_editor.display_error(error_message)
277295

278296
def open_folder(self):
279297
"""Handle opening a folder"""
@@ -283,6 +301,7 @@ def open_folder(self):
283301
self.file_tree.set_root_path(folder)
284302
self.selected_file = None # Reset the selected file when a folder is selected
285303
self.selected_object = None # Reset the selected object as well
304+
self.property_editor.property_model.clear()
286305
self.update_status_bar() # Update status bar
287306

288307
def handle_exception(self, exc_type, exc_value, exc_tb):

src/object_tree.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
class ObjectTree(QTreeView):
8-
# Define a new signal to notify MainWindow when an object is selected
9-
object_selected_signal = pyqtSignal(str)
8+
# Signal to notify when an object is selected
9+
object_selected_signal = pyqtSignal(object)
1010

1111
def __init__(self, parent=None):
1212
super().__init__(parent)
@@ -18,10 +18,7 @@ def __init__(self, parent=None):
1818
self.selectionModel().selectionChanged.connect(self.on_item_selected)
1919

2020
def load_objects(self, windows):
21-
"""
22-
Load windows into the tree view.
23-
:param windows: List of Window objects to display in the tree.
24-
"""
21+
"""Load the windows into the tree view."""
2522
self.model.clear()
2623
self._populate_tree(windows, self.model)
2724

@@ -32,7 +29,8 @@ def _populate_tree(self, windows, parent_item):
3229
:param parent_item: Parent item in the tree to append items
3330
"""
3431
for window in windows:
35-
item = QStandardItem(f"{window.options.get('WINDOWTYPE')} - {window.options.get('NAME', 'Unnamed')}")
32+
item = QStandardItem(f"{window.properties.get('WINDOWTYPE')} - {window.properties.get('NAME', 'Unnamed')}")
33+
item.setData(window)
3634
parent_item.appendRow(item)
3735
if window.children:
3836
self._populate_tree(window.children, item)
@@ -43,12 +41,10 @@ def on_item_selected(self, selected, deselected):
4341
"""
4442
selected_indexes = self.selectedIndexes()
4543
if selected_indexes:
46-
# Get the selected item and extract its text
44+
# Get the selected item
4745
selected_item = self.model.itemFromIndex(selected_indexes[0])
48-
selected_object_name = selected_item.text()
49-
50-
# Emit the signal to notify MainWindow of the selected object
51-
self.object_selected_signal.emit(selected_object_name)
46+
selected_object = selected_item.data()
47+
self.object_selected_signal.emit(selected_object)
5248

5349
def display_error(self, error_message):
5450
"""

0 commit comments

Comments
 (0)