Skip to content

Commit

Permalink
Display error message when running in non-Sway environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunderland93 committed Sep 1, 2023
1 parent 0ff5ab0 commit 22e4650
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 21 deletions.
3 changes: 2 additions & 1 deletion locale-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ pylupdate5 -noobsolete \
ui_about.py \
ui_mainwindow.py \
ui_selectlayout.py \
-ts "$langs"/"lang_$lang.ts"
ui_error_message.py \
-ts "$langs"/"lang_$lang.ts"
Binary file modified sway_input_config/langs/lang_ru_RU.qm
Binary file not shown.
21 changes: 9 additions & 12 deletions sway_input_config/langs/lang_ru_RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
<!DOCTYPE TS>
<TS version="2.1" language="ru_RU" sourcelanguage="en">
<context>
<name>AboutDialog</name>
<name>ErrorMessage</name>
<message>
<location filename="../main.py" line="710"/>
<source>Version: </source>
<translation>Версия: </translation>
<location filename="../ui_error_message.py" line="69"/>
<source>Sway socket not found!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../ui_error_message.py" line="70"/>
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Sway Input Configurator only supports Sway. You are probably using an unsupported window manager or there are problems with your Sway configuration.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
Expand Down Expand Up @@ -408,14 +413,6 @@
<translation>Метод клика (только для кликпадов):</translation>
</message>
</context>
<context>
<name>SelectKeyboardLayout</name>
<message>
<location filename="../main.py" line="730"/>
<source>A user defined custom layout</source>
<translation>Пользовательская раскладка</translation>
</message>
</context>
<context>
<name>SelectKeyboardLayoutDialog</name>
<message>
Expand Down
36 changes: 28 additions & 8 deletions sway_input_config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
from sway_input_config.ui_mainwindow import Ui_MainWindow
from sway_input_config.ui_about import Ui_about
from sway_input_config.ui_selectlayout import Ui_SelectKeyboardLayoutDialog
from sway_input_config.ui_error_message import Ui_ErrorMessage

app_version = "1.3.0"
sway_version = get_sway_version()
data_dir = ""
config_home = get_config_home()

sway_config = os.path.join(config_home, "sway", "config")
if os.getenv("SWAYSOCK"):
sway_version = get_sway_version()
config_home = get_config_home()
sway_config = os.path.join(config_home, "sway", "config")

dir_name = os.path.dirname(__file__)
shortcut_list = os.path.join(dir_name, "data/shortcuts.json")
kbd_model_list = os.path.join(dir_name, "data/kbd_model.json")
Expand All @@ -33,6 +36,19 @@
default_settings = os.path.join(dir_name, "data/defaults.json")


class ErrorMessage(QDialog):
def __init__(self):
super(ErrorMessage, self).__init__()
self.ui = Ui_ErrorMessage()
self.ui.setupUi(self)

self.btnOk = self.ui.buttonBox.button(QDialogButtonBox.Ok)
self.btnOk.clicked.connect(self.on_clicked_ok)

def on_clicked_ok(self):
self.close()


class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
Expand Down Expand Up @@ -943,11 +959,15 @@ def main():
copy2(os.path.join(dir_name, "data/defaults.json"), os.path.join(data_dir, "settings"))
sys.exit(0)

load_settings()

win = MainWindow()
win.show()
sys.exit(app.exec_())
if os.getenv("SWAYSOCK"):
load_settings()
win = MainWindow()
win.show()
sys.exit(app.exec_())
else:
win = ErrorMessage()
win.show()
sys.exit(app.exec_())


if __name__ == "__main__":
Expand Down
96 changes: 96 additions & 0 deletions sway_input_config/ui/error_message.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ErrorMessage</class>
<widget class="QDialog" name="ErrorMessage">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>115</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>670</width>
<height>115</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>670</width>
<height>115</height>
</size>
</property>
<property name="windowTitle">
<string>Sway socket not found!</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Sway Input Configurator only supports Sway. You are probably using an unsupported window manager or there are problems with your Sway configuration.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
72 changes: 72 additions & 0 deletions sway_input_config/ui_error_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'error_message.ui'
##
## Created by: Qt User Interface Compiler version 5.15.8
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import * # type: ignore
from PySide2.QtGui import * # type: ignore
from PySide2.QtWidgets import * # type: ignore


class Ui_ErrorMessage(object):
def setupUi(self, ErrorMessage):
if not ErrorMessage.objectName():
ErrorMessage.setObjectName(u"ErrorMessage")
ErrorMessage.setWindowModality(Qt.WindowModal)
ErrorMessage.resize(670, 115)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(ErrorMessage.sizePolicy().hasHeightForWidth())
ErrorMessage.setSizePolicy(sizePolicy)
ErrorMessage.setMinimumSize(QSize(670, 115))
ErrorMessage.setMaximumSize(QSize(670, 115))
self.verticalLayout = QVBoxLayout(ErrorMessage)
self.verticalLayout.setObjectName(u"verticalLayout")
self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

self.verticalLayout.addItem(self.verticalSpacer_2)

self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.label = QLabel(ErrorMessage)
self.label.setObjectName(u"label")
self.label.setTextFormat(Qt.AutoText)
self.label.setWordWrap(True)

self.horizontalLayout.addWidget(self.label)


self.verticalLayout.addLayout(self.horizontalLayout)

self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

self.verticalLayout.addItem(self.verticalSpacer)

self.horizontalLayout_3 = QHBoxLayout()
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
self.buttonBox = QDialogButtonBox(ErrorMessage)
self.buttonBox.setObjectName(u"buttonBox")
self.buttonBox.setStandardButtons(QDialogButtonBox.Ok)

self.horizontalLayout_3.addWidget(self.buttonBox)


self.verticalLayout.addLayout(self.horizontalLayout_3)


self.retranslateUi(ErrorMessage)

QMetaObject.connectSlotsByName(ErrorMessage)
# setupUi

def retranslateUi(self, ErrorMessage):
ErrorMessage.setWindowTitle(QCoreApplication.translate("ErrorMessage", u"Sway socket not found!", None))
self.label.setText(QCoreApplication.translate("ErrorMessage", u"<html><head/><body><p><span style=\" font-size:10pt;\">Sway Input Configurator only supports Sway. You are probably using an unsupported window manager or there are problems with your Sway configuration.</span></p></body></html>", None))
# retranslateUi

0 comments on commit 22e4650

Please sign in to comment.