Sikkepitje.nl

Sikkepitje.nl

this private cloud

DevShack

LuisterguiPy

#!/usr/bin/python
# luistergui.py gebaseerd op autowidth.py uit wxPython tutorial (zetcode.com)
# 20090326 Paul Wiegmans (p.wiegmans@bonhoeffer.nl)
#
# info uit luistergui.py is
# received message: logon,BPW01303,laurens.andriessen,20080611
# from: ('172.23.0.216', 1741)
#
# contextmenu (popupmenu) werkt niet

import wx
import sys
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin

ID_QUIT = 1
ID_INFO = 2
ID_STAT = 3

actresses = [('jessica alba', 'pomona', '1981'), ('sigourney weaver', 'new york', '1949'),
    ('angelina jolie', 'los angeles', '1975'), ('natalie portman', 'jerusalem', '1981'),
    ('rachel weiss', 'london', '1971'), ('scarlett johansson', 'new york', '1984' )]


class MyPopupMenu(wx.Menu):
    '''uit contextmenu.py'''
    def __init__(self, parent):
        wx.Menu.__init__(self)

        self.parent = parent

        minimize = wx.MenuItem(self, wx.NewId(), 'minimize')
        self.AppendItem(minimize)
        self.Bind(wx.EVT_MENU, self.OnMinimize, id=minimize.GetId())

        close = wx.MenuItem(self, wx.newId(), 'Close')
        self.AppendItem(close)
        self.Bind(wx.EVT_MENU, self.OnClose, id=close.GetId())

    def OnMinimize(self, event):
        self.parent.Iconize()

    def OnClose(self, event):
        self.parent.Close()



class AutoWidthListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin):
    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)
        ListCtrlAutoWidthMixin.__init__(self)


class LuisterGUI(wx.Frame):
    '''show statusbar item_check uit checkmenuitem.py'''
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(380, 230))

        menubar = wx.MenuBar()
        file = wx.Menu()
        file.Append(-1, '&New')
        file.Append(-1, '&Open')
        file.Append(-1, '&Save')
        file.AppendSeparator()
        quit = wx.MenuItem(file, ID_QUIT, '&Quit\tCtrl+W')
        # quit.SetBitmap(wx.Bitmap('icons/exit.png')
        file.AppendItem(quit)
        # file.Append(-1, 'Quit', 'Quit application')

        edit = wx.Menu()
        view = wx.Menu()
        self.shst = view.Append(ID_STAT, 'Show statusbar', 'Show Statusbar', kind=wx.ITEM_CHECK)
        view.Check(ID_STAT, True)
        self.Bind(wx.EVT_MENU, self.ToggleStatusBar, id=ID_STAT)

        help = wx.Menu()
        info = wx.MenuItem(help, ID_INFO, '&Info')
        help.AppendItem(info)
        # help.Append(-1, '&Info')

        menubar.Append(file, '&File')
        menubar.Append(edit, '&Edit')
        menubar.Append(view, '&View')
        menubar.Append(help, '&Help')
        self.SetMenuBar(menubar)

        self.statusbar = self.CreateStatusBar()

        hbox = wx.BoxSizer(wx.HORIZONTAL)

        panel = wx.Panel(self, -1)

        self.list = AutoWidthListCtrl(panel)
        self.list.InsertColumn(0, 'event', width=72)
        self.list.InsertColumn(1, 'date', width=96)
        self.list.InsertColumn(2, 'computer', width=100)
        self.list.InsertColumn(3, 'user', width=100)
        self.list.InsertColumn(4, 'version', width=100)
        self.list.InsertColumn(5, 'ip', wx.LIST_FORMAT_RIGHT, 90)

        for i in actresses:
            index = self.list.InsertStringItem(sys.maxint, i[0])
            self.list.SetStringItem(index, 1, i[1])
            self.list.SetStringItem(index, 2, i[2])

        hbox.Add(self.list, 1, wx.EXPAND)
        panel.SetSizer(hbox)

        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)

        self.Centre()
        self.Show(True)

    def ToggleStatusBar(self, event):
        if self.shst.IsChecked():
            self.statusbar.Show()
        else:
            self.statusbar.Hide()

    def OnRightDown(self, event):
        self.Popupmenu(MyPopupmenu(self), event.GetPosition())

app = wx.App()
LuisterGUI(None, -1, 'LuisterGUI')
app.MainLoop()