@@ -76,13 +76,36 @@ def main():
7676 my_lines += ["QT_API=pyqt5" ]
7777 if (PYPANDOC_PANDOC := WINPYDIRBASE / "t" / "pandoc.exe" ).is_file ():
7878 my_lines += [f"PYPANDOC_PANDOC={ PYPANDOC_PANDOC } " ]
79-
79+
8080 # theorical option: a "winpython.ini" file as an initial parameter
8181 if len (args ) >= 2 and args [1 ].endswith ("winpython.ini" ):
8282 file_name = args [1 ]
8383 args = args [1 :]
8484 else :
8585 file_name = "..\\ settings\\ winpython.ini"
86+
87+ # env_for_icons.bat default directory logic transfered to WinpythonIni.py
88+
89+ env ['WINPYWORKDIR' ] = WINPYWORKDIR = WINPYDIRBASE / "Notebooks"
90+ my_lines += [f"WINPYWORKDIR={ WINPYWORKDIR } " ]
91+
92+ # supposing winpython.ini is given the %* parameters to apply in python the [tricky] change of directory logic
93+ # if a file or directory is in %1 parameter, and current directory is not the icon nor scripts, we use that directory to define WINPYWORKDIR1
94+ WINPYWORKDIR1 = WINPYWORKDIR
95+ if len (args ) >= 2 :
96+ if Path (args [1 :1 ]).isfile ():
97+ WINPYWORKDIR1 = Path (args [1 :1 ]).parent
98+ if Path (args [1 :1 ]).isdir ():
99+ WINPYWORKDIR1 = Path (args [1 :1 ])
100+
101+ # if WinPython launched from another directory than icon origin, it's not a Drag&Drop so keep current directory
102+ CD_directory = Path (os .getcwd ())
103+ dp0_directory = Path (__file__ ).parent
104+ if CD_directory != dp0_directory and CD_directory / "scripts" != dp0_directory :
105+ WINPYWORKDIR1 = CD_directory
106+ env ['WINPYWORKDIR' ] = WINPYWORKDIR1
107+ my_lines += [f"WINPYWORKDIR1={ WINPYWORKDIR1 } " ]
108+
86109 # classic WinpythonIni.py actions: digesting winpython.ini file
87110 my_lines += get_file (file_name ).splitlines ()
88111
@@ -119,12 +142,13 @@ def main():
119142 if segment == "debug" and data [0 ].strip () == "state" :
120143 txt += f"{ prefix } WINPYDEBUG={ data [1 ].strip ()} { postfix } "
121144
122- print (txt )
123-
124- # set potential directory
125- for i in ('HOME' , 'WINPYWORKDIR' ):
145+ # create potential directory
146+ for i in ('HOME' , 'WINPYWORKDIR' , 'WINPYWORKDIR1' ):
126147 if i in env :
127148 os .makedirs (Path (env [i ]), exist_ok = True )
149+ # output to push change upward
150+ print (txt )
151+
128152 # later_version:
129153 # p = subprocess.Popen(["start", "cmd", "/k", "set"], shell = True)
130154 # p.wait() # I can wait until finished (although it too finishes after start finishes)
0 commit comments