newbie request for help

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

newbie request for help

alexxxm
Hi everybody,
I need some help to understand if tkinter is in fact the right tool to use for me.

I intend to write a very bare-bone wiki in python. It should be able to:

1) open a text file
2) display the text file, with links in the form {{image.jpg}} replaced by the image, and [[linkname|linkfile.txt]] replaced by linkname
3) when clicking on linkname, save the current text file and open in its place the file linkfile.txt

really, I'm not interested in nothing more.

Do you believe it can be easily accomplished with tkinter, or do I need some more complicated widget?

Thanks for any help...


alessandro
Reply | Threaded
Open this post in threaded view
|

Re: newbie request for help

Cam-26
You should be able to accomplish this easily with the tkinter "Text" widget.

Cam Farnell

On 11-06-07 10:03 AM, alexxxm wrote:

>
> Hi everybody,
> I need some help to understand if tkinter is in fact the right tool to use
> for me.
>
> I intend to write a very bare-bone wiki in python. It should be able to:
>
> 1) open a text file
> 2) display the text file, with links in the form {{image.jpg}} replaced by
> the image, and [[linkname|linkfile.txt]] replaced by linkname
> 3) when clicking on linkname, save the current text file and open in its
> place the file linkfile.txt
>
> really, I'm not interested in nothing more.
>
> Do you believe it can be easily accomplished with tkinter, or do I need some
> more complicated widget?
>
> Thanks for any help...
>
>
> alessandro
>
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: newbie request for help

John W. Shipman
In reply to this post by alexxxm
+--
| 1) open a text file
| 2) display the text file, with links in the form {{image.jpg}} replaced by
| the image, and [[linkname|linkfile.txt]] replaced by linkname
| 3) when clicking on linkname, save the current text file and open in its
| place the file linkfile.txt
+--

Tkinter can do all that.  A few suggestions:

- You will want to use a Text widget for your main display.
   Conceptually, this widget displays a sequence of lines of text.
   An image is treated as a single character: it is displayed on a
   line between the text that comes before it and the text that
   comes after it.

- Use tags to change the appearance of links so the reader will
   know they are clickable.  You can apply named tags to any
   number of regions in your Text widget.  Each tag is associated
   with options such as text color, background color, and font.

Here's a Tkinter reference that may help you:

     http://www.nmt.edu/tcc/help/pubs/tkinter

Read closely the sections of "The Text Widget", especially
the subsections "Text widget tags" and "Methods on Text
widgets".  In the latter subsection, note these methods:

.tag_add:  For applying a specific tag to a region of text.
.tag_bind:  Make regions tagged with a certain tag respond to
             events such as mouse clicks.
.tag_config:  Change the appearance of all regions tagged
               with a certain tag.

Best regards,
John Shipman ([hidden email]), Applications Specialist, NM Tech Computer Center,
Speare 119, Socorro, NM 87801, (575) 835-5735, http://www.nmt.edu/~john
   ``Let's go outside and commiserate with nature.''  --Dave Farber
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: newbie request for help

Cameron Laird-2
In reply to this post by Cam-26
On Tue, Jun 07, 2011 at 11:05:09AM -0300, Cam wrote:
                        .
                        .
                        .
> You should be able to accomplish this easily with the tkinter "Text" widget.
>
> Cam Farnell
>
> On 11-06-07 10:03 AM, alexxxm wrote:
                        .
                        .
                        .
> >Do you believe it can be easily accomplished with tkinter, or do I need
> >some
> >more complicated widget?
                        .
                        .
                        .
Text() is indeed a powerhouse.  Its capabilities might astonish you.
In particular, it can do all you describe for your model of a Wiki.
While studying Text(), make a point of learning about its powerful
notion of "tag".
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: newbie request for help

alexxxm
In reply to this post by alexxxm
I thank you all for your help and I'm looking forward to implement it.
At the moment however I'm unable to do it since it appears I'm missing a basic piece:

trying to approach the links, at first I used the code found at http://effbot.org/zone/tkinter-text-hyperlink.htm:
<code>
import tkHyperlinkManager
from Tkinter import *

root = Tk()
root.title("hyperlink-1")

text = Text(root)
text.pack()

hyperlink = tkHyperlinkManager.HyperlinkManager(text)

def click1():
    print "click 1"

text.insert(INSERT, "this is a ")
text.insert(INSERT, "link", hyperlink.add(click1))
text.insert(INSERT, "\n\n")

def click2():
    print "click 2"

text.insert(INSERT, "this is another ")
text.insert(INSERT, "link", hyperlink.add(click2))
text.insert(INSERT, "\n\n")

mainloop()
</code>


but I get this:
ImportError: No module named tkHyperlinkManager

I work on Linux Fedora13, and my Tkinter version is tkinter-2.6.4-27.fc13.x86_64
Probably tkHyperlinkManager is not included by default in the Tkinter distribution?


As approach #2 I tried this (courtesy of StackOverflow):
<code>
import Tkinter

class App:
    def __init__(self, root):
        self.root = root
        for text in ("link1", "link2", "link3"):
            link = Tkinter.Label(text=text, foreground="#0000ff")
            link.bind("<1>", lambda event, text=text: \
                          self.click_link(event, text))
            link.pack()
    def click_link(self, event, text):
        print "you clicked '%s'" % text

root=Tkinter.Tk()
app = App(root)
root.mainloop()
</code>

and this works. Do you recommend this approach?

alessandro


alexxxm wrote
Hi everybody,
I need some help to understand if tkinter is in fact the right tool to use for me.

I intend to write a very bare-bone wiki in python. It should be able to:

