Using Playgrounds as a notepad

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Playgrounds as a notepad

Andy Burnett
I often find that I need to do simple manipulations to passages of text, e.g. remove all carriage returns, or extract email addresses etc. 

Pasting the text into a Playground doesn't work because there is always an apostrophe, or line break or... etc. and the playground complains.

Is there a way to tell a Playground to just ignore the text, and give me a handle to its contents, so that I can then do something like

playgroundId contents splitOn:Character space.

Alternatively, is there another object that would be more appropriate? Playground would be really useful just because it is in the menu, and always available.

Cheers
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

Tudor Girba-2
Hi,

> On Jan 4, 2016, at 3:21 AM, Andy Burnett <[hidden email]> wrote:
>
> I often find that I need to do simple manipulations to passages of text, e.g. remove all carriage returns, or extract email addresses etc.
>
> Pasting the text into a Playground doesn't work because there is always an apostrophe, or line break or... etc. and the playground complains.
>
> Is there a way to tell a Playground to just ignore the text, and give me a handle to its contents, so that I can then do something like
>
> playgroundId contents splitOn:Character space.
>
> Alternatively, is there another object that would be more appropriate? Playground would be really useful just because it is in the menu, and always available.

The Playground does not yet allow you to do that. But, you can use the Clipboard:

Clipboard clipboardText splitOn:Character space.

Cheers,
Doru

> Cheers
> Andy

--
www.tudorgirba.com
www.feenk.com

"Value is always contextual."





Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

kilon.alios
In reply to this post by Andy Burnett
have you tried the Workspace ?

Workspace open.

or you can built your own starting with TextMorph

tm := TextMorph new.
tm openInWindow .

On Mon, Jan 4, 2016 at 3:22 AM Andy Burnett <[hidden email]> wrote:
I often find that I need to do simple manipulations to passages of text, e.g. remove all carriage returns, or extract email addresses etc. 

Pasting the text into a Playground doesn't work because there is always an apostrophe, or line break or... etc. and the playground complains.

Is there a way to tell a Playground to just ignore the text, and give me a handle to its contents, so that I can then do something like

playgroundId contents splitOn:Character space.

Alternatively, is there another object that would be more appropriate? Playground would be really useful just because it is in the menu, and always available.

Cheers
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

Sven Van Caekenberghe-2
In reply to this post by Tudor Girba-2

> On 04 Jan 2016, at 07:34, Tudor Girba <[hidden email]> wrote:
>
> Hi,
>
>> On Jan 4, 2016, at 3:21 AM, Andy Burnett <[hidden email]> wrote:
>>
>> I often find that I need to do simple manipulations to passages of text, e.g. remove all carriage returns, or extract email addresses etc.
>>
>> Pasting the text into a Playground doesn't work because there is always an apostrophe, or line break or... etc. and the playground complains.
>>
>> Is there a way to tell a Playground to just ignore the text, and give me a handle to its contents, so that I can then do something like
>>
>> playgroundId contents splitOn:Character space.
>>
>> Alternatively, is there another object that would be more appropriate? Playground would be really useful just because it is in the menu, and always available.
>
> The Playground does not yet allow you to do that. But, you can use the Clipboard:
>
> Clipboard clipboardText splitOn:Character space.

I do this a lot: using #clipboardText is a way to get to a copied string without any problems.

You can also do a Print It on 'Clipboard clipboardText asString' which will render the string using the Pharo quoting conventions.

> Cheers,
> Doru
>
>> Cheers
>> Andy
>
> --
> www.tudorgirba.com
> www.feenk.com
>
> "Value is always contextual."


Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

Peter Uhnak
a) Spec

~~~~~~~~~~~
tm := TextModel new.
tm autoAccept: true. "otherwise you would have to pres ctrl+s to 'save' the result in memory"
tm openWithSpec. "this will open text window

"and then you can do"
tm text. "retrieve current text from the TextModel (returns an instance of Text)"
tm text: 'new content' "set a new content"
~~~~~~~~~~

b) Workspace

~~~~~~~~~~~~~~~~~~~
w := Workspace new.
w open.

w contents. "note that you must ctrl+s the content in the workspace for it to appear here (there's a yellow triangle in top right corner if the content is not saved"
w contents: '123'.
~~~~~~~~~~~~~~~~~~
Workspace can also be saved/loaded to disk.

c) Playground

~~~~~~~~~~~~~~~~~~
(page := GTPlayPage new)
saveContent: 'initial content'.
(playground := GTPlayground new)
openOn: page.

page content. "retrieve the content; just like with Workspace you must ctrl+s when editing in the Playground itself"

"updating is a bit more complex, but it still seems to work"
page saveContent: 'new content'.
playground update.
~~~~~~~~~~~~~~~~~~~

Peter

On Mon, Jan 4, 2016 at 11:51 AM, Sven Van Caekenberghe <[hidden email]> wrote:

