Remove aspect option, which and titles/snapshots bindings

This commit is contained in:
Milan Nikolic 2024-10-11 19:12:38 +02:00
parent f235b519e9
commit 6e3b052ba1
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
10 changed files with 50 additions and 173 deletions

View file

@ -23,15 +23,13 @@ import tempfile
from subprocess import Popen, PIPE
import binascii
from m64py.utils import which
try:
import rarfile
HAS_RAR = True
RAR_CMD = None
except ImportError:
HAS_RAR = False
RAR_CMD = which("rar") or which("unrar")
RAR_CMD = shutil.which("rar") or shutil.which("unrar")
try:
from py7zlib import Archive7z
@ -39,7 +37,7 @@ try:
LZMA_CMD = None
except ImportError:
HAS_7Z = False
LZMA_CMD = which("7z")
LZMA_CMD = shutil.which("7z")
ZIP, GZIP, BZIP, RAR, LZMA, ROM = range(6)

View file

@ -17,7 +17,7 @@
import ctypes
from PyQt6.QtWidgets import QApplication
from PyQt6.QtGui import QSurfaceFormat, QGuiApplication
from PyQt6.QtGui import QSurface, QSurfaceFormat, QGuiApplication
from sdl2 import SDL_WasInit, SDL_InitSubSystem, SDL_QuitSubSystem, SDL_INIT_VIDEO
from sdl2 import SDL_GetNumDisplayModes, SDL_DisplayMode, SDL_GetDisplayMode
@ -73,6 +73,8 @@ class Video:
if QGuiApplication.platformName() != "wayland":
self.glcontext.setFormat(self.glformat)
self.widget.setSurfaceType(QSurface.SurfaceType.OpenGLSurface)
return M64ERR_SUCCESS
def init_with_render_mode(self, mode):
@ -87,6 +89,8 @@ class Video:
self.glcontext.moveToThread(QApplication.instance().thread())
self.glcontext = None
self.widget.destroy()
return M64ERR_SUCCESS
def list_modes(self, size_array, num_sizes):

View file

@ -20,19 +20,12 @@ from PyQt6.QtGui import QWindow, QOpenGLContext, QSurface
class GLWidget(QWindow):
def __init__(self, parent=None):
self.parent = parent
QWindow.__init__(self, None)
self.setSurfaceType(QSurface.SurfaceType.OpenGLSurface)
self.parent = parent
self.ctx = QOpenGLContext()
def context(self):
return self.ctx
def resizeEvent(self, event):
size = event.size()
width, height = int(size.width() * self.devicePixelRatio()), int(size.height() * self.devicePixelRatio())
self.resize(width, height)
def mouseDoubleClickEvent(self, event):
self.parent.toggle_fs.emit()

View file

