Completed
Pull Request — master (#52)
by Yoshihiro
04:22
created

subfunction   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 53
dl 0
loc 118
rs 10
c 0
b 0
f 0
wmc 14

6 Methods

Rating   Name   Duplication   Size   Complexity  
A SubFunctionClass.btn_click() 0 27 2
A SubFunctionClass.clear_btn_click() 0 16 2
A SubFunctionClass.mouse_y_scroll() 0 14 3
A SubFunctionClass.resize_gif() 0 22 4
A SubFunctionClass.__init__() 0 7 1
A SubFunctionClass.print_gif() 0 18 2
1
import os
2
import shutil
3
import tkinter.filedialog as filedialog
4
5
from PIL import Image, ImageTk
6
7
8
class SubFunctionClass():
9
    def __init__(self, app):
10
        """
11
        Args:
12
            app (instance): lineframeインスタンス
13
14
        """
15
        self.APP = app
16
17
    def mouse_y_scroll(self, event=None):
18
        """マウスホイール移動の設定
19
20
        ・イメージキャンバスでマウスホイールを回したときにイメージキャンバス
21
        をスクロールする。
22
23
        Args:
24
            event (instance): tkinter.Event のインスタンス
25
26
        """
27
        if event.delta > 0:
28
            self.APP.image_space.yview_scroll(-1, 'units')
29
        elif event.delta < 0:
30
            self.APP.image_space.yview_scroll(1, 'units')
31
32
    def btn_click(self, event=None):
33
        """似顔絵ボタンを押したとき
34
35
        ・似顔絵ボタンを押したときに画像イメージを似顔絵フレームに
36
        貼り付ける。
37
38
        Args:
39
            event (instance): tkinter.Event のインスタンス
40
41
        """
42
        fTyp = [(u"gif画像", ".gif")]
43
        iDir = os.path.abspath(os.path.dirname(__file__))
44
        self.APP.filepath = filedialog.askopenfilename(
45
            filetypes=fTyp,
46
            initialdir=iDir
47
        )
48
        if not self.APP.filepath == "":
49
            path, ___ = os.path.splitext(os.path.basename(self.APP.now_path))
50
            ____, ext = os.path.splitext(os.path.basename(self.APP.filepath))
51
            title = shutil.copyfile(
52
                self.APP.filepath,
53
                "./data/character/{0}{1}".format(
54
                    path,
55
                    ext
56
                )
57
            )
58
            self.print_gif(title)
59
60
    def clear_btn_click(self, event=None):
61
        """消去ボタンをクリックしたとき
62
63
        ・消去ボタンをクリックしたときに画像イメージから画像を
64
        削除する。
65
66
        Args:
67
            event (instance): tkinter.Event のインスタンス
68
69
        """
70
        files = "./data/character/{0}.gif".format(
71
            self.APP.select_list_item
72
        )
73
        if os.path.isfile(files):
74
            os.remove(files)
75
            self.APP.cv.delete("all")
76
77
    def resize_gif(self, im):
78
        """画像をリサイズする
79
80
        ・イメージファイルを縦が長いときは縦を、横が長いときは横を、
81
        同じときは両方を150pxに設定する。
82
83
        Args:
84
            im (instance): イメージインスタンス
85
86
        Returns:
87
            instance: イメージインスタンス
88
89
        """
90
        if im.size[0] == im.size[1]:
91
            resized_image = im.resize((150, 150))
92
        elif im.size[0] > im.size[1]:
93
            zoom = int(im.size[1] * 150 / im.size[0])
94
            resized_image = im.resize((150, zoom))
95
        elif im.size[0] < im.size[1]:
96
            zoom = int(im.size[0] * 200 / im.size[1])
97
            resized_image = im.resize((zoom, 200))
98
        return resized_image
0 ignored issues
show
introduced by
The variable resized_image does not seem to be defined for all execution paths.
Loading history...
99
100
    def print_gif(self, title):
101
        """gifを表示する
102
103
        ・似顔絵キャンバスに画像を張り付ける。
104
105
        Args:
106
            title (str): タイトル
107
108
        """
109
110
        if not title == "":
111
            giffile = Image.open(title)
112
            self.APP.cv.photo = ImageTk.PhotoImage(self.resize_gif(giffile))
113
            print(self.APP.cv.photo)
114
            giffile.close()
115
            self.APP.cv.itemconfig(
116
                self.APP.image_on_canvas,
117
                image=self.APP.cv.photo
118
            )
119