1414appIcon = "assets/logo.png"
1515appLogo = "assets/logo.png"
1616appLogo2 = "assets/logo2.png"
17- dataPath = os .path .abspath (os .path .dirname (__file__ )).replace ("\\ " , "/" ) # replace \ to / for qss usage, qss only support /
17+ dataPath = os .path .abspath (os .path .dirname (__file__ )).replace (
18+ "\\ " , "/"
19+ ) # replace \ to / for qss usage, qss only support /
1820assetsDir = os .path .join (dataPath , "assets" ).replace ("\\ " , "/" )
19- if not os .path .exists (assetsDir ): # for pyinstaller pack
21+ if not os .path .exists (assetsDir ): # for pyinstaller pack
2022 dataPath = os .path .dirname (dataPath )
2123 assetsDir = os .path .join (dataPath , "assets" ).replace ("\\ " , "/" )
2224
23- defaultBaudrates = [9600 , 19200 , 38400 , 57600 , 74880 , 115200 , 921600 , 1000000 , 1500000 , 2000000 , 4500000 ]
25+ defaultBaudrates = [
26+ 9600 ,
27+ 19200 ,
28+ 38400 ,
29+ 57600 ,
30+ 74880 ,
31+ 115200 ,
32+ 921600 ,
33+ 1000000 ,
34+ 1500000 ,
35+ 2000000 ,
36+ 4500000 ,
37+ ]
2438encodings = ["ASCII" , "UTF-8" , "UTF-16" , "GBK" , "GB2312" , "GB18030" ]
2539customSendItemHeight = 40
2640
2741author = "Neucrack"
2842
43+
2944def get_config_path (configFileName ):
3045 configFilePath = configFileName
3146 try :
@@ -36,15 +51,24 @@ def get_config_path(configFileName):
3651 pass
3752 return configFilePath
3853
39- configFileName = "config.json"
40- configFilePath = configFileName
4154
42- if sys .platform .startswith ('linux' ) or sys .platform .startswith ('darwin' ) or sys .platform .startswith ('freebsd' ):
55+ configFileName = "config.json"
56+ configFilePath = configFileName
57+
58+ if (
59+ sys .platform .startswith ("linux" )
60+ or sys .platform .startswith ("darwin" )
61+ or sys .platform .startswith ("freebsd" )
62+ ):
4363 configFileDir = os .path .join (os .getenv ("HOME" ), ".config/comtool" )
4464 configFilePath = get_config_path (configFileName )
65+ elif sys .platform .startswith ("win" ):
66+ appdata = os .getenv ("APPDATA" ) or os .path .expanduser ("~\\ AppData\\ Roaming" )
67+ configFileDir = os .path .join (appdata , "COMTool" )
68+ configFilePath = get_config_path (configFileName )
4569else :
4670 configFileDir = os .path .abspath (os .getcwd ())
47- configFilePath = os .path .join (configFileDir , configFileName )
71+ configFilePath = os .path .join (configFileDir , configFileName )
4872
4973logPath = os .path .join (configFileDir , "run.log" )
5074log = Logger (file_path = logPath )
@@ -60,7 +84,7 @@ class Parameters:
6084 "encoding" : "UTF-8" ,
6185 "skipVersion" : None ,
6286 "connId" : "serial" ,
63- "pluginsInfo" : { # enabled plugins ID
87+ "pluginsInfo" : { # enabled plugins ID
6488 "external" : {
6589 # "myplugin2": {
6690 # # "package": "myplugin", # package installed as a python package
@@ -81,11 +105,10 @@ class Parameters:
81105 # }
82106 # },
83107 # "plugin": {
84-
85108 # }
86109 # }
87110 # }
88- ]
111+ ],
89112 }
90113
91114 def save (self , path ):
@@ -102,7 +125,7 @@ def load(self, path):
102125 config = json .load (f )
103126 if "version" in config and config ["version" ] == self .config ["version" ]:
104127 self .config = config
105- else : # for old config, just backup
128+ else : # for old config, just backup
106129 t = datetime .now ().strftime ("%Y-%m-%d_%H-%M-%S" )
107130 old_path = "{}.bak.{}.json" .format (path , t )
108131 log .w ("Old config file, backup to" , old_path )
@@ -119,30 +142,23 @@ def __str__(self) -> str:
119142 return json .dumps (self .config )
120143
121144
122- strStyleShowHideButtonLeft = '''
145+ strStyleShowHideButtonLeft = """
123146QPushButton {
124147 border-image: url("$DataPath/assets/arrow-left.png")
125148}
126149QPushButton:hover {
127150 border-image: url("$DataPath/assets/arrow-left-white.png")
128- }'''
151+ }"""
129152
130- strStyleShowHideButtonRight = '''
153+ strStyleShowHideButtonRight = """
131154QPushButton {
132155 border-image: url("$DataPath/assets/arrow-right.png")
133156}
134157QPushButton:hover {
135158 border-image: url("$DataPath/assets/arrow-right-white.png")
136- }'''
159+ }"""
137160
138161styleForCode = {
139- "light" :{
140- "iconColor" : "white" ,
141- "iconSelectorColor" : "#929599"
142- },
143- "dark" :{
144- "iconColor" : "#bcbcbd" ,
145- "iconSelectorColor" : "#bcbcbd"
146- }
162+ "light" : {"iconColor" : "white" , "iconSelectorColor" : "#929599" },
163+ "dark" : {"iconColor" : "#bcbcbd" , "iconSelectorColor" : "#bcbcbd" },
147164}
148-
0 commit comments