2024年2月1日木曜日

Folder Restore Operation


 

When utilizing the folder dialog in Python with ctypes, it appears that the solver fails to provide a solution. This is likely because Python is executed at the front end of the solver startup and alters the default folder. Unfortunately, there is no known method to fix this issue other than having the user manually change the folder back to its default state.


import sc3
import datetime
import ctypes
import os
import csv
import win32gui, win32con

def get_open_file_name(title):
    filter='csv\0*.csv\0'
    customfilter='Other file types\0*.*\0'
    fname, customfilter, flags=win32gui.GetOpenFileNameW(
    InitialDir=project_file_path, 
    Flags=win32con.OFN_ALLOWMULTISELECT|win32con.OFN_EXPLORER,
    File='', DefExt='csv',
    Title=title,#
    Filter=filter,
    CustomFilter=customfilter,
    FilterIndex=0)
    return str(fname)

def get_shift_info():
    filename=get_open_file_name("Open CSV File")
    print(filename)
    list=[]
    with open(filename, encoding='utf8', newline='') as f:
        csvreader = csv.reader(f)
        for row in csvreader:
            list.append(row)
            print(row)
    

initial_path = os.getcwd() #Get initial folder path
#print(initial_path)
get_shift_info()#Your Operation
os.chdir(initial_path)#Restore initial folder path for solving engine.

0 件のコメント:

コメントを投稿