Passed
Push — master ( bd08dd...19e348 )
by Yoshihiro
01:04 queued 10s
created

neditor.main_window_create()   B

Complexity

Conditions 5

Size

Total Lines 84
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 35
CRAP Score 5.0488

Importance

Changes 0
Metric Value
cc 5
eloc 55
nop 1
dl 0
loc 84
ccs 35
cts 40
cp 0.875
crap 5.0488
rs 8.006
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

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