Skip to content

Commit 2486910

Browse files
committed
Adding all the build stuff to do an exe as well and the pip install stuff. Also modded app to use the root directory on install for either install method mentioned. I think some other small bug fixes.
On branch change_tree_design_to_bases_only Your branch is up to date with 'origin/change_tree_design_to_bases_only'. Changes to be committed: modified: BBB_NMS_Save_File_Manipulator.py modified: CustomTreeWidget.py modified: DataModels.py modified: IniFileManager.py modified: WhichStarshipsToUpgradeDialog.py modified: app_preferences.ini new file: build.sh modified: imports.py
1 parent 747e0ae commit 2486910

8 files changed

+65
-32
lines changed

BBB_NMS_Save_File_Manipulator.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def global_exception_handler(exc_type, exc_value, exc_traceback):
2121
traceback.print_exception(exc_type, exc_value, exc_traceback)
2222

2323
# Set the global exception handler
24-
sys.excepthook = global_exception_handler
25-
24+
sys.excepthook = global_exception_handler
2625

2726
class MainWindow(QMainWindow):
2827
background_processing_signal = pyqtSignal(int, str)
@@ -31,8 +30,6 @@ def __init__(self):
3130
self.ini_file_manager = ini_file_manager
3231
super().__init__()
3332

34-
#self.ini_file_manager = ini_file_manager #global
35-
3633
self.tabs = QTabWidget()
3734

3835
self.tab1 = FirstTabContent(self)

CustomTreeWidget.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,11 @@ def backup_a_base(self, item):
345345
base_name = json_data['Name']
346346
text_data = json.dumps(json_data, indent=4)
347347

348-
349348
# Open the save file dialog
350349
options = QFileDialog.Options()
351350

352-
#file_path, _ = QFileDialog.getSaveFileName(None, "Save File", base_name, "NMS Base Files (*.nms_base.json);;All Files (*)", options=options)
353-
354351
#mainWindow is active window; path will include the name of the last 'bases' save file at this point:
355-
path_string = QApplication.instance().activeWindow().ini_file_manager.get_last_working_file_path()
356-
#chop off the file_name so we have just the path:
357-
path_string = os.path.dirname(path_string)
352+
path_string = QApplication.instance().activeWindow().ini_file_manager.get_base_pathdir()
358353
#assume we want to use the base name for the file name:
359354
path_string += f"\\{base_name}"
360355

DataModels.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ class DataModel(QObject):
1616
def __init__(self, last_working_file_path):
1717
logger.debug("DataModel(QObject).__init__ ENTER")
1818
super().__init__()
19-
self.model_data = None
20-
21-
#self.last_file_path = ini_file_manager.get_last_working_file_path()
19+
self.model_data = None
2220
self.last_file_path = last_working_file_path
2321

2422
logger.debug("DataModel(QObject).__init__ EXIT")
@@ -53,18 +51,19 @@ def init_model_data(self):
5351
logger.debug("init_model_data() ENTER")
5452
new_model_data = None
5553

56-
if self.last_file_path and os.path.exists(self.last_file_path):
57-
# If the file exists, load its contents
58-
try:
59-
with open(self.last_file_path, 'r') as file:
60-
new_model_data = json.loads(file.read())
61-
except Exception as e:
62-
print(f"Failed to load text from {self.last_file_path}: {e}")
63-
new_model_data = json.loads(self.INIT_TEXT)
64-
else:
54+
#for now we're going to just assume start with demo data:
55+
# if self.last_file_path and os.path.exists(self.last_file_path):
56+
# # If the file exists, load its contents
57+
# try:
58+
# with open(self.last_file_path, 'r') as file:
59+
# new_model_data = json.loads(file.read())
60+
# except Exception as e:
61+
# print(f"Failed to load text from {self.last_file_path}: {e}")
62+
# new_model_data = json.loads(self.INIT_TEXT)
63+
# else:
6564
# Fall back to INIT_TEXT if no file path is found or the file doesn't exist
66-
new_model_data = json.loads(self.INIT_TEXT)
6765

66+
new_model_data = json.loads(self.INIT_TEXT)
6867
self.__set_self_with_json_data(new_model_data)
6968

7069
logger.debug("init_model_data() EXIT")

