2014-04-04 1 views
0

나는 IconView을 사용하여 파이썬에서 gtk (pygtk) 기반 GUI 파일 브라우저를 만들고 있습니다. 두 신호 - selection-changed은 한 번의 클릭으로 이미지를 선택하면 트리거되고, 두 번 클릭하면 트리거됩니다 : item-activated입니다. 프로그램에서 두 신호 (자르기/복사 할 폴더를 선택하려면 selection-changed, 하위 폴더 및 파일을 탐색하려면 item-activated)가 필요합니다.두 번 클릭 이벤트를 실제로 트리거하려고 할 때 한 번 클릭 이벤트의 이중 실행을 방지하는 방법은 무엇입니까?

그러나 두 번 클릭하면 두 개의 selection-changed 신호와 하나의 item-activated 신호가 생성됩니다. 신호를 생성하려면 item-activated 만 있으면됩니다.

따라서 질문입니다.

답변

1

두 번째 한 번 클릭 이벤트와 두 번 클릭 이벤트는 동시에 도착해야합니다.

밀리 초 (또는 증가) 후에 모든 단일 클릭을 실행하려면 glib.timeout_add(interval, callback, ...)을 사용할 수 있습니다. 잠시 동안 두 번 클릭하면 단일 클릭 이벤트가 실행되지 않습니다.

구현 힌트 : 변수를 사용하여 마지막 두 번 클릭했을 때 저장하고 마지막 클릭에 대해 변수를 time.time()으로 사용합니다. 더블 클릭과 싱글 클릭이 아주 가까운 경우, 클릭 클릭 코드를 실행하지 마십시오. 시간 제한을 사용하기 때문에 한 번 클릭하면 항상 두 번 클릭 한 후에 실행됩니다.

0

어떤 항목을 선택했는지 추적하지 않는 이유는 무엇입니까? 선택 무시는 두 번째 클릭에서 변경되었으므로 변경되지 않았습니다. 다음은이 사건을 처리하도록 수정 된 pytk FAQ의 예입니다 ...

import gtk 
import gtk.gdk 


current_path = [] 
current_path.append(None) 

def on_selection_changed(iconview, current_path): 
    if iconview.get_selected_items(): 
     if cmp(current_path[0], iconview.get_selected_items()[0]): 
      print "selection-changed" 
     current_path[0] = iconview.get_selected_items()[0] 

def on_item_activated(iconview, path): 
    print "item-activated" 

# First create an iconview 
view = gtk.IconView() 
view.connect("selection-changed", on_selection_changed, current_path) 
view.connect("item-activated", on_item_activated) 

# Create a store for our iconview and fill it with stock icons 
store = gtk.ListStore(str, gtk.gdk.Pixbuf) 
for attr in dir(gtk): 
    if attr.startswith('STOCK_'): 
     stock_id = getattr(gtk, attr) 
     pixbuf = view.render_icon(stock_id, 
      size=gtk.ICON_SIZE_BUTTON, detail=None) 
     if pixbuf: 
      store.append(['gtk.%s' % attr, pixbuf]) 

# Connect our iconview with our store 
view.set_model(store) 
# Map store text and pixbuf columns to iconview 
view.set_text_column(0) 
view.set_pixbuf_column(1) 

# Pack our iconview into a scrolled window 
swin = gtk.ScrolledWindow() 
swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 
swin.add_with_viewport(view) 
swin.show_all() 

# pack the scrolled window into a simple dialog and run it 
dialog = gtk.Dialog('IconView Demo') 
close = dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_NONE) 
dialog.set_default_size(400,400) 
dialog.vbox.pack_start(swin) 
dialog.run() 
관련 문제