[xiph-commits] r7416 - in trunk/xinloe: . icons/16x16

arc at motherfish-iii.xiph.org arc
Thu Aug 5 18:58:32 PDT 2004


Author: arc
Date: Thu Aug  5 18:58:32 2004
New Revision: 7416

Added:
trunk/xinloe/AUTHORS
trunk/xinloe/general.py
trunk/xinloe/handlers.py
trunk/xinloe/icons/16x16/nonfree.png
Removed:
trunk/xinloe/images.py
Modified:
trunk/xinloe/infobox.py
trunk/xinloe/main.py
trunk/xinloe/sandbox.py
Log:
Added codec handlers, moved stuff from images.py to general.py and
centralized external imports to this one file.

Info box is just dummy static info for right now, but with the codec
handlers more robust, it should be able to display real info tomarrow.



Added: trunk/xinloe/AUTHORS
===================================================================
--- trunk/xinloe/AUTHORS	2004-07-29 23:49:57 UTC (rev 7415)
+++ trunk/xinloe/AUTHORS	2004-07-30 04:09:33 UTC (rev 7416)
@@ -0,0 +1,2 @@
+Arc <arc at Xiph.org>
+

Added: trunk/xinloe/general.py
===================================================================
--- trunk/xinloe/general.py	2004-07-29 23:49:57 UTC (rev 7415)
+++ trunk/xinloe/general.py	2004-07-30 04:09:33 UTC (rev 7416)
@@ -0,0 +1,43 @@
+'''
+  Xinloe -- A Python-Based Non-Linear Ogg Editor
+  Copyright (C) 2004 Arc Riley <arc at Xiph.org>
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+'''
+
+#
+# We'll import all external modules here
+#
+import os
+import wx
+import ogg2
+import time
+from wxPython.wx import *
+from wxPython.lib.scrolledpanel import wxScrolledPanel
+
+def geticon(name, size=1):
+  sizes=('16x16','22x22','32x32','48x48')
+  f = 'icons/%s/%s.png' % (sizes[size], name)
+  return wxImage(f, wxBITMAP_TYPE_PNG).ConvertToBitmap()
+
+def gettext(parent, string, size=1):
+  text = wxStaticText(parent, -1, string)
+  font = text.GetFont()
+  font.SetPointSize(font.GetPointSize()+size)
+  text.SetFont(font)
+  return text
+
+

