質問編集履歴

1

詳しく書きました。

2020/09/18 07:25

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- [Python初心者] MediaInfoをText Boxに表示したい。
1
+ [Python初心者] Class 継承を利用してMediaInfoで取得した情報を表示したい。
test CHANGED
@@ -8,6 +8,220 @@
8
8
 
9
9
  ```Python
10
10
 
11
+ import tkinter as tk
12
+
13
+ from tkinter import filedialog
14
+
15
+ import os
16
+
17
+ import sys
18
+
19
+ import subprocess
20
+
21
+
22
+
23
+ win = tk.Tk()
24
+
25
+ win.title("IVT Transcode app")
26
+
27
+
28
+
29
+ win.geometry("700x700") #Turn on for locked Resolution
30
+
31
+ win.configure(background='#52514F') # DARK MODE! | ダークモード!
32
+
33
+ icon_photo = tk.PhotoImage(file = '/Volumes/UNSUNG HERO/PYTHON/IVTC_tool/film.png') # icon file | アイコンファイル
34
+
35
+ win.iconphoto(False, icon_photo) # Sets the icon | アイコン
36
+
37
+
38
+
39
+
40
+
41
+ # ----Dictionaries & Variables | 辞書と変数----
42
+
43
+ output_format = ['.MP4', '.AVI', '.MOV', '.MXF']
44
+
45
+ ffmpeg_path = open(os.path.join(sys.path[0], "ffmpeg/ffmpeg"), "r")
46
+
47
+ ffprobe_path = open(os.path.join(sys.path[0], "ffmpeg/ffprobe"), "r")
48
+
49
+
50
+
51
+ ## Input Settings ##
52
+
53
+ class FirstFrame:
54
+
55
+ def __init__(self,master):
56
+
57
+ FrameOne = tk.LabelFrame(master, text="Input Settings", fg="white", bg="#52514F", padx="5", pady="5")
58
+
59
+ FrameOne.grid(column=2, row=2, padx='20', pady='5', sticky='nsew')
60
+
61
+
62
+
63
+ self.file_dialog_input = None
64
+
65
+ self.Text_Input_Path = tk.Label(FrameOne, text="Input Path ",
66
+
67
+ fg="white", bg="#52514F", font=('Helvetica', 10))
68
+
69
+ self.Text_Input_Path.grid(column=0, row=0, sticky='w')
70
+
71
+ self.Field_Input_Path = tk.Entry(FrameOne, fg="black", highlightbackground="#52514F")
72
+
73
+ self.Field_Input_Path.grid(column=1, row=0, sticky='nsew')
74
+
75
+ self.Button_Input_Path = tk.Button(FrameOne, text="Open File", command=self.file_dialog_input_path, highlightbackground="#52514F", font=('Helvetica', 10))
76
+
77
+ self.Button_Input_Path.grid(column=2, row=0, sticky='e')
78
+
79
+
80
+
81
+ def file_dialog_input_path(self):
82
+
83
+ self.file_dialog_input = tk.filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes=[('MOV file (*.mov)', '*mov'), ('AVI file (*.avi)', '*.avi'),('MP4 file (*.mp4)', '*.mp4')])
84
+
85
+ self.Field_Input_Path.insert(tk.END, self.file_dialog_input)
86
+
87
+ print (self.file_dialog_input)
88
+
89
+
90
+
91
+
92
+
93
+ ## Output Settings ##
94
+
95
+ class SecondFrame:
96
+
97
+ def __init__(self,master):
98
+
99
+ FrameTwo = tk.LabelFrame(master, text="Output Settings", fg="white", bg="#52514F", padx="5", pady="5")
100
+
101
+ FrameTwo.grid(column=2, row=3, padx='20', pady='5', sticky='nsew')
102
+
103
+
104
+
105
+ self.file_dialog_output = None
106
+
107
+ self.Text_Output_Path = tk.Label(FrameTwo, text="Output Path", fg="white", bg="#52514F", font=('Helvetica', 10))
108
+
109
+ self.Text_Output_Path.grid(column=0, row=0, sticky='w')
110
+
111
+ self.Text_Output_Name = tk.Label(FrameTwo, text="Output Filename", fg="white", bg="#52514F", font=('Helvetica', 10))
112
+
113
+ self.Text_Output_Name.grid(column=0, row=1, sticky='w')
114
+
115
+ self.Field_Output_Path = tk.Entry(FrameTwo, fg="black", highlightbackground="#52514F")
116
+
117
+ self.Field_Output_Path.grid(column=1, row=0, sticky='nsew')
118
+
119
+ self.Field_Output_Name = tk.Entry(FrameTwo, fg="black", highlightbackground="#52514F")
120
+
121
+ self.Field_Output_Name.grid(column=1, row=1, sticky='nsew')
122
+
123
+ self.Button_Output_Path = tk.Button(FrameTwo, text="Select Path", command=self.file_dialog_output_path, highlightbackground="#52514F", pady='2', font=('Helvetica', 10))
124
+
125
+ self.Button_Output_Path.grid(column=2, row=0, sticky='nsew')
126
+
127
+
128
+
129
+ #Extention Option | 拡張子選択
130
+
131
+ self.Extension_Value = tk.StringVar()
132
+
133
+ self.Extension_Value.set(".MOV") # default value as MOV | デフォルトMOV
134
+
135
+ self.Extension_Option = tk.OptionMenu(FrameTwo, self.Extension_Value, *output_format)
136
+
137
+ self.Extension_Option.config(bg='#52514F', font=('Helvetica', 10), pady='2')
138
+
139
+ self.Extension_Option.grid(column=2, row=1, sticky='nsew')
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+ def file_dialog_output_path(self):
148
+
149
+ self.file_dialog_output = tk.filedialog.askdirectory(initialdir = "/",title = "Select path")
150
+
151
+ self.Field_Output_Path.insert(tk.END, self.file_dialog_output)
152
+
153
+ print (self.file_dialog_output)
154
+
155
+ #TextOutputText = tk.Text(FifthFrame, height=8, width=45, bg="grey", highlightbackground='grey')
156
+
157
+ #TextOutputText.delete('1.0', tk.END)
158
+
159
+ #TextOutputText.insert(tk.END, self.file_dialog_output)
160
+
161
+
162
+
163
+ ## Buttoun Settings##
164
+
165
+ class ThirdFrame:
166
+
167
+ def __init__(self,master):
168
+
169
+ FrameThree = tk.LabelFrame(master, text="Button", fg="white", bg="#52514F", pady="5", padx="5")
170
+
171
+ FrameThree.grid(column=3, row=2, rowspan=2, padx='20', pady='5', sticky='nsew')
172
+
173
+
174
+
175
+ #Analyze
176
+
177
+ self.file_dialog_input = None
178
+
179
+ self.ButtonOne = tk.Button(FrameThree,text="Analyze (MediaInfo)", highlightbackground="#52514F", padx=3, pady=3,)
180
+
181
+ self.ButtonOne.grid(column=2, row=0, sticky='nw', pady=1, padx=1)
182
+
183
+ #Preview
184
+
185
+ ButtonTwo = tk.Button(FrameThree, text="Preview", highlightbackground="#52514F", padx=3, pady=3)
186
+
187
+ ButtonTwo.grid(column=2, row=1, sticky='nw', pady=1, padx=1)
188
+
189
+ #Simple Transcode
190
+
191
+ Button_ffm_simple = tk.Button(FrameThree, text="Simple Transcode", highlightbackground="#52514F", padx=3, pady=3)
192
+
193
+ Button_ffm_simple.grid(column=2, row=2, sticky='nw', pady=1, padx=1)
194
+
195
+
196
+
197
+
198
+
199
+ ## Progress Settings ##
200
+
201
+ class ForthFrame:
202
+
203
+ def __init__(self,master):
204
+
205
+ FrameFour = tk.LabelFrame(master, text="Progress", fg="white", bg="#52514F", padx="5", pady="5")
206
+
207
+ FrameFour.grid(column=2, columnspan=2, row=4, padx='20', pady='5', sticky='nsew')
208
+
209
+
210
+
211
+ #Progress | 進捗ウィンドウの設定
212
+
213
+ TextOutputText = tk.Text(FrameFour, height=3, width=90, bg="grey", highlightbackground='grey')
214
+
215
+ TextOutputText.grid(column=1, columnspan=2, row=1, sticky='nsew', pady=5, padx=5)
216
+
217
+ ClearButton = tk.Button(FrameFour, text="Clear", highlightbackground="#52514F", padx=1, pady=1)
218
+
219
+ ClearButton.grid(column=2, row=2, sticky='e', pady=1, padx=1)
220
+
221
+
222
+
223
+ ##Preview Window Settings ##
224
+
11
225
  class FifthFrame:
12
226
 
13
227
  def __init__(self,master):
@@ -50,28 +264,98 @@
50
264
 
51
265
  #Media Infomation | メディア情報
52
266
 
53
- MediaInfoOut = tk.Text(FrameFive, height=20, width=40, bg="white", highlightbackground='grey', command=get_media_info)
267
+ self.MediaInfoOut = tk.Text(FrameFive, height=20, width=40, bg="white", highlightbackground='grey')
54
-
268
+
55
- MediaInfoOut.grid(column=3, row=1, rowspan=5, sticky='nsew', pady=5, padx=10)
269
+ self.MediaInfoOut.grid(column=3, row=1, rowspan=5, sticky='nsew', pady=5, padx=10)
270
+
271
+
272
+
273
+ def __init__(self,master):
274
+
275
+ # 変数を定義する
276
+
277
+ targetfile = file_dialog_input
278
+
279
+ # コマンドを定義して、変数を挿入する
280
+
281
+ command = 'ffprobe -i {}'.format(targetfile)
282
+
283
+ # コマンドを実行する
284
+
285
+ subprocess.run(command, shell=True)
56
286
 
57
287
 
58
288
 
59
- def get_media_info(self):
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+ f1 = FirstFrame(win)
298
+
299
+ f2 = SecondFrame(win)
300
+
301
+ f3 = ThirdFrame(win)
302
+
303
+ f4 = ForthFrame(win)
304
+
305
+ f5 = FifthFrame(win)
306
+
307
+
308
+
309
+
310
+
311
+ #Start the GUI | GUI開始
312
+
313
+ win.mainloop()
314
+
315
+ ```
316
+
317
+
318
+
319
+ Class FirstFrameで入手したInput_Pathを
320
+
321
+ ```
322
+
323
+ def file_dialog_input_path(self):
324
+
325
+ self.file_dialog_input = tk.filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes=[('MOV file (*.mov)', '*mov'), ('AVI file (*.avi)', '*.avi'),('MP4 file (*.mp4)', '*.mp4')])
326
+
327
+ self.Field_Input_Path.insert(tk.END, self.file_dialog_input)
328
+
329
+ print (self.file_dialog_input)
330
+
331
+ ```
332
+
333
+
334
+
335
+ Class FifthFrameのtargetfileを変数として使いたい。
336
+
337
+ ```
338
+
339
+ def __init__(self,master):
60
340
 
61
341
  # 変数を定義する
62
342
 
63
- targetfile = self.file_dialog_input
343
+ targetfile = file_dialog_input
64
344
 
65
345
  # コマンドを定義して、変数を挿入する
66
346
 
67
- command = 'ffmpeg -i {} -vn -ar 44100 -ac 1 -acodec flac -y -f flac output.flac'.format(targetfile)
347
+ command = 'ffprobe -i {}'.format(targetfile)
68
348
 
69
349
  # コマンドを実行する
70
350
 
71
- subprocess.run(cmd, shell=True)
351
+ subprocess.run(command, shell=True)
72
-
73
-
74
-
75
- print (command)
352
+
76
-
77
- ```
353
+ ```
354
+
355
+
356
+
357
+ Class 継承をする際のコードの書き方がいまいちわからず困っております。
358
+
359
+
360
+
361
+ どなたかご教示いただけると幸いです。