foxtail.py :  » GUI » FXPy » FXPy-1.0.5 » contrib » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » FXPy 
FXPy » FXPy 1.0.5 » contrib » foxtail.py
#!/bin/env python
#
# A tail application along the lines of tailtk.py.
# Contributed by John Przybylski (johnp9@bellatlantic.net).
#

from threading import *
from FXPy.fox import *
from Queue import *
import sys,os,time,re

class MyThread(Thread):
    def __init__(self, queue, name='foo'):
        Thread.__init__(self)
        self.name = name
        self.queue = queue
        self.file = open(self.name, 'r')
        return

    def run(self):
        while 1:
            data = self.file.readline()
      data = re.sub("\n", '', data) 
            self.queue.put(data)
            #time.sleep(.1)
        return

class ListWindow(FXMainWindow):

    ID_TIMEOUT, ID_CHORE = \
        range(FXMainWindow.ID_LAST, FXMainWindow.ID_LAST+2)

    def __init__(self, app):

        FXMainWindow.__init__(self, app, "List Test", w=600, h=400)

        FXMAPFUNC(self,SEL_CHORE,ListWindow.ID_CHORE,ListWindow.onChore)
        FXMAPFUNC(self,SEL_TIMEOUT,ListWindow.ID_TIMEOUT,ListWindow.onTimeout)

        listframe = FXHorizontalFrame(self, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_THICK|FRAME_RAISED)
        self.simplelist = FXList(listframe, 1, None, 0, LIST_EXTENDEDSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
        self.simplelist.appendItem("Start")

        self.queue = Queue(10)
        self.thread = MyThread(self.queue, sys.argv[1])
        self.thread.start()
 
        self.timer = 0
        self.chore = self.getApp().addChore(self,self.ID_CHORE)
        
    def create(self):
        FXMainWindow.create(self)
        self.show(PLACEMENT_SCREEN)

    # Do something whenever timer fires
    def onTimeout(self,sender,sel,ptr):
        self.timer = self.getApp().addTimeout(10,self,self.ID_TIMEOUT)

    # Do something whenever a chore message is received
    def onChore(self,sender,sel,ptr):
        try:
            while 1:
              str = self.queue.get(0)
              if len(str)>0:
            self.simplelist.appendItem(str)
                  if self.simplelist.getNumItems() > 100:
                      self.simplelist.removeItem(0)
        else:
            time.sleep(.1)
              break
        except Empty:
            pass
        except:
            import traceback
            traceback.print_exc()
        self.chore = self.getApp().addChore(self,self.ID_CHORE)

def runme():
    import sys
    if len(sys.argv) < 2:
        print "usage: foxtail.py <file>"
        sys.exit(1)
    application = FXApp()
    application.init(sys.argv)
    ListWindow(application)
    application.create()
    application.run()

# Main program starts here
if __name__ == '__main__':
    runme()


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.