2013-04-07 37 views
5

Tôi đang tìm một ví dụ về kéo và thả wx haskell. Tôi chưa tìm thấy.wx haskell Ví dụ kéo và thả

Mọi thứ khả dụng? hoặc gợi ý?

Cho đến nay:

  • tôi có thể thấy một sự kiện on drag (nhưng không "trên thả")
  • chuột chỉ là đưa ra một left up trên mục tiêu
  • tôi thấy một số bình luận mà tôi đang phải để áp dụng mục tiêu thả vào đối tượng, nhưng tôi không thấy nó được gọi như thế nào:

    Graphics.UI.WXCore.DragAndDrop

    L 51

    - | Tạo 'DropSource'. Sau đó, 'dragAndDrop' thay thế mục tiêu 'DataObject' bằng 'DataObject' này.

    dropSource :: DataObject a -> Window b -> IO (DropSource())

  • Tôi không thể nhìn thấy nơi được lớp WX trên Graphics.UI.WXCore.DragAndDrop

  • đây là (quá) cũ tôi đoán: [0]: http://bb10.com/haskell-wxhaskell-general/2007-08/msg00035.html

dù sao, khá mờ cho bây giờ ...


chỉnh sửa: đây là nơi tôi đứng bây giờ: khi kéo không được kích hoạt, vì vậy không có dragAndDrop hoặc (trên chuột trong xinput là chỉ để xem những gì đang xảy ra) (dragger là những gì tôi nhận được từ [O]), nhưng tôi làm không nhận được sự kiện từ này)

--- test where DnD from yinput to xinput 
module Main where 

import CustoWidget 
import Graphics.UI.WX hiding (empty) 
import Data.Graph.Inductive 
import Data.Maybe 
import Control.Monad 
import Graphics.UI.WX.Events 
import Graphics.UI.WXCore.WxcClassesMZ 
import Graphics.UI.WXCore.WxcClassesAL 
import Graphics.UI.WXCore.DragAndDrop 
import Graphics.UI.WXCore.Events 
import Debug.Trace 
main 
    = start ballsFrame 
    -- @next : try andrun start within a state 

ballsFrame 
    = do 

     f  <- frame [text := "Layout test"] 
     p  <- panel f []      -- panel for color and tab management. 
     ok  <- button p [text := "Ok"] 
     can <- button p [text := "Cancel", on command := infoDialog f "Info" "Pressed 'Cancel'"] 
     xinput <- textEntry p [text := "100", alignment := AlignRight] 
     yinput <- textEntry p [text := "100", alignment := AlignRight] 

     set f [defaultButton := ok 
      ,layout := container p $ 
         margin 10 $ 
         column 5 [boxed "coordinates" (grid 5 5 [[label "x:", hfill $ widget xinput] 
                   ,[label "y:", hfill $ widget yinput]]) 
           ,floatBottomRight $ row 5 [widget ok,widget can]] 
           ] 
     set xinput [ on mouse := showMe] --, on keyboard := showMeK 
     set yinput [ ] --on mouse := showMe, on keyboard := showMeK ] 
--  fileDropTarget xinput (\pt file -> putStrLn $ show file) 


     -- prepare the drop source 

     textdata <- textDataObjectCreate "" 
     drop <- dropTarget xinput textdata 

     textdata' <- textDataObjectCreate "text" 
     src <- dropSource textdata' yinput 

     -- activate on drag the do drag drop 
     set yinput [ on drag := onDrag src] 
     set ok [ on command := onOk f textdata] 




     return() 



onDrag s p = trace ("on drag " ++ show s ++ " " ++ show p) 
    dragAndDrop s Default (\_ -> return()) 



onOk f textdata = do 

      txt <- textDataObjectGetText textdata 
      infoDialog f "resultText" txt 
      close f 

showMe = \x -> do putStrLn $ show x 

dragger win wout = do 
      textdata <- textDataObjectCreate "" 
      drop <- dropTarget wout textdata 
      textdata' <- textDataObjectCreate "text" 
      src <- dropSource textdata' win 
      dragAndDrop src Default (\_ -> return()) 
      txt <- textDataObjectGetText textdata 
      infoDialog wout "resultText" txt 

