2013-04-07 9 views
5

Ich bin auf der Suche nach einem Wx Haskell Drag and Drop Beispiel. Ich habe noch keine gefunden.wx haskell Drag & Drop Beispiel

Irgendwelche verfügbar? oder Hinweise?

Bisher:

  • Ich kann ein on drag Ereignis sehen (aber nicht „auf drop“)
  • Maus nur ein left up am Ziel geben
  • Ich sehe einige Kommentare, wo soll ich ein Drop-Ziel zu auf Objekt zum einhängen, aber ich sehe nicht, wie es aufgerufen wird:

    Graphics.UI.WXCore.DragAndDrop

    L 51

    - | Erstellen Sie "DropSource". Dann ersetzt "dragAndDrop" das "DataObject" des Ziels durch dieses "DataObject".

    dropSource :: Datenobjekt ein -> Fenster b -> IO (DropSource())

  • Ich kann nicht sehen, wo die WX-Schicht über Graphics.UI.WXCore.DragAndDrop

  • dies (auch das ist alt) denke ich: [0]: http://bb10.com/haskell-wxhaskell-general/2007-08/msg00035.html

sowieso, ganz flockig jetzt ...


edit: das ist wo ich jetzt stehe: auf ziehen nicht aktiviert werden, so dass keine DragAndDrop entweder (auf Maus in Xinput ist nur da, um zu sehen, was los ist) (dragger ist, was ich von [O]), aber ich nicht von diesem erhält die Veranstaltung)

--- 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 

Antwort

2

Zusammenfassung:

  • erstellen und ein droptarget dropSource: von Graphics.UI.WXCore.DragAndDrop
  • das Ereignis "on drag" auf der Quelle verwenden Widget, von wo aus man dragAndDrop von Graphics.UI.WXCore.Events

Meine Fehler und falsche Annahmen aufrufen würden:

  • Ich war auf der Suche nach einem „auf drop“ Ereignis, auf das Ziel. existiert nicht und wird nicht benötigt, weil:
  • Wenn "auf ziehen" sind die anderen Ereignisse ausgesetzt. nicht mehr mouse up oder mouse down. Wenn nicht auf (DnD) -Ziel freigegeben, wird der Ziehvorgang abgebrochen und normale Ereignisse werden fortgesetzt. [0]
  • Beachten Sie, dass ein textEntry einen Fokus benötigt, um das "Einfügen" zu erhalten, jedoch tritt der Tropfen immer noch auf. schau dir "on drag Activated" auf der Konsole an.
  • Die ausgetauschten Texte stammen von den DataObjects (und nicht von der Quelle, wenn dies ein textEntry wäre). siehe "Text gelöscht".

Der folgende Code-Dumps, die Ereignisse auf der Konsole zu experimentieren:

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 

ich andere Leckereien gesehen habe ich erforschen können, wie Sie den Cursor während der Verschleppung zu ändern, oder auf verschiedenen Varianten von Tropfen reagieren .

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