[Ann] pyeater, a (wx)py scripts launcher

I'm a little bit tired of creating shortcuts and walking through the directories.
This afternoon, I decided to fix this.I wrote a small (and handy?) wxapp scripts
launcher: pyeater.

The code is not too long (~200lines). I submit here for testing purpose.
Feedback is wellcome.

Time to go to sleep.
Jean-Michel Fauth, Switzerland

···

#---------------------------------------------------------------------
# Name: pyeater.py
# Purpose: A starter for py scripts..
# Author: Jean-Michel Fauth, Switzerland
# Copyright: (c) 2004 Jean-Michel Fauth
# Licence: GPL
#---------------------------------------------------------------------
# os dev: windows 98
# py dev: Python 2.3.4
# wx dev: wxPython 2.5.2.8
# Revision: 3 September 2004
#---------------------------------------------------------------------
# To do:
# python.exe option ???
#-------------------------------------------------------------------

import sys
import wx

#-------------------------------------------------------------------

def jmintfmt(i):
    s = str(i)
    k = []
    while len(s) > 3:
        k.append(s[-3:])
        s = s[:-3]
    k.append(s)
    k.reverse()
    return ' '.join(k)

#-------------------------------------------------------------------

class MyPanel(wx.Panel):
    
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize)
        self.parent = parent
        
        #constants
        self.AppFileName = 'pyeaterdb.txt'
        self.PythonPath = 'c:\\Python23\\python.exe'
        self.PythonwPath = 'c:\\Python23\\pythonw.exe'
        myfont = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Verdana')
        
        #versions
        s = 'Python ' + sys.version.split()[0]
        s += ' - wxPython ' + wx.VERSION_STRING
        s += '\nFree memory ' + jmintfmt(wx.GetFreeMemory()) + ' bytes'
        
        pos = (8, 8)
        size = (500, -1)
        self.statxt = wx.StaticText(self, wx.NewId(), s, pos, size, wx.ST_NO_AUTORESIZE)
        self.statxt.SetForegroundColour(wx.BLACK)
        self.statxt.SetFont(myfont)
        
        pos = (8, 42)
        size = (350, -1)
        self.combo = wx.ComboBox(self, wx.NewId(), '', pos, size, [], wx.CB_DROPDOWN)
        self.combo.SetFont(myfont)
            
        pos = (8, 68)
        size = wx.DefaultSize
        RadioList = ['python.exe', 'pythonw.exe']
        self.radio = wx.RadioBox(self, wx.NewId(), '', pos, size, RadioList)
        self.radio.SetSelection(1)
        
        pos = (200, 80)
        size = (110, 20)
        self.checkbox = wx.CheckBox(self, wx.NewId(), 'Quit after start', pos, size)
        self.checkbox.SetFont(myfont)

        pos = (8, 118)
        size = wx.DefaultSize
        self.but2 = wx.Button(self, wx.NewId(), 'browse', pos, size)
        self.but2.SetFont(myfont)
        
        pos = (110, 118)
        size = wx.DefaultSize
        self.but3 = wx.Button(self, wx.NewId(), 'add to list', pos, size)
        self.but3.SetFont(myfont)
        
        pos = (282, 118)
        size = wx.DefaultSize
        self.but1 = wx.Button(self, wx.NewId(), 'start', pos, size)
        self.but1.SetForegroundColour(wx.RED)
        self.but1.SetFont(myfont)

        self.infolist = []
        try:
            f = open(self.AppFileName, 'rU')
            self.infolist = f.readlines()
            f.close()
        except:
            self.combo.SetValue('***error in reading ' + self.AppFileName + '***')

        self.parseinfofile()
        
        self.combo.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter)
        self.but1.Bind(wx.EVT_BUTTON, self.OnClick1)
        self.but2.Bind(wx.EVT_BUTTON, self.OnClick2)
        self.but3.Bind(wx.EVT_BUTTON, self.OnClick3)

    def parseinfofile(self):
        #remove empty lines
        first = True
        self.infolist = [e.strip() for e in self.infolist if len(e.strip()) != 0]
        for e in self.infolist:
            if e[0] == '#':
                pass
            else:
                token = e.split('=')
                token = [t.strip() for t in token]
                if token[0] == 'pythonpath':
                    self.pythonpath = token[0]
                elif token[0] == 'pythonwpath':
                    self.pythonwpath = token[0]
                elif token[0] == 'app':
                    self.pythonwpath = token[0]
                    if first:
                        self.combo.SetValue(token[1])
                        first = False
                    self.combo.Append(token[1])
                else:
                    pass

    def OnClick1(self, event):
        try:
            cmd = ''
            appstr = self.combo.GetValue()
            quit = self.checkbox.GetValue()
            #python or pythonw?
            if appstr[-3:] == 'pyw':
                cmd = self.PythonwPath + ' ' + appstr
            else:
                if self.radio.GetSelection() == 0:
                    cmd = self.PythonPath + ' ' + appstr
                else:
                    cmd = self.PythonwPath + ' ' + appstr
            #instance of a process
            process = wx.Process(self.parent)
            #run the process
            pid = wx.Execute(cmd, wx.EXEC_ASYNC, process)
            #~ print 'process id:', pid, 'of', cmd
            #~ delete process
            #leave this app
            if quit:
                self.parent.OnCloseWindow(None)
        except:
            self.combo.SetValue('*** process fail ***')

    def OnClick2(self, event):
        flags = wx.OPEN | wx.HIDE_READONLY | wx.FILE_MUST_EXIST
        wc = 'py files (*.py)|*.py|pyw files (*.pyw)|*.pyw|all files (*.*)|*.*'
        dlg = wx.FileDialog(self, 'Select a Python file', '.', '', wc, flags)
        if dlg.ShowModal() == wx.ID_OK:
            fn = dlg.GetPath() #= filename + path
            self.combo.SetValue(fn)
        else:
            fn = ''
        dlg.Destroy()

    def OnClick3(self, event):
        try:
            f = open(self.AppFileName, 'a')
            a = self.combo.GetValue()
            s = 'app=' + a + '\n'
            f.write(s)
            f.close()
            self.combo.Append(a)
        except:
            pass

    def OnTextEnter(self, event):
        self.OnClick1(None)