Trả lời

2

Tóm tắt:

  • tạo dropTarget và dropSource: từ Graphics.UI.WXCore.DragAndDrop
  • sử dụng tổ chức sự kiện "on drag" trên nguồn widget, từ nơi bạn sẽ gọi dragAndDrop từ Graphics.UI.WXCore.Events

sai lầm của tôi và giả định sai:

  • tôi đang tìm kiếm một "trên thả" sự kiện, trên target. không tồn tại và không cần thiết, bởi vì:
  • Khi "đang kéo", các sự kiện khác sẽ bị tạm ngưng. không còn mouse up hoặc mouse down nữa. Nếu không được phát hành trên (DnD) mục tiêu, kéo sẽ hủy bỏ và các sự kiện bình thường tiếp tục. [0]
  • Lưu ý rằng textEntry cần tập trung để có được "dán", tuy nhiên thả vẫn xảy ra. nhìn vào "on drag Activated" trên bảng điều khiển.
  • văn bản được trao đổi là văn bản từ DataObjects (và không phải từ nguồn, nếu điều này sẽ là textEntry.). xem "văn bản bị xóa".

Các mã sau bãi các sự kiện trên giao diện điều khiển, thử nghiệm:

module Main where 


import Graphics.UI.WX hiding (empty) 

import Data.Maybe 
import Control.Monad 
import Graphics.UI.WX.Events 
import Graphics.UI.WXCore.WxcClassesMZ 
--import Graphics.UI.WXCore.WxcClassesAL 
import Graphics.UI.WXCore.DragAndDrop 
import Graphics.UI.WXCore.Events 

main 
    = start dndtest 


dndtest 
    = do 

     f  <- frame [text := "Drag And Drop test"] 
     p  <- panel f []      
     ok  <- button p [text := "Ok"] 
     xinput <- textEntry p [text := "here :"] 
     yinput <- staticText p [text := "drag me"] 

     set f [defaultButton := ok 
      ,layout := container p $ 
         margin 10 $ 
         column 5 [boxed "coordinates" (grid 5 5 [[label "source:", hfill $ widget yinput] 
                   ,[label "target(focus first):", hfill $ widget xinput] 
                   ]) 
           ,floatBottomRight $ row 5 [widget ok]] 
           ] 

     set xinput [ on enter := onEnter] 

     set yinput [ ] 
--------------------------------------------------------- 
--- meaningful stuff starts here 
--------------------------------------------------------- 

     -- prepare the drop source : create a DataObject and associate it with the source 
     textdata' <- textDataObjectCreate "text dropped" 
     src <- dropSource textdata' yinput 

     -- prepare the drop target: create a DataObject (placeholder here) and associate it with the target 
     textdata <- textDataObjectCreate ".." 
     drop <- dropTarget xinput textdata 


     -- activate on drag the do dragdrop. this will replace the target dataObject with the source one. 
     -- Try with and without giving focus to the textEntry field 
     -- Try and source from your favorite editor also (focus first!) 
     set yinput [ on drag := onDrag src ] 
--------------------------------------------------------- 
--- meaningful stuff stops here 
--------------------------------------------------------- 

     set ok [ on command := close f ] 
     return() 





--onDrag:: Graphics.UI.WXCore.WxcClassTypes.DropSource a -> Point -> IO() 
onDrag s p = do 
    dragAndDrop s Default (\_ -> return()) 
    putStrLn "on Drag activated:" 



showMeE :: EventMouse -> IO() 
showMeE (MouseMotion point mod) = putStr "" --- discard meaningless Motion event 
showMeE e = putStrLn $ show e 


onEnter p = putStrLn $ "on Enter:" ++ show p 

Tôi đã thấy goodies khác tôi có thể khám phá, như thay đổi con trỏ trong kéo, hoặc phản ứng trên những phiên bản khác nhau của thả .

[0]: http://docs.wxwidgets.org/2.8/wx_wxdndoverview.html