@ -48,7 +48,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
file_opening = pyqtSignal(str)
set_caption = pyqtSignal(str)
state_changed = pyqtSignal(tuple)
save_image = pyqtSignal(bool)
info_dialog = pyqtSignal(str)
archive_dialog = pyqtSignal(list)
vidext_init = pyqtSignal(QOpenGLContext)
@ -70,8 +69,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.statusbar_label.setIndent(2)
self.statusbar_label.setSizePolicy(QSizePolicy.Policy.Ignored, QSizePolicy.Policy.Fixed)
self.statusbar.addPermanentWidget(self.statusbar_label, 1)
self.update_status(self.tr(
"Welcome to M64Py version %s." % FRONTEND_VERSION))
self.update_status(self.tr("M64Py version %s." % FRONTEND_VERSION))
self.sizes = {
SIZE_1X: self.action1X,
@ -107,16 +105,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.windowState() == Qt.WindowState.WindowMaximized):
self.maximized = True
def resizeEvent(self, event):
event.ignore()
size = event.size()
if self.widgets_height:
width, height = size.width(), size.height()
self.window_size_triggered((width, height))
else:
width, height = size.width(), size.height()
self.resize(width, height)
def showEvent(self, event):
if not self.widgets_height:
width, height = self.settings.get_size_safe()
@ -136,49 +124,44 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if modifiers & Qt.KeyboardModifier.AltModifier and (key == Qt.Key.Key_Enter or key == Qt.Key.Key_Return):
self.toggle_fs.emit()
elif key == Qt.Key.Key_F3:
self.worker.save_title()
elif key == Qt.Key.Key_F4:
self.worker.save_snapshot()
else:
try:
sdl_key = QT2SDL2[key]
self.worker.send_sdl_keydown(sdl_key)
except KeyError:
pass
if key in QT2SDL2:
self.worker.send_sdl_keydown(QT2SDL2[key])
def keyReleaseEvent(self, event):
if self.worker.state != M64EMU_RUNNING:
return
key = event.key()
try:
sdl_key = QT2SDL2[key]
self.worker.send_sdl_keyup(sdl_key)
except KeyError:
pass
if key in QT2SDL2:
self.worker.send_sdl_keyup(QT2SDL2[key])
def resizeEvent(self, event):
event.ignore()
size = event.size()
if self.widgets_height:
width, height = size.width(), size.height()
self.window_size_triggered((width, height))
else:
width, height = size.width(), size.height()
self.resize(width, height)
def window_size_triggered(self, size):
window_width, window_height = size
width, height = size
if self.vidext and self.worker.core.get_handle():
game_height = window_height - self.widgets_height
game_width = window_width
if not sys.platform == "win32":
if bool(self.settings.get_int_safe("keep_aspect", 1)):
game_width = int((4 / 3) * window_height)
self.worker.core.config.open_section("Video-General")
self.worker.core.config.set_parameter("ScreenWidth", game_width)
self.worker.core.config.set_parameter("ScreenHeight", game_height)
self.worker.core.config.set_parameter("ScreenWidth", width)
self.worker.core.config.set_parameter("ScreenHeight", height - self.widgets_height)
video_size = (game_width << 16) + game_height
video_size = ((int(width * self.devicePixelRatio()) << 16) +
(int(height * self.devicePixelRatio()) - self.widgets_height))
if self.worker.state in (M64EMU_RUNNING, M64EMU_PAUSED):
self.worker.core_state_set(M64CORE_VIDEO_SIZE, video_size)
self.set_sizes((window_width, window_height - self.widgets_height))
self.settings.qset.setValue("size", (window_width, window_height - self.widgets_height))
self.resize(window_width, window_height)
self.set_sizes((width, height - self.widgets_height))
self.settings.qset.setValue("size", (width, height - self.widgets_height))
self.resize(width, height)
def set_sizes(self, size):
"""Sets 'Window Size' radio buttons on resize event."""
@ -189,21 +172,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
for action in self.sizes.values():
action.setChecked(False)
def keep_aspect(self, size):
"""Keeps 4:3 aspect ratio."""
width, height = size
if self.maximized:
return width, height
fixed_ratio = 1.3333333333333333
current_ratio = float(width)/float(height)
if fixed_ratio > current_ratio:
w = int(width)
h = int(width/fixed_ratio)
else:
h = int(height)
w = int(height*fixed_ratio)
return w, h
def center_widget(self):
"""Centers widget on desktop."""
size = self.size()
@ -221,7 +189,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.file_opening.connect(self.on_file_opening)
self.set_caption.connect(self.on_set_caption)
self.state_changed.connect(self.on_state_changed)
self.save_image.connect(self.on_save_image)
self.info_dialog.connect(self.on_info_dialog)
self.archive_dialog.connect(self.on_archive_dialog)
self.toggle_fs.connect(self.on_toggle_fs)
@ -316,10 +283,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.update_status("Loading %s..." % (
os.path.basename(filepath)))
def on_save_image(self, title):
"""Saves snapshot or title image."""
self.worker.save_image(title)
def on_info_dialog(self, info):
"""Shows info dialog."""
self.settings.show_page(0)

View file

@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
from PyQt6.QtCore import Qt, QSettings
from PyQt6.QtWidgets import QDialog, QFileDialog, QRadioButton, QVBoxLayout
@ -250,13 +249,6 @@ class Settings(QDialog, Ui_Settings):
self.checkVsync.setToolTip(
self.get_parameter_help_safe("VerticalSync"))
if sys.platform == "win32":
self.checkKeepAspect.setChecked(False)
self.checkKeepAspect.setEnabled(False)
else:
keep_aspect = bool(self.get_int_safe("keep_aspect", 1))
self.checkKeepAspect.setChecked(keep_aspect)
disable_screensaver = bool(self.get_int_safe("disable_screensaver", 1))
self.checkDisableScreenSaver.setChecked(disable_screensaver)
@ -340,7 +332,7 @@ class Settings(QDialog, Ui_Settings):
self.core.config.set_parameter("ScreenHeight", int(height))
self.core.config.set_parameter("Fullscreen", self.checkFullscreen.isChecked())
self.core.config.set_parameter("VerticalSync", self.checkVsync.isChecked())
self.qset.setValue("keep_aspect", int(self.checkKeepAspect.isChecked()))
self.qset.setValue("disable_screensaver", int(self.checkDisableScreenSaver.isChecked()))
self.qset.setValue("enable_vidext", int(self.checkEnableVidExt.isChecked()))

