デモ・地番チェッカー

投稿者: | 2023-01-15

TODO

  • 検索ボタンを押した後、検索結果を画面に表示させる、など
import PySimpleGUI as sg

singletiban_layout = [
    [sg.Text("供給地点特定番号:")],
    [sg.Input("", size=(25,1), key='-tiban-'), sg.Text("", size=(3,1), key="-digit-")],
    [sg.HSep()],
    [sg.Frame("対象月",[
            [sg.Radio('直近の対象月:', group_id=1, default=True, key="-latest_month-"), sg.Text("", size=(5,1), key="-latest_YYMM-")], 
            [sg.Radio('対象月を指定:', group_id=1, default=False, key="-past_one_month-"), sg.Push(), sg.Input("YYMM", size=(5,1), justification='center', key="-past_YYMM-")],])],
    [sg.Button("検索", key='-search-')],
    [sg.Multiline('', size=(60, 5), key="-ML-", auto_size_text=True)],
    [sg.Button("close", key="-close-")],
]

mulittiban_layout = [[sg.Text("未実装")]]

layout = []

layout += [[sg.TabGroup([[
    sg.Tab(' 単月で検索 ', singletiban_layout),
    # sg.Tab('複数期間で検索', mulittiban_layout),
]])]]

window = sg.Window('Tiban Checker', layout, keep_on_top=True)

while True:
    # timeoutだとずっとリフレッシュする。ログが取りにくい。テキスト入力をイベントにできないか。
    event, value = window.read(timeout=500)
    print("画面を作成")
    if event in (sg.WIN_CLOSED, '-close-'):
        break

    tiban = value["-tiban-"]
    tiban_digit = len(tiban)
    window["-digit-"].update(tiban_digit)

    # 検索を押したら、桁数チェック(22桁、0または1はじまり、対象月を探し表示、または対象月YYMM表記があっているか、対象月の期間か?)
    if event == "-search-":

        # 地番チェック    
        tiban = value["-tiban-"]
        tiban_digit = len(tiban)
        print(f'{tiban_digit=}')
        window["-digit-"].update(tiban_digit)

        cond1 = (int(tiban_digit) == 22)
        cond2 = (tiban[0:2] in ["0" + str(i) for i in range(1,10)] + ["10"])
        check_tiban = cond1 & cond2
        if check_tiban != True:
            sg.popup_error("地番が違います。再度入力して検索してください。")

    # ラジオボタンの挙動
    if value["-latest_month-"]:
        print("直近の対象月で検索する")
        target_m = value["-latest_month-"]
        # データから最新のYYMMを取得し、"-latest_YYMM-"へupdate送る
        # window["-latest_YYMM-"].update(****)
    if value["-past_one_month-"]:
        print("対象月を指定して検索する")
        target_m = value["-past_one_month-"]
        # そのYYMM表記が正しいか?
        # 最新のYYMMより小さいか?


window.close()
import PySimpleGUI as sg

singletiban_layout = [
    [sg.Text("供給地点特定番号:")],
    [sg.Input("", size=(25,1), key='-tiban-'), sg.Text("", size=(3,1), key="-digit-")],
    [sg.HSep()],
    [sg.Text("単月で検索")],
    [sg.Frame("対象月",[
            [sg.Radio('直近の対象月:', group_id=1, default=True, key="-latest_month-"), sg.Text("", size=(5,1), key="-latest_YYMM-")], 
            [sg.Radio('対象月を指定:', group_id=1, default=False, key="-past_one_month-"), sg.Push(), sg.Input("YYMM", size=(5,1), justification='center', key="-past_YYMM-")],])],
    [sg.Button("検索", key='-search-')]
]

mulittiban_layout = [[sg.Text("未実装")]]

layout = []

layout += [[sg.TabGroup([[
    sg.Tab('単月で検索', singletiban_layout),
    # sg.Tab('複数期間で検索', mulittiban_layout),
]])]]

window = sg.Window('Tiban Checker', layout)

while True:
    # TODO:timeoutだとずっとリフレッシュする。ログが取りにくい。テキスト入力をイベントにできないか。
    event, value = window.read(timeout=500)
    print("画面を作成")
    if event in (sg.WIN_CLOSED, '-close-'):
        break

    tiban = value["-tiban-"]
    tiban_digit = len(tiban)
    window["-digit-"].update(tiban_digit)

    # 検索を押したら、桁数チェック(22桁、0または1はじまり、対象月を探し表示、または対象月YYMM表記があっているか、対象月の期間か?)
    if event == "-search-":

        # 地番チェック    
        tiban = value["-tiban-"]
        tiban_digit = len(tiban)
        print(f'{tiban_digit=}')
        window["-digit-"].update(tiban_digit)

        cond1 = (int(tiban_digit) == 22)
        cond2 = (tiban[0:2] in ["0" + str(i) for i in range(1,10)] + ["10"])
        check_tiban = cond1 & cond2
        if check_tiban != True:
            sg.popup_error("地番が違います。再度入力して検索してください。")

    # ラジオボタンの挙動
    if value["-latest_month-"]:
        print("直近の対象月で検索する")
        target_m = value["-latest_month-"]
        # データから最新のYYMMを取得し、"-latest_YYMM-"へupdate送る
        # window["-latest_YYMM-"].update(****)
    if value["-past_one_month-"]:
        print("対象月を指定して検索する")
        target_m = value["-past_one_month-"]
        # そのYYMM表記が正しいか?
        # 最新のYYMMより小さいか?


window.close()