Conditions | 5 |
Total Lines | 84 |
Code Lines | 55 |
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), |
||
50 | str(lh), |
||
51 | str(int(ww/2-lw/2)), |
||
52 | str(int(wh/2-lh/2)) |
||
53 | ) |
||
54 | ) |
||
55 | root.deiconify() |
||
56 | |||
57 | # windowsのみタイトルバーを削除 |
||
58 | # OS別判断 |
||
59 | if os.name == 'nt': |
||
60 | root.overrideredirect(True) |
||
61 | elif os.name == 'posix': |
||
62 | root.wm_attributes('-type', 'splash') |
||
63 | # 描画するが処理は止めない |
||
64 | root.update() |
||
65 | # Janomeを使って日本語の形態素解析を起動 |
||
66 | tokenizer = Tokenizer() |
||
67 | # wikipediaapiを起動 |
||
68 | wiki_wiki = wikipediaapi.Wikipedia('Novel Editor([email protected])','ja') |
||
69 | # メイン画面を削除 |
||
70 | root.destroy() |
||
71 | # 再度メイン画面を作成 |
||
72 | root = customtkinter.CTk() |
||
73 | # アイコンを設定 |
||
74 | root.tk.call( |
||
75 | 'wm', |
||
76 | 'iconphoto', |
||
77 | root._w, |
||
78 | tk.PhotoImage(data=data.ICO_BINARY) |
||
79 | ) |
||
80 | # タイトルの表示 |
||
81 | root.title(dic.get_dict("Novel Editor")) |
||
82 | # フレームを表示する |
||
83 | app = MainProcessing.MainProcessingClass( |
||
84 | tokenizer, |
||
85 | wiki_wiki, |
||
86 | locale_var, |
||
87 | root |
||
88 | ) |
||
89 | app.grid(column=0, row=0, sticky=(tk.N, tk.S, tk.E, tk.W)) |
||
90 | # 終了時にon_closingを行う |
||
91 | root.protocol("WM_DELETE_WINDOW", app.fmc.on_closing) |
||
92 | root.columnconfigure(0, weight=1) |
||
93 | root.rowconfigure(0, weight=1) |
||
94 | pf = platform.system() |
||
95 | if pf == 'Windows': |
||
96 | root.state('zoomed') |
||
97 | else: |
||
98 | root.attributes("-zoomed", "1") |
||
99 | |||
100 | return root |
||
101 |