#-------------------------------------------------------------------

class MyFrame(wx.Frame):

    def __init__(self, parent, id):
        sty = wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX
        wx.Frame.__init__(self, parent, id, 'pyeater', (0, 0), (372, 176), style=sty)

        try:
            fn = 'py.ico'
            icon = wx.Icon(fn, wx.BITMAP_TYPE_ICO)
            self.SetIcon(icon)
            del icon
        except:
            pass

        self.panel = MyPanel(self, -1)

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    def OnCloseWindow(self, event):
        self.Destroy()

#-------------------------------------------------------------------

class MyApp(wx.App):
    
    def OnInit(self):
        frame = MyFrame(None, -1)
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

#-------------------------------------------------------------------

def main():
    app = MyApp(False)
    app.MainLoop()

#-------------------------------------------------------------------

if __name__ == "__main__" :
    main()

#eof-------------------------------------------------------------------

the db file pyeaterdb.txt

#this is a comment
#empty lines are not interpreted

#path for the python applications
pythonpath=c:\Python23\python.exe
pythonwpath=c:\Python23\pythonw.exe

#list of applications, the first item is the default item.
app=c:\small\small.py
app=c:\small\a.py
app=c:\small\b.py
app=c:\small\c.py
app=c:\jm\jmpy\wxfullapp\wese208beta6\wese.py
app=c:\jm\jmpy\wxfullapp\pxy204beta5\pxy.pyw
app=C:\jm\jmpy\wxapp\charmap\charmap6.py
app=C:\jm\jmpy\psi\psi60\psi.pyw
app="C:\Program Files\sma2.py"

end of msg

Hello Jean-Michel,

the pyeater is a splendid idea, I like it very much.

I'm a little bit tired of creating shortcuts and walking through the directories.
This afternoon, I decided to fix this.I wrote a small (and handy?) wxapp scripts
launcher: pyeater.

The code is not too long (~200lines). I submit here for testing purpose.
Feedback is wellcome.

Maybe two things in addition:

1) Able to delete out one entry from the combobox (and the db file)-

2) Another Combobox to select another pyeaterdb file.
for example: sizer_testsdb, demo_files.db, whole_apps.db

best regards.

···

On Fri, 3 Sep 2004 23:46:09 +0200, "Jean-Michel Fauth" <jmfauth@bluewin.ch> wrote:
--
Franz Steinhäusler

Interesting app...
Well... as feedback... you sould make sure that the error message that appears when pyeaterdb.txt doesn't exist is not saved as an app :wink:

I guess it is a matter of habits if this app is in any way useful.
I cannot see how it could help me as I'm always launching the scripts from SciTE... I need the output and if it is an app I use often I take the time to create a handy dandy shortcut with a nice icon :slight_smile:
However, with few additions it might turn out to be something useful even for me :slight_smile:

Add a window to capture output... some might find that helpful.
Add an "Open in Editor" option.
Think about replacing the combo with a list...
right now is:
- zero-in on combo's arrow
- click arrow
- zero-in on desired script
- click script
- zero-in on start button
- click start button

with a list it could be:
- zero-in on desired script
- double-click

···

On Fri, 3 Sep 2004 23:46:09 +0200, Jean-Michel Fauth <jmfauth@bluewin.ch> wrote:

I'm a little bit tired of creating shortcuts and walking through the directories.
This afternoon, I decided to fix this.I wrote a small (and handy?) wxapp scripts
launcher: pyeater.

The code is not too long (~200lines). I submit here for testing purpose.
Feedback is wellcome.

--
Peter Damoc
Hacker Wannabe

Hello Jean-Michel,

        self.PythonPath = 'c:\\Python23\\python.exe'

See sys.executable

HTH.

···

--
------------------------------------------------------------------------
Miki Tebeka <miki.tebeka@zoran.com>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys