Skip to content

Commit

Permalink
feat: add grid size adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Nov 9, 2021
1 parent c19b22d commit 1dd4d61
Show file tree
Hide file tree
Showing 18 changed files with 64,351 additions and 63,825 deletions.
51 changes: 51 additions & 0 deletions gridplayer/dialogs/input_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QLayout, QSpinBox, QVBoxLayout


class QCustomSpinboxInput(QDialog):
def __init__(self, **kwargs):
super().__init__(**kwargs)

self.spinbox = QSpinBox(self)
self.spinbox.setRange(0, 1000)
self.spinbox.setSpecialValueText("Auto")

self.buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self
)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)

for btn in self.buttons.buttons():
btn.setIcon(QIcon())

main_layout = QVBoxLayout(self)
main_layout.setSizeConstraint(QLayout.SetMinAndMaxSize)
main_layout.addWidget(self.spinbox)
main_layout.addWidget(self.buttons)

@classmethod
def get_int( # noqa: WPS211
cls,
parent,
title,
special_text=None,
initial_value=0,
_min=-2147483647,
_max=2147483647,
step=1,
):
dialog = cls(parent=parent)
dialog.setWindowTitle(title)
dialog.spinbox.setRange(_min, _max)
dialog.spinbox.setValue(initial_value)
dialog.spinbox.setSingleStep(step)

if special_text:
dialog.spinbox.setSpecialValueText(special_text)

if dialog.exec():
return dialog.spinbox.value()

return initial_value
25 changes: 11 additions & 14 deletions gridplayer/dialogs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def __init__(self, parent):
"player/pause_minimized": self.playerPauseWhenMinimized,
"player/inhibit_screensaver": self.playerInhibitScreensaver,
"player/one_instance": self.playerOneInstance,
"playlist/grid_mode": self.playlistGridMode,
"playlist/grid_mode": self.gridMode,
"playlist/grid_fit": self.gridFit,
"playlist/grid_size": self.gridSize,
"playlist/save_position": self.playlistSavePosition,
"playlist/save_state": self.playlistSaveState,
"playlist/save_window": self.playlistSaveWindow,
Expand Down Expand Up @@ -102,7 +104,7 @@ def ui_customize(self): # noqa: WPS213

def ui_fill(self):
self.fill_playerVideoDriver()
self.fill_playlistGridMode()
self.fill_gridMode()
self.fill_videoAspect()
self.fill_logLevel()
self.fill_logLevelVLC()
Expand All @@ -115,6 +117,9 @@ def ui_customize_dynamic(self):
self.timeoutOverlay.setRange(1, 60)
self.timeoutMouseHide.setRange(1, 60)

self.gridSize.setRange(0, 1000)
self.gridSize.setSpecialValueText("Auto")

