forked from crftwr/cfiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfiler_mainwindow.py
7042 lines (5448 loc) · 278 KB
/
cfiler_mainwindow.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
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import gc
import re
import io
import math
import time
import cProfile
import fnmatch
import threading
import configparser
import traceback
import ctypes
import msvcrt
import unicodedata
import pyauto
import ckit
from ckit.ckit_const import *
import cfiler_filelist
import cfiler_isearch
import cfiler_archiver
import cfiler_statusbar
import cfiler_msgbox
import cfiler_listwindow
import cfiler_resultwindow
import cfiler_overwritewindow
import cfiler_renamewindow
import cfiler_grepwindow
import cfiler_textviewer
import cfiler_imageviewer
import cfiler_musicplayer
import cfiler_configmenu
import cfiler_bookmark
import cfiler_commandline
import cfiler_history
import cfiler_misc
import cfiler_filecmp
import cfiler_native
import cfiler_resource
import cfiler_error
import cfiler_debug
MessageBox = cfiler_msgbox.MessageBox
OverWriteWindow = cfiler_overwritewindow.OverWriteWindow
## @addtogroup mainwindow
## @{
#--------------------------------------------------------------------
class Log:
def __init__(self):
self.lock = threading.Lock()
self.log = [""]
self.last_line_terminated = False
def write( self, s ):
s = unicodedata.normalize( "NFC", s )
self.lock.acquire()
try:
while True:
return_pos = s.find("\n")
if return_pos < 0 : break
if self.last_line_terminated:
self.log.append("")
self.log[-1] += s[:return_pos]
s = s[return_pos+1:]
self.last_line_terminated = True
if len(s)>0 :
if self.last_line_terminated:
self.log.append("")
self.log[-1] += s
self.last_line_terminated = False
if len(self.log)>1000:
self.log = self.log[-1000:]
finally:
self.lock.release()
def numLines(self):
return len(self.log)
def getLine(self,lineno):
try:
return self.log[lineno]
except IndexError:
return ""
#--------------------------------------------------------------------
class History:
def __init__(self):
self.items = []
def append( self, path, cursor_filename, visible=True, mark=False ):
for i in range(len(self.items)):
if self.items[i][0]==path:
if self.items[i][3] : mark=True
del self.items[i]
break
self.items.insert( 0, ( path, cursor_filename, visible, mark ) )
if len(self.items)>100:
self.items = self.items[:100]
def remove( self, path ):
for i in range(len(self.items)):
if self.items[i][0]==path:
del self.items[i]
return
raise KeyError
def find( self, path ):
for item in self.items:
if item[0]==path:
return item
return None
def findStartWith( self, path ):
for item in self.items:
if item[0][:len(path)].upper()==path.upper():
return item
return None
def findLastVisible(self):
for item in self.items:
if item[2]:
return item
return None
def save( self, ini, section ):
i=0
for item in self.items:
if item[2]:
ini.set( section, "history_%d"%(i,), item[0] )
i+=1
while True:
if not ini.remove_option( section, "history_%d"%(i,) ) : break
i+=1
def load( self, ini, section ):
for i in range(100):
try:
item = ( ckit.normPath(ini.get( section, "history_%d"%(i,) )), "", True, False )
self.items.append(item)
except configparser.NoOptionError:
break
#--------------------------------------------------------------------
class MouseInfo:
def __init__( self, mode, **args ):
self.mode = mode
self.__dict__.update(args)
#--------------------------------------------------------------------
PAINT_LEFT_LOCATION = 1<<0
PAINT_LEFT_HEADER = 1<<1
PAINT_LEFT_ITEMS = 1<<2
PAINT_LEFT_FOOTER = 1<<3
PAINT_RIGHT_LOCATION = 1<<4
PAINT_RIGHT_HEADER = 1<<5
PAINT_RIGHT_ITEMS = 1<<6
PAINT_RIGHT_FOOTER = 1<<7
PAINT_FOCUSED_LOCATION = 1<<8
PAINT_FOCUSED_HEADER = 1<<9
PAINT_FOCUSED_ITEMS = 1<<10
PAINT_FOCUSED_FOOTER = 1<<11
PAINT_VERTICAL_SEPARATOR = 1<<12
PAINT_LOG = 1<<13
PAINT_STATUS_BAR = 1<<14
PAINT_LEFT = PAINT_LEFT_LOCATION | PAINT_LEFT_HEADER | PAINT_LEFT_ITEMS | PAINT_LEFT_FOOTER
PAINT_RIGHT = PAINT_RIGHT_LOCATION | PAINT_RIGHT_HEADER | PAINT_RIGHT_ITEMS | PAINT_RIGHT_FOOTER
PAINT_FOCUSED = PAINT_FOCUSED_LOCATION | PAINT_FOCUSED_HEADER | PAINT_FOCUSED_ITEMS | PAINT_FOCUSED_FOOTER
PAINT_UPPER = PAINT_LEFT | PAINT_RIGHT | PAINT_VERTICAL_SEPARATOR
PAINT_ALL = PAINT_LEFT | PAINT_RIGHT | PAINT_VERTICAL_SEPARATOR | PAINT_LOG | PAINT_STATUS_BAR
## ファイラのメインウインドウ
#
# ファイラの主な機能を実現しているクラスです。\n\n
# 設定ファイル config.py の configure に渡される window 引数は、MainWindow クラスのオブジェクトです。
#
class MainWindow( ckit.TextWindow ):
FOCUS_LEFT = 0
FOCUS_RIGHT = 1
image_file_ext_list = ( ".bmp", ".gif", ".jpg", ".jpeg", ".png", ".psd", ".tga", ".tif", ".tiff" )
music_file_ext_list = ( ".mp3", ".wma", ".wav" )
def __init__( self, config_filename, ini_filename, debug=False, profile=False ):
self.initialized = False
self.quit_required = True
self.top_level_quitting = False
self.config_filename = config_filename
self.debug = debug
self.profile = profile
self.ini = configparser.RawConfigParser()
self.ini_filename = ini_filename
self.loadState()
self.loadTheme()
x = self.ini.getint( "GEOMETRY", "x" )
y = self.ini.getint( "GEOMETRY", "y" )
# ウインドウの左上位置のDPIによってをフォントサイズ決定する
dpi_scale = ckit.TextWindow.getDisplayScalingFromPosition( x, y )
font_size = self.ini.getint( "FONT", "size" )
font_size = round( font_size * dpi_scale )
ckit.TextWindow.__init__(
self,
x=x,
y=y,
width=self.ini.getint( "GEOMETRY", "width" ),
height=self.ini.getint( "GEOMETRY", "height" ),
font_name = self.ini.get( "FONT", "name" ),
font_size = font_size,
bg_color = ckit.getColor("bg"),
cursor0_color = ckit.getColor("cursor0"),
cursor1_color = ckit.getColor("cursor1"),
border_size = 2,
title_bar = True,
title = cfiler_resource.cfiler_appname,
cursor = True,
sysmenu=True,
activate_handler = self._onActivate,
close_handler = self._onClose,
move_handler = self._onMove,
size_handler = self._onSize,
dpi_handler = self._onDpi,
keydown_handler = self._onKeyDown,
keyup_handler = self._onKeyUp,
char_handler = self._onChar,
lbuttondown_handler = self._onLeftButtonDownOutside,
lbuttonup_handler = self._onLeftButtonUpOutside,
mbuttondown_handler = self._onMiddleButtonDownOutside,
mbuttonup_handler = self._onMiddleButtonUpOutside,
rbuttondown_handler = self._onRightButtonDownOutside,
rbuttonup_handler = self._onRightButtonUpOutside,
lbuttondoubleclick_handler = self._onLeftButtonDoubleClickOutside,
mousemove_handler = self._onMouseMoveOutside,
mousewheel_handler= self._onMouseWheelOutside,
)
# モニター境界付近でウインドウが作成された場合を考慮して、DPIを再確認する
dpi_scale2 = self.getDisplayScaling()
if dpi_scale2 != dpi_scale:
self.updateFont()
if self.ini.getint( "DEBUG", "detect_block" ):
cfiler_debug.enableBlockDetector()
if self.ini.getint( "DEBUG", "print_errorinfo" ):
cfiler_debug.enablePrintErrorInfo()
self.setCursorPos( -1, -1 )
self.updateHotKey()
self.focus = MainWindow.FOCUS_LEFT
self.left_window_width = self.ini.getint( "GEOMETRY", "left_window_width" )
self.log_window_height = self.ini.getint( "GEOMETRY", "log_window_height" )
self.command = ckit.CommandMap(self)
self.show_hidden = False
self.status_bar = cfiler_statusbar.StatusBar()
self.status_bar_layer = cfiler_statusbar.SimpleStatusBarLayer()
self.status_bar_resistered = False
self.status_bar_paint_hook = None
self.commandline_edit = None
self.progress_bar = None
self.bookmark = cfiler_bookmark.Bookmark()
self.bookmark.load( self.ini, "BOOKMARK" )
class Pane:
pass
self.left_pane = Pane()
self.left_pane.history = History()
self.left_pane.history.load( self.ini, "LEFTPANE" )
self.left_pane.found_prefix = ""
self.left_pane.found_location = ""
self.left_pane.found_items = []
self.left_pane.file_list = cfiler_filelist.FileList( self, cfiler_filelist.lister_Empty() )
self.left_pane.scroll_info = ckit.ScrollInfo()
self.left_pane.cursor = 0
self.left_pane.footer_paint_hook = None
self.right_pane = Pane()
self.right_pane.history = History()
self.right_pane.history.load( self.ini, "RIGHTPANE" )
self.right_pane.found_prefix = ""
self.right_pane.found_location = ""
self.right_pane.found_items = []
self.right_pane.file_list = cfiler_filelist.FileList( self, cfiler_filelist.lister_Empty() )
self.right_pane.scroll_info = ckit.ScrollInfo()
self.right_pane.cursor = 0
self.right_pane.footer_paint_hook = None
self.log_pane = Pane()
self.log_pane.log = Log()
self.log_pane.scroll_info = ckit.ScrollInfo()
self.log_pane.selection = [ [ 0, 0 ], [ 0, 0 ] ]
self.keymap = ckit.Keymap()
self.jump_list = []
self.filter_list = []
self.select_filter_list = []
self.compare_list = []
self.compare_tool_list = []
self.sorter_list = []
self.archiver_list = []
self.association_list = []
self.itemformat_list = []
self.itemformat = cfiler_filelist.itemformat_Name_Ext_Size_YYMMDD_HHMMSS
self.editor = "notepad.exe"
self.diff_editor = None
self.commandline_list = []
self.commandline_history = cfiler_history.History(1000)
self.commandline_history.load( self.ini, "COMMANDLINE" )
self.pattern_history = cfiler_history.History()
self.pattern_history.load( self.ini, "PATTERN" )
self.search_history = cfiler_history.History()
self.search_history.load( self.ini, "SEARCH" )
self.launcher = cfiler_commandline.commandline_Launcher(self)
self.keydown_hook = None
self.char_hook = None
self.enter_hook = None
self.mouse_event_mask = False
self.mouse_click_info = None
self.musicplayer = None
self.migemo = None
self.task_queue_stack = []
self.synccall = ckit.SyncCall()
self.user_input_ownership = threading.Lock()
self.setTimer( self.onTimerJob, 10 )
self.setTimer( self.onTimerSyncCall, 10 )
self.setTimer( self.onTimerAutoRefresh, 100 )
cfiler_misc.registerNetConnectionHandler( self._onCheckNetConnection )
try:
self.createThemePlane()
except Exception:
cfiler_debug.printErrorInfo()
try:
self.wallpaper = None
self.updateWallpaper()
except Exception:
cfiler_debug.printErrorInfo()
self.wallpaper = None
self.initialized = True
self.quit_required = False
self.paint()
def destroy(self):
self.left_pane.file_list.destroy()
self.right_pane.file_list.destroy()
cfiler_debug.disableBlockDetector()
ckit.TextWindow.destroy(self)
def messageLoop( self, continue_cond_func=None ):
if not continue_cond_func:
def defaultLoopCond():
if self.quit_required:
self.quit_required = False
return False
return True
continue_cond_func = defaultLoopCond
ckit.TextWindow.messageLoop( self, continue_cond_func )
def topLevelMessageLoop(self):
def isLoopContinue():
if self.quit_required:
self.top_level_quitting = True
self.enable(False)
if self.task_queue_stack:
for task_queue in self.task_queue_stack:
task_queue.cancel()
return True
return False
return True
self.messageLoop(isLoopContinue)
def quit(self):
self.quit_required = True
def isQuitting(self):
return self.top_level_quitting
## ユーザ入力権を獲得する
#
# @param self -
# @param blocking ユーザ入力権を獲得するまでブロックするか
#
# 内骨格をマウスやキーボードで操作させる権利を獲得するための関数です。\n\n
#
# バックグラウンド処理の途中や最後でユーザの操作を受け付ける場合には、
# releaseUserInputOwnership と releaseUserInputOwnership を使って、
# 入力権を所有する必要があります。
# さもないと、フォアグラウンドのユーザ操作と衝突してしまい、ユーザが混乱したり、
# 内骨格が正しく動作しなくなります。\n\n
#
# @sa releaseUserInputOwnership
#
def acquireUserInputOwnership( self, blocking=1 ):
return self.user_input_ownership.acquire(blocking)
## ユーザ入力権を解放する
#
# @sa acquireUserInputOwnership
#
def releaseUserInputOwnership(self):
self.user_input_ownership.release()
def onTimerJob(self):
# タスクキューが空っぽだったら破棄する
if len(self.task_queue_stack)>0:
if self.task_queue_stack[-1].numItems()==0:
self.task_queue_stack[-1].cancel()
self.task_queue_stack[-1].join()
self.task_queue_stack[-1].destroy()
del self.task_queue_stack[-1]
# 新しくアクティブになったタスクキューを再開する
if len(self.task_queue_stack)>0:
self.task_queue_stack[-1].restart()
if not self.acquireUserInputOwnership(False) : return
try:
ckit.JobQueue.checkAll()
finally:
self.releaseUserInputOwnership()
def onTimerSyncCall(self):
self.synccall.check()
def onTimerAutoRefresh(self):
if len(self.task_queue_stack)>0 : return
if not self.acquireUserInputOwnership(False) : return
try:
if self.left_pane.file_list.isChanged():
self.refreshFileList( self.left_pane, True, True )
self.paint(PAINT_LEFT)
if self.right_pane.file_list.isChanged():
self.refreshFileList( self.right_pane, True, True )
self.paint(PAINT_RIGHT)
finally:
self.releaseUserInputOwnership()
## サブスレッドで処理を実行する
#
# @param self -
# @param func サブスレッドで実行する呼び出し可能オブジェクト
# @param arg 引数 func に渡す引数
# @param cancel_func ESCキーが押されたときのキャンセル処理
# @param cancel_func_arg 引数 cancel_func に渡す引数
# @param raise_error 引数 func のなかで例外が発生したときに、それを raise するか
#
# メインスレッドのユーザインタフェイスの更新を止めずに、サブスレッドの中で任意の処理を行うための関数です。\n\n
#
# この関数のなかでは、引数 func をサブスレッドで呼び出しながら、メインスレッドでメッセージループを回します。
# 返値には、引数 func の返値がそのまま返ります。\n\n
#
# ファイルのコピーや画像のデコードなどの、比較的時間のかかる処理は、メインスレッドではなくサブスレッドの中で処理するように心がけるべきです。
# さもないと、メインスレッドがブロックし、ウインドウの再描画などが長時間されないままになるといった弊害が発生します。
#
def subThreadCall( self, func, arg, cancel_func=None, cancel_func_arg=(), raise_error=False ):
class SubThread( threading.Thread ):
def __init__( self, main_window ):
threading.Thread.__init__(self)
self.main_window = main_window
self.result = None
self.error = None
def run(self):
ckit.setBlockDetector()
try:
self.result = func(*arg)
except Exception as e:
cfiler_debug.printErrorInfo()
self.error = e
def onKeyDown( vk, mod ):
if vk==VK_ESCAPE:
if cancel_func:
cancel_func(*cancel_func_arg)
return True
def onChar( ch, mod ):
return True
keydown_hook_old = self.keydown_hook
char_hook_old = self.char_hook
mouse_event_mask_old = self.mouse_event_mask
sub_thread = SubThread(self)
sub_thread.start()
self.keydown_hook = onKeyDown
self.char_hook = onChar
self.mouse_event_mask = True
self.removeKeyMessage()
self.messageLoop( sub_thread.isAlive )
sub_thread.join()
result = sub_thread.result
error = sub_thread.error
del sub_thread
self.keydown_hook = keydown_hook_old
self.char_hook = char_hook_old
self.mouse_event_mask = mouse_event_mask_old
if error:
if raise_error:
raise error
else:
print( error )
return result
## コンソールプログラムをサブプロセスとして実行する
#
# @param self -
# @param cmd コマンドと引数のシーケンス
# @param cwd サブプロセスのカレントディレクトリ
# @param env サブプロセスの環境変数
# @param enable_cancel True:ESCキーでキャンセルする False:ESCキーでキャンセルしない
#
# 任意のコンソールプログラムを、ファイラのサブプロセスとして実行し、そのプログラムの出力を、ログペインにリダイレクトします。\n\n
#
# 引数 cmd には、サブプロセスとして実行するプログラムと引数をリスト形式で渡します。\n
# 例: [ "subst", "R:", "//remote-machine/public/" ]
#
def subProcessCall( self, cmd, cwd=None, env=None, enable_cancel=False ):
p = ckit.SubProcess(cmd,cwd,env)
if enable_cancel:
cancel_handler = p.cancel
else:
cancel_handler = None
return self.subThreadCall( p, (), cancel_handler )
## バックグラウンドタスクのキューに、タスクを投入する
#
# @param self -
# @param job_item バックグラウンドタスクとして実行する JobItem オブジェクト
# @param comment ユーザに説明する際のタスクの名前
# @param create_new_queue 新しいタスクキューを作成し、優先的に処理するか。( True:作成する False:作成しない None:問い合わせる )
#
# 内骨格はバックグランド処理をサポートしており、ファイルのコピーや検索などの時間のかかる処理をバックグラウンドで実行しながら、
# ほかのディレクトリを閲覧したり、次に実行するバックグランド処理を予約したりすることが出来ます。\n\n
#
# バックグランド処理は、複数予約することが出来ますが、同時に実行することが出来るのは1つだけで、キュー(待ち行列)に投入されて、
# 順番に処理されます。
#
def taskEnqueue( self, job_item, comment="", create_new_queue=None ):
if len(self.task_queue_stack)>0:
if create_new_queue==None:
result = cfiler_msgbox.popMessageBox( self, MessageBox.TYPE_YESNO, "タスクの処理順序の確認", "優先的に処理を行いますか?" )
if result==MessageBox.RESULT_YES:
create_new_queue = True
elif result==MessageBox.RESULT_NO:
create_new_queue = False
else:
return
else:
create_new_queue = True
# メッセージダイアログ中にキューが空っぽになった場合は、キューを作成する
if len(self.task_queue_stack)==0:
create_new_queue = True
if create_new_queue:
new_task_queue = ckit.JobQueue()
# まず前のタスクキューをポーズする処理を投入する
if len(self.task_queue_stack)>0:
prev_task_queue = self.task_queue_stack[-1]
def jobPause( job_item ):
prev_task_queue.pause()
pause_job_item = ckit.JobItem( jobPause, None )
new_task_queue.enqueue(pause_job_item)
self.task_queue_stack.append(new_task_queue)
else:
if comment and self.task_queue_stack[-1].numItems()>0:
self.setStatusMessage( "タスクを予約しました : %s" % comment, 3000 )
# バックグラウンド処理中、lister が破棄されないようにコピーする
left_lister, tmp = self.leftFileList().getLister().getCopy("")
right_lister, tmp = self.rightFileList().getLister().getCopy("")
def destroyLister(job_item):
left_lister.destroy()
right_lister.destroy()
job_item.finished_func_list += [ destroyLister ]
self.task_queue_stack[-1].enqueue(job_item)
## コマンドラインで文字列を入力する
#
# @param self -
# @param title コマンド入力欄の左側に表示されるタイトル文字列
# @param text コマンド入力欄の初期文字列
# @param selection コマンド入力欄の初期選択範囲
# @param auto_complete 自動補完を有効にするか
# @param autofix_list 入力確定をする文字のリスト
# @param return_modkey 入力欄が閉じたときに押されていたモディファイアキーを取得するか
# @param update_handler コマンド入力欄の変更があったときに通知を受けるためのハンドラ
# @param candidate_handler 補完候補を列挙するためのハンドラ
# @param candidate_remove_handler 補完候補を削除するためのハンドラ
# @param status_handler コマンド入力欄の右側に表示されるステータス文字列を返すためのハンドラ
# @param enter_handler コマンド入力欄でEnterキーが押されたときのハンドラ
# @return 入力された文字列
#
# 内骨格のメインウインドウの下端のステータスバーの領域をつかって、任意の文字列の入力を受け付けるための関数です。\n\n
#
def commandLine( self, title, text="", selection=None, auto_complete=False, autofix_list=None, return_modkey=False, update_handler=None, candidate_handler=None, candidate_remove_handler=None, status_handler=None, enter_handler=None ):
title = " " + title + " "
title_width = self.getStringWidth(title)
status_string = [ "" ]
result = [ None ]
result_mod = [ 0 ]
class CommandLine:
def __init__( self, main_window ):
self.main_window = main_window
self.planned_command_list = []
def _onKeyDown( self, vk, mod ):
result_mod[0] = mod
if self.main_window.commandline_edit.onKeyDown( vk, mod ):
return True
if vk==VK_RETURN:
result[0] = self.main_window.commandline_edit.getText()
if enter_handler:
self.closeList()
if enter_handler( self, result[0], mod ):
return True
self.quit()
elif vk==VK_ESCAPE:
if self.main_window.commandline_edit.getText():
self.main_window.commandline_edit.clear()
else:
self.quit()
return True
def _onChar( self, ch, mod ):
result_mod[0] = mod
self.main_window.commandline_edit.onChar( ch, mod )
return True
def _onUpdate( self, update_info ):
if update_handler:
if not update_handler(update_info):
return False
if status_handler:
status_string[0] = status_handler(update_info)
self.main_window.paint(PAINT_STATUS_BAR)
def _onPaint( self, x, y, width, height ):
status_string_for_paint = " " + status_string[0] + " "
status_width = self.main_window.getStringWidth(status_string_for_paint)
attr = ckit.Attribute( fg=ckit.getColor("bar_fg"))
self.main_window.putString( x, y, title_width, height, attr, title )
self.main_window.putString( x+width-status_width, y, status_width, height, attr, status_string_for_paint )
if self.main_window.theme_enabled:
client_rect = self.main_window.getClientRect()
offset_x, offset_y = self.main_window.charToClient( 0, 0 )
char_w, char_h = self.main_window.getCharSize()
frame_width = 2
self.main_window.plane_statusbar.setPosSize( 0, (self.main_window.height()-1)*char_h+offset_y-frame_width, client_rect[2], client_rect[3]-((self.main_window.height()-1)*char_h+offset_y-frame_width) )
self.main_window.plane_commandline.setPosSize( title_width*char_w+offset_x, (self.main_window.height()-1)*char_h+offset_y-frame_width, client_rect[2]-((title_width+status_width)*char_w+offset_x), char_h+frame_width*2 )
self.main_window.commandline_edit.setPosSize( x+title_width, y, width-title_width-status_width, height )
self.main_window.commandline_edit.enableCursor(True)
self.main_window.commandline_edit.paint()
def getText(self):
return self.main_window.commandline_edit.getText()
def setText( self, text ):
self.main_window.commandline_edit.setText(text)
def getSelection(self):
return self.main_window.commandline_edit.getSelection()
def setSelection(self,selection):
self.main_window.commandline_edit.setSelection(selection)
def selectAll(self):
self.main_window.commandline_edit.selectAll()
def closeList(self):
self.main_window.commandline_edit.closeList()
def planCommand( self, command, info, history ):
self.planned_command_list.append( ( command, info, history ) )
def appendHistory(self,newentry):
self.main_window.commandline_history.append(newentry)
def quit(self):
self.main_window.quit()
commandline_edit_old = self.commandline_edit
keydown_hook_old = self.keydown_hook
char_hook_old = self.char_hook
mouse_event_mask_old = self.mouse_event_mask
status_bar_paint_hook_old = self.status_bar_paint_hook
commandline = CommandLine(self)
self.commandline_edit = ckit.EditWidget( self, title_width, self.height()-1, self.width()-title_width, 1, text, selection, auto_complete=auto_complete, no_bg=True, autofix_list=autofix_list, update_handler=commandline._onUpdate, candidate_handler=candidate_handler, candidate_remove_handler=candidate_remove_handler )
self.keydown_hook = commandline._onKeyDown
self.char_hook = commandline._onChar
self.mouse_event_mask = True
self.status_bar_paint_hook = commandline._onPaint
if status_handler:
status_string[0] = status_handler(ckit.EditWidget.UpdateInfo(text,selection))
if self.theme_enabled:
self.plane_commandline.show(True)
self.paint(PAINT_STATUS_BAR)
self.removeKeyMessage()
self.messageLoop()
self.commandline_edit.destroy()
self.commandline_edit = commandline_edit_old
self.keydown_hook = keydown_hook_old
self.char_hook = char_hook_old
self.mouse_event_mask = mouse_event_mask_old
self.status_bar_paint_hook = status_bar_paint_hook_old
if self.theme_enabled:
self.plane_commandline.show(False)
self.enableIme(False)
self.setCursorPos( -1, -1 )
self.updateThemePosSize()
self.paint(PAINT_STATUS_BAR)
for command, info, history in commandline.planned_command_list:
try:
command(info)
if history:
self.commandline_history.append(history)
except Exception as e:
print( e )
cfiler_debug.printErrorInfo()
if return_modkey:
return result[0], result_mod[0]
else:
return result[0]
def _onActivate( self, active ):
self.active = active
def _onClose( self ):
self.quit()
def _onMove( self, x, y ):
if not self.initialized : return
if self.commandline_edit:
self.commandline_edit.onWindowMove()
def _onSize( self, width, height ):
if not self.initialized : return
if self.left_window_width>width-1 : self.left_window_width=width-1
if self.log_window_height>height-4 : self.log_window_height=height-4
if self.log_window_height<0 : self.log_window_height=0
self.left_pane.scroll_info.makeVisible( self.left_pane.cursor, self.fileListItemPaneHeight(), 1 )
self.right_pane.scroll_info.makeVisible( self.right_pane.cursor, self.fileListItemPaneHeight(), 1 )
self.updateThemePosSize()
if self.wallpaper:
self.wallpaper.adjust()
self.paint()
def updateFont(self):
scale = self.getDisplayScaling()
font_name = self.ini.get("FONT","name")
font_size = self.ini.getint( "FONT", "size" )
font_size = round( font_size * scale )
self.setFont( font_name, font_size )
original_width = self.width()
original_height = self.height()
window_rect = self.getWindowRect()
self.setPosSize( (window_rect[0] + window_rect[2]) // 2, window_rect[1], original_width, original_height, ORIGIN_X_CENTER | ORIGIN_Y_TOP )
def _onDpi( self, scale ):
self.updateFont()
def _onKeyDown( self, vk, mod ):
pane = self.activePane()
#print( "_onKeyDown", vk, mod )
if self.keydown_hook:
if self.keydown_hook( vk, mod ):
return True
selected = 0
if pane.file_list.selected():
selected = 1
try:
func = self.keymap.table[ ckit.KeyEvent(vk,mod,extra=selected) ]
except KeyError:
return
if not self.acquireUserInputOwnership(False) : return
try:
if self.profile:
cProfile.runctx( "func( ckit.CommandInfo() )", globals(), locals() )
else:
func( ckit.CommandInfo() )
finally:
self.releaseUserInputOwnership()
return True
def _onKeyUp( self, vk, mod ):
#print( "_onKeyUp", vk, mod )
pass
def _onChar( self, ch, mod ):
pane = self.activePane()
#print( "_onChar", ch, mod )
if self.char_hook:
if self.char_hook( ch, mod ):
return
def _onLeftButtonDownOutside( self, x, y, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onLeftButtonDown(x, y, mod)
finally:
self.releaseUserInputOwnership()
def _onLeftButtonUpOutside( self, x, y, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onLeftButtonUp(x, y, mod)
finally:
self.releaseUserInputOwnership()
def _onMiddleButtonDownOutside( self, x, y, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onMiddleButtonDown(x, y, mod)
finally:
self.releaseUserInputOwnership()
def _onMiddleButtonUpOutside( self, x, y, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onMiddleButtonUp(x, y, mod)
finally:
self.releaseUserInputOwnership()
def _onRightButtonDownOutside( self, x, y, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onRightButtonDown(x, y, mod)
finally:
self.releaseUserInputOwnership()
def _onRightButtonUpOutside( self, x, y, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onRightButtonUp(x, y, mod)
finally:
self.releaseUserInputOwnership()
def _onLeftButtonDoubleClickOutside( self, x, y, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onLeftButtonDoubleClick(x, y, mod)
finally:
self.releaseUserInputOwnership()
def _onMouseMoveOutside( self, x, y, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onMouseMove(x, y, mod)
finally:
self.releaseUserInputOwnership()
def _onMouseWheelOutside( self, x, y, wheel, mod ):
if not self.acquireUserInputOwnership(False) : return
try:
self._onMouseWheel(x, y, wheel, mod)
finally:
self.releaseUserInputOwnership()
def _mouseCommon( self, x, y, focus=True ):
client_rect = self.getClientRect()
offset_x, offset_y = self.charToClient( 0, 0 )
char_w, char_h = self.getCharSize()
char_x = (x-offset_x) // char_w
char_y = (y-offset_y) // char_h
left_pane_rect = list( self.leftPaneRect() )
right_pane_rect = list( self.rightPaneRect() )
log_pane_rect = list( self.logPaneRect() )
region = None
pane = None
pane_rect = None
if left_pane_rect[0]<=char_x<left_pane_rect[2] and left_pane_rect[1]<=char_y<left_pane_rect[3]:
if focus : self.command.FocusLeft()
if left_pane_rect[1]==char_y:
region = PAINT_LEFT_LOCATION
pane = self.left_pane