Skip to content

Commit 22e4650

Browse files
committed
Display error message when running in non-Sway environment
1 parent 0ff5ab0 commit 22e4650

File tree

6 files changed

+207
-21
lines changed

6 files changed

+207
-21
lines changed

locale-gen.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ pylupdate5 -noobsolete \
2424
ui_about.py \
2525
ui_mainwindow.py \
2626
ui_selectlayout.py \
27-
-ts "$langs"/"lang_$lang.ts"
27+
ui_error_message.py \
28+
-ts "$langs"/"lang_$lang.ts"

sway_input_config/langs/lang_ru_RU.qm

646 Bytes
Binary file not shown.

sway_input_config/langs/lang_ru_RU.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
<!DOCTYPE TS>
33
<TS version="2.1" language="ru_RU" sourcelanguage="en">
44
<context>
5-
<name>AboutDialog</name>
5+
<name>ErrorMessage</name>
66
<message>
7-
<location filename="../main.py" line="710"/>
8-
<source>Version: </source>
9-
<translation>Версия: </translation>
7+
<location filename="../ui_error_message.py" line="69"/>
8+
<source>Sway socket not found!</source>
9+
<translation type="unfinished"></translation>
10+
</message>
11+
<message>
12+
<location filename="../ui_error_message.py" line="70"/>
13+
<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>
14+
<translation type="unfinished"></translation>
1015
</message>
1116
</context>
1217
<context>
@@ -408,14 +413,6 @@
408413
<translation>Метод клика (только для кликпадов):</translation>
409414
</message>
410415
</context>
411-
<context>
412-
<name>SelectKeyboardLayout</name>
413-
<message>
414-
<location filename="../main.py" line="730"/>
415-
<source>A user defined custom layout</source>
416-
<translation>Пользовательская раскладка</translation>
417-
</message>
418-
</context>
419416
<context>
420417
<name>SelectKeyboardLayoutDialog</name>
421418
<message>

sway_input_config/main.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
from sway_input_config.ui_mainwindow import Ui_MainWindow
1919
from sway_input_config.ui_about import Ui_about
2020
from sway_input_config.ui_selectlayout import Ui_SelectKeyboardLayoutDialog
21+
from sway_input_config.ui_error_message import Ui_ErrorMessage
2122

2223
app_version = "1.3.0"
23-
sway_version = get_sway_version()
2424
data_dir = ""
25-
config_home = get_config_home()
2625

27-
sway_config = os.path.join(config_home, "sway", "config")
26+
if os.getenv("SWAYSOCK"):
27+
sway_version = get_sway_version()
28+
config_home = get_config_home()
29+
sway_config = os.path.join(config_home, "sway", "config")
30+
2831
dir_name = os.path.dirname(__file__)
2932
shortcut_list = os.path.join(dir_name, "data/shortcuts.json")
3033
kbd_model_list = os.path.join(dir_name, "data/kbd_model.json")
@@ -33,6 +36,19 @@
3336
default_settings = os.path.join(dir_name, "data/defaults.json")
3437

3538

39+
class ErrorMessage(QDialog):
40+
def __init__(self):
41+
super(ErrorMessage, self).__init__()
42+
self.ui = Ui_ErrorMessage()
43+
self.ui.setupUi(self)
44+
45+
self.btnOk = self.ui.buttonBox.button(QDialogButtonBox.Ok)
46+
self.btnOk.clicked.connect(self.on_clicked_ok)
47+
48+
def on_clicked_ok(self):
49+
self.close()
50+
51+
3652
class MainWindow(QMainWindow):
3753
def __init__(self):
3854
super(MainWindow, self).__init__()
@@ -943,11 +959,15 @@ def main():
943959
copy2(os.path.join(dir_name, "data/defaults.json"), os.path.join(data_dir, "settings"))
944960
sys.exit(0)
945961

946-
load_settings()
947-
948-
win = MainWindow()
949-
win.show()
950-
sys.exit(app.exec_())
962+
if os.getenv("SWAYSOCK"):
963+
load_settings()
964+
win = MainWindow()
965+
win.show()
966+
sys.exit(app.exec_())
967+
else:
968+
win = ErrorMessage()
969+
win.show()
970+
sys.exit(app.exec_())
951971

952972

953973
if __name__ == "__main__":