Added: trunk/xinloe/handlers.py
===================================================================
--- trunk/xinloe/handlers.py	2004-07-29 23:49:57 UTC (rev 7415)
+++ trunk/xinloe/handlers.py	2004-07-30 04:09:33 UTC (rev 7416)
@@ -0,0 +1,151 @@
+'''
+  Xinloe -- A Python-Based Non-Linear Ogg Editor
+  Copyright (C) 2004 Arc Riley <arc at Xiph.org>
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+'''
+
+#
+# Every codec is expected to have a name, desc, icon, and version
+# All other variables are up to the codec to set and use as needed
+#
+
+class GenCodec:
+  def __init__(self, header):
+    self.name = ''
+    self.desc = ''
+    self.icon = ''
+    self.version = 0
+
+class Vorbis(GenCodec):
+  def __init__(self, header):
+    GenCodec.__init__(self, '')
+    if header[:7] == '\x01vorbis':
+      self.icon = 'vorbis'
+      if header[7:11] == '\x00\x00\x00\x00' :
+        self.name = 'Vorbis I'
+        self.desc = 'General Purpose Audio'
+        self.version = 0
+        self.channels = ord(header[11])
+        self.samplerate = ord(header[12]) + (ord(header[13])*256) + \
+                  (ord(header[14])*65536) + (ord(header[15])*16777216)
+      else :
+        self.name = 'Vorbis (Unsupported Version)'
+        self.desc = ''
+        self.version = chr(ord(header[7]) + (ord(header[8])*256) + \
+                   (ord(header[9])*65536) + (ord(header[10])*16777216))
+
+class Theora(GenCodec):
+  def __init__(self, header):
+    GenCodec.__init__(self, '')
+    if header[:7] == '\x80theora':
+      self.icon = 'theora'
+      if header[7:9] == '\x03\x02' :
+        self.name = 'Theora I'
+        self.desc = 'General Purpose Video'
+        self.version = '3.2.'+str(ord(header[9]))
+        self.size = str(ord(header[16]) + (ord(header[15])*256) + \
+                        (ord(header[14])*65536)) + 'x' + \
+                    str(ord(header[19]) + (ord(header[18])*256) +
+                        (ord(header[17])*65536))
+        n = ord(header[25]) + (ord(header[24])*256) + \
+            (ord(header[23])*65536) + (ord(header[22])*16777216)
+        d = ord(header[29]) + (ord(header[28])*256) + \
+            (ord(header[27])*65536) + (ord(header[26])*16777216)
+        self.framerate = float(n)/float(d)
+        self.b = ord(header[39]) + (ord(header[38])*256) + \
+                 (ord(header[37])*65536)
+        self.q = int(round((((ord(header[40]) & 252) >> 2) / 6.3)))
+        self.keyshift = ((ord(header[40]) & 3) << 3)+\
+                        ((ord(header[41]) & 224) >> 5)
+
+      else :
+        self.name = 'Theora (Unsupported Version)'
+        self.desc = ''
+        self.version = str(ord(header[7])) + '.' + \
+                       str(ord(header[8])) + '.' + \
+                       str(ord(header[9]))
+
+class Speex(GenCodec):
+  def __init__(self, header):
+    GenCodec.__init__(self, '')
+    if header[:8] == 'Speex   ':
+      self.icon = 'speex'
+      self.version = header[8:28]
+      if header[28:32] == '\x01\x00\x00\x00' :
+        self.name = 'Speex I'
+        self.desc = 'Low Bitrate Voice'
+        self.samplerate = ord(header[36]) + (ord(header[37])*256) + \
+                  (ord(header[38])*65536) + (ord(header[39])*16777216)
+        if header[40] == '\x00' :
+          self.q = 'NarrowBand'
+        elif header[40] == '\x01' :
+          self.q = 'WideBand'
+        elif header[40] == '\x02' :
+          self.q = 'UltraWideBand'
+        else : self.q = 'Unknown'
+        self.channels = ord(header[48])
+        if header[52:56] == '\xff\xff\xff\xff' :
+          self.b = 0
+        else :
+          self.b = ord(header[52]) + (ord(header[53])*256) + \
+           (ord(header[54])*65536) + (ord(header[55])*16777216)
+        self.framesize = ord(header[56]) + (ord(header[57])*256) + \
+                 (ord(header[58])*65536) + (ord(header[59])*16777216)
+      else :
+        self.name = 'Speex (Unsupported Version)'
+        self.desc = ''
+        self.version = str(ord(header[28]) + (ord(header[29])*256) + \
+                   (ord(header[30])*65536) + (ord(header[31])*16777216))
+
+class FLAC(GenCodec):
+  def __init__(self, header):
+    GenCodec.__init__(self, '')
+    if header[:4] == 'fLaC':
+      self.name = 'FLAC'
+      self.desc = 'Lossless Audio'
+      self.icon = 'flac'
+      self.version = '0'
+      #
+      # Someone needs to teach these guys about Ogg info headers!!!
+      #
+      #self.channels = ord(header[11])
+      #self.samplerate = ord(header[12]) + (ord(header[13])*256) + \
+      #          (ord(header[14])*65536) + (ord(header[15])*16777216)
+
+class Writ(GenCodec):
+  def __init__(self, header):
+    GenCodec.__init__(self, '')
+    if header[:5] == '\x00writ':
+      if header[5] == '\x01' :
+        self.name = 'Writ I'
+        self.desc = 'Timed Text Phrases'
+        self.icon = ''
+        self.version = '1.'+str(ord(header[6]))
+        n = ord(header[7]) + (ord(header[8])*256) + \
+            (ord(header[9])*65536) + (ord(header[10])*16777216)
+        d = ord(header[11]) + (ord(header[12])*256) + \
+            (ord(header[13])*65536) + (ord(header[14])*16777216)
+        self.framerate = float(n)/float(d)
+        print self.version, self.framerate
+      else :
+        self.name = 'Writ (Unsupported Version)'
+        self.desc = ''
+        self.version = str(ord(header[5]))
+
+codecs = (Vorbis, Theora, Speex, FLAC, Writ, GenCodec)
+
+

Added: trunk/xinloe/icons/16x16/nonfree.png
===================================================================
(Binary files differ)


Property changes on: trunk/xinloe/icons/16x16/nonfree.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream

