Conditions | 5 |
Total Lines | 71 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | #!/usr/bin/env python3 |
||
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 |