Skip to content

Commit

Permalink
some refactoring and restructuring of GUI related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Oct 8, 2012
1 parent 10620f9 commit 3e9ad9c
Show file tree
Hide file tree
Showing 7 changed files with 670 additions and 544 deletions.
34 changes: 8 additions & 26 deletions State.py
Expand Up @@ -3,26 +3,6 @@
from utils import *
from Song import Song

def loadQueue(state):
print "load queue"

def songs():
if state.curSong:
# We just started the player and we have a current song from persistent storage.
# Yield it now so that we begin playing with this song.
# Yield the Song object itself, though, not the ObjectProxy. The ObjectProxy
# would result in very strange behavior later for onSongChange events.
song = state.curSong.__get__(None)
song.openFile()
yield song
import queue
while True:
song = queue.getNextSong()
song.openFile()
yield song

return songs()

from collections import deque

class RecentlyplayedList:
Expand Down Expand Up @@ -81,34 +61,36 @@ def playPause(self):
def nextSong(self):
self.player.nextSong()

@UserAttrib(type=Traits.OneLineText, updateHandler=lambda *args:None, alignRight=True, variableWidth=True)
@UserAttrib(type=Traits.OneLineText, alignRight=True, variableWidth=True)
@property
def curSongStr(self):
if not self.player.curSong: return ""
try: return self.player.curSong.userString
except: return "???"

@UserAttrib(type=Traits.OneLineText, updateHandler=lambda *args:None, alignRight=True)
@UserAttrib(type=Traits.OneLineText, alignRight=True)
@property
def curSongPos(self):
if not self.player.curSong: return ""
try: return formatTime(self.player.curSongPos) + " / " + formatTime(self.player.curSong.duration)
except: return "???"

@UserAttrib(type=Traits.SongDisplay, updateHandler=lambda *args:None)
@UserAttrib(type=Traits.SongDisplay)
def curSongDisplay(self): pass

@UserAttrib(type=Traits.List)
@initBy
def recentlyPlayedList(self): return PersistentObject(RecentlyplayedList, "recentlyplayed.dat")

@UserAttrib(type=Traits.Object, updateHandler=lambda *args:None)
@UserAttrib(type=Traits.Object, spaceY=0)
@initBy
def curSong(self): return PersistentObject(Song, "cursong.dat")

@UserAttrib(type=Traits.List)
@UserAttrib(type=Traits.List, spaceY=0)
@initBy
def queue(self): return loadQueue(self)
def queue(self):
import queue
return queue.queue

@initBy
def updates(self): return OnRequestQueue()
Expand Down
16 changes: 15 additions & 1 deletion Traits.py
@@ -1,10 +1,24 @@

from contextlib import contextmanager

class TraitType: pass

# These types just say what a property/UserAttrib/object should behave like, i.e. what protocol it should support.
# This is not really defined yet/strictly. It is used for now by the GUI.

class List(TraitType): pass
class List(TraitType):
def onInsert(self, index): pass
def onRemove(self, index): pass

@property
@contextmanager
def lock(self): yield

def insert(self, index, value): pass
def remove(self, index): pass
def __getitem__(self, index): pass
def __len__(self): pass

class OneLineText(TraitType): pass
class Enum(TraitType):
def __init__(self, enums):
Expand Down

0 comments on commit 3e9ad9c

Please sign in to comment.