Skip to content

Commit

Permalink
Adding all the build stuff to do an exe as well and the pip install s…
Browse files Browse the repository at this point in the history
…tuff. 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
  • Loading branch information
waryder committed Nov 9, 2024
1 parent 747e0ae commit 2486910
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 32 deletions.
5 changes: 1 addition & 4 deletions BBB_NMS_Save_File_Manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def global_exception_handler(exc_type, exc_value, exc_traceback):
traceback.print_exception(exc_type, exc_value, exc_traceback)

# Set the global exception handler
sys.excepthook = global_exception_handler

sys.excepthook = global_exception_handler

class MainWindow(QMainWindow):
background_processing_signal = pyqtSignal(int, str)
Expand All @@ -31,8 +30,6 @@ def __init__(self):
self.ini_file_manager = ini_file_manager
super().__init__()

#self.ini_file_manager = ini_file_manager #global

self.tabs = QTabWidget()

self.tab1 = FirstTabContent(self)
Expand Down
7 changes: 1 addition & 6 deletions CustomTreeWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,11 @@ def backup_a_base(self, item):
base_name = json_data['Name']
text_data = json.dumps(json_data, indent=4)


# Open the save file dialog
options = QFileDialog.Options()

#file_path, _ = QFileDialog.getSaveFileName(None, "Save File", base_name, "NMS Base Files (*.nms_base.json);;All Files (*)", options=options)

#mainWindow is active window; path will include the name of the last 'bases' save file at this point:
path_string = QApplication.instance().activeWindow().ini_file_manager.get_last_working_file_path()
#chop off the file_name so we have just the path:
path_string = os.path.dirname(path_string)
path_string = QApplication.instance().activeWindow().ini_file_manager.get_base_pathdir()
#assume we want to use the base name for the file name:
path_string += f"\\{base_name}"

Expand Down
25 changes: 12 additions & 13 deletions DataModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class DataModel(QObject):
def __init__(self, last_working_file_path):
logger.debug("DataModel(QObject).__init__ ENTER")
super().__init__()
self.model_data = None

#self.last_file_path = ini_file_manager.get_last_working_file_path()
self.model_data = None
self.last_file_path = last_working_file_path

logger.debug("DataModel(QObject).__init__ EXIT")
Expand Down Expand Up @@ -53,18 +51,19 @@ def init_model_data(self):
logger.debug("init_model_data() ENTER")
new_model_data = None

if self.last_file_path and os.path.exists(self.last_file_path):
# If the file exists, load its contents
try:
with open(self.last_file_path, 'r') as file:
new_model_data = json.loads(file.read())
except Exception as e:
print(f"Failed to load text from {self.last_file_path}: {e}")
new_model_data = json.loads(self.INIT_TEXT)
else:
#for now we're going to just assume start with demo data:
# if self.last_file_path and os.path.exists(self.last_file_path):
# # If the file exists, load its contents
# try:
# with open(self.last_file_path, 'r') as file:
# new_model_data = json.loads(file.read())
# except Exception as e:
# print(f"Failed to load text from {self.last_file_path}: {e}")
# new_model_data = json.loads(self.INIT_TEXT)
# else:
# Fall back to INIT_TEXT if no file path is found or the file doesn't exist
new_model_data = json.loads(self.INIT_TEXT)

new_model_data = json.loads(self.INIT_TEXT)
self.__set_self_with_json_data(new_model_data)

