Pasted Text

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Pasted Text

Post by lohill » Sat May 08, 2010 4:27 pm

My application calls for copying a page of data from a website and then pasting it into a scrolling field in REV where I then parse it for the information I want. The parsing requires that I be able to read the text. A few days ago I was able to do that pretty well. I must have changed something but I'm not sure what because now when I paste into the field the text is very tiny and not readable. When I use the Inspector to look at the contents of the field everything is very readable except there is bolding of characters etc.

Is there a setting in the inspector for that field I have accidentally changed or have I made some change to my browser that is causing this? Any suggestions will be appreciated.

Thanks,
Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Pasted Text

Post by lohill » Sat May 08, 2010 8:10 pm

If I put the following code in the script of the field in question and then send the field the message 'FormatRawPages' nothing gets changed.

Code: Select all

on FormatRawPages   
      set the textstyle of me to "plain"
      set the textfont of me to "Ariel"
      set the textsize of me to 12
end FormatRawPages
If I change the code of 'FormatPages' to the following it does work but takes 'forever' due to lots of lines.

Code: Select all

on formatRawPages
      put the number of lines of me onto tLines
      repeat with i = 1 to tLines
         set the textstyle of line i of me to "plain"
         set the textfont of line i of me to "Ariel"
         set the textsize of line i of me to 12
      end repeat
end formatRawPages
There must be something better that I'm missing.
Larry

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Pasted Text

Post by sturgis » Sat May 08, 2010 9:34 pm

From your description it sounds like your field had some of the lines formatted individually, if not all of them. Setting the font size etc for the control itself won't override chunk font settings.

If you change your code to this..

Code: Select all

on FormatRawPages  
      set the text of me to me -- silly I know, but it works. 
-- then set the control thusly. 
      set the textstyle of me to "plain"
      set the textfont of me to "Ariel"
      set the textsize of me to 12
end FormatRawPages
I haven't tried it, but if the problem is that formatting is coming in with the past you might try copying with your browser and have a button to paste with code something like

Code: Select all

put the clipboardData["text"] into field "yourfieldname"
at which point your original FormatRawPages should work fine. And might not even be necessary.

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Pasted Text

Post by lohill » Sun May 09, 2010 2:19 am

Hi sturgis,
Thanks for the suggestions. They both seemed to work when tested outside my program but both failed when I tried to build them into my menu system. Ideally I would like to have my menupick item for "Paste" to be your second suggestion and that would be it. When that didn't work I looked up clipBoardData in the Dictionary. I did not find any reference to 'put' but only 'set' so I'm not sure where your suggestion came from.

When I tried your first suggestion with my 'Paste' menu with just a 'paste' followed by a send "FormatRawPages" to field "RawPages" it did not even paste any data. Now my status is that with just a 'paste ' statement nothing is pasted. With a little experimentation, I have found while 'paste' does nothing with the original copied data, I can open TextEdit and paste the data there. Then if I copy the data from TextEdit and paste to the field in my application, it gets paste there just fine.

Any ideas,

Larry

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Pasted Text

Post by sturgis » Sun May 09, 2010 2:43 am

In the case of ClipboardData, its a property which in this case can be Set or Get. If you were to do

get the clipboardData["text"]

if there was text in the clipboard it would put it into the it variable.

By doing it as a put there is an implicit get.

put the clipboardData["text"] into container should work fine if there IS text in the clipboard of type text.

Perhaps therein lies part of the problem. What exactly are you copying? Is it straight text? Are there graphics/smileys/anything unsusual?

You might try "put the clipboard" which should state what type of data is currently in the clipboard.

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Pasted Text

Post by lohill » Sun May 09, 2010 8:08 pm

Hi sturgis,
put the clipboardData["text"] into container should work fine if there IS text in the clipboard of type text.

Perhaps therein lies part of the problem. What exactly are you copying? Is it straight text? Are there graphics/smileys/anything unsusual?

You might try "put the clipboard" which should state what type of data is currently in the clipboard.
This is really getting interesting. Do you remember how I started this thread out with the fact that when I did a paste of my copied data that it came out as tiny text where previously it had come out as looking pretty normal. Now when I paste nothing shows up in the field. Yes I am copying an entire page from Investors Business Daily. I do a click at the top and a shift-click at the bottom to make my selection. As I look at the selected text in the browser it appears that the text is selected but not the graphs or advertisements.

My Card has a scrollable field called "RawPages' and a button called Paste. The script of the button is:

Code: Select all

on mouseUp
   put the clipboardData["text"] into field "RawPages"
