glib.timeout_add()
및 glib.source_remove()
을 사용하여 한 번 클릭 이벤트를 두 번 클릭 이벤트에서 분리하려고합니다. 여기에 내가 그 일을하고 어떻게 :pygtk의 두 번 클릭 이벤트 및 단일 클릭 이벤트 처리
class Exchange:
'''
some code
'''
def __init__(self):
self.timeoutID_1 = 0
self.timeoutID_2 = 0
self.startTime1 = 0.0
self.stopTime1 = 0.0
self.startTime2 = 0.0
self.stopTime2 = 0.0
'''
some code
'''
## THE DOUBLE CLICK SIGNAL - item-activated
iconView1.connect("item-activated", self.on_item_activated_1,upButton1, store1)
sw1.add(iconView1)
iconView2.connect("item-activated", self.on_item_activated_2,upButton2, store2)
sw2.add(iconView2)
## THE SINGLE CLICK SIGNAL - selection-changed
iconView1.connect("selection-changed", self.on_selection_changed_1, copyButton1, cutButton1, pasteButton1, deleteButton1)
iconView2.connect("selection-changed", self.on_selection_changed_2, copyButton2, cutButton2, pasteButton2, deleteButton2)
def on_selection_changed_1(self, iconView1, copyButton1, cutButton1, pasteButton1, deleteButton1) :
self.startTime1 = time.time()
self.timeoutID_1 = glib.timeout_add(2000, self.selectIcon_1, iconView1, copyButton1, cutButton1, pasteButton1, deleteButton1)
def on_selection_changed_2(self, iconView2, copyButton2, cutButton2, pasteButton2, deleteButton2) :
self.startTime2 = time.time()
self.timeoutID_2 = glib.timeout_add(2000, self.selectIcon_2, iconView2, copyButton2, cutButton2, pasteButton2, deleteButton2)
def selectIcon_1(self, iconView1, copyButton1, cutButton1, pasteButton1, deleteButton1) :
copyButton1.set_sensitive(True)
cutButton1.set_sensitive(True)
pasteButton1.set_sensitive(True)
deleteButton1.set_sensitive(True)
def selectIcon_2(self, iconView2, copyButton2, cutButton2, pasteButton2, deleteButton2) :
copyButton2.set_sensitive(True)
cutButton2.set_sensitive(True)
pasteButton2.set_sensitive(True)
deleteButton2.set_sensitive(True)
def on_item_activated_1(self, iconView1, item, upButton1, store1) :
self.stopTime1 = time.time()
if self.stopTime1 - self.startTime1 < 1.50 :
glib.source_remove(self.timeoutID_1)
'''
some code
'''
def on_item_activated_2(self, iconView2, item, upButton2, store2) :
self.stopTime2 = time.time()
if self.stopTime2 - self.startTime2 < 1.50 :
glib.source_remove(self.timeoutID_2)
'''
some code
'''
(유효한 더블 클릭을 의미) 인 True
self.stopTime - self.startTime <1.50
에도 불구하고, 단 한번의 클릭 이벤트가 각각 단일 클릭에 대해, 2 초 후 단 한 번만 실행됩니다. 유효한 더블 클릭에 대해 selectIcon
메소드의 실행을 완전히 취소하려면 어떻게해야합니까?
UPDATE
는 mtwebster의 대답에 따라 나는 button_press_event
을 사용했습니다. 슬프게도 나는 다시 정사각형으로 돌아 간다.
def on_button_press_event(self, widget, event) :
if event.button == 1 :
data = widget.get_path_at_pos(int(event.x), int(event.y))
if data :
if event.type == gtk.gdk._2BUTTON_PRESS :
print " double click "
elif event.type == gtk.gdk.BUTTON_PRESS :
print " single click "
OUTPUT ::
[email protected]:~/Documents/Project$ python draft6.py
single click
single click
double click
는 세 개의 클릭 이벤트가 두 번 클릭, 두 개의 단일 클릭과 더블 클릭에 대해 실행되는 내 불황에 추가!
glib.timeout_add()
대신에 사용할 수있는 다른 타이밍 메커니즘이 있습니까? 반복 된 호출 넌센스의 불확실성을 해결할 필요가없는 곳이 있습니까?
왜 신호에게 '자신을 모든' "버튼을 눌러/해제 이벤트를"처리할까요? 논리를 올바르게 얻는 것은 귀찮은 일입니다. 문서는 "item-activated"가 DOUBLE-CLICK이 활성화되어 있다고 (''on-single-click ''속성이'FALSE'와 다른 foo로 설정되어 있고''선택 변경 ' '는 일반적으로 한 번의 클릭으로 활성화됩니다 (또는 화살표 키를 누르십시오). 당신이 원하는 행동을 정교하게 만들 수 있습니까? – drahnr
@drahnr 나는 이러한 메소드를 사용했지만 iconView의 모든 단일 클릭에 대해'selection-changed'도 트리거됩니다. 잘라 내기/복사/붙여 넣기/삭제 유틸리티를 사용하여 파일 브라우저를 구축 중입니다. 따라서 파일/폴더를 클릭 할 때마다 잘라 내기/복사 등을 선택할 수 있으며 폴더를 두 번 클릭하면 해당 폴더의 내용을 볼 수 있습니다. –
그래도 문제는 표시되지 않습니다. ''item-activated ''를 열 /보기 폴더 재미를 위해 콜백과 함께 사용하고''selected-changed ''를 사용하여 선택을 강조 표시하는 것을 정확히 막을 수 있습니까? 'button-press/release-events'는 전혀 필요하지 않습니다. 이벤트는 암시 적으로 분리됩니다. 내가 놓친 게 있니? – drahnr