|
14 | 14 | ############################################################################## |
15 | 15 | """This module contains global parameters needed by PDFgui.""" |
16 | 16 |
|
17 | | -import os.path |
18 | 17 | from importlib.resources import files |
| 18 | +from pathlib import Path |
19 | 19 |
|
20 | 20 | from diffpy.pdfgui.gui import debugoptions |
21 | 21 |
|
|
24 | 24 | # Maximum number of files to be remembered |
25 | 25 | MAXMRU = 5 |
26 | 26 | # The location of the configuration file |
27 | | -configfilename = os.path.expanduser("~/.pdfgui_py3.cfg") |
| 27 | +configfilename = Path.home() / ".pdfgui_py3.cfg" |
28 | 28 | # Project modification flag |
29 | 29 | isAltered = False |
30 | 30 |
|
31 | | -# Resolve APPDATADIR base path to application data files. |
32 | | -try: |
33 | | - _mydir = os.path.abspath(str(files(__name__))) |
34 | | -except TypeError: # For Python < 3.12 |
35 | | - _mydir = os.path.abspath(os.path.dirname(__file__)) |
| 31 | +_mydir = Path(str(files(__name__))).resolve() |
36 | 32 |
|
37 | | -_upbasedir = os.path.normpath(_mydir + "/../../..") |
38 | | -_development_mode = os.path.basename(_upbasedir) == "src" and os.path.isfile( |
39 | | - os.path.join(_upbasedir, "../pyproject.toml") |
40 | | -) |
| 33 | +_upbasedir = _mydir.parents[2] |
| 34 | +_development_mode = _upbasedir.name == "src" and (_upbasedir.parent / "pyproject.toml").is_file() |
41 | 35 |
|
42 | 36 | # Requirement must have egg-info. Do not use in _development_mode. |
43 | 37 | _req = "diffpy.pdfgui" |
44 | 38 |
|
45 | | -# pavol |
46 | | -# APPDATADIR = (os.path.dirname(_upbasedir) if _development_mode |
47 | | -# else str(files(_req))) |
48 | | -# long |
49 | 39 | if _development_mode: |
50 | | - APPDATADIR = os.path.dirname(_mydir) |
| 40 | + APPDATADIR = _mydir.parent |
51 | 41 | else: |
52 | | - APPDATADIR = str(files(_req)) |
| 42 | + APPDATADIR = Path(str(files(_req))).resolve() |
53 | 43 |
|
54 | | -APPDATADIR = os.path.abspath(APPDATADIR) |
| 44 | +APPDATADIR = APPDATADIR.resolve() |
55 | 45 |
|
56 | 46 | # Location of the HTML manual |
57 | 47 | docMainFile = "https://diffpy.github.io/diffpy.pdfgui/manual.html" |
|
62 | 52 |
|
63 | 53 |
|
64 | 54 | def iconpath(iconfilename): |
65 | | - """Full path to the icon file in pdfgui installation. This function |
66 | | - should be used whenever GUI needs access to custom icons. |
| 55 | + """Full path to the icon file in pdfgui installation. |
67 | 56 |
|
68 | | - iconfilename -- icon file name without any path |
| 57 | + This function should be used whenever GUI needs access to custom |
| 58 | + icons. |
69 | 59 |
|
70 | | - Return string. |
| 60 | + Parameters |
| 61 | + ---------- |
| 62 | + iconfilename : str |
| 63 | + The icon file name without any path. |
| 64 | +
|
| 65 | + Returns |
| 66 | + ------- |
| 67 | + str |
| 68 | + The full path to the icon file. |
71 | 69 | """ |
72 | | - rv = os.path.join(APPDATADIR, "icons", iconfilename) |
73 | | - assert os.path.isfile(rv), "icon file does not exist" |
74 | | - return rv |
| 70 | + rv = APPDATADIR / "icons" / iconfilename |
| 71 | + assert rv.is_file(), "icon file does not exist" |
| 72 | + return str(rv) |
75 | 73 |
|
76 | 74 |
|
77 | 75 | # options and arguments passed on command line |
78 | 76 | cmdopts = [] |
79 | 77 | cmdargs = [] |
80 | 78 |
|
81 | 79 | # debugging options: |
82 | | - |
83 | 80 | dbopts = debugoptions.DebugOptions() |
84 | 81 |
|
85 | 82 | # End of file |
0 commit comments