View file

@ -205,53 +205,6 @@ class Worker(QThread):
"""Saves screenshot."""
self.core.take_next_screenshot()
def get_screenshot(self, path):
"""Gets last saved screenshot."""
name = self.core.rom_header.Name.decode()
rom_name = name.replace(' ', '_').lower()
screenshots = []
for filename in os.listdir(path):
if filename.startswith(rom_name):
screenshots.append(os.path.join(
path, filename))
if screenshots:
return sorted(screenshots)[-1]
return None
def save_image(self, title=True):
"""Saves snapshot or title image."""
data_path = self.core.config.get_path("UserData")
capture = "title" if title else "snapshot"
dst_path = os.path.join(data_path, capture)
if not os.path.isdir(dst_path):
os.makedirs(dst_path)
screenshot = self.get_screenshot(
os.path.join(data_path, "screenshot"))
if screenshot:
image_name = "%X%X.png" % (
sl(self.core.rom_header.CRC1), sl(self.core.rom_header.CRC2))
try:
shutil.copyfile(screenshot, os.path.join(dst_path, image_name))
log.info("Captured %s" % capture)
except IOError:
log.exception("couldn't save image %s" % image_name)
def save_title(self):
"""Saves title."""
self.save_screenshot()
QTimer.singleShot(1500, self.save_title_image)
def save_snapshot(self):
"""Saves snapshot."""
self.save_screenshot()
QTimer.singleShot(1500, self.save_snapshot_image)
def save_title_image(self):
self.parent.save_image.emit(True)
def save_snapshot_image(self):
self.parent.save_image.emit(False)
def state_load(self, state_path=None):
"""Loads state."""
self.core.state_load(state_path)

View file

@ -587,8 +587,8 @@
</message>
<message>
<location filename="mainwindow.py" line="60"/>
<source>Welcome to M64Py version %s.</source>
<translation type="unfinished">Willkommen zu M64py version %s.</translation>
<source>M64Py version %s.</source>
<translation type="unfinished">M64py version %s.</translation>
</message>
<message>
<location filename="mainwindow.py" line="323"/>

View file

@ -586,7 +586,7 @@
</message>
<message>
<location filename="mainwindow.py" line="60"/>
<source>Welcome to M64Py version %s.</source>
<source>M64Py version %s.</source>
<translation type="unfinished"></translation>
</message>
<message>

View file

@ -426,26 +426,6 @@ QGroupBox::title {
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QCheckBox" name="checkOSD">
<property name="text">
<string>On Screen Display</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkDisableScreenSaver">
<property name="toolTip">
<string>Disables ScreenSaver when emulator is running</string>
</property>
<property name="text">
<string>Disable ScreenSaver</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkEnableVidExt">
<property name="toolTip">
@ -459,13 +439,23 @@ QGroupBox::title {
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="checkKeepAspect">
<item row="1" column="0">
<widget class="QCheckBox" name="checkDisableScreenSaver">
<property name="toolTip">
<string>Maintain aspect-ratio on resizing</string>
<string>Disables ScreenSaver when emulator is running</string>
</property>
<property name="text">
<string>Keep Aspect Ratio</string>
<string>Disable ScreenSaver</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkOSD">
<property name="text">
<string>On Screen Display</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>

View file

@ -13,25 +13,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import re
def which(prog):
def is_exe(fp):
return os.path.exists(fp) and os.access(fp, os.X_OK)
fpath, fname = os.path.split(prog)
if fpath:
if is_exe(prog):
return prog
else:
for path in os.environ["PATH"].split(os.pathsep):
filename = os.path.join(path, prog)
if is_exe(filename):
return filename
return None
def version_split(ver):
return "%d.%d.%d" % (
((ver >> 16) & 0xffff),