Repository navigation
Expand file tree
/
Copy pathclnch_configmenu.py
More file actions
497 lines (342 loc) · 15.8 KB
/
Copy pathclnch_configmenu.py
File metadata and controls
497 lines (342 loc) · 15.8 KB
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
import os
import sys
import pyauto
import ckit
from ckit.ckit_const import *
import clnch_listwindow
import clnch_msgbox
import clnch_misc
import clnch_ini
import clnch_resource
import clnch_statusbar
#--------------------------------------------------------------------
def _configTheme( main_window ):
def enumThemes():
theme_list = []
theme_parent = os.path.join( ckit.getAppExePath(), 'theme' )
theme_dir_list = os.listdir(theme_parent)
for theme_dir in theme_dir_list:
if os.path.exists( os.path.join( theme_parent, theme_dir, "theme.ini" ) ):
theme_list.append( theme_dir )
return theme_list
theme_list = enumThemes()
current_theme_name = clnch_ini.get( "THEME", "name", "" )
try:
initial_select = theme_list.index(current_theme_name)
except:
initial_select = 0
result = clnch_listwindow.popMenu( main_window, 40, 16, "テーマ", theme_list, initial_select )
if result<0 : return
clnch_ini.set( "THEME", "name", theme_list[result] )
main_window.reloadTheme()
return False
def _configFontName( main_window ):
font_list = main_window.enumFonts()
current_font_name = clnch_ini.get( "FONT", "name", "" )
try:
initial_select = font_list.index(current_font_name)
except:
initial_select = 0
result = clnch_listwindow.popMenu( main_window, 40, 16, "フォント", font_list, initial_select )
if result<0 : return
clnch_ini.set( "FONT", "name", font_list[result] )
main_window.updateFont()
def _configFontSize( main_window ):
size_list = range(6,33)
current_font_size = clnch_ini.getint( "FONT", "size", 12 )
try:
initial_select = size_list.index(current_font_size)
except:
initial_select = 0
size_list = list(map( str, size_list ))
result = clnch_listwindow.popMenu( main_window, 40, 16, "フォントサイズ", size_list, initial_select )
if result<0 : return
clnch_ini.set( "FONT", "size", size_list[result] )
main_window.updateFont()
def _configMinWidth( main_window ):
width_list = range(12,81)
min_width = clnch_ini.getint( "GEOMETRY", "min_width", 18 )
try:
initial_select = width_list.index(min_width)
except:
initial_select = 0
width_list = list(map( str, width_list ))
result = clnch_listwindow.popMenu( main_window, 40, 16, "最小のウインドウサイズ", width_list, initial_select )
if result<0 : return
clnch_ini.set( "GEOMETRY", "min_width", width_list[result] )
def _configMaxWidth( main_window ):
width_list = range(16,161)
max_width = clnch_ini.getint( "GEOMETRY", "max_width", 80 )
try:
initial_select = width_list.index(max_width)
except:
initial_select = 0
width_list = list(map( str, width_list ))
result = clnch_listwindow.popMenu( main_window, 40, 16, "最大のウインドウサイズ", width_list, initial_select )
if result<0 : return
clnch_ini.set( "GEOMETRY", "max_width", width_list[result] )
def _configPosition( main_window ):
result = clnch_msgbox.popMessageBox( main_window, clnch_msgbox.MSGBOX_TYPE_YESNO, "ウインドウ位置の保存の確認", "現在のウインドウ位置を保存しますか?" )
if result!=clnch_msgbox.MSGBOX_RESULT_YES : return
rect = list( main_window.getWindowRect() )
monitor_info_list = pyauto.Window.getMonitorInfo()
for i in range(len(monitor_info_list)):
monitor_info = monitor_info_list[i]
if monitor_info[0][0] <= rect[0] < monitor_info[0][2] and monitor_info[0][1] <= rect[1] < monitor_info[0][3]:
if rect[2]>monitor_info[0][2]:
delta = rect[2]-monitor_info[0][2]
rect[0] -= delta
rect[2] -= delta
if rect[3]>monitor_info[0][3]:
delta = rect[3]-monitor_info[0][3]
rect[1] -= delta
rect[3] -= delta
break
else:
left = monitor_info_list[0][0][0]
top = monitor_info_list[0][0][1]
rect = [ left, top, left+rect[2]-rect[0], top+rect[3]-rect[1] ]
for i in range(len(monitor_info_list)):
monitor_info = monitor_info_list[i]
if monitor_info[0][0] <= rect[0] < monitor_info[0][2] and monitor_info[0][1] <= rect[1] < monitor_info[0][3]:
clnch_ini.set( "GEOMETRY", "monitor", str(i) )
if rect[0]-monitor_info[0][0] <= monitor_info[0][2]-rect[2]:
# モニター左端からの相対位置
clnch_ini.set( "GEOMETRY", "x", str(rect[0]-monitor_info[0][0]) )
else:
# モニター右端からの相対位置
clnch_ini.set( "GEOMETRY", "x", str(rect[2]-monitor_info[0][2]-1) )
if rect[1]-monitor_info[0][1] <= monitor_info[0][3]-rect[3]:
# モニター上端からの相対位置
clnch_ini.set( "GEOMETRY", "y", str(rect[1]-monitor_info[0][1]) )
else:
# モニター下端からの相対位置
clnch_ini.set( "GEOMETRY", "y", str(rect[3]-monitor_info[0][3]-1) )
break
clnch_msgbox.popMessageBox( main_window, clnch_msgbox.MSGBOX_TYPE_OK, "ウインドウ位置の保存完了", "ウインドウ位置を保存しました。" )
def _configTopMost( main_window ):
items = []
items.append( ( "通常", "0" ) )
items.append( ( "最前面", "1" ) )
items.append( ( "最前面のなかの最前面", "2" ) )
topmost = clnch_ini.get( "GEOMETRY", "topmost", "0" )
initial_select = 0
for i in range(len(items)):
if items[i][1]==topmost :
initial_select = i
break
result = clnch_listwindow.popMenu( main_window, 40, 16, "ウインドウの最前面表示", items, initial_select )
if result<0 : return
clnch_ini.set( "GEOMETRY", "topmost", items[result][1] )
main_window.updateTopMost()
def _configDirectorySeparator( main_window ):
items = []
items.append( ( "スラッシュ : / ", "slash" ) )
items.append( ( "バックスラッシュ : \\ ", "backslash" ) )
directory_separator = clnch_ini.get( "MISC", "directory_separator", "backslash" )
initial_select = 0
for i in range(len(items)):
if items[i][1]==directory_separator:
initial_select = i
break
result = clnch_listwindow.popMenu( main_window, 40, 16, "ディレクトリ区切り文字", items, initial_select )
if result<0 : return
clnch_ini.set( "MISC", "directory_separator", items[result][1] )
if items[result][1]=="slash":
ckit.setPathSlash(True)
else:
ckit.setPathSlash(False)
def _configKeyMap( main_window ):
items = []
items.append( ( "101キーボード", "101" ) )
items.append( ( "106キーボード", "106" ) )
default_keymap = clnch_ini.get( "MISC", "default_keymap", "106" )
initial_select = 0
for i in range(len(items)):
if items[i][1]==default_keymap:
initial_select = i
break
result = clnch_listwindow.popMenu( main_window, 40, 16, "キー割り当て", items, initial_select )
if result<0 : return
clnch_ini.set( "MISC", "default_keymap", items[result][1] )
main_window.configure()
def _configAutoComplete( main_window ):
items = []
items.append( ( "自動補完しない", "0" ) )
items.append( ( "自動補完する", "1" ) )
auto_complete = clnch_ini.get( "MISC", "auto_complete", "1" )
initial_select = 0
for i in range(len(items)):
if items[i][1]==auto_complete:
initial_select = i
break
result = clnch_listwindow.popMenu( main_window, 40, 16, "自動補完", items, initial_select )
if result<0 : return
clnch_ini.set( "MISC", "auto_complete", items[result][1] )
def _configHotKeyAssign( main_window ):
RESULT_CANCEL = 0
RESULT_OK = 1
class HotKeyWindow( ckit.TextWindow ):
def __init__( self, x, y, parent_window, show=True ):
ckit.TextWindow.__init__(
self,
x=x,
y=y,
width=29,
height=2,
origin= ORIGIN_X_CENTER | ORIGIN_Y_CENTER,
parent_window=parent_window,
show=show,
bg_color = ckit.getColor("bg"),
cursor0_color = ckit.getColor("cursor0"),
cursor1_color = ckit.getColor("cursor1"),
resizable = False,
title = "ホットキー",
minimizebox = False,
maximizebox = False,
cursor = True,
close_handler = self.onClose,
keydown_handler = self.onKeyDown,
)
self.setCursorPos( -1, -1 )
self.result = RESULT_CANCEL
activate_vk = clnch_ini.getint( "HOTKEY", "activate_vk", 0 )
activate_mod = clnch_ini.getint( "HOTKEY", "activate_mod", 0 )
self.activate_hotkey = ckit.HotKeyWidget( self, 0, 0, self.width(), 1, activate_vk, activate_mod )
self.plane_statusbar = ckit.ThemePlane3x3( self, 'bar.png', 2 )
client_rect = self.getClientRect()
tmp, statusbar_top = self.charToClient( 0, self.height()-1 )
self.plane_statusbar.setPosSize( 0, statusbar_top, client_rect[2]-0, client_rect[3]-statusbar_top )
self.status_bar = clnch_statusbar.StatusBar()
self.status_bar_layer = clnch_statusbar.SimpleStatusBarLayer()
self.status_bar.registerLayer(self.status_bar_layer)
self.updateStatusBar()
self.paint()
def onClose(self):
self.result = RESULT_CANCEL
self.quit()
def onEnter(self):
self.result = RESULT_OK
self.quit()
def onKeyDown( self, vk, mod ):
if mod==0 and vk==VK_ESCAPE:
self.result = RESULT_CANCEL
self.quit()
elif mod==0 and vk==VK_RETURN:
self.result = RESULT_OK
self.quit()
else:
self.activate_hotkey.onKeyDown( vk, mod )
def updateStatusBar(self):
self.status_bar_layer.setMessage("Return:決定 Esc:キャンセル")
def paint(self):
self.activate_hotkey.enableCursor(True)
self.activate_hotkey.paint()
self.status_bar.paint( self, 0, self.height()-1, self.width(), 1 )
def getResult(self):
if self.result:
return [ self.activate_hotkey.getValue() ]
else:
return None
pos = main_window.centerOfWindowInPixel()
hotkey_window = HotKeyWindow( pos[0], pos[1], main_window, show=False )
clnch_misc.adjustWindowPosition( main_window, hotkey_window, default_up=False )
hotkey_window.show(True)
main_window.enable(False)
hotkey_window.messageLoop()
result = hotkey_window.getResult()
main_window.enable(True)
main_window.activate()
hotkey_window.destroy()
if result==None : return
clnch_ini.set( "HOTKEY", "activate_vk", str(result[0][0]) )
clnch_ini.set( "HOTKEY", "activate_mod", str(result[0][1]) )
main_window.updateHotKey()
def _configHotKeyBehavior( main_window ):
items = []
items.append( ( "アクティブ化", "activate" ) )
items.append( ( "トグル", "toggle" ) )
hotkey_behavior = clnch_ini.get( "MISC", "hotkey_behavior", "activate" )
initial_select = 0
for i in range(len(items)):
if items[i][1]==hotkey_behavior :
initial_select = i
break
result = clnch_listwindow.popMenu( main_window, 40, 16, "ホットキー動作設定", items, initial_select )
if result<0 : return
clnch_ini.set( "MISC", "hotkey_behavior", items[result][1] )
main_window.updateHotKey()
def _editConfigFile( main_window ):
info = ckit.CommandInfo()
info.args = [ main_window.config_filename ]
main_window.command.Edit(info)
return False
def _reloadConfigFile( main_window ):
main_window.configure()
print( "設定スクリプトをリロードしました.\n" )
return False
def _configAppearance( main_window ):
select = 0
while True:
items = []
items.append( ( "テーマ", _configTheme ) )
items.append( ( "フォント名", _configFontName ) )
items.append( ( "フォントサイズ", _configFontSize ) )
items.append( ( "最小の横幅", _configMinWidth ) )
items.append( ( "最大の横幅", _configMaxWidth ) )
items.append( ( "表示位置の保存", _configPosition ) )
items.append( ( "最前面に表示", _configTopMost ) )
items.append( ( "ディレクトリ区切り文字", _configDirectorySeparator ) )
select = clnch_listwindow.popMenu( main_window, 40, 16, "表示オプション", items, select )
if select<0 : return
loop_continue = items[select][1]( main_window )
if loop_continue==False:
return False
def _configInput( main_window ):
select = 0
while True:
items = []
items.append( ( "キー割り当て", _configKeyMap ) )
items.append( ( "自動補完", _configAutoComplete ) )
select = clnch_listwindow.popMenu( main_window, 40, 16, "入力オプション", items, select )
if select<0 : return
items[select][1]( main_window )
def _configHotKey( main_window ):
select = 0
while True:
items = []
items.append( ( "ホットキー割り当て", _configHotKeyAssign ) )
items.append( ( "ホットキー動作設定", _configHotKeyBehavior ) )
select = clnch_listwindow.popMenu( main_window, 40, 16, "ホットキー設定", items, select )
if select<0 : return
items[select][1]( main_window )
def _configInactive( main_window ):
items = []
items.append( ( "空欄", "empty" ) )
items.append( ( "時計", "clock" ) )
items.append( ( "非表示", "hide" ) )
inactive_behavior = clnch_ini.get( "MISC", "inactive_behavior", "clock" )
initial_select = 0
for i in range(len(items)):
if items[i][1]==inactive_behavior :
initial_select = i
break
result = clnch_listwindow.popMenu( main_window, 40, 16, "非アクティブ時の動作", items, initial_select )
if result<0 : return
clnch_ini.set( "MISC", "inactive_behavior", items[result][1] )
main_window.updateInactiveBehavior()
def doConfigMenu( main_window ):
select = 0
while True:
items = []
items.append( ( "表示オプション", _configAppearance ) )
items.append( ( "入力オプション", _configInput ) )
items.append( ( "ホットキー設定", _configHotKey ) )
items.append( ( "非アクティブ時の動作", _configInactive ) )
items.append( ( "config.py を編集", _editConfigFile ) )
items.append( ( "config.py をリロード", _reloadConfigFile ) )
select = clnch_listwindow.popMenu( main_window, 40, 16, "設定メニュー", items, select )
if select<0 : return
loop_continue = items[select][1]( main_window )
if loop_continue==False:
return