Test Failed
Push — master ( 705b0f...728f1f )
by Yoshihiro
03:24
created

neditor.mp.MainProcessingClass.__init__()   B

Complexity

Conditions 1

Size

Total Lines 55
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 44
nop 8
dl 0
loc 55
rs 8.824
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
import os
3
import shutil
4
import platform
5
import tkinter as tk
6
import tkinter.ttk as ttk
7
8
from . import pm
9
from . import fm
10
from . import fp
11
from . import lm
12
13
14
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
        master (instance): toplevel のインスタンス
27
    """
28
29
    def __init__(
30
        self,
31
        tree_folder,
32
        tokenizer,
33
        wiki_wiki,
34
        title_binary,
35
        class_instance,
36
        version,
37
        master=None
38
    ):
39
        super().__init__(master)
40
        self.TREE_FOLDER = tree_folder
41
        # 自作クラスの読み込み
42
        self.cwc = class_instance['cw'].CreateWindowClass(self)
43
        self.epc = class_instance['ep'].EventProcessingClass(self)
44
        self.spc = class_instance['sp'].SubfunctionProcessingClass(
45
            self
46
        )
47
        self.hpc = class_instance['hp'].HighlightProcessingClass(
48
            self,
49
            tokenizer
50
        )
51
        self.fpc = class_instance['fp'].FindProcessingClass(self)
52
        self.cpc = class_instance['cp'].ComplementProcessingClass(
53
            self,
54
            tokenizer
55
        )
56
        self.fmc = class_instance['fm'].FileMenuClass(
57
            self,
58
            master,
59
            self.TREE_FOLDER
60
        )
61
        self.emc = class_instance['em'].EditMenuClass(self)
62
        self.pmc = class_instance['pm'].ProcessingMenuClass(
63
            self,
64
            wiki_wiki,
65
            tokenizer
66
        )
67
        self.lmc = class_instance['lm'].ListMenuClass(
68
            self,
69
            master,
70
            self.TREE_FOLDER
71
        )
72
        self.hmc = class_instance['hm'].HelpMenuClass(
73
            self,
74
            title_binary,
75
            version
76
        )
77
        # メニューバーの作成
78
        self.menu_bar = tk.Menu(self.master)
79
        self.master.config(menu=self.menu_bar)
80
        # 初期化処理
81
        self.initialize()
82
        self.cwc.create_widgets()
83
        self.epc.create_event()
84
85
    def initialize(self):
86
        """初期化処理.
87
88
        ・変数の初期化及び起動準備をする。
89
        """
90
        # 今の処理ししているファイルのパス
91
        fm.FileMenuClass.now_path = ""
92
        # 現在開いているファイル
93
        fm.FileMenuClass.file_path = ""
94
        # 検索文字列
95
        fp.FindProcessingClass.find_text = ""
96
        # 現在入力中の初期テキスト
97
        lm.ListMenuClass.text_text = ""
98
        lm.ListMenuClass.select_list_item = ""
99
        # 文字の大きさ
100
        pm.ProcessingMenuClass.font_size = 16
101
        self.pmc.APPID = ""
102
        if os.path.isfile("./appid.txt"):
103
            f = open("./appid.txt", "r", encoding="utf-8")
104
            self.pmc.APPID = f.read()
105
            f.close()
106
        if u"ここを消して、" in self.pmc.APPID:
107
            self.pmc.APPID = ""
108
        # フォントをOSごとに変える
109
        pf = platform.system()
110
        if pf == 'Windows':
111
            self.font = "メイリオ"
112
        elif pf == 'Darwin':  # MacOS
113
            self.font = "Osaka-等幅"
114
        elif pf == 'Linux':
115
            self.font = "IPAゴシック"
116
        # dataフォルダがあるときは、削除する
117
        if os.path.isdir('./data'):
118
            shutil.rmtree('./data')
119
        # 新しくdataフォルダを作成する
120
        for val in self.TREE_FOLDER:
121
            os.makedirs('./{0}'.format(val[0]))
122