From: strawman <str...@la...> - 2012-04-07 23:40:50
|
From the wx docs for wxDataObjectSimple: "Notice that this is still an abstract base class and cannot be used but should be derived from. The objects supporting rendering the data must override GetDataSize and GetDataHere while the objects which may be set must override SetData." Is it possible to use this class from Lua? I'm trying to register a custom clipboard format and can't see any other way of passing a custom wxDataFormat. |
From: John L. <jla...@gm...> - 2012-04-09 03:57:31
|
On Sat, Apr 7, 2012 at 7:40 PM, strawman <str...@la...> wrote: > From the wx docs for wxDataObjectSimple: > > "Notice that this is still an abstract base class and cannot be used but > should be derived from. > The objects supporting rendering the data must override GetDataSize and > GetDataHere while the objects which may be set must override SetData." > > Is it possible to use this class from Lua? I'm trying to register a > custom clipboard format and can't see any other way of passing a custom > wxDataFormat. I just added it, you can of course simply use a seriallized string for exchanging any kind of data and in some cases that might be simplest. However to use a wxDataObjectSimple, get the newest version of wxLua from subversion. Usage is as follows: ------------------------ d = wx.wxLuaDataObjectSimple(wx.wxDataFormat("asd")) d.data = "x" -- store the data somewhere print(d:SetData("aaa"), d.data, d:GetDataSize(), d:GetDataHere()) d.GetDataSize = function(d) return string.len(d.data) end d.GetDataHere = function(d) return true, d.data end -- len must equal GetDataSize() d.SetData = function(d,s) d.data = s; return true end print(d:SetData("aaa"), d.data, d:GetDataSize(), d:GetDataHere()) ----------------------------- output will be: false x 0 false true aaa 3 true aaa I have not had time to test it further, but it should work with the clipboard, please let me know if it doesn't. Regards, John |
From: strawman <str...@la...> - 2012-04-11 21:39:11
|
On 09/04/2012 04:57, John Labenski wrote: > Usage is as follows: > > ------------------------ > d = wx.wxLuaDataObjectSimple(wx.wxDataFormat("asd")) > > d.data = "x" -- store the data somewhere > > print(d:SetData("aaa"), d.data, d:GetDataSize(), d:GetDataHere()) > > d.GetDataSize = function(d) return string.len(d.data) end > d.GetDataHere = function(d) return true, d.data end -- len must equal > GetDataSize() > d.SetData = function(d,s) d.data = s; return true end > > print(d:SetData("aaa"), d.data, d:GetDataSize(), d:GetDataHere()) > ----------------------------- > output will be: > > false x 0 false > true aaa 3 true aaa > > > I have not had time to test it further, but it should work with the > clipboard, please let me know if it doesn't. Thanks for the update; the example above works as shown, however it doesn't seem to play nicely with the clipboard: fmt = wx.wxDataFormat("HTML Format") obj = wx.wxLuaDataObjectSimple(fmt) obj.data = "test" function obj:GetDataHere() return true, self.data end function obj:GetDataSize() return self.data:len() end function obj:SetData(d) self.data = d return true end clip = wx.wxClipboard.Get() print(clip:IsSupported(fmt), clip:GetData(obj)) --> true false print(obj.data) --> "test" I've doublechecked the contents of the clipboard and there is definitely data available. I've also tried passing 1 and 13 (CF_TEXT and CF_UNICODETEXT) to wxDataFormat, with the same result. |
From: John L. <jla...@gm...> - 2012-04-12 04:24:06
|
On Wed, Apr 11, 2012 at 5:38 PM, strawman <str...@la...> wrote: > > Thanks for the update; the example above works as shown, however it > doesn't seem to play nicely with the clipboard: > > fmt = wx.wxDataFormat("HTML Format") > obj = wx.wxLuaDataObjectSimple(fmt) > obj.data = "test" > function obj:GetDataHere() return true, self.data end > function obj:GetDataSize() return self.data:len() end > function obj:SetData(d) self.data = d return true end > > clip = wx.wxClipboard.Get() > print(clip:IsSupported(fmt), clip:GetData(obj)) > --> true false > print(obj.data) > --> "test" > > I've doublechecked the contents of the clipboard and there is definitely > data available. I've also tried passing 1 and 13 (CF_TEXT and > CF_UNICODETEXT) to wxDataFormat, with the same result. I think for custom formats you have to set the data to the clipboard yourself. Is that what you're doing or are you trying to get HTML data from copying from some other program? Try pasting a different wx.wxLuaDataObjectSimple to the clipboard, but with the same wxDataFormat and see if you can retrieve that. If all you want is HTML from the some other program in the clipboard, use wxDF_HTML and don't bother with the wxLuaDataObjectSimple, see : http://wxlua.sourceforge.net/docs/wxluaref.html#wxDataFormatId Regards, John |
From: strawman <str...@la...> - 2012-04-12 21:27:15
|
On 12/04/2012 05:23, John Labenski wrote: > Is that what you're doing or are you trying to get HTML data from copying from some other program? I'm trying to get HTML clipboard data from Firefox/Chrome; they register a format called "HTML Format" at runtime, which has a different internal ID to CF_HTML/wxDF_HTML, and the ID changes every time Windows is restarted. fmt = wx.wxDataFormat("HTML Format") print(fmt:GetType(), wx.wxClipboard.Get():IsSupported(fmt)) -- 49358 true fmt = wx.wxDataFormat(wx.wxDF_HTML) print(fmt:GetType(), wx.wxClipboard.Get():IsSupported(fmt)) -- 30 false I've checked this against a clipboard inspection tool and it matches the actual contents of the clipboard, so registering the DataFormat seems to be working. > If all you want is HTML from the some other program in the clipboard, > use wxDF_HTML and don't bother with the wxLuaDataObjectSimple, see : > http://wxlua.sourceforge.net/docs/wxluaref.html#wxDataFormatId Is this possible without using a DataObjectSimple? From looking at the manual, DataFormatId is only used by DataFormat, which is only used by DataObjectSimple. |
From: John L. <jla...@gm...> - 2012-04-13 22:02:16
|
On Thu, Apr 12, 2012 at 5:27 PM, strawman <str...@la...> wrote: > On 12/04/2012 05:23, John Labenski wrote: > > Is that what you're doing or are you trying to get HTML data from > copying from some other program? > > I'm trying to get HTML clipboard data from Firefox/Chrome; they register > a format called "HTML Format" at runtime, which has a different internal > ID to CF_HTML/wxDF_HTML, and the ID changes every time Windows is restarted. > > fmt = wx.wxDataFormat("HTML Format") > print(fmt:GetType(), wx.wxClipboard.Get():IsSupported(fmt)) > -- 49358 true > fmt = wx.wxDataFormat(wx.wxDF_HTML) > print(fmt:GetType(), wx.wxClipboard.Get():IsSupported(fmt)) > -- 30 false Weird, I don't know anything about wxDF_HTML, but the wxWidgets docs say that it's only supported with Visual Studio and non unicode builds, so there's something special about it. > I've checked this against a clipboard inspection tool and it matches the > actual contents of the clipboard, so registering the DataFormat seems to > be working. > > > If all you want is HTML from the some other program in the clipboard, > > use wxDF_HTML and don't bother with the wxLuaDataObjectSimple, see : > > http://wxlua.sourceforge.net/docs/wxluaref.html#wxDataFormatId > > Is this possible without using a DataObjectSimple? From looking at the > manual, DataFormatId is only used by DataFormat, which is only used by > DataObjectSimple. I guess not, try this after copying from Firefox or Internet Explorer. I get text from wxDF_TEXT and "HTML Format" and the HTML from the derived wxLuaDataObjectSimple, but with some sort of header on it. ----------------- htmlDataObject = wx.wxLuaDataObjectSimple(wx.wxDataFormat("HTML Format")) htmlDataObject.data = "x" -- store the data somewhere print(htmlDataObject:SetData("aaa"), htmlDataObject.data, htmlDataObject:GetDataSize(), htmlDataObject:GetDataHere()) htmlDataObject.GetDataSize = function(htmlDataObject) return string.len(htmlDataObject.data) end htmlDataObject.GetDataHere = function(htmlDataObject) return true, htmlDataObject.data end -- len must equal htmlDataObject.SetData = function(htmlDataObject,s) htmlDataObject.data = s; return true end print(htmlDataObject:SetData("aaa"), htmlDataObject.data, htmlDataObject:GetDataSize(), htmlDataObject:GetDataHere()) function GetFromClipboard(dataformat, fmt_str) local clipboard = wx.wxClipboard.Get() -- Read some text if clipboard:Open() then if clipboard:IsSupported( dataformat ) then local data = wx.wxTextDataObject() clipboard:GetData( data ) --wx.wxMessageBox( data:GetText() ) print(dataformat:GetType(), fmt_str, data:GetText()) if (fmt_str == "HTML Format") then clipboard:GetData( htmlDataObject ) print(dataformat:GetType(), fmt_str, htmlDataObject.data) end else print(dataformat:GetType(), fmt_str, "NO AVAILABLE DATA IN THIS FORMAT!") end clipboard:Close() end end GetFromClipboard(wx.wxDataFormat(wx.wxDF_TEXT), "Text") GetFromClipboard(wx.wxDataFormat(wx.wxDF_HTML), "wxDF_HTML") GetFromClipboard(wx.wxDataFormat("HTML Format"), "HTML Format") ----------- I copied the word "Include" colored red from the wxWidgets documentation in Firefox, then ran the above. false x 0 false true aaa 3 true aaa 1 Text Include 30 wxDF_HTML NO AVAILABLE DATA IN THIS FORMAT! 49379 HTML Format Include 49379 HTML Format Version:0.9 StartHTML:00000172 EndHTML:00000286 StartFragment:00000206 EndFragment:00000250 SourceURL:http://docs.wxwidgets.org/2.8/wx_wxdataobject.html#wxdataobject <html><body> <!--StartFragment--><b><font color="#FF0000">Include </font></b><!--EndFragment--> </body> </html> -------------- Regards, John |
From: John L. <jla...@gm...> - 2012-04-13 22:06:10
|
ps. Do a SVN update. I had the signature wrong on wxLuaDataObjectSimple::SetData() so it would never be called by wxWidgets. Regards, John |
From: strawman <str...@la...> - 2012-04-18 00:08:15
|
On 13/04/2012 23:06, John Labenski wrote: > ps. Do a SVN update. I had the signature wrong on > wxLuaDataObjectSimple::SetData() so it would never be called by > wxWidgets. Looks like this was the issue; thanks again for the help, it works perfectly now. |