logger.debug("init_model_data() EXIT")
Expand Down
19 changes: 12 additions & 7 deletions IniFileManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ def __init__(self, ini_file=None):
Initializes the IniFileManager class.
:param ini_file: The path to the .ini file.
"""

# Set the ini file path to be in the same directory as the script
self.ini_file = os.path.join(os.path.dirname(__file__), ini_file)
self.base_path_dir = None
if hasattr(sys, "_MEIPASS"):
self.base_path_dir = os.path.join(sys._MEIPASS)
else:
self.base_path_dir = os.path.dirname(__file__)

self.ini_file = os.path.join(self.base_path_dir, ini_file)
self.config = configparser.ConfigParser()

#config = configparser.ConfigParser(allow_no_value=True)

# Check if ini file exists, if not create a new one
if os.path.exists(self.ini_file):
self.config.read(self.ini_file)
Expand All @@ -20,8 +25,10 @@ def __init__(self, ini_file=None):

# Initialize the working file path from the ini file if it exists
self.tab1_working_file_path = self.config.get('Preferences', 'tab1_working_file_path', fallback='')
self.tab2_working_file_path = self.config.get('Preferences', 'tab2_working_file_path', fallback='')
self.tab2_working_file_path = self.config.get('Preferences', 'tab2_working_file_path', fallback='')

def get_base_pathdir(self):
return self.base_path_dir

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

return output

return output

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

# Show a confirmation message
QMessageBox.information(QApplication.instance().activeWindow(), 'File Saved', f'File saved at: {last_file_path}')
Expand Down
12 changes: 12 additions & 0 deletions WhichStarshipsToUpgradeDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@ def __init__(self, starship_names = None):
# Create layout for checkboxes
layout = QVBoxLayout()

label = QLabel("Please do not select any custom built Starships!!\nThis upgrade method will kill them!\n")
# Make the label text bold
font = QFont()
font.setBold(True)
label.setFont(font)
label.setStyleSheet("padding-left: 10px;")
layout.addWidget(label)

# Create 12 checkboxes and add to layout
self.checkboxes = []
for index, starship_name in enumerate(self.starship_names):
checkbox = QCheckBox(f"{starship_name}")
checkbox.setProperty('starshipListIdx', index)
checkbox.setStyleSheet("padding-left: 20px;")
self.checkboxes.append(checkbox)
layout.addWidget(checkbox)

lineSpaceLabel = QLabel("")
layout.addWidget(lineSpaceLabel)

# Create OK and Cancel buttons
button_layout = QHBoxLayout()
ok_button = QPushButton("OK")
Expand Down
3 changes: 2 additions & 1 deletion app_preferences.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[Preferences]
tab2_working_file_path = C:/Users/billr/development/BBB-NMS-Save-File-Manipulator/starship_list_test.json
tab1_working_file_path = C:/Users/billr/Desktop/BBB NMS SFM Files/Main Char 1 original 10_10_24 Updated.json
tab2_working_file_path = C:/Users/billr/development/BBB-NMS-Save-File-Manipulator/starship_list_test.json


24 changes: 24 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

#make the exe:
rm -rf dist
rm -rf .venv
rm -rf build
pyinstaller --onefile --add-data "C:\MBIN_PROJECTS\Working_Projects\BBB-NMS-SFM-Project\help;help" BBB_NMS_Save_File_Manipulator.py
mv dist/BBB_NMS_Save_File_Manipulator.exe dist/$1.exe

#let's make the zip:
rm -rf build/to_be_zipped
mkdir -p build/to_be_zipped/BBB_NMS_Save_File_Manipulator
cp setup.py MANIFEST.in requirements.txt build/to_be_zipped
cp *.py build/to_be_zipped/BBB_NMS_Save_File_Manipulator
cp *.json build/to_be_zipped/BBB_NMS_Save_File_Manipulator
cp -R help build/to_be_zipped/BBB_NMS_Save_File_Manipulator

cd build/to_be_zipped
7z a ../../build/$1.zip *
cd ../..

mv build/$1.zip dist


2 changes: 1 addition & 1 deletion imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
QAbstractItemView, QDialog, QLineEdit, QInputDialog, QMenu, QHeaderView,
QPlainTextEdit, QTextBrowser)
from PyQt5.QtGui import (QClipboard, QDragEnterEvent, QDropEvent, QDragMoveEvent, QDrag, QTextCursor,
QColor, QPalette, QKeySequence)
QColor, QPalette, QKeySequence, QFont)
from PyQt5.QtCore import Qt, QThread # Import the Qt namespace
from PyQt5 import QtCore, QtGui, QtWidgets

Expand Down

0 comments on commit 2486910

Please sign in to comment.