sway_input_config/ui/error_message.ui

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>ErrorMessage</class>
4+
<widget class="QDialog" name="ErrorMessage">
5+
<property name="windowModality">
6+
<enum>Qt::WindowModal</enum>
7+
</property>
8+
<property name="geometry">
9+
<rect>
10+
<x>0</x>
11+
<y>0</y>
12+
<width>670</width>
13+
<height>115</height>
14+
</rect>
15+
</property>
16+
<property name="sizePolicy">
17+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
18+
<horstretch>0</horstretch>
19+
<verstretch>0</verstretch>
20+
</sizepolicy>
21+
</property>
22+
<property name="minimumSize">
23+
<size>
24+
<width>670</width>
25+
<height>115</height>
26+
</size>
27+
</property>
28+
<property name="maximumSize">
29+
<size>
30+
<width>670</width>
31+
<height>115</height>
32+
</size>
33+
</property>
34+
<property name="windowTitle">
35+
<string>Sway socket not found!</string>
36+
</property>
37+
<layout class="QVBoxLayout" name="verticalLayout">
38+
<item>
39+
<spacer name="verticalSpacer_2">
40+
<property name="orientation">
41+
<enum>Qt::Vertical</enum>
42+
</property>
43+
<property name="sizeHint" stdset="0">
44+
<size>
45+
<width>20</width>
46+
<height>40</height>
47+
</size>
48+
</property>
49+
</spacer>
50+
</item>
51+
<item>
52+
<layout class="QHBoxLayout" name="horizontalLayout">
53+
<item>
54+
<widget class="QLabel" name="label">
55+
<property name="text">
56+
<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>
57+
</property>
58+
<property name="textFormat">
59+
<enum>Qt::AutoText</enum>
60+
</property>
61+
<property name="wordWrap">
62+
<bool>true</bool>
63+
</property>
64+
</widget>
65+
</item>
66+
</layout>
67+
</item>
68+
<item>
69+
<spacer name="verticalSpacer">
70+
<property name="orientation">
71+
<enum>Qt::Vertical</enum>
72+
</property>
73+
<property name="sizeHint" stdset="0">
74+
<size>
75+
<width>20</width>
76+
<height>40</height>
77+
</size>
78+
</property>
79+
</spacer>
80+
</item>
81+
<item>
82+
<layout class="QHBoxLayout" name="horizontalLayout_3">
83+
<item>
84+
<widget class="QDialogButtonBox" name="buttonBox">
85+
<property name="standardButtons">
86+
<set>QDialogButtonBox::Ok</set>
87+
</property>
88+
</widget>
89+
</item>
90+
</layout>
91+
</item>
92+
</layout>
93+
</widget>
94+
<resources/>
95+
<connections/>
96+
</ui>

sway_input_config/ui_error_message.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
3+
################################################################################
4+
## Form generated from reading UI file 'error_message.ui'
5+
##
6+
## Created by: Qt User Interface Compiler version 5.15.8
7+
##
8+
## WARNING! All changes made in this file will be lost when recompiling UI file!
9+
################################################################################
10+
11+
from PySide2.QtCore import * # type: ignore
12+
from PySide2.QtGui import * # type: ignore
13+
from PySide2.QtWidgets import * # type: ignore
14+
15+
16+
class Ui_ErrorMessage(object):
17+
def setupUi(self, ErrorMessage):
18+
if not ErrorMessage.objectName():
19+
ErrorMessage.setObjectName(u"ErrorMessage")
20+
ErrorMessage.setWindowModality(Qt.WindowModal)
21+
ErrorMessage.resize(670, 115)
22+
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
23+
sizePolicy.setHorizontalStretch(0)
24+
sizePolicy.setVerticalStretch(0)
25+
sizePolicy.setHeightForWidth(ErrorMessage.sizePolicy().hasHeightForWidth())
26+
ErrorMessage.setSizePolicy(sizePolicy)
27+
ErrorMessage.setMinimumSize(QSize(670, 115))
28+
ErrorMessage.setMaximumSize(QSize(670, 115))
29+
self.verticalLayout = QVBoxLayout(ErrorMessage)
30+
self.verticalLayout.setObjectName(u"verticalLayout")
31+
self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
32+
33+
self.verticalLayout.addItem(self.verticalSpacer_2)
34+
35+
self.horizontalLayout = QHBoxLayout()
36+
self.horizontalLayout.setObjectName(u"horizontalLayout")
37+
self.label = QLabel(ErrorMessage)
38+
self.label.setObjectName(u"label")
39+
self.label.setTextFormat(Qt.AutoText)
40+
self.label.setWordWrap(True)
41+
42+
self.horizontalLayout.addWidget(self.label)
43+
44+
45+
self.verticalLayout.addLayout(self.horizontalLayout)
46+
47+
self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
48+
49+
self.verticalLayout.addItem(self.verticalSpacer)
50+
51+
self.horizontalLayout_3 = QHBoxLayout()
52+
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
53+
self.buttonBox = QDialogButtonBox(ErrorMessage)
54+
self.buttonBox.setObjectName(u"buttonBox")
55+
self.buttonBox.setStandardButtons(QDialogButtonBox.Ok)
56+
57+
self.horizontalLayout_3.addWidget(self.buttonBox)
58+
59+
60+
self.verticalLayout.addLayout(self.horizontalLayout_3)
61+
62+
63+
self.retranslateUi(ErrorMessage)
64+
65+
QMetaObject.connectSlotsByName(ErrorMessage)
66+
# setupUi
67+
68+
def retranslateUi(self, ErrorMessage):
69+
ErrorMessage.setWindowTitle(QCoreApplication.translate("ErrorMessage", u"Sway socket not found!", None))
70+
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))
71+
# retranslateUi
72+

0 commit comments

Comments
 (0)