Adding Extra Text to Trees?

Hi all,

I'm working as a Co-op student at my university on a telescope
project. The idea is to place the telescope in a remote location far
away, and operate it via the internet from here. Part of my work
involves writing a GUI with wxpython to run some pre-existing scripts
for the telescope. I'd like to create a help directory, where users
who haven't used the GUI before will know what each of the buttons do.
I've only been using Python for a few days now, but I've managed to
create a tree structure that will separate various help topics.
However, when the help directory is launched, I'd like more text to be
able seen after clicking on a particular item in the tree. For
example, if they clicked on 'Begin Imaging', I'd like to have a
description in the right hand side of what 'Begin Imaging' refers to.
I haven't found any way to do this yet. Would anyone be so kind to
help me? :slight_smile:

Below is the class for the help directory that I've created. One
should be able to copy, paste, and run in a terminal. Any help would
be greatly appreciated!

Thanks!

···

----------------------------------------------------------------------------

import wx
import wx.gizmos as gizmos

class Help(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
wx.Size(600, 450))

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        vbox = wx.BoxSizer(wx.VERTICAL)
        panel1 = wx.Panel(self, -1)
        panel2 = wx.Panel(self, -1)

        self.tree = wx.TreeCtrl(panel1, 1, wx.DefaultPosition,
(-1,-1), wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)
        root = self.tree.AddRoot('Anything')
  TI = self.tree.AppendItem(root, 'Telescope Information')
        WS = self.tree.AppendItem(root, 'Weather Station')
        CT = self.tree.AppendItem(root, 'Check Telescope')
        TO = self.tree.AppendItem(root, 'Telescope Operation')
        self.tree.AppendItem(WS, 'Temperature')
        self.tree.AppendItem(WS, 'Humidity')
        self.tree.AppendItem(WS, 'Wind Speed')
        self.tree.AppendItem(WS, 'Wind Direction')
        self.tree.AppendItem(WS, 'Pressure')
  self.tree.AppendItem(WS, 'Rain Fall')
  self.tree.AppendItem(CT, 'Dome Status')
  self.tree.AppendItem(CT, 'Power Cabinet Status')
  self.tree.AppendItem(CT, 'NPS Status')
  self.tree.AppendItem(CT, 'Emergency Switch Status')
  self.tree.AppendItem(TO, 'Open/Close Dome')
  self.tree.AppendItem(TO, 'Point RA/DEC')
  self.tree.AppendItem(TO, 'Track Star')
  self.tree.AppendItem(TO, 'Park Telescope')
  self.tree.AppendItem(TO, 'Begin Imaging')
  self.tree.AppendItem(TO, 'Filters')
  self.tree.AppendItem(TO, 'Shutdown')
        self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged,
id=1)
        self.display = wx.StaticText(panel2, -1, 'Welcome to the Help
Directory! \n\nClick on a topic at the left to view \nits contents',
(10,10), style=wx.ALIGN_LEFT)
        vbox.Add(self.tree, 1, wx.EXPAND)
        hbox.Add(panel1, 1, wx.EXPAND)
        hbox.Add(panel2, 1, wx.EXPAND)
        panel1.SetSizer(vbox)
        self.SetSizer(hbox)
        self.Centre()
  self.Show(True)

    def OnSelChanged(self, event):
        item = event.GetItem()
        self.display.SetLabel(self.tree.GetItemText(item))

app = wx.PySimpleApp()
Frame = Help(None, -1,'Help Directory')
app.MainLoop()

P.S.

I'm using Ubuntu 9.04, with wxpython 2.8.

- Nick

···

On Jun 1, 5:04 pm, Nick <nick.ser...@gmail.com> wrote:

Hi all,