1) open a text file
2) display the text file, with links in the form {{image.jpg}} replaced by the image, and [[linkname|linkfile.txt]] replaced by linkname
3) when clicking on linkname, save the current text file and open in its place the file linkfile.txt

really, I'm not interested in nothing more.

Do you believe it can be easily accomplished with tkinter, or do I need some more complicated widget?

Thanks for any help...


alessandro
Reply | Threaded
Open this post in threaded view
|

Re: newbie request for help

alexxxm
ooops, I just found out:
the code for tkHyperlinkManager is at http://pastebin.com/mWfDm7eZ

alessandro

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

alexxxm wrote
I thank you all for your help and I'm looking forward to implement it.
At the moment however I'm unable to do it since it appears I'm missing a basic piece:

trying to approach the links, at first I used the code found at http://effbot.org/zone/tkinter-text-hyperlink.htm:
<code>
import tkHyperlinkManager
from Tkinter import *

root = Tk()
root.title("hyperlink-1")

text = Text(root)
text.pack()

hyperlink = tkHyperlinkManager.HyperlinkManager(text)

def click1():
    print "click 1"

text.insert(INSERT, "this is a ")
text.insert(INSERT, "link", hyperlink.add(click1))
text.insert(INSERT, "\n\n")

def click2():
    print "click 2"

text.insert(INSERT, "this is another ")
text.insert(INSERT, "link", hyperlink.add(click2))
text.insert(INSERT, "\n\n")

mainloop()
</code>


but I get this:
ImportError: No module named tkHyperlinkManager

I work on Linux Fedora13, and my Tkinter version is tkinter-2.6.4-27.fc13.x86_64
Probably tkHyperlinkManager is not included by default in the Tkinter distribution?


As approach #2 I tried this (courtesy of StackOverflow):
<code>
import Tkinter

class App:
    def __init__(self, root):
        self.root = root
        for text in ("link1", "link2", "link3"):
            link = Tkinter.Label(text=text, foreground="#0000ff")
            link.bind("<1>", lambda event, text=text: \
                          self.click_link(event, text))
            link.pack()
    def click_link(self, event, text):
        print "you clicked '%s'" % text

root=Tkinter.Tk()
app = App(root)
root.mainloop()
</code>

and this works. Do you recommend this approach?

alessandro


alexxxm wrote
Hi everybody,
I need some help to understand if tkinter is in fact the right tool to use for me.

I intend to write a very bare-bone wiki in python. It should be able to:

1) open a text file
2) display the text file, with links in the form {{image.jpg}} replaced by the image, and [[linkname|linkfile.txt]] replaced by linkname
3) when clicking on linkname, save the current text file and open in its place the file linkfile.txt

really, I'm not interested in nothing more.

Do you believe it can be easily accomplished with tkinter, or do I need some more complicated widget?

Thanks for any help...


alessandro
Reply | Threaded
Open this post in threaded view
|

Re: newbie request for help

Kevin Buchs-2
In reply to this post by alexxxm
Alessandro,
The suggestion on this email list has been to use the Text widget,
making use of tags. The second option you gave is going a different
direction than that by using Labels. I do not think that will take you
where you want to go. It may be that tkHyperlinkManager is the optimal
choice when implementing hyperlinked text using Text, but I am unsure.
I got the impression through brief review of the dialog here that
there was a capability native to Text that would give you what you
need.

To get tkHyperlinkManager installed here is what I would recommend. If
the command easy_install is not currently available, then you may be
able to install the corresponding "distutils" module for Python using
Fedora's package maintenance capability. Probably installing something
like "Python distutils" should do the job. Once that is done then you
should have the command easy_install. Then it is simply a matter of
using this command line: easy_install tkHyperlinkManager. Depending on
the OS setup, you may need to run that as su/sudo to have the
permissions to write into the Python packages directories.

Kevin
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: newbie request for help

Kevin Walzer-5
On 6/8/11 8:29 AM, Kevin Buchs wrote:

>
> To get tkHyperlinkManager installed here is what I would recommend. If
> the command easy_install is not currently available, then you may be
> able to install the corresponding "distutils" module for Python using
> Fedora's package maintenance capability. Probably installing something
> like "Python distutils" should do the job. Once that is done then you
> should have the command easy_install. Then it is simply a matter of
> using this command line: easy_install tkHyperlinkManager. Depending on
> the OS setup, you may need to run that as su/sudo to have the
> permissions to write into the Python packages directories.

tkHyperlinkManager is just a single module at effbot's site. Just copy
the code and put it in site-packages.

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: newbie request for help

Cameron Laird-2
On Wed, Jun 08, 2011 at 08:55:39AM -0400, Kevin Walzer wrote:
                        .
                        .
                        .

> >To get tkHyperlinkManager installed here is what I would recommend. If
> >the command easy_install is not currently available, then you may be
> >able to install the corresponding "distutils" module for Python using
> >Fedora's package maintenance capability. Probably installing something
> >like "Python distutils" should do the job. Once that is done then you
> >should have the command easy_install. Then it is simply a matter of
> >using this command line: easy_install tkHyperlinkManager. Depending on
> >the OS setup, you may need to run that as su/sudo to have the
> >permissions to write into the Python packages directories.
>
> tkHyperlinkManager is just a single module at effbot's site. Just copy
> the code and put it in site-packages.
                        .
                        .
                        .
Alessandro, do you understand what Kevin is saying?  This is
important:  *it's just source*, and in this case, brief and
simply-organized source.  Alessandro, make sure you look over
<URL: http://effbot.org/zone/tkinter-text-hyperlink.htm >.
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss