PythonWin保存会话状态

我希望能够在PythonWin编辑器中保存我的会话状态(例如,这三个文件在PythonWin窗口中的这些特定位置打开并定位)。我可以使用win32gui获取PythonWin中每个子窗口的句柄,以及每个文件的标题和窗口的位置/大小。我不清楚如何获得列为子窗口名称的文件的完整路径(即如果子窗口名称是test.py而test.py位于c: python test.py,我不知道知道如何获得c: python)。我想我会写出哪些文件被打开加上他们的窗口位置到一个小文件,然后我会在PythonWin开始时调用它来加载。 有关如何获取子窗口名称的完整路径的任何想法? 或者,如果有人已经有一个更优雅的解决方案来保存PythonWin中的会话状态,请传递它。 下面是我正在使用的代码(感谢Michal Niklas提供的使用win32gui的入门代码)。
import win32gui
import re

MAIN_HWND = 0

def is_win_ok(hwnd, starttext):
    s = win32gui.GetWindowText(hwnd)
    if s.startswith(starttext):
        global MAIN_HWND
        MAIN_HWND = hwnd
        return None
    return 1


def find_main_window(starttxt):
    global MAIN_HWND
    win32gui.EnumChildWindows(0, is_win_ok, starttxt)
    return MAIN_HWND


def winPos(hwnd):
    if  type(hwnd) == type(1): ( left, top, right, bottom ) = win32gui.GetWindowRect(hwnd)
    return "%i, %i, %i, %i" % (left, right, top, bottom)


def winName(hwnd, children):
    s = win32gui.GetWindowText(hwnd)

    rePy = re.compile(r'[a-zA-Z1-9_ ]*.py')
    rePySearch = rePy.search(s)

    if rePySearch is not None:
        if rePySearch.group()[0:7] != "Running":
            s = s + ',' + winPos(hwnd) + 'n'
            children.append(s)
    return 1

def main():

    children = []
    main_app = 'PythonWin'
    hwnd = win32gui.FindWindow(None, main_app)

    if hwnd < 1:
        hwnd = find_main_window(main_app)

    if hwnd:
        win32gui.EnumChildWindows(hwnd, winName, children)

    filename = "sessionInfo.txt"
    sessionFile = os.path.join(sys.path[0],filename)

    fp=open(sessionFile, 'wb')
    for i in range(len(children)):
        fp.write(children[i])
    fp.close()

main()
    
已邀请:
我可能是错的,但不是用Python编写的PythonWin? 您是否尝试将源读取到“保存”命令以确定其存储完整路径的位置? (我自己看看,但是我已经五年没用过Windows了)     

要回复问题请先登录注册