Deleted: trunk/xinloe/images.py
===================================================================
--- trunk/xinloe/images.py	2004-07-29 23:49:57 UTC (rev 7415)
+++ trunk/xinloe/images.py	2004-07-30 04:09:33 UTC (rev 7416)
@@ -1,6 +0,0 @@
-from wxPython.wx import *
-
-def geticon(name, size=1):
-  sizes=('16x16','22x22','32x32','48x48')
-  f = 'icons/%s/%s.png' % (sizes[size], name)
-  return wxImage(f, wxBITMAP_TYPE_PNG).ConvertToBitmap()

Modified: trunk/xinloe/infobox.py
===================================================================
--- trunk/xinloe/infobox.py	2004-07-29 23:49:57 UTC (rev 7415)
+++ trunk/xinloe/infobox.py	2004-07-30 04:09:33 UTC (rev 7416)
@@ -18,28 +18,26 @@

'''

-from wxPython.wx import *
-from wxPython.lib.scrolledpanel import wxScrolledPanel
-import images
+from general import *

class InfoboxPanel(wxWindow, wxScrolledPanel):
def __init__(self, parent):
wxScrolledPanel.__init__(self, parent, -1)
self.SetBackgroundColour('White')
-    vbox = wxBoxSizer(wxVERTICAL)
-    desc = wxStaticText(self, -1, '''Theora I - General Purpose Video Codec
-
-293293942 bytes (1:59.00 @ 205kbps) 25fps 4:2:0 YUV''')
-    print dir(desc.GetFont())
-    print desc.GetFont().GetPointSize()
-
-    hbox = wxBoxSizer(wxHORIZONTAL)
-    bmp = images.geticon('theora',3)
+    infobox = wxBoxSizer(wxVERTICAL)
+    title = gettext(self, ' Theora I - General Purpose Video ', 5)
+    general = gettext(self, '00:01:59 205kbps (293293942 bytes)', 3)
+    topbox = wxBoxSizer(wxHORIZONTAL)
+    bmp = geticon('theora',3)
logo = wxStaticBitmap(self, -1, bmp, wxPoint(16, 16),
wxSize(bmp.GetWidth(), bmp.GetHeight()))
-    hbox.Add(logo, 0, wxALIGN_LEFT, 4)
-    hbox.Add(desc, 0, wxALIGN_RIGHT, 4)
-    self.SetSizer(vbox)
+    topbox.Add(logo, 0, wxALIGN_LEFT, 4)
+    titlebox = wxBoxSizer(wxVERTICAL)
+    titlebox.Add(title, 0, wxALIGN_LEFT, 4)
+    titlebox.Add(general, 0, wxALIGN_CENTER, 4)
+    topbox.AddSizer(titlebox, 0)
+    self.SetSizer(infobox)
self.SetAutoLayout(1)
self.SetupScrolling(scroll_x=False)
-    vbox.AddSizer(hbox, 0)
+    infobox.AddSizer(topbox, 0)
+

Modified: trunk/xinloe/main.py
===================================================================
--- trunk/xinloe/main.py	2004-07-29 23:49:57 UTC (rev 7415)
+++ trunk/xinloe/main.py	2004-07-30 04:09:33 UTC (rev 7416)
@@ -18,18 +18,10 @@

'''

-from wxPython.wx import *
-import wx
-import time
+from general import *
from sandbox import *
from infobox import *
-from images import geticon

-def geticon(name, size=1):
-  sizes=('16x16','22x22','32x32')
-  f = 'icons/%s/%s.png' % (sizes[size], name)
-  return wxImage(f, wxBITMAP_TYPE_PNG).ConvertToBitmap()
-
class MainFrame(wxFrame):
def __init__(self):
wxFrame.__init__(self, None, -1, 'Xinloe', size=(620,400))

Modified: trunk/xinloe/sandbox.py
===================================================================
--- trunk/xinloe/sandbox.py	2004-07-29 23:49:57 UTC (rev 7415)
+++ trunk/xinloe/sandbox.py	2004-07-30 04:09:33 UTC (rev 7416)
@@ -18,12 +18,9 @@

