This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
390 lines (345 loc) · 15.2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import sys
import os
from shutil import copyfile
import json
from PyQt4 import QtGui
from PyQt4 import QtCore
from UI.main import Ui_MainWindow
homePath = os.path.expanduser('~')
try:
appPath = os.path.dirname(os.path.abspath(__file__))
except NameError:
appPath = os.path.dirname(os.path.abspath(sys.argv[0]))
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowIcon(QtGui.QIcon(os.path.join(appPath, 'assets', 'images', 'icon.jpg')))
self.apps = []
self.workspaces = []
self.keyboards = []
self.modes = {}
self.initConfig()
self.prepareUi()
self.listenButtons()
self.show()
def initConfig(self):
self.configFolder = os.path.join(homePath, '.config', 'i3-manager')
if not os.path.exists(self.configFolder):
os.makedirs(self.configFolder)
if not os.path.exists(os.path.join(self.configFolder, 'config.json')):
copyfile(os.path.join(appPath, 'stubs', 'config.json'), os.path.join(self.configFolder, 'config.json'))
self.readConfig()
def readConfig(self):
with open(os.path.join(self.configFolder, 'config.json')) as data:
self.config = json.load(data)
for workspace in self.config['workspaces']:
self.workspaces.append(workspace)
for app in self.config['app']:
self.apps.append({
"command": app['command'],
"class": app['class'],
"hotkey": app['hotkey'],
"workspace": app['workspace'],
"floating": app['floating'],
"move": app['move']
})
for hotkey in self.config['hotkey']:
self.keyboards.append({
"key": hotkey['key'],
"action": hotkey['action']
})
for modeKey in self.config['mode']:
self.modes[modeKey] = {}
def listenButtons(self):
self.ui.btnInsertWorkspace.clicked.connect(self.insertWorkspace)
self.ui.pushButton_5.clicked.connect(self.insertApp)
self.ui.btnKeyboardInsert.clicked.connect(self.insertKeyboard)
def insertWorkspace(self):
name = self.ui.workspaceName.text()
self.workspaces.append(name)
self.refreshWorkspaces()
self.refreshAppWorkspace()
def insertApp(self):
command = self.ui.appName.text()
appClass = self.ui.appClass.text()
hotkey = self.ui.appHotkey.text()
if self.ui.appWorkspace.currentIndex() == 0:
workspace = None
else:
workspace = self.ui.appWorkspace.currentIndex()
if self.ui.appFloating.currentIndex() == 0:
floating = None
elif self.ui.appFloating.currentIndex() == 1:
floating = "enable"
else:
floating = "disable"
if self.ui.appMove.currentIndex() == 0:
move = None
else:
move = "center"
self.apps.append({
"command": command,
"class": appClass,
"hotkey": hotkey,
"workspace": workspace,
"floating": floating,
"move": move
})
self.refreshApps()
def insertKeyboard(self):
hotkey = self.ui.keyboardHotkey.text()
action = self.ui.keyboardAction.text()
self.keyboards.append({
"key": hotkey,
"action": action
})
self.refreshKeyboards()
def prepareUi(self):
self.readModifierKey()
self.readFloatingKey()
self.readOrientation()
self.readWorkspaceLayout()
self.readBorders()
self.readWindowDecoration()
self.readBar()
self.refreshWorkspaces()
self.refreshAppWorkspace()
self.refreshApps()
self.refreshKeyboards()
self.refreshModes()
self.readStartup()
def readModifierKey(self):
if self.config['modKey'] == 'Mod1':
self.ui.modKey.setCurrentIndex(0)
elif self.config['modKey'] == 'Mod4':
self.ui.modKey.setCurrentIndex(1)
elif self.config['modKey'] == 'CTRL':
self.ui.modKey.setCurrentIndex(2)
elif self.config['modKey'] == 'Shift':
self.ui.modKey.setCurrentIndex(3)
def readFloatingKey(self):
if self.config['floatingKey'] == 'Mod1':
self.ui.floatingKey.setCurrentIndex(0)
elif self.config['floatingKey'] == 'Mod4':
self.ui.floatingKey.setCurrentIndex(1)
elif self.config['floatingKey'] == 'CTRL':
self.ui.floatingKey.setCurrentIndex(2)
elif self.config['floatingKey'] == 'Shift':
self.ui.floatingKey.setCurrentIndex(3)
def readOrientation(self):
if self.config['orientation'] == 'auto':
self.ui.orientation.setCurrentIndex(2)
elif self.config['orientation'] == 'horizontal':
self.ui.orientation.setCurrentIndex(0)
elif self.config['orientation'] == 'vertical':
self.ui.orientation.setCurrentIndex(1)
def readWorkspaceLayout(self):
if self.config['workspaceLayout'] == 'default':
self.ui.workspaceLayout.setCurrentIndex(0)
elif self.config['workspaceLayout'] == 'stacking':
self.ui.workspaceLayout.setCurrentIndex(2)
elif self.config['workspaceLayout'] == 'tabbed':
self.ui.workspaceLayout.setCurrentIndex(1)
def readBorders(self):
if self.config['borders'] == 'none':
self.ui.borders.setCurrentIndex(0)
elif self.config['borders'] == 'vertical':
self.ui.borders.setCurrentIndex(1)
elif self.config['borders'] == 'horizontal':
self.ui.borders.setCurrentIndex(2)
elif self.config['borders'] == 'both':
self.ui.borders.setCurrentIndex(3)
elif self.config['borders'] == 'smart':
self.ui.borders.setCurrentIndex(4)
def readWindowDecoration(self):
window = self.config['theme']['window']
focused = window['focused']
self.ui.windowFocusBorder.setText(focused['border'])
self.ui.windowFocusBackground.setText(focused['background'])
self.ui.windowFocusText.setText(focused['text'])
self.ui.windowFocusIndicator.setText(focused['indicator'])
unfocused = window['unfocused']
self.ui.windowUnfocusBorder.setText(unfocused['border'])
self.ui.windowUnfocusBackground.setText(unfocused['background'])
self.ui.windowUnfocusText.setText(unfocused['text'])
self.ui.windowUnfocusIndicator.setText(unfocused['indicator'])
inactive = window['inactive']
self.ui.windowInactiveBorder.setText(inactive['border'])
self.ui.windowInactiveBackground.setText(inactive['background'])
self.ui.windowInactiveText.setText(inactive['text'])
self.ui.windowInactiveIndicator.setText(inactive['indicator'])
urgent = window['urgent']
self.ui.windowUrgentBorder.setText(urgent['border'])
self.ui.windowUrgentBackground.setText(urgent['background'])
self.ui.windowUrgentText.setText(urgent['text'])
self.ui.windowUrgentIndicator.setText(urgent['indicator'])
def readBar(self):
bar = self.config['theme']['bar']
self.ui.barBackground.setText(bar['background'])
self.ui.barSeparator.setText(bar['separator'])
self.ui.barStatus.setText(bar['status'])
focused = bar['focused']
self.ui.barFocusBorder.setText(focused['border'])
self.ui.barFocusBackground.setText(focused['background'])
self.ui.barFocusText.setText(focused['text'])
active = bar['active']
self.ui.barActiveBorder.setText(active['border'])
self.ui.barActiveBackground.setText(active['background'])
self.ui.barActiveText.setText(active['text'])
inactive = bar['inactive']
self.ui.barInactiveBorder.setText(inactive['border'])
self.ui.barInactiveBackground.setText(inactive['background'])
self.ui.barInactiveText.setText(inactive['text'])
urgent = bar['urgent']
self.ui.barUrgentBorder.setText(urgent['border'])
self.ui.barUrgentBackground.setText(urgent['background'])
self.ui.barUrgentText.setText(urgent['text'])
mode = bar['mode']
self.ui.barModeBorder.setText(mode['border'])
self.ui.barModeBackground.setText(mode['background'])
self.ui.barModeText.setText(mode['text'])
def refreshWorkspaces(self):
table = self.ui.workspacesTable
table.setRowCount(0)
row = 0
for workspace in self.workspaces:
table.insertRow(row)
table.setItem(row, 0, QtGui.QTableWidgetItem(workspace))
removeBtn = QtGui.QPushButton(table)
removeBtn.setText('Remove')
table.setCellWidget(row, 1, removeBtn)
row+=1
def refreshAppWorkspace(self):
workspacesCombo = self.ui.appWorkspace
workspacesCombo.clear()
workspacesCombo.addItem("None Workspace")
for workspace in self.workspaces:
workspacesCombo.addItem(workspace)
def refreshApps(self):
table = self.ui.appsTable
table.setRowCount(0)
row = 0
for app in self.apps:
table.insertRow(row)
table.setItem(row, 0, QtGui.QTableWidgetItem(app['command']))
table.setItem(row, 1, QtGui.QTableWidgetItem(app['class']))
table.setItem(row, 2, QtGui.QTableWidgetItem(app['hotkey']))
# Workspaces Cell
workspacesCombo = QtGui.QComboBox()
workspacesTableModel = self.ui.workspacesTable.model()
workspacesCombo.addItem("None Workspace")
for workspaceRow in range(workspacesTableModel.rowCount()):
workspacesCombo.addItem(self.ui.workspacesTable.model().index(workspaceRow, 0).data())
if app['workspace']:
workspacesCombo.setCurrentIndex(app['workspace'])
else:
workspacesCombo.setCurrentIndex(0)
table.setCellWidget(row, 3, workspacesCombo)
# Floating Cell
floatingCombo = QtGui.QComboBox()
floatingCombo.addItem("No Force")
floatingCombo.addItem("Force Enable")
floatingCombo.addItem("Force Disable")
if(app['floating'] == 'enable'):
floatingCombo.setCurrentIndex(1)
elif(app['floating'] == 'disable'):
floatingCombo.setCurrentIndex(2)
else:
floatingCombo.setCurrentIndex(0)
table.setCellWidget(row, 4, floatingCombo)
# Move Cell
moveCombo = QtGui.QComboBox()
moveCombo.addItem("No Force")
moveCombo.addItem("Move Center")
if (app['move'] == 'center'):
moveCombo.setCurrentIndex(1)
else:
moveCombo.setCurrentIndex(0)
table.setCellWidget(row, 5, moveCombo)
# Remove Cell
removeBtn = QtGui.QPushButton(table)
removeBtn.setText('Remove')
table.setCellWidget(row, 6, removeBtn)
row+=1
def refreshKeyboards(self):
table = self.ui.keyboardTable
table.setRowCount(0)
row = 0
for hotkey in self.keyboards:
table.insertRow(row)
table.setItem(row, 0, QtGui.QTableWidgetItem(hotkey['key']))
table.setItem(row, 1, QtGui.QTableWidgetItem(hotkey['action']))
removeBtn = QtGui.QPushButton(table)
removeBtn.setText('Remove')
table.setCellWidget(row, 2, removeBtn)
row += 1
def readStartup(self):
table = self.ui.startupTable
row = 0
for startup in self.config['startup']:
table.insertRow(row)
table.setItem(row, 0, QtGui.QTableWidgetItem(startup))
removeBtn = QtGui.QPushButton(table)
removeBtn.setText('Remove')
table.setCellWidget(row, 1, removeBtn)
row += 1
def refreshModes(self):
tabs = self.ui.modesTab
tabs.clear()
for modeKey in self.modes:
tabContent = QtGui.QWidget()
modeKeyboardTable = QtGui.QTableWidget(tabContent)
modeKeyboardTable.setGeometry(QtCore.QRect(10, 10, 700, 350))
modeKeyboardTable.setObjectName("mode"+modeKey+"KeyboardTable")
modeKeyboardTable.setColumnCount(3)
modeKeyboardTable.setRowCount(0)
item = QtGui.QTableWidgetItem("Hotkey")
modeKeyboardTable.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem("Action")
modeKeyboardTable.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem("Remove")
modeKeyboardTable.setHorizontalHeaderItem(2, item)
table = modeKeyboardTable
row = 0
for modeHotkey in self.config['mode'][modeKey]:
table.insertRow(row)
table.setItem(row, 0, QtGui.QTableWidgetItem(modeHotkey['key']))
table.setItem(row, 1, QtGui.QTableWidgetItem(modeHotkey['action']))
removeBtn = QtGui.QPushButton(table)
removeBtn.setText('Remove')
table.setCellWidget(row, 2, removeBtn)
row += 1
modeFormLayoutWidget1 = QtGui.QWidget(tabContent)
modeFormLayoutWidget1.setGeometry(QtCore.QRect(10, 370, 211, 22))
modeFormLayoutWidget1.setObjectName("mode"+modeKey+"FormLayoutWidget1")
modeFormLayout1 = QtGui.QFormLayout(modeFormLayoutWidget1)
modeFormLayout1.setMargin(0)
modeFormLayout1.setObjectName("mode"+modeKey+"FormLayout1")
modeFormLabel = QtGui.QLabel(modeFormLayoutWidget1)
modeFormLabel.setText("Hotkey")
modeFormLayout1.setWidget(0, QtGui.QFormLayout.LabelRole, modeFormLabel)
keyboardHotkey = QtGui.QLineEdit(modeFormLayoutWidget1)
keyboardHotkey.setObjectName("mode"+modeKey+"keyboardHotkey")
modeFormLayout1.setWidget(0, QtGui.QFormLayout.FieldRole, keyboardHotkey)
modeFormLayoutWidget2 = QtGui.QWidget(tabContent)
modeFormLayoutWidget2.setGeometry(QtCore.QRect(230, 370, 421, 22))
modeFormLayout2 = QtGui.QFormLayout(modeFormLayoutWidget2)
modeFormLayout2.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
modeFormLayout2.setMargin(0)
keyboardAction = QtGui.QLineEdit(modeFormLayoutWidget2)
keyboardAction.setObjectName("mode"+modeKey+"keyboardAction")
modeFormLayout2.setWidget(0, QtGui.QFormLayout.FieldRole, keyboardAction)
modeFormLabel2 = QtGui.QLabel(modeFormLayoutWidget2)
modeFormLabel2.setText("Action")
modeFormLayout2.setWidget(0, QtGui.QFormLayout.LabelRole, modeFormLabel2)
btnKeyboardInsert = QtGui.QPushButton(tabContent)
btnKeyboardInsert.setGeometry(QtCore.QRect(660, 370, 55, 21))
btnKeyboardInsert.setText("Insert")
tabs.addTab(tabContent, modeKey)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
i3manager = MainWindow()
i3manager.show()
sys.exit(app.exec_())