added _MEIPASS to read xpm/rgb for pyinstaller

This commit is contained in:
Fredrick W. Warren 2025-03-09 21:40:26 -06:00
parent f45f25dd9d
commit 16ca19db37

View File

@ -26,7 +26,7 @@ Some changes to handle the additional event handling in pywmgeneral
First workingish version
"""
import os, re
import os, re, sys
import configparser
charset_start = None
@ -145,7 +145,13 @@ def readXPM(fileName):
Raise IOError if we run into trouble when trying to read the file. This
function has not been tested extensively. do not try to use more than
"""
with open(fileName, 'r') as f:
if hasattr(sys, '_MEIPASS'):
base_path = os.path.join(sys._MEIPASS, "wmdocklib")
else:
base_path = "wmdocklib"
filePath = os.path.join(base_path, fileName)
with open(filePath, 'r') as f:
lines = [l.rstrip('\n') for l in f.readlines()]
s = ''.join(lines)
res = []
@ -436,7 +442,13 @@ def getColorCode(colorName, rgbFileName=None):
if rgbFileName is None:
raise ValueError('cannot find rgb file')
with open(rgbFileName, 'r') as f:
if hasattr(sys, '_MEIPASS'):
base_path = os.path.join(sys._MEIPASS, "wmdocklib")
else:
base_path = "wmdocklib"
rgbFilePath = os.path.join(base_path, rgbFileName)
with open(rgbFilePath, 'r') as f:
lines = f.readlines()
for l in lines:
if l[0] != '!':