Console: Center window on show()
This commit is contained in:
parent
c6b9f5c64f
commit
e4638c2fa3
2 changed files with 30 additions and 5 deletions
|
@ -61,7 +61,7 @@ class GameProcessApp(RareApp):
|
||||||
server: QLocalServer
|
server: QLocalServer
|
||||||
socket: Optional[QLocalSocket] = None
|
socket: Optional[QLocalSocket] = None
|
||||||
exit_app = pyqtSignal()
|
exit_app = pyqtSignal()
|
||||||
console: Console = None
|
console: Optional[Console] = None
|
||||||
success: bool = True
|
success: bool = True
|
||||||
|
|
||||||
def __init__(self, args: Namespace):
|
def __init__(self, args: Namespace):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
from PyQt5.QtCore import QProcessEnvironment, pyqtSignal
|
from PyQt5.QtCore import QProcessEnvironment, pyqtSignal, QSize
|
||||||
from PyQt5.QtGui import QTextCursor, QFont
|
from PyQt5.QtGui import QTextCursor, QFont, QCursor
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QPlainTextEdit,
|
QPlainTextEdit,
|
||||||
QDialog,
|
QDialog,
|
||||||
|
@ -10,7 +10,7 @@ from PyQt5.QtWidgets import (
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QHBoxLayout,
|
QHBoxLayout,
|
||||||
QSpacerItem,
|
QSpacerItem,
|
||||||
QSizePolicy, QTableWidgetItem, QHeaderView,
|
QSizePolicy, QTableWidgetItem, QHeaderView, QApplication,
|
||||||
)
|
)
|
||||||
|
|
||||||
from rare.ui.components.extra.console_env import Ui_ConsoleEnv
|
from rare.ui.components.extra.console_env import Ui_ConsoleEnv
|
||||||
|
@ -24,7 +24,7 @@ class Console(QDialog):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(Console, self).__init__(parent=parent)
|
super(Console, self).__init__(parent=parent)
|
||||||
self.setWindowTitle("Rare - Console")
|
self.setWindowTitle("Rare - Console")
|
||||||
self.setGeometry(0, 0, 600, 400)
|
self.setGeometry(0, 0, 640, 480)
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
|
|
||||||
self.console = ConsoleEdit(self)
|
self.console = ConsoleEdit(self)
|
||||||
|
@ -63,6 +63,31 @@ class Console(QDialog):
|
||||||
self.env_variables = ConsoleEnv(self)
|
self.env_variables = ConsoleEnv(self)
|
||||||
self.env_variables.hide()
|
self.env_variables.hide()
|
||||||
|
|
||||||
|
def show(self) -> None:
|
||||||
|
super(Console, self).show()
|
||||||
|
self.center_window()
|
||||||
|
|
||||||
|
def center_window(self):
|
||||||
|
# get the margins of the decorated window
|
||||||
|
margins = self.windowHandle().frameMargins()
|
||||||
|
# get the screen the cursor is on
|
||||||
|
current_screen = QApplication.screenAt(QCursor.pos())
|
||||||
|
if not current_screen:
|
||||||
|
current_screen = QApplication.primaryScreen()
|
||||||
|
# get the available screen geometry (excludes panels/docks)
|
||||||
|
screen_rect = current_screen.availableGeometry()
|
||||||
|
decor_width = margins.left() + margins.right()
|
||||||
|
decor_height = margins.top() + margins.bottom()
|
||||||
|
window_size = QSize(self.width(), self.height()).boundedTo(
|
||||||
|
screen_rect.size() - QSize(decor_width, decor_height)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.resize(window_size)
|
||||||
|
self.move(
|
||||||
|
screen_rect.center()
|
||||||
|
- self.rect().adjusted(0, 0, decor_width, decor_height).center()
|
||||||
|
)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
file, ok = QFileDialog.getSaveFileName(
|
file, ok = QFileDialog.getSaveFileName(
|
||||||
self, "Save output", "", "Log Files (*.log);;All Files (*)"
|
self, "Save output", "", "Log Files (*.log);;All Files (*)"
|
||||||
|
|
Loading…
Reference in a new issue