IniFileManager.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ def __init__(self, ini_file=None):
66
Initializes the IniFileManager class.
77
:param ini_file: The path to the .ini file.
88
"""
9+
910
# Set the ini file path to be in the same directory as the script
10-
self.ini_file = os.path.join(os.path.dirname(__file__), ini_file)
11+
self.base_path_dir = None
12+
if hasattr(sys, "_MEIPASS"):
13+
self.base_path_dir = os.path.join(sys._MEIPASS)
14+
else:
15+
self.base_path_dir = os.path.dirname(__file__)
16+
17+
self.ini_file = os.path.join(self.base_path_dir, ini_file)
1118
self.config = configparser.ConfigParser()
1219

13-
#config = configparser.ConfigParser(allow_no_value=True)
14-
1520
# Check if ini file exists, if not create a new one
1621
if os.path.exists(self.ini_file):
1722
self.config.read(self.ini_file)
@@ -20,8 +25,10 @@ def __init__(self, ini_file=None):
2025

2126
# Initialize the working file path from the ini file if it exists
2227
self.tab1_working_file_path = self.config.get('Preferences', 'tab1_working_file_path', fallback='')
23-
self.tab2_working_file_path = self.config.get('Preferences', 'tab2_working_file_path', fallback='')
28+
self.tab2_working_file_path = self.config.get('Preferences', 'tab2_working_file_path', fallback='')
2429

30+
def get_base_pathdir(self):
31+
return self.base_path_dir
2532

2633
def create_empty_ini_file(self):
2734
"""Creates an empty ini file if it doesn't exist."""
@@ -142,8 +149,7 @@ def open_file(self, tab):
142149
except Exception as e:
143150
QMessageBox.critical(QApplication.instance().activeWindow(), "Error", f"Failed to open file: {e}")
144151

145-
return output
146-
152+
return output
147153

148154
def save_file(self, tab, data):
149155
"""Saves the file using the last saved path, or prompts if no path is set."""
@@ -160,7 +166,6 @@ def save_file(self, tab, data):
160166
try:
161167
with open(last_file_path, 'w') as f:
162168
f.write(data)
163-
#f.write(self.model.get_text())
164169

165170
# Show a confirmation message
166171
QMessageBox.information(QApplication.instance().activeWindow(), 'File Saved', f'File saved at: {last_file_path}')

WhichStarshipsToUpgradeDialog.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,26 @@ def __init__(self, starship_names = None):
1717
# Create layout for checkboxes
1818
layout = QVBoxLayout()
1919

20+
label = QLabel("Please do not select any custom built Starships!!\nThis upgrade method will kill them!\n")
21+
# Make the label text bold
22+
font = QFont()
23+
font.setBold(True)
24+
label.setFont(font)
25+
label.setStyleSheet("padding-left: 10px;")
26+
layout.addWidget(label)
27+
2028
# Create 12 checkboxes and add to layout
2129
self.checkboxes = []
2230
for index, starship_name in enumerate(self.starship_names):
2331
checkbox = QCheckBox(f"{starship_name}")
2432
checkbox.setProperty('starshipListIdx', index)
33+
checkbox.setStyleSheet("padding-left: 20px;")
2534
self.checkboxes.append(checkbox)
2635
layout.addWidget(checkbox)
2736

37+
lineSpaceLabel = QLabel("")
38+
layout.addWidget(lineSpaceLabel)
39+
2840
# Create OK and Cancel buttons
2941
button_layout = QHBoxLayout()
3042
ok_button = QPushButton("OK")

app_preferences.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[Preferences]
2-
tab2_working_file_path = C:/Users/billr/development/BBB-NMS-Save-File-Manipulator/starship_list_test.json
32
tab1_working_file_path = C:/Users/billr/Desktop/BBB NMS SFM Files/Main Char 1 original 10_10_24 Updated.json
3+
tab2_working_file_path = C:/Users/billr/development/BBB-NMS-Save-File-Manipulator/starship_list_test.json
4+
45

build.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
#make the exe:
4+
rm -rf dist
5+
rm -rf .venv
6+
rm -rf build
7+
pyinstaller --onefile --add-data "C:\MBIN_PROJECTS\Working_Projects\BBB-NMS-SFM-Project\help;help" BBB_NMS_Save_File_Manipulator.py
8+
mv dist/BBB_NMS_Save_File_Manipulator.exe dist/$1.exe
9+
10+
#let's make the zip:
11+
rm -rf build/to_be_zipped
12+
mkdir -p build/to_be_zipped/BBB_NMS_Save_File_Manipulator
13+
cp setup.py MANIFEST.in requirements.txt build/to_be_zipped
14+
cp *.py build/to_be_zipped/BBB_NMS_Save_File_Manipulator
15+
cp *.json build/to_be_zipped/BBB_NMS_Save_File_Manipulator
16+
cp -R help build/to_be_zipped/BBB_NMS_Save_File_Manipulator
17+
18+
cd build/to_be_zipped
19+
7z a ../../build/$1.zip *
20+
cd ../..
21+
22+
mv build/$1.zip dist
23+
24+

imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
QAbstractItemView, QDialog, QLineEdit, QInputDialog, QMenu, QHeaderView,
88
QPlainTextEdit, QTextBrowser)
99
from PyQt5.QtGui import (QClipboard, QDragEnterEvent, QDropEvent, QDragMoveEvent, QDrag, QTextCursor,
10-
QColor, QPalette, QKeySequence)
10+
QColor, QPalette, QKeySequence, QFont)
1111
from PyQt5.QtCore import Qt, QThread # Import the Qt namespace
1212
from PyQt5 import QtCore, QtGui, QtWidgets
1313

0 commit comments

Comments
 (0)