1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
import os |
3
|
|
|
import sys |
4
|
|
|
import platform |
5
|
|
|
import tkinter as tk |
6
|
|
|
import tkinter.messagebox as messagebox |
7
|
|
|
import customtkinter |
8
|
|
|
|
9
|
|
|
import wikipediaapi |
10
|
|
|
from janome.tokenizer import Tokenizer |
11
|
|
|
|
12
|
|
|
from . import MainProcessing as MainProcessing |
13
|
|
|
from . import data |
14
|
|
|
import i18n |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
def main_window_create(locale_var): |
18
|
|
|
"""タイトルウインドウの作成. |
19
|
|
|
|
20
|
|
|
・タイトルウインドウを作成する。 |
21
|
|
|
|
22
|
|
|
Args: |
23
|
|
|
locale_var (str): ロケーション |
24
|
|
|
""" |
25
|
|
|
dic = i18n.initialize(locale_var) |
26
|
|
|
root = tk.Tk() |
27
|
|
|
root.withdraw() |
28
|
|
|
if os.path.isdir("./data"): |
29
|
|
|
messagebox.showerror( |
30
|
|
|
dic.get_dict("Novel Editor"), |
31
|
|
|
dic.get_dict("This program cannot be started more than once."), |
32
|
|
|
) |
33
|
|
|
sys.exit() |
34
|
|
|
|
35
|
|
|
root.geometry("600x300") |
36
|
|
|
root.title(dic.get_dict("Novel Editor")) |
37
|
|
|
img = tk.PhotoImage(data=data.TITLE_BINARY) |
38
|
|
|
label = tk.Label(image=img) |
39
|
|
|
# タイトルを表示する |
40
|
|
|
label.pack() |
41
|
|
|
# センターに表示する |
42
|
|
|
root.update_idletasks() |
43
|
|
|
ww = root.winfo_screenwidth() |
44
|
|
|
lw = root.winfo_width() |
45
|
|
|
wh = root.winfo_screenheight() |
46
|
|
|
lh = root.winfo_height() |
47
|
|
|
root.geometry( |
48
|
|
|
"{0}x{1}+{2}+{3}".format( |
49
|
|
|
str(lw), str(lh), str(int(ww / 2 - lw / 2)), str(int(wh / 2 - lh / 2)) |
50
|
|
|
) |
51
|
|
|
) |
52
|
|
|
root.deiconify() |
53
|
|
|
|
54
|
|
|
# windowsのみタイトルバーを削除 |
55
|
|
|
# OS別判断 |
56
|
|
|
if os.name == "nt": |
57
|
|
|
root.overrideredirect(True) |
58
|
|
|
elif os.name == "posix": |
59
|
|
|
root.wm_attributes("-type", "splash") |
60
|
|
|
# 描画するが処理は止めない |
61
|
|
|
root.update() |
62
|
|
|
# Janomeを使って日本語の形態素解析を起動 |
63
|
|
|
tokenizer = Tokenizer() |
64
|
|
|
# wikipediaapiを起動 |
65
|
|
|
wiki_wiki = wikipediaapi.Wikipedia("Novel Editor([email protected])", "ja") |
66
|
|
|
# メイン画面を削除 |
67
|
|
|
root.destroy() |
68
|
|
|
# 再度メイン画面を作成 |
69
|
|
|
root = customtkinter.CTk() |
70
|
|
|
# アイコンを設定 |
71
|
|
|
root.tk.call("wm", "iconphoto", root._w, tk.PhotoImage(data=data.ICO_BINARY)) |
72
|
|
|
# タイトルの表示 |
73
|
|
|
root.title(dic.get_dict("Novel Editor")) |
74
|
|
|
# フレームを表示する |
75
|
|
|
app = MainProcessing.MainProcessingClass(tokenizer, wiki_wiki, locale_var, root) |
76
|
|
|
app.grid(column=0, row=0, sticky=(tk.N, tk.S, tk.E, tk.W)) |
77
|
|
|
# 終了時にon_closingを行う |
78
|
|
|
root.protocol("WM_DELETE_WINDOW", app.fmc.on_closing) |
79
|
|
|
root.columnconfigure(0, weight=1) |
80
|
|
|
root.rowconfigure(0, weight=1) |
81
|
|
|
pf = platform.system() |
82
|
|
|
if pf == "Windows": |
83
|
|
|
root.state("zoomed") |
84
|
|
|
else: |
85
|
|
|
root.attributes("-zoomed", "1") |
86
|
|
|
|
87
|
|
|
return root |
88
|
|
|
|