commit 836658c9f975ba7d3ab4230406f8c6cb34b3565e
parent b3c64523a07174991fafdec19bc1849ee78c800e
Author: gearsix <gearsix@tuta.io>
Date: Mon, 17 May 2021 12:22:55 +0100
mostly finished gui options cfg, added --gui arg
Diffstat:
M | gui.py | | | 60 | ++++++++++++++++++++++++++++++++++++++++++++++-------------- |
M | sya.py | | | 12 | ++++++------ |
2 files changed, 52 insertions(+), 20 deletions(-)
diff --git a/gui.py b/gui.py
@@ -1,32 +1,49 @@
import os
+import sys
+import PyQt5.QtCore as pyqt_core
import PyQt5.QtWidgets as pyqt_widgets
import PyQt5.QtGui as pyqt_gui
class Args:
def __init__(self, args):
self.args = args
- self.done = False
- self._widget = pyqt_widgets.QWidget()
self._edits = {}
- # elements
+
+ self._app = pyqt_widgets.QApplication(sys.argv)
+ self._widget = pyqt_widgets.QWidget()
+
layout = pyqt_widgets.QGridLayout()
self._tracklistKey = 'Tracklist:'
layout.addLayout(self._init_filepicker(self._tracklistKey, self._filepicker_tracklist), 0, 0, 1, 3)
+
formats = ['mp3', 'flv', 'wav', 'ogg', 'aac']
layout.addLayout(self._init_combobox('Format:', self._set_format, formats), 1, 0)
+
qualities = ['0 (better)', '1', '2', '3', '4', '5', '6', '7', '8', '9 (worse)']
layout.addLayout(self._init_combobox('Quality:', self._set_quality, qualities), 2, 0)
+
+ self.args.quality = '0'
keep = pyqt_widgets.QCheckBox('keep original', self._widget)
keep.toggled.connect(self._keep_toggle)
+ layout.addWidget(keep, 1, 1, 2, 1)
+
self._outputKey = 'Output:'
- layout.addWidget(keep, 2, 1)
layout.addLayout(self._init_filepicker(self._outputKey, self._filepicker_output), 3, 0, 1, 3)
- done_btn = pyqt_widgets.QPushButton('OK')
- layout.addWidget(done_btn)
- # container
+
+ self._ok = pyqt_widgets.QPushButton('OK')
+ self._ok.clicked.connect(self._exit)
+ layout.addWidget(self._ok, 4, 1)
+ self._check_exit()
+
+ self._widget.setWindowTitle('sya')
self._widget.setLayout(layout)
+ #widget.setWindowIcon(pyqt_widgets.QIcon(''))
+ sg = pyqt_widgets.QDesktopWidget().screenGeometry()
+ wg = self._widget.geometry()
+ self._widget.move(sg.width() / 2 - wg.width() / 2, sg.height() / 2 - wg.height() / 2)
self._widget.show()
+ self._app.exec()
def _init_filepicker(self, labelText, filepickerFn):
layout = pyqt_widgets.QHBoxLayout()
@@ -57,8 +74,12 @@ class Args:
file = pyqt_widgets.QFileDialog.getOpenFileName(self._widget,
'Select a tracklist', os.path.expanduser("~"), "Plain-Text file (*.txt)")
if len(file) > 0:
- self.tracklist = file[0]
- self._edits[self._tracklistKey].setText(file[0])
+ self.args.tracklist = file[0]
+ self._edits[self._tracklistKey].setText(self.args.tracklist)
+ if len(self._edits[self._outputKey].text()) == 0:
+ self.args.output = os.path.splitext(self.args.tracklist)[0]
+ self._edits[self._outputKey].setText(self.args.output)
+ self._check_exit()
def _filepicker_output(self, signal):
file = pyqt_widgets.QFileDialog.getExistingDirectory(self._widget,
@@ -66,12 +87,23 @@ class Args:
if len(file) > 0:
self.args.output = file
self._edits[self._outputKey].setText(file)
+ self._check_exit()
- def _set_format(self, signal):
- self.args.format = signal
+ def _set_format(self, format):
+ self.args.format = format
- def _set_quality(self, signal):
- self.args.quality = signal
+ def _set_quality(self, quality):
+ self.args.quality = quality[0]
- def _keep_toggle(self, signal):
+ def _keep_toggle(self):
self.args.keep = not self.args.keep
+
+ def _check_exit(self):
+ if self.args.tracklist != None and os.path.exists(self.args.tracklist) and len(self.args.output) > 0:
+ self._ok.setEnabled(True)
+ else:
+ self._ok.setEnabled(False)
+
+ def _exit(self):
+ self.args.gui = False
+ self._app.quit()
diff --git a/sya.py b/sya.py
@@ -43,6 +43,8 @@ def parse_args():
help='path of the "ffmpeg" binary to use')
parser.add_argument('-k', '--keep', action='store_true',
help='keep any files removed during processing (full video/audio file)')
+ parser.add_argument('-g', '--gui', action='store_true',
+ help='run the gui for configuring options')
return parser.parse_args()
def check_bin(*binaries):
@@ -121,14 +123,12 @@ def split_tracks(ffmpeg, audio_fpath, tracks, format='mp3', outpath='out'):
if __name__ == '__main__':
args = parse_args()
- if len(sys.argv) == 1:
- app = pyqt.QApplication([])
+ if args.gui:
argsGui = gui.Args(args)
- while app.exec_():
- continue
- print('remove this sys.exit()')
args = argsGui.args
- sys.exit()
+ del(argsGui)
+ if args.gui == True: # cancel exit
+ sys.exit()
if check_bin(args.youtubedl, args.ffmpeg) == False:
error_exit('required binaries are missing')
tracklist = load_tracklist(args.tracklist)