'''

-import os
-import ogg2
-from wxPython.wx import *
+from general import *
+import handlers

-import images
-
class SBTreeCtrl(wxTreeCtrl):
def OnCompareItems(self, item1, item2):
t1 = self.GetItemText(item1)
@@ -45,20 +42,22 @@
| wxTR_TWIST_BUTTONS)
isz = (16,16)
il = wxImageList(isz[0], isz[1])
-    self.lclidx = il.Add(images.geticon('dev-lcl',0))
-    self.p2pidx = il.Add(images.geticon('dev-p2p',0))
-    self.webidx = il.Add(images.geticon('dev-web',0))
+    self.lclidx = il.Add(geticon('dev-lcl',0))
+    self.p2pidx = il.Add(geticon('dev-p2p',0))
+    self.webidx = il.Add(geticon('dev-web',0))
self.fldridx     = il.Add(wxArtProvider_GetBitmap(wxART_FOLDER, wxART_OTHER, isz))
self.fldropenidx = il.Add(wxArtProvider_GetBitmap(wxART_FILE_OPEN, wxART_OTHER, isz))
self.fileidx     = il.Add(wxArtProvider_GetBitmap(wxART_REPORT_VIEW, wxART_OTHER, isz))
-    self.muxpackidx  = il.Add(images.geticon('mux-packed',0))
-    self.muxopenidx  = il.Add(images.geticon('mux-opened',0))
-    self.vorbisidx   = il.Add(images.geticon('vorbis',0))
-    self.theoraidx   = il.Add(images.geticon('theora',0))
-    self.speexidx    = il.Add(images.geticon('speex',0))
-    self.flacidx     = il.Add(images.geticon('flac',0))
-    self.unknownidx  = il.Add(images.geticon('unknown',0))
+    self.muxpackidx  = il.Add(geticon('mux-packed',0))
+    self.muxopenidx  = il.Add(geticon('mux-opened',0))

+    self.codecidx = { 'vorbis'  : il.Add(geticon('vorbis',0)),
+                      'theora'  : il.Add(geticon('theora',0)),
+                      'speex'   : il.Add(geticon('speex',0)),
+                      'flac'    : il.Add(geticon('flac',0)),
+                      'nonfree' : il.Add(geticon('nonfree',0)),
+                      ''        : il.Add(geticon('unknown',0))}
+
self.tree.SetImageList(il)
self.il = il

@@ -144,35 +143,14 @@
byte = bp.read(8)
if type(byte) == int : header = header + chr(byte)
else : break
-          if header[:7] == '\x01vorbis':
-            if header[7:11] == '\x00\x00\x00\x00' :
-              ch = ord(header[11])
-              sa = ord(header[12])+(ord(header[13])*256)
-              sa = sa+(ord(header[14])*65536)+(ord(header[15])*16777216)
-              stream = self.tree.AppendItem(chain,  'Vorbis I (%d channels, %d samples/sec)' % (ch, sa))
-              self.tree.SetPyData(stream, ('vorbis', 0, ch, sa))
-            else :
-              stream = self.tree.AppendItem(chain,  'Vorbis (Unsupported Version)')
-              self.tree.SetPyData(stream, ('vorbis',))
-            self.tree.SetItemImage(stream, self.vorbisidx, which = wxTreeItemIcon_Normal)
-          elif header[:7] == '\x80theora':
-            stream = self.tree.AppendItem(chain,  'Theora')
-            self.tree.SetPyData(stream, None)
-            self.tree.SetItemImage(stream, self.theoraidx, which = wxTreeItemIcon_Normal)
-          elif header[:5] == 'Speex':
-            stream = self.tree.AppendItem(chain,  'Speex')
-            self.tree.SetPyData(stream, None)
-            self.tree.SetItemImage(stream, self.speexidx, which = wxTreeItemIcon_Normal)
-          elif header[:4] == 'fLaC':
-            stream = self.tree.AppendItem(chain,  'FLAC')
-            self.tree.SetPyData(stream, None)
-            self.tree.SetItemImage(stream, self.flacidx, which = wxTreeItemIcon_Normal)
-          elif header[:5] == '\x00writ':
-            stream = self.tree.AppendItem(chain,  'Writ')
-            self.tree.SetPyData(stream, None)
-            self.tree.SetItemImage(stream, self.unknownidx, which = wxTreeItemIcon_Normal)
-          else :
-            stream = self.tree.AppendItem(chain,  'Unknown Codec')
-            self.tree.SetPyData(stream, None)
-            self.tree.SetItemImage(stream, self.unknownidx, which = wxTreeItemIcon_Normal)
+          for c in handlers.codecs :
+            handler = c(header)
+            if handler.name : break
+          stream = self.tree.AppendItem(chain,  handler.name)
+          self.tree.SetPyData(stream, handler)
+          if not self.codecidx.has_key(handler.icon) :
+            print 'Missing icon for %s' % handler.name
+            handler.icon = ''
+          self.tree.SetItemImage(stream, self.codecidx[handler.icon],
+                                 which = wxTreeItemIcon_Normal)
else : break



More information about the commits mailing list