> On 04 Jan 2016, at 07:34, Tudor Girba <[hidden email]> wrote:
>
> Hi,
>
>> On Jan 4, 2016, at 3:21 AM, Andy Burnett <[hidden email]> wrote:
>>
>> I often find that I need to do simple manipulations to passages of text, e.g. remove all carriage returns, or extract email addresses etc.
>>
>> Pasting the text into a Playground doesn't work because there is always an apostrophe, or line break or... etc. and the playground complains.
>>
>> Is there a way to tell a Playground to just ignore the text, and give me a handle to its contents, so that I can then do something like
>>
>> playgroundId contents splitOn:Character space.
>>
>> Alternatively, is there another object that would be more appropriate? Playground would be really useful just because it is in the menu, and always available.
>
> The Playground does not yet allow you to do that. But, you can use the Clipboard:
>
> Clipboard clipboardText splitOn:Character space.

I do this a lot: using #clipboardText is a way to get to a copied string without any problems.

You can also do a Print It on 'Clipboard clipboardText asString' which will render the string using the Pharo quoting conventions.

> Cheers,
> Doru
>
>> Cheers
>> Andy
>
> --
> www.tudorgirba.com
> www.feenk.com
>
> "Value is always contextual."



Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

Andy Burnett
In reply to this post by Andy Burnett
@Dimitris

Thanks for the Workspace idea. That is pretty much what I am looking for. However, I am struggling to get it to behave the way I want.
When I type into the Workspace, and then inspect
 
ws contents

I just get an empty string. Is there a simple way to get the ws to update its contents so that I can access it?

@Sven, @Doru. Thanks. The Clipboard approach is very slick. I will use that for the time being. Out of curiosity, is it possible to access any other data on the clipboard. For instance, if I copy a pictured from my desktop, is that accessible via the Clipboard object? I only saw text oriented methods.

Thanks
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

kilon.alios
you need to accept the contents in order for the workspace to store your text, you can use either right click menu and accept or the shortcut that menus shows then you can get the contents as a string via

ws := Workspace open.
"type text and then accept it"
ws contents asString


On Tue, Jan 5, 2016 at 3:57 AM Andy Burnett <[hidden email]> wrote:
@Dimitris

Thanks for the Workspace idea. That is pretty much what I am looking for. However, I am struggling to get it to behave the way I want.
When I type into the Workspace, and then inspect
 
ws contents

I just get an empty string. Is there a simple way to get the ws to update its contents so that I can access it?

@Sven, @Doru. Thanks. The Clipboard approach is very slick. I will use that for the time being. Out of curiosity, is it possible to access any other data on the clipboard. For instance, if I copy a pictured from my desktop, is that accessible via the Clipboard object? I only saw text oriented methods.

Thanks
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

Peter Uhnak
> Out of curiosity, is it possible to access any other data on the clipboard.

