Skip to content

Commit 013c054

Browse files
authored
Add WIP macOS support to the converter (#10)
* [Converter] minor formatting and added requirements.txt for easier setup * [Converter] Fix path operations being hardcoded for windows * [Converter] Add icon files for macOS .app * [Converter] avoid an empty Tk window * [Converter] fix multiprocessing for frozen builds — This should already have been there on windows (https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html#multi-processing) Use proper resourcesPath for macOS frozen builds * [Converter] Updated pyinstaller build command for macOS * [Converter] Update PyInstaller command for packaging macOS app * [Converter] macOS fixed non frozen version not finding its config * Revert "[Converter] minor formatting This reverts commit 231bdc0.
1 parent 4b3c8c6 commit 013c054

6 files changed

Lines changed: 92 additions & 10 deletions

File tree

Converter/Sequence_Converter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def convert_model(self, file):
130130
splitted_file.pop() # We remove the last element, which is the file ending
131131
file_name = ''.join(splitted_file)
132132

133-
inputfile = self.convertSettings.inputPath + "\\"+ file
134-
outputfile = self.convertSettings.outputPath + "\\" + file_name + ".ply"
133+
inputfile = os.path.join(self.convertSettings.inputPath, file)
134+
outputfile = os.path.join(self.convertSettings.outputPath, file_name + ".ply")
135135

136136
ms = ml.MeshSet()
137137

@@ -420,13 +420,13 @@ def convert_image(self, file):
420420
file_name = splitted_file[0]
421421
for x in range(1, len(splitted_file) - 1):
422422
file_name += "." + splitted_file[x]
423-
inputfile = self.convertSettings.inputPath + "\\"+ file
423+
inputfile = os.path.join(self.convertSettings.inputPath, file)
424424

425425
sizeDDS = 0
426426
sizeASTC = 0
427427

428428
if(self.convertSettings.convertToDDS):
429-
outputfileDDS = self.convertSettings.outputPath + "\\" + file_name + ".dds"
429+
outputfileDDS = os.path.join(self.convertSettings.outputPath, file_name + ".dds")
430430
cmd = self.convertSettings.resourcePath + "texconv " + "\"" + inputfile + "\"" + " -o " + "\"" + self.convertSettings.outputPath + "\"" +" -m 1 -f DXT1 -y -nologo"
431431
if(self.convertSettings.convertToSRGB):
432432
cmd += " -srgbo"
@@ -435,7 +435,7 @@ def convert_image(self, file):
435435
return
436436

437437
if(self.convertSettings.convertToASTC):
438-
outputfileASCT = self.convertSettings.outputPath + "\\" + file_name + ".astc"
438+
outputfileASCT = os.path.join(self.convertSettings.outputPath, file_name + ".astc")
439439
cmd = self.convertSettings.resourcePath + "astcenc -cl " + "\"" + inputfile + "\"" + " " + "\"" + outputfileASCT + "\"" + " 6x6 -medium -silent"
440440
if(subprocess.run(cmd, stdout=open(os.devnull, 'wb')).returncode != 0):
441441
self.processFinishedCB(True, "Error converting ASTC texture: " + inputfile)

Converter/Sequence_Converter_UI.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
22
import sys
33
import re
4+
import multiprocessing
5+
if getattr(sys, 'frozen', False):
6+
multiprocessing.freeze_support() # for PyInstaller support
47
import configparser
58
from threading import Event
69
from threading import Lock
@@ -28,7 +31,9 @@ class ConverterUI:
2831
### +++++++++++++++++++++++++ PACKAGE INTO SINGLE EXECUTABLE ++++++++++++++++++++++++++++++++++
2932
#Use this prompt in the terminal to package this script into a single executable for your system
3033
#You need to have PyInstaller installed in your local environment
31-
# pyinstaller Sequence_Converter_UI.py --collect-all=pymeshlab --collect-all=numpy --icon=resources/logo.ico -F
34+
# pyinstaller Sequence_Converter_UI.py --collect-all=pymeshlab --collect-all=numpy --icon=resources/logo.ico -F
35+
### +++++++++++++++++++++++++ PACKAGE INTO SINGLE MACOS APP ++++++++++++++++++++++++++++++++++
36+
# pyinstaller Sequence_Converter_UI.py --icon=resources/logo.icns --windowed --strip
3237

3338
isRunning = False
3439
conversionFinished = False
@@ -185,10 +190,14 @@ def InitDefaultPaths(self):
185190
elif __file__:
186191
self.applicationPath = os.path.abspath(os.path.dirname(__file__))
187192

188-
self.applicationPath += "\\"
193+
self.applicationPath += os.sep
189194

190-
self.resourcesPath = self.applicationPath + "resources\\"
191-
self.configPath = self.resourcesPath + "config.ini"
195+
if (sys.platform == "darwin") and (getattr(sys, 'frozen', False)):
196+
self.resourcesPath = os.path.abspath(self.applicationPath + "../Resources/")
197+
else:
198+
self.resourcesPath = os.path.join(self.applicationPath, "resources") + os.sep
199+
200+
self.configPath = os.path.join(self.resourcesPath, "config.ini")
192201
self.config = configparser.ConfigParser()
193202

194203
def open_file_dialog(self, path):
@@ -261,7 +270,7 @@ def validate_input_files(self, input_path):
261270
def set_proposed_output_files(self, input_path):
262271

263272
if(len(self.outputSequencePath) < 1 or self.outputSequencePath == self.noPathWarning):
264-
self.proposedOutputPath = input_path + "\\converted"
273+
self.proposedOutputPath = os.path.join(input_path, "converted")
265274
self.output_path_label_set("Proposed path: " + self.proposedOutputPath)
266275

267276
def set_output_files(self, new_output_path):
@@ -513,5 +522,6 @@ def RunUI(self):
513522
dpg.destroy_context()
514523

515524
if (__name__ == '__main__'):
525+
Tk().withdraw() # make sure Tkinter is loaded before starting DearPyGUI -- e.g. https://github.com/python/cpython/issues/90731
516526
UI = ConverterUI()
517527
UI.RunUI()

Converter/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
numpy
2+
pymeshlab
3+
dearpygui
4+
pillow

Converter/resources/logo.icns

35.6 KB
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Loading
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"fill" : {
3+
"automatic-gradient" : "extended-srgb:0.00000,0.47843,1.00000,1.00000"
4+
},
5+
"groups" : [
6+
{
7+
"blur-material" : null,
8+
"layers" : [
9+
{
10+
"glass" : true,
11+
"hidden" : false,
12+
"image-name" : "logo.svg",
13+
"name" : "logo",
14+
"opacity" : 1,
15+
"position" : {
16+
"scale" : 0.54,
17+
"translation-in-points" : [
18+
0,
19+
0
20+
]
21+
}
22+
}
23+
],
24+
"lighting" : "individual",
25+
"shadow" : {
26+
"kind" : "neutral",
27+
"opacity" : 0.5
28+
},
29+
"specular" : true,
30+
"translucency" : {
31+
"enabled" : true,
32+
"value" : 0.5
33+
}
34+
}
35+
],
36+
"supported-platforms" : {
37+
"squares" : "shared"
38+
}
39+
}

0 commit comments

Comments
 (0)