def ui_connect(self):
qt_connect(
(self.playerVideoDriver.currentIndexChanged, self.driver_selected),
Expand Down Expand Up @@ -168,19 +173,15 @@ def fill_videoAspect(self):

_fill_combo_box(self.videoAspect, aspect_ratios)

def fill_playlistGridMode(self):
def fill_gridMode(self):
grid_modes = {
GridMode.AUTO_ROWS: "Auto Rows First",
GridMode.AUTO_COLS: "Auto Columns First",
GridMode.AUTO_ROWS_FIT: "Auto Rows First (Fit)",
GridMode.AUTO_COLS_FIT: "Auto Columns First (Fit)",
GridMode.AUTO_ROWS: "Rows First",
GridMode.AUTO_COLS: "Columns First",
}

_fill_combo_box(self.playlistGridMode, grid_modes)
_fill_combo_box(self.gridMode, grid_modes)

def fill_playerVideoDriver(self):
video_drivers_disabled = []

if platform.system() == "Darwin":
video_drivers = {
VideoDriver.VLC_HW_SP: f"Hardware SP <VLC {params_env.VLC_VERSION}>",
Expand All @@ -196,10 +197,6 @@ def fill_playerVideoDriver(self):

_fill_combo_box(self.playerVideoDriver, video_drivers)

for vd in video_drivers_disabled:
idx = self.playerVideoDriver.findData(vd)
self.playerVideoDriver.model().item(idx).setEnabled(False)

def driver_selected(self, idx):
driver_id = self.playerVideoDriver.itemData(idx)

Expand Down
57 changes: 40 additions & 17 deletions gridplayer/dialogs/settings_dialog_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Ui_SettingsDialog(object):
def setupUi(self, SettingsDialog):
SettingsDialog.setObjectName("SettingsDialog")
SettingsDialog.resize(435, 409)
SettingsDialog.resize(440, 409)
self.lay_main = QtWidgets.QVBoxLayout(SettingsDialog)
self.lay_main.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
self.lay_main.setObjectName("lay_main")
Expand Down Expand Up @@ -38,19 +38,6 @@ def setupUi(self, SettingsDialog):
self.section_playlist.setFont(font)
self.section_playlist.setObjectName("section_playlist")
self.lay_left_column.addWidget(self.section_playlist)
self.lay_playlistGridMode = QtWidgets.QHBoxLayout()
self.lay_playlistGridMode.setObjectName("lay_playlistGridMode")
self.playlistGridModeLabel = QtWidgets.QLabel(SettingsDialog)
self.playlistGridModeLabel.setObjectName("playlistGridModeLabel")
self.lay_playlistGridMode.addWidget(self.playlistGridModeLabel)
self.playlistGridMode = QtWidgets.QComboBox(SettingsDialog)
self.playlistGridMode.setObjectName("playlistGridMode")
self.lay_playlistGridMode.addWidget(self.playlistGridMode)
spacerItem = QtWidgets.QSpacerItem(
40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum
)
self.lay_playlistGridMode.addItem(spacerItem)
self.lay_left_column.addLayout(self.lay_playlistGridMode)
self.playlistSaveWindow = QtWidgets.QCheckBox(SettingsDialog)
self.playlistSaveWindow.setObjectName("playlistSaveWindow")
self.lay_left_column.addWidget(self.playlistSaveWindow)
Expand All @@ -60,6 +47,39 @@ def setupUi(self, SettingsDialog):
self.playlistSaveState = QtWidgets.QCheckBox(SettingsDialog)
self.playlistSaveState.setObjectName("playlistSaveState")
self.lay_left_column.addWidget(self.playlistSaveState)
self.section_grid = QtWidgets.QLabel(SettingsDialog)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.section_grid.setFont(font)
self.section_grid.setObjectName("section_grid")
self.lay_left_column.addWidget(self.section_grid)
self.lay_gridMode = QtWidgets.QHBoxLayout()
self.lay_gridMode.setObjectName("lay_gridMode")
self.gridModeLabel = QtWidgets.QLabel(SettingsDialog)
self.gridModeLabel.setObjectName("gridModeLabel")
self.lay_gridMode.addWidget(self.gridModeLabel)
self.gridMode = QtWidgets.QComboBox(SettingsDialog)
self.gridMode.setObjectName("gridMode")
self.lay_gridMode.addWidget(self.gridMode)
spacerItem = QtWidgets.QSpacerItem(
40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum
)
self.lay_gridMode.addItem(spacerItem)
self.lay_left_column.addLayout(self.lay_gridMode)
self.lay_gridSize = QtWidgets.QHBoxLayout()
self.lay_gridSize.setObjectName("lay_gridSize")
self.gridSize = QtWidgets.QSpinBox(SettingsDialog)
self.gridSize.setObjectName("gridSize")
self.lay_gridSize.addWidget(self.gridSize)
self.gridSizeLabel = QtWidgets.QLabel(SettingsDialog)
self.gridSizeLabel.setObjectName("gridSizeLabel")
self.lay_gridSize.addWidget(self.gridSizeLabel)
self.lay_gridSize.setStretch(1, 1)
self.lay_left_column.addLayout(self.lay_gridSize)
self.gridFit = QtWidgets.QCheckBox(SettingsDialog)
self.gridFit.setObjectName("gridFit")
self.lay_left_column.addWidget(self.gridFit)
self.section_video_defaults = QtWidgets.QLabel(SettingsDialog)
font = QtGui.QFont()
font.setBold(True)
Expand Down Expand Up @@ -226,9 +246,6 @@ def retranslateUi(self, SettingsDialog):
_translate("SettingsDialog", "Allow only one instance")
)
self.section_playlist.setText(_translate("SettingsDialog", "Playlist"))
self.playlistGridModeLabel.setText(
_translate("SettingsDialog", "Default grid mode")
)
self.playlistSaveWindow.setText(
_translate("SettingsDialog", "Save window position and size")
)
Expand All @@ -238,6 +255,12 @@ def retranslateUi(self, SettingsDialog):
self.playlistSaveState.setText(
_translate("SettingsDialog", "Save videos playing / paused status")
)
self.section_grid.setText(
_translate("SettingsDialog", "Default Grid Parameters")
)
self.gridModeLabel.setText(_translate("SettingsDialog", "Grid mode"))
self.gridSizeLabel.setText(_translate("SettingsDialog", "Grid size"))
self.gridFit.setText(_translate("SettingsDialog", "Fit grid cells"))
self.section_video_defaults.setText(
_translate("SettingsDialog", "Default Video Parameters")
)
Expand Down
10 changes: 10 additions & 0 deletions gridplayer/params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pydantic import BaseModel

from gridplayer.params_static import GridMode
from gridplayer.settings import default_field


class GridState(BaseModel):
mode: GridMode = default_field("playlist/grid_mode")
is_fit: bool = default_field("playlist/grid_fit")
size: int = default_field("playlist/grid_size")
2 changes: 0 additions & 2 deletions gridplayer/params_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def _generate_next_value_(name, start, count, last_values): # noqa: WPS120
class GridMode(AutoName):
AUTO_ROWS = auto()
AUTO_COLS = auto()
AUTO_ROWS_FIT = auto()
AUTO_COLS_FIT = auto()


class VideoAspect(AutoName):
Expand Down
28 changes: 17 additions & 11 deletions gridplayer/player/managers/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@
"func": ("set_grid_mode", GridMode.AUTO_COLS),
"check": ("is_grid_mode_set_to", GridMode.AUTO_COLS),
},
"Rows First (Fit)": {
"key": "Alt+3",
"icon": "grid-rows-first",
"func": ("set_grid_mode", GridMode.AUTO_ROWS_FIT),
"check": ("is_grid_mode_set_to", GridMode.AUTO_ROWS_FIT),
},
"Columns First (Fit)": {
"key": "Alt+4",
"icon": "grid-columns-first",
"func": ("set_grid_mode", GridMode.AUTO_COLS_FIT),
"check": ("is_grid_mode_set_to", GridMode.AUTO_COLS_FIT),
"Fit Cells": {
"key": "Alt+F",
"icon": "grid-fit",
"func": "switch_is_grid_fit",
"check": "is_grid_fit",
},
"Size: %v": {
"key": "Alt+N",
"icon": "grid-size",
"func": "ask_grid_size",
"value": "get_grid_size",
},
"Zoom In": {
"key": "+",
Expand Down Expand Up @@ -287,4 +287,10 @@ def _make_action(self, cmd, cmd_name):
if is_enabled_test is not None:
action.is_enabled_test = self._ctx.commands.resolve(is_enabled_test)

value_getter = cmd.get("value")
action.is_dynamic = value_getter is not None
if value_getter is not None:
action.value_template = cmd_name
action.value_getter = self._ctx.commands.resolve(value_getter)

return action
Loading

0 comments on commit 1dd4d61

Please sign in to comment.