end mouseUp
There is also a menu Item in the edit menu which is called Paste and the menuPick case statement simply has 'paste' in it so I can paste in either of two different ways. Here is what now is happening and as noted before, this is the third different behavior.
1. Copy a page of data from the browser.
2. Go to the REV Message Box, type 'put the clipboard' and then press Return. It responds 'text'.
3. Put an insertion point in my field and press the Paste button (or go to the edit menu and take the choice for Paste - I have tried both ways.) In either case, nothing shows up in the field RawPages.
4. Next open the program called TextEdit and do a paste there. The data shows up nicely. It is mostly text with a little of what I would call 'garbage'.
5. Now if I a copy that data in TextEdit for a second time and then go back to my REV field and do a paste there, either from the button or the edit menu, it shows up in the field and looks exactly like the data in TextEdit. What is now in the field is perfectly workable for further processing in my REV program. It is not satisfactory because of the extra step to use TextEdit however.

I haven't tried this with other than eIBD web pages but the fact that I have gotten three different behavior from the process has me worried about handing off this application to a user.

If you see anything in this that gives you any ideas for a solution, please let me know.
Larry

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Pasted Text

Post by sturgis » Sun May 09, 2010 8:47 pm

At this point, lets take a page out of the Klaus book of troubleshooting.

Make a new stack with just a field, and just a paste button.

In the paste button put this

Code: Select all

on mouseUp
if the clipboard is text then
put the clipboardData into field 1
else
put the clipboard
end if
end mouseUp
If the clipboard contains data other than text it will tell you the type. If its empty, of course nothing will show up in the message box. If its type text, hopefully it will paste successfully into the field.

If it works, it might be time to start slowly duplicating your main stack in the new stack. Make incremental backups so you can revert if things go blooey again, and try to figure out where things go wrong.

Its possible that something has just gone hinky and a fresh start might solve it all. At this point I've little clue whats going on. If you want to post the stack I can look at it but I don't have an account at investors business daily so a true check won't be possible.

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Pasted Text

Post by lohill » Mon May 10, 2010 12:34 am

Hi sturgis,
I did exactly as you suggested. When I pressed the Button nothing showed up. I then went into debug mode and stepped through the Button code. I could see that the clipboard was "text" only because the step 'put the clipboardData into field 1' was executed. The message box didn't show anything.

I then opened TextEdit and did a paste there and then selected and copied all the text in TextEdit. Then I went back to my new stack and pressed the button again and the data appeared. I had made a new main stack for this experiment but had not removed the old one from memory. Is that worth trying?

I was hoping you could suggest some 'silly' solution like 'set the text of me to me'.

Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Pasted Text

Post by lohill » Mon May 10, 2010 1:18 am

sturgis,

It may be related to the browser I am copying from. I have been copying from Safari because I am working on the Mac side of my computer. I tried doing the copy from the Windows side which uses FireFox and it worked. I am going to have to experiment with various combinations of browsers to see what the differences are. I'll get back to you on that.

Larry

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Pasted Text

Post by sturgis » Mon May 10, 2010 1:47 am

K. Good luck, at this point i'm stumped.

Curry
Posts: 111
Joined: Mon Oct 15, 2007 11:34 pm
Contact:

Re: Pasted Text

Post by Curry » Mon May 10, 2010 9:55 am

BTW, looking at your original code, if you ever need to clear styles, you can also use:

Code: Select all

on FormatRawPages   
      set the textstyle of char 1 to -1 of me to ""
      set the textfont of char 1 to -1 of me to ""
      set the textsize of char 1 to -1 of me to ""
end FormatRawPages
Then all text will inherit field setting. There's no need to loop through each line. You can set any range of characters or lines that you wish. But "put me into me" is good too!

But that's just FYI in case you need it elsewhere; all that is completely unnecessary if you're putting the clipboarddata["text"] into a field. Either you're doing something wrong, or Revolution is. Funny thing, I tried using the clipboarddata of the IBD web page from Safari on Mac, issuing command from the message box with Rev 4.0, and Rev crashed, repeatedly! Doing the same with Rev 2.9 worked just fine. Perhaps you're running into a bug on the Mac side of a certain version of Rev.

Rather than pasting your web page text, you could grab it directly and save another step, cut out the browser middleman: see the "url" keyword. It'll give you html, and you can either strip tags (more reliable) or set htmltext of a field and clear styles if desired. Since Rev can download pages directly, you don't really have to copy and paste the page text.
Best wishes,

Curry Kenworthy

LiveCode Development, Training & Consulting
http://livecodeconsulting.com/

WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/

Post Reply