I'm working as a Co-op student at my university on a telescope
project. The idea is to place the telescope in a remote location far
away, and operate it via the internet from here. Part of my work
involves writing a GUI with wxpython to run some pre-existing scripts
for the telescope. I'd like to create a help directory, where users
who haven't used the GUI before will know what each of the buttons do.
I've only been using Python for a few days now, but I've managed to
create a tree structure that will separate various help topics.
However, when the help directory is launched, I'd like more text to be
able seen after clicking on a particular item in the tree. For
example, if they clicked on 'Begin Imaging', I'd like to have a
description in the right hand side of what 'Begin Imaging' refers to.
I haven't found any way to do this yet. Would anyone be so kind to
help me? :slight_smile:

Below is the class for the help directory that I've created. One
should be able to copy, paste, and run in a terminal. Any help would
be greatly appreciated!

Thanks!

----------------------------------------------------------------------------

import wx
import wx.gizmos as gizmos

class Help(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
wx.Size(600, 450))

    hbox = wx\.BoxSizer\(wx\.HORIZONTAL\)
    vbox = wx\.BoxSizer\(wx\.VERTICAL\)
    panel1 = wx\.Panel\(self, \-1\)
    panel2 = wx\.Panel\(self, \-1\)

    self\.tree = wx\.TreeCtrl\(panel1, 1, wx\.DefaultPosition,

(-1,-1), wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)
root = self.tree.AddRoot('Anything')
TI = self.tree.AppendItem(root, 'Telescope Information')
WS = self.tree.AppendItem(root, 'Weather Station')
CT = self.tree.AppendItem(root, 'Check Telescope')
TO = self.tree.AppendItem(root, 'Telescope Operation')
self.tree.AppendItem(WS, 'Temperature')
self.tree.AppendItem(WS, 'Humidity')
self.tree.AppendItem(WS, 'Wind Speed')
self.tree.AppendItem(WS, 'Wind Direction')
self.tree.AppendItem(WS, 'Pressure')
self.tree.AppendItem(WS, 'Rain Fall')
self.tree.AppendItem(CT, 'Dome Status')
self.tree.AppendItem(CT, 'Power Cabinet Status')
self.tree.AppendItem(CT, 'NPS Status')
self.tree.AppendItem(CT, 'Emergency Switch Status')
self.tree.AppendItem(TO, 'Open/Close Dome')
self.tree.AppendItem(TO, 'Point RA/DEC')
self.tree.AppendItem(TO, 'Track Star')
self.tree.AppendItem(TO, 'Park Telescope')
self.tree.AppendItem(TO, 'Begin Imaging')
self.tree.AppendItem(TO, 'Filters')
self.tree.AppendItem(TO, 'Shutdown')
self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged,
id=1)
self.display = wx.StaticText(panel2, -1, 'Welcome to the Help
Directory! \n\nClick on a topic at the left to view \nits contents',
(10,10), style=wx.ALIGN_LEFT)
vbox.Add(self.tree, 1, wx.EXPAND)
hbox.Add(panel1, 1, wx.EXPAND)
hbox.Add(panel2, 1, wx.EXPAND)
panel1.SetSizer(vbox)
self.SetSizer(hbox)
self.Centre()
self.Show(True)

def OnSelChanged\(self, event\):
    item =  event\.GetItem\(\)
    self\.display\.SetLabel\(self\.tree\.GetItemText\(item\)\)

app = wx.PySimpleApp()
Frame = Help(None, -1,'Help Directory')
app.MainLoop()

Hello,

tree_pydata.py (2.77 KB)

···

On Jun 1, 2009, at 7:04 PM, Nick wrote:

Hi all,

I'm working as a Co-op student at my university on a telescope
project. The idea is to place the telescope in a remote location far
away, and operate it via the internet from here. Part of my work
involves writing a GUI with wxpython to run some pre-existing scripts
for the telescope. I'd like to create a help directory, where users
who haven't used the GUI before will know what each of the buttons do.
I've only been using Python for a few days now, but I've managed to
create a tree structure that will separate various help topics.
However, when the help directory is launched, I'd like more text to be
able seen after clicking on a particular item in the tree. For
example, if they clicked on 'Begin Imaging', I'd like to have a
description in the right hand side of what 'Begin Imaging' refers to.
I haven't found any way to do this yet. Would anyone be so kind to
help me? :slight_smile:

Here are a couple ways to do this,

1) You can set extra data on the tree items (see modified attachment), if its just small strings that you want to add to the display this is probably the simplest.

2) You could store a mapping of tree items to long descriptions in a dictionary or the like and load it when the item is selected.

Thank-you so much! I used your code, but have created separate files
for each topic to be loaded from the OS. It also looks like it is
automatically wrapping, which means I don't have to hard code '/n'
into the text. :slight_smile:

I appreciate your help!

···

On Jun 1, 5:31 pm, Cody Precord <codyprec...@gmail.com> wrote:

Hello,

On Jun 1, 2009, at 7:04 PM, Nick wrote:

> Hi all,

> I'm working as a Co-op student at my university on a telescope
> project. The idea is to place the telescope in a remote location far
> away, and operate it via the internet from here. Part of my work
> involves writing a GUI with wxpython to run some pre-existing scripts
> for the telescope. I'd like to create a help directory, where users
> who haven't used the GUI before will know what each of the buttons do.
> I've only been using Python for a few days now, but I've managed to
> create a tree structure that will separate various help topics.
> However, when the help directory is launched, I'd like more text to be
> able seen after clicking on a particular item in the tree. For
> example, if they clicked on 'Begin Imaging', I'd like to have a
> description in the right hand side of what 'Begin Imaging' refers to.
> I haven't found any way to do this yet. Would anyone be so kind to
> help me? :slight_smile:

Here are a couple ways to do this,

1) You can set extra data on the tree items (see modified attachment),
if its just small strings that you want to add to the display this is
probably the simplest.

2) You could store a mapping of tree items to long descriptions in a
dictionary or the like and load it when the item is selected.

tree_pydata.py
2KViewDownload

Cody

Hi all again,

Is there an easy way to change the size of the panels without having
them occupy equal areas? For example, I would like the left panel in
my code to be half the size of the right panel in the code. (i.e. 200
pixels for the left panel, 400 pixels for the right panel).

Thanks! :smiley:

···

On Jun 2, 11:35 am, Nick <nick.ser...@gmail.com> wrote:

Thank-you so much! I used your code, but have created separate files
for each topic to be loaded from the OS. It also looks like it is
automatically wrapping, which means I don't have to hard code '/n'
into the text. :slight_smile:

I appreciate your help!

On Jun 1, 5:31 pm, Cody Precord <codyprec...@gmail.com> wrote:

> Hello,

> On Jun 1, 2009, at 7:04 PM, Nick wrote:

> > Hi all,

> > I'm working as a Co-op student at my university on a telescope
> > project. The idea is to place the telescope in a remote location far
> > away, and operate it via the internet from here. Part of my work
> > involves writing a GUI with wxpython to run some pre-existing scripts
> > for the telescope. I'd like to create a help directory, where users
> > who haven't used the GUI before will know what each of the buttons do.
> > I've only been using Python for a few days now, but I've managed to
> > create a tree structure that will separate various help topics.
> > However, when the help directory is launched, I'd like more text to be
> > able seen after clicking on a particular item in the tree. For
> > example, if they clicked on 'Begin Imaging', I'd like to have a
> > description in the right hand side of what 'Begin Imaging' refers to.
> > I haven't found any way to do this yet. Would anyone be so kind to
> > help me? :slight_smile:

> Here are a couple ways to do this,

> 1) You can set extra data on the tree items (see modified attachment),
> if its just small strings that you want to add to the display this is
> probably the simplest.

> 2) You could store a mapping of tree items to long descriptions in a
> dictionary or the like and load it when the item is selected.

> tree_pydata.py
> 2KViewDownload

> Cody