At least for linux this is most likely not possible, as the underlying VM code requests unicode string (that's what I remember when I was debugging it about a year ago). In X11 clipboard, the client must explicitly request the type of content he is interested in.

On Tue, Jan 5, 2016 at 8:14 AM, Dimitris Chloupis <[hidden email]> wrote:
you need to accept the contents in order for the workspace to store your text, you can use either right click menu and accept or the shortcut that menus shows then you can get the contents as a string via

ws := Workspace open.
"type text and then accept it"
ws contents asString


On Tue, Jan 5, 2016 at 3:57 AM Andy Burnett <[hidden email]> wrote:
@Dimitris

Thanks for the Workspace idea. That is pretty much what I am looking for. However, I am struggling to get it to behave the way I want.
When I type into the Workspace, and then inspect
 
ws contents

I just get an empty string. Is there a simple way to get the ws to update its contents so that I can access it?

@Sven, @Doru. Thanks. The Clipboard approach is very slick. I will use that for the time being. Out of curiosity, is it possible to access any other data on the clipboard. For instance, if I copy a pictured from my desktop, is that accessible via the Clipboard object? I only saw text oriented methods.

Thanks
Andy

Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

abergel
In reply to this post by Peter Uhnak
Useful code snippet! Thanks!

Alexandre


> On Jan 4, 2016, at 10:47 PM, Peter Uhnák <[hidden email]> wrote:
>
> a) Spec
>
> ~~~~~~~~~~~
> tm := TextModel new.
> tm autoAccept: true. "otherwise you would have to pres ctrl+s to 'save' the result in memory"
> tm openWithSpec. "this will open text window
>
> "and then you can do"
> tm text. "retrieve current text from the TextModel (returns an instance of Text)"
> tm text: 'new content' "set a new content"
> ~~~~~~~~~~
>
> b) Workspace
>
> ~~~~~~~~~~~~~~~~~~~
> w := Workspace new.
> w open.
>
> w contents. "note that you must ctrl+s the content in the workspace for it to appear here (there's a yellow triangle in top right corner if the content is not saved"
> w contents: '123'.
> ~~~~~~~~~~~~~~~~~~
> Workspace can also be saved/loaded to disk.
>
> c) Playground
>
> ~~~~~~~~~~~~~~~~~~
> (page := GTPlayPage new)
> saveContent: 'initial content'.
> (playground := GTPlayground new)
> openOn: page.
>
> page content. "retrieve the content; just like with Workspace you must ctrl+s when editing in the Playground itself"
>
> "updating is a bit more complex, but it still seems to work"
> page saveContent: 'new content'.
> playground update.
> ~~~~~~~~~~~~~~~~~~~
>
> Peter
>
> On Mon, Jan 4, 2016 at 11:51 AM, Sven Van Caekenberghe <[hidden email]> wrote:
>
> > On 04 Jan 2016, at 07:34, Tudor Girba <[hidden email]> wrote:
> >
> > Hi,
> >
> >> On Jan 4, 2016, at 3:21 AM, Andy Burnett <[hidden email]> wrote:
> >>
> >> I often find that I need to do simple manipulations to passages of text, e.g. remove all carriage returns, or extract email addresses etc.
> >>
> >> Pasting the text into a Playground doesn't work because there is always an apostrophe, or line break or... etc. and the playground complains.
> >>
> >> Is there a way to tell a Playground to just ignore the text, and give me a handle to its contents, so that I can then do something like
> >>
> >> playgroundId contents splitOn:Character space.
> >>
> >> Alternatively, is there another object that would be more appropriate? Playground would be really useful just because it is in the menu, and always available.
> >
> > The Playground does not yet allow you to do that. But, you can use the Clipboard:
> >
> > Clipboard clipboardText splitOn:Character space.
>
> I do this a lot: using #clipboardText is a way to get to a copied string without any problems.
>
> You can also do a Print It on 'Clipboard clipboardText asString' which will render the string using the Pharo quoting conventions.
>
> > Cheers,
> > Doru
> >
> >> Cheers
> >> Andy
> >
> > --
> > www.tudorgirba.com
> > www.feenk.com
> >
> > "Value is always contextual."
>
>
>

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

stepharo
In reply to this post by Andy Burnett
This is where I would like our tools to try not to be smarter but let us
do what we want.

Stef

Le 4/1/16 02:21, Andy Burnett a écrit :

> I often find that I need to do simple manipulations to passages of
> text, e.g. remove all carriage returns, or extract email addresses etc.
>
> Pasting the text into a Playground doesn't work because there is
> always an apostrophe, or line break or... etc. and the playground
> complains.
>
> Is there a way to tell a Playground to just ignore the text, and give
> me a handle to its contents, so that I can then do something like
>
> playgroundId contents splitOn:Character space.
>
> Alternatively, is there another object that would be more appropriate?
> Playground would be really useful just because it is in the menu, and
> always available.
>
> Cheers
> Andy


Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

Andy Burnett
In reply to this post by Andy Burnett
Thanks everyone!
I completely forgot that I should ctrl+s on the workspace. I think I have just become too used to google docs etc., and it didn't occur to me that I had to save in order to update a model.

Right, I now have two ways forward, and they both look useful for different problems.

ws := Workspace open

Gives me a simple way to paste in text, and do some initial hand editing

Clipboard clipboardText

Will be great when I know there is a 'clean-up' method that I need to run on e.g. a table I have grabbed from the web.

Cheers
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Using Playgrounds as a notepad

kilon.alios
you really have tons of options what we told you is just the tip of the icebeg, for example you can still use the playground if you enclose your text inside single quotes which will convert it to a pharo string or double quotes which will convert to a comment. Having it as a string gives you a lot of parsing abilities to extract any info you want. The string class comes with methods like substrings , tokens etc but my favorite way is regex that can do some pretty complex detections.

TextMorph also comes with PlugableTextMorph which includes a scroll bare for long text and there is also the option to auto accept any new contents so you dont have to manually accept them.

If your get info from websites then its better to use BeautifulSoupd a library specialised on extracting information from websites the easy way.

Stating exactly what you want with actual examples will allows us to help you more with a specific solution. Pharo is huge with around 800 thousands method spacking an enormous amount of features making it comparable even with behemoths like Java :)

On Tue, Jan 5, 2016 at 11:32 PM Andy Burnett <[hidden email]> wrote:
Thanks everyone!
I completely forgot that I should ctrl+s on the workspace. I think I have just become too used to google docs etc., and it didn't occur to me that I had to save in order to update a model.

Right, I now have two ways forward, and they both look useful for different problems.

ws := Workspace open

Gives me a simple way to paste in text, and do some initial hand editing

Clipboard clipboardText

Will be great when I know there is a 'clean-up' method that I need to run on e.g. a table I have grabbed from the web.

Cheers
Andy