Passed
Push — master ( 63399a...705b0f )
by Yoshihiro
02:57
created

NovelEditor.MP.MainProcessingClass.__init__()   A

Complexity

Conditions 1

Size

Total Lines 31
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 27
nop 8
dl 0
loc 31
ccs 19
cts 19
cp 1
crap 1
rs 9.232
c 0
b 0
f 0

How to fix   Many Parameters   

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