Passed
Push — master ( 1d2121...eed8cd )
by Yoshihiro
02:50
created

neditor.mp.MainProcessingClass.__init__()   B

Complexity

Conditions 1

Size

Total Lines 58
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 47
nop 10
dl 0
loc 58
ccs 20
cts 20
cp 1
crap 1
rs 8.7345
c 0
b 0
f 0

How to fix   Long Method    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
#!/usr/bin/env python3
2 1
import os
3 1
import shutil
4 1
import platform
5 1
import tkinter as tk
6 1
import tkinter.ttk as ttk
7
8 1
from . import pm
9 1
from . import fm
10 1
from . import fp
11 1
from . import lm
12
13
14 1
class MainProcessingClass(ttk.Frame):
15
    """メインフレーム処理のクラス.
16
17
    ・初期設定をするプログラム群
18
19
    Args:
20
        TREE_FOLDER (list): ツリーフォルダの配列
21
        tokenizer (instance): Tokenizer のインスタンス
22
        wiki_wiki (instance): wikipediaapi.Wikipedia のインスタンス
23
        TITLE_BINARY (str): タイトルイメージファイルバイナリ
24
        class_instance (dict): 自作クラスのインスタント群
25
        VERSION (str): バージョン情報
26
        locale (str): ロケーション
27
        master (instance): toplevel のインスタンス
28
    """
29
30 1
    def __init__(
31
        self,
32
        TREE_FOLDER,
33
        tokenizer,
34
        WIKI_WIKI,
35
        TITLE_BINARY,
36
        BLANK_IMAGE,
37
        class_instance,
38
        VERSION,
39
        dic,
40
        master=None
41
    ):
42 1
        super().__init__(master)
43 1
        self.TREE_FOLDER = TREE_FOLDER
44 1
        self.dic = dic
45
        # 自作クラスの読み込み
46 1
        self.cwc = class_instance['cw'].CreateWindowClass(self, BLANK_IMAGE)
47 1
        self.epc = class_instance['ep'].EventProcessingClass(self)
48 1
        self.spc = class_instance['sp'].SubfunctionProcessingClass(
49
            self
50
        )
51 1
        self.hpc = class_instance['hp'].HighlightProcessingClass(
52
            self,
53
            tokenizer
54
        )
55 1
        self.fpc = class_instance['fp'].FindProcessingClass(self)
56 1
        self.cpc = class_instance['cp'].ComplementProcessingClass(
57
            self,
58
            tokenizer
59
        )
60 1
        self.fmc = class_instance['fm'].FileMenuClass(
61
            self,
62
            master,
63
            self.TREE_FOLDER
64
        )
65 1
        self.emc = class_instance['em'].EditMenuClass(self)
66 1
        self.pmc = class_instance['pm'].ProcessingMenuClass(
67
            self,
68
            WIKI_WIKI,
69
            tokenizer
70
        )
71 1
        self.lmc = class_instance['lm'].ListMenuClass(
72
            self,
73
            master,
74
            self.TREE_FOLDER
75
        )
76 1
        self.hmc = class_instance['hm'].HelpMenuClass(
77
            self,
78
            TITLE_BINARY,
79
            VERSION
80
        )
81
        # メニューバーの作成
82 1
        self.menu_bar = tk.Menu(self.master)
83 1
        self.master.config(menu=self.menu_bar)
84
        # 初期化処理
85 1
        self.initialize()
86 1
        self.cwc.create_widgets()
87 1
        self.epc.create_event()
88
89 1
    def initialize(self):
90
        """初期化処理.
91
92
        ・変数の初期化及び起動準備をする。
93
        """
94
        # 今の処理ししているファイルのパス
95 1
        fm.FileMenuClass.now_path = ""
96
        # 現在開いているファイル
97 1
        fm.FileMenuClass.file_path = ""
98
        # 検索文字列
99 1
        fp.FindProcessingClass.find_text = ""
100
        # 現在入力中の初期テキスト
101 1
        lm.ListMenuClass.text_text = ""
102 1
        lm.ListMenuClass.select_list_item = ""
103
        # 文字の大きさ
104 1
        pm.ProcessingMenuClass.font_size = 16
105 1
        self.pmc.yahoo_appid = ""
106 1
        if os.path.isfile("./appid.txt"):
107 1
            f = open("./appid.txt", "r", encoding="utf-8")
108 1
            self.pmc.yahoo_appid = f.read()
109 1
            f.close()
110 1
        if u"ここを消して、" in self.pmc.yahoo_appid:
111
            self.pmc.yahoo_appid = ""
112
        # フォントをOSごとに変える
113 1
        pf = platform.system()
114 1
        if pf == 'Windows':
115 1
            self.font = "メイリオ"
116
        elif pf == 'Darwin':  # MacOS
117
            self.font = "Osaka-等幅"
118
        elif pf == 'Linux':
119
            self.font = "IPAゴシック"
120
        else:
121
            self.font = ""
122
123
        # dataフォルダがあるときは、削除する
124 1
        if os.path.isdir('./data'):
125 1
            shutil.rmtree('./data')
126
        # 新しくdataフォルダを作成する
127 1
        for val in self.TREE_FOLDER:
128
            os.makedirs('./{0}'.format(val[0]))
129