My first program - What did I do wrong

Hi, new to python and wxpython. I am having alot of fun and learning from this list. All comments welcome. this is a little program that converts ogg theora video to avi. All comments welcome;

#!/usr/bin/python

# Oggtoavi
# Gentoo dependences
# wxpython
# mplayer with "encode USE set"

import os
import sys
import wx

class Oggtoavi(wx.Dialog):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title, size=(360, 370))

        panel = wx.Panel(self, -1)
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        hbox2 = wx.BoxSizer(wx.HORIZONTAL)

        st1 = wx.StaticText(panel, -1, 'Enter Ogg: ')
        st2 = wx.StaticText(panel, -1, 'Enter Avi: ')

        self.tc1 = wx.TextCtrl(panel, -1, size=(180, -1))
        self.tc2 = wx.TextCtrl(panel, -1, size=(180, -1))

        button_send = wx.Button(panel, 1, 'Convert')

        hbox1.Add(st1, 0, wx.LEFT, 10)
        hbox1.Add(self.tc1, 0, wx.LEFT, 10)
        hbox2.Add(st2, 0, wx.LEFT, 10)
        hbox2.Add(self.tc2, 0, wx.LEFT, 15)

        vbox.Add(hbox1, 0, wx.TOP, 50)
        vbox.Add(hbox2, 0, wx.TOP, 50)
        vbox.Add(button_send, 0, wx.ALIGN_CENTER | wx.TOP | wx.TOP | wx.BOTTOM, 100)

        self.Bind(wx.EVT_BUTTON, self.OnConvert, id=1)
        panel.SetSizer(vbox)

        self.Centre()
        self.ShowModal()
        self.Destroy()

    def OnConvert(self, event):
        ogg = self.tc1.GetValue()
        avi = self.tc2.GetValue()

        os.system("%s %s %s %s %s %s %s %s" % ('mencoder', ogg, '-ovc', 'lavc', '-oac', 'mp3lame', '-o', avi))
        if os.path.exists(avi):
            dlg = wx.MessageDialog(self, 'Your avi file was created.', 'Success', wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
            sys.exit()
        else:
            dlg = wx.MessageDialog(self, 'Failed to convert.', 'Error', wx.OK | wx.ICON_ERROR)

            dlg.ShowModal()
            dlg.Destroy()
            sys.exit()

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

From your subject, it would seem that you are asking "why doesn't this

work like I expect?" A proper lead-in to the question is, "I expect
this to work like X. It doesn't. What am I doing wrong?"

If you can clarify, we might be able to help you :slight_smile: (I do have an idea
of what you are expecting, and if that's correct, what you did wrong,
but getting into the habit of telling people what you expect, why you
expect, and then asking a question is not a bad exercise).

- Josiah

···

On Wed, Sep 10, 2008 at 3:38 PM, david <python@abbottdavid.com> wrote:

Hi, new to python and wxpython. I am having alot of fun and learning from
this list. All comments welcome. this is a little program that converts ogg
theora video to avi. All comments welcome;

#!/usr/bin/python

# Oggtoavi
# Gentoo dependences
# wxpython
# mplayer with "encode USE set"

import os
import sys
import wx

class Oggtoavi(wx.Dialog):
  def __init__(self, parent, id, title):
      wx.Dialog.__init__(self, parent, id, title, size=(360, 370))

      panel = wx.Panel(self, -1)
      vbox = wx.BoxSizer(wx.VERTICAL)
      hbox1 = wx.BoxSizer(wx.HORIZONTAL)
      hbox2 = wx.BoxSizer(wx.HORIZONTAL)

      st1 = wx.StaticText(panel, -1, 'Enter Ogg: ')
      st2 = wx.StaticText(panel, -1, 'Enter Avi: ')

      self.tc1 = wx.TextCtrl(panel, -1, size=(180, -1))
      self.tc2 = wx.TextCtrl(panel, -1, size=(180, -1))

      button_send = wx.Button(panel, 1, 'Convert')

      hbox1.Add(st1, 0, wx.LEFT, 10)
      hbox1.Add(self.tc1, 0, wx.LEFT, 10)
      hbox2.Add(st2, 0, wx.LEFT, 10)
      hbox2.Add(self.tc2, 0, wx.LEFT, 15)

      vbox.Add(hbox1, 0, wx.TOP, 50)
      vbox.Add(hbox2, 0, wx.TOP, 50)
      vbox.Add(button_send, 0, wx.ALIGN_CENTER | wx.TOP | wx.TOP |
wx.BOTTOM, 100)

      self.Bind(wx.EVT_BUTTON, self.OnConvert, id=1)
      panel.SetSizer(vbox)

      self.Centre()
      self.ShowModal()
      self.Destroy()

  def OnConvert(self, event):
      ogg = self.tc1.GetValue()
      avi = self.tc2.GetValue()

      os.system("%s %s %s %s %s %s %s %s" % ('mencoder', ogg, '-ovc',
'lavc', '-oac', 'mp3lame', '-o', avi))
      if os.path.exists(avi):
          dlg = wx.MessageDialog(self, 'Your avi file was created.',
'Success', wx.OK | wx.ICON_INFORMATION)
          dlg.ShowModal()
          dlg.Destroy()
          sys.exit()
      else:
          dlg = wx.MessageDialog(self, 'Failed to convert.', 'Error', wx.OK
> wx.ICON_ERROR)

          dlg.ShowModal()
          dlg.Destroy()
          sys.exit()

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Josiah Carlson wrote:

>From your subject, it would seem that you are asking "why doesn't this
work like I expect?" A proper lead-in to the question is, "I expect
this to work like X. It doesn't. What am I doing wrong?"

It is working fine, I just wanted to know if there were any pointers anyone had and if I was starting any bad habits.

If you can clarify, we might be able to help you :slight_smile: (I do have an idea
of what you are expecting, and if that's correct, what you did wrong,
but getting into the habit of telling people what you expect, why you
expect, and then asking a question is not a bad exercise).

- Josiah

thanks

david wrote:

---snip---

       hbox1 = wx.BoxSizer(wx.HORIZONTAL)
       hbox2 = wx.BoxSizer(wx.HORIZONTAL)

       st1 = wx.StaticText(panel, -1, 'Enter Ogg: ')
       st2 = wx.StaticText(panel, -1, 'Enter Avi: ')

       self.tc1 = wx.TextCtrl(panel, -1, size=(180, -1))
       self.tc2 = wx.TextCtrl(panel, -1, size=(180, -1))

---snip---

Slightly better and a lot more userfriendly (or user-proof !) is doing
this for the st1 control :

       st1 = wx.FilePickerCtrl(panel, -1, message='Enter Ogg:
',wildcard='*.ogg')

However for the AVI you cannot use this a.f.a.i.k. because the
FilePicker only allows you to pick existing files.

Regards
Niels

Niels Huylebroeck wrote:


david wrote:
---snip---
       hbox1 = wx.BoxSizer(wx.HORIZONTAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
st1 = wx.StaticText(panel, -1, 'Enter Ogg: ')
st2 = wx.StaticText(panel, -1, 'Enter Avi: ')
self.tc1 = wx.TextCtrl(panel, -1, size=(180, -1))
self.tc2 = wx.TextCtrl(panel, -1, size=(180, -1))

---snip---
Slightly better and a lot more userfriendly (or user-proof !) is doing
this for the st1 control :
st1 = wx.FilePickerCtrl(panel, -1, message='Enter Ogg:
',wildcard='*.ogg')

Sorry,

I mixed up the st1 and the tc1 :smiley:

   st1 = wx.StaticText(panel, -1, 'Enter Ogg: ')

   st2 = wx.StaticText(panel, -1, 'Enter Avi: ')

   self.tc1 = wx.FilePickerCtrl(panel, -1, message='Select Ogg',

wildcard=‘*.ogg’, size=(180, -1))

   self.tc2 = wx.TextCtrl(panel, -1, size=(180, -1))

Should work :slight_smile: