Skip to content

Commit

Permalink
restructure to remove from toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
fossfreedom committed May 21, 2013
1 parent 23a5932 commit b5af47d
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 137 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
*.py[co]

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

img/usericons/popups.xml
Binary file removed Countdown-Clock.png
Binary file not shown.
266 changes: 129 additions & 137 deletions countdown_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import random, string, copy, os

ui_string = \
"""<ui>
<toolbar name="ToolBar">
<placeholder name="CountdownPlaylistPlaceholder" >
<toolitem name="Countdown Playlist" action="CountdownPlaylist" />
</placeholder>
</toolbar>
"""<ui>
<menubar name="MenuBar">
<menu name="ControlMenu" action="Control">
<menuitem name="Countdown Playlist" action="CountdownPlaylist"/>
</menu>
</menubar>
</ui>"""

class CountdownPlaylist (GObject.GObject, Peas.Activatable):
Expand All @@ -37,20 +37,12 @@ def __init__(self):
GObject.Object.__init__(self)

def do_activate(self):
self.shell = self.object
self.sp = self.shell.props.shell_player
icon_file_name = os.path.dirname(__file__) + "/Countdown-Clock.png"
iconsource = Gtk.IconSource()
iconsource.set_filename(icon_file_name)
iconset = Gtk.IconSet()
iconset.add_source(iconsource)
iconfactory = Gtk.IconFactory()
iconfactory.add("mybutton", iconset)
iconfactory.add_default()
self.shell = self.object
self.sp = self.shell.props.shell_player

action = Gtk.Action("CountdownPlaylist", "Countdown",
"Create a playlist for a set period of time",
"mybutton");
"");
action.connect("activate", self.countdown_playlist)
self.action_group = Gtk.ActionGroup('CountdownPlaylistActionGroup')
self.action_group.add_action(action)
Expand All @@ -66,133 +58,133 @@ def deactivate(self):
ui_manager.ensure_update();

def createSuitablePlaylist(self, theList, Duration):
print "createSuitablePlaylist with duration:"
print "createSuitablePlaylist with duration:"

tempList = copy.copy(theList)
manList = []
attempts = 0
while Duration >= 30:
randomSong = int(random.random() * len(tempList))
theSongInfo = tempList[randomSong]
manList.append( theSongInfo )
Duration = Duration - theSongInfo[1]
tempList = copy.copy(theList)
manList = []
attempts = 0
while Duration >= 30:
randomSong = int(random.random() * len(tempList))
theSongInfo = tempList[randomSong]
manList.append( theSongInfo )
Duration = Duration - theSongInfo[1]

if Duration < -30:
## we're going to try to keep the list close to ##
# +- 30 seconds, but we're not failing more #
# than 10 times so as not to waste cycles #
attempts = attempts + 1
if attempts < 10 and len(manList):
manList.pop()
Duration = Duration + theSongInfo[1] ## correct for above
retries = attempts
if attempts > len(manList):
retries = len(manList)
for i in range(0, retries):
tempInfo = manList.pop()
Duration = Duration + tempInfo[1]
tempList.append(tempInfo)
else:
tempList.pop(randomSong)
## Unfortunately RB won't add songs to the ##
# queue more than once, so we have to stop here #
if not len(tempList):
#tempList = copy.copy(theList)
return manList
if Duration < -30:
## we're going to try to keep the list close to ##
# +- 30 seconds, but we're not failing more #
# than 10 times so as not to waste cycles #
attempts = attempts + 1
if attempts < 10 and len(manList):
manList.pop()
Duration = Duration + theSongInfo[1] ## correct for above
retries = attempts
if attempts > len(manList):
retries = len(manList)
for i in range(0, retries):
tempInfo = manList.pop()
Duration = Duration + tempInfo[1]
tempList.append(tempInfo)
else:
tempList.pop(randomSong)
## Unfortunately RB won't add songs to the ##
# queue more than once, so we have to stop here #
if not len(tempList):
#tempList = copy.copy(theList)
return manList

return manList
return manList

def addTracksToQueue(self, theList):
print "addTracksToQueue"
for track in theList:
self.shell.props.queue_source.add_entry(track[0], -1)
print "addTracksToQueue"
for track in theList:
self.shell.props.queue_source.add_entry(track[0], -1)

def ClearQueue(self):
print "ClearQueue"
for row in self.shell.props.queue_source.props.query_model:
entry = row[0]
self.shell.props.queue_source.remove_entry(entry)
print "ClearQueue"
for row in self.shell.props.queue_source.props.query_model:
entry = row[0]
self.shell.props.queue_source.remove_entry(entry)

def CreateGuiGetInfo(self):
print "CreateGuiGetInfo"
keyword = ""
dur = []
dialog = Gtk.Dialog("CountdownPlaylist Specs", None, 0,
(Gtk.STOCK_OK, Gtk.ResponseType.YES,
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
entryKeyword = Gtk.Entry()
labelKeyword = Gtk.Label("Keywords (Separated by commas, blank for anything): ")
entryHour = Gtk.Entry()
labelDuration = Gtk.Label("Duration (hour min sec): ")
entryKeyword.set_editable(1)
entryHour.set_editable(1)
entryHour.set_size_request(50, 25)
entryMinute = Gtk.Entry()
entryMinute.set_editable(1)
entryMinute.set_max_length(6)
entryMinute.set_size_request(50, 25)
entrySecond = Gtk.Entry()
entrySecond.set_editable(1)
entrySecond.set_max_length(9)
entrySecond.set_size_request(50, 25)
dialog.vbox.pack_start(labelKeyword, True, True, 0)
labelKeyword.show()
dialog.vbox.pack_start(entryKeyword, True, True, 0)
entryKeyword.show()
dialog.vbox.pack_start(labelDuration, True, True, 0)
labelDuration.show()
box1 = Gtk.HBox(False, 0)
dialog.vbox.pack_start(box1, True, True, 0)
box1.show()
labelHour = Gtk.Label("h")
labelMinute = Gtk.Label("m")
labelSecond = Gtk.Label("s")
box1.pack_start(entryHour, True, True, 0)
entryHour.show()
box1.pack_start(labelHour, True, True, 0)
labelHour.show()
box1.pack_start(entryMinute, True, True, 0)
entryMinute.show()
box1.pack_start(labelMinute, True, True, 0)
labelMinute.show()
box1.pack_start(entrySecond, True, True, 0)
entrySecond.show()
box1.pack_start(labelSecond, True, True, 0)
labelSecond.show()
response = dialog.run()
keyword = entryKeyword.get_text()
for i in range(0, 3):
dur.append("0")
if entryHour.get_text():
dur[0] = entryHour.get_text()
if entryMinute.get_text():
dur[1] = entryMinute.get_text()
if entrySecond.get_text():
dur[2] = entrySecond.get_text()
dialog.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response is Gtk.ResponseType.CANCEL:
return (0, 0)
else:
return (keyword, dur)
print "CreateGuiGetInfo"
keyword = ""
dur = []
dialog = Gtk.Dialog("CountdownPlaylist Specs", None, 0,
(Gtk.STOCK_OK, Gtk.ResponseType.YES,
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))

entryKeyword = Gtk.Entry()
labelKeyword = Gtk.Label("Keywords (Separated by commas, blank for anything): ")

entryHour = Gtk.Entry()
labelDuration = Gtk.Label("Duration (hour min sec): ")

entryKeyword.set_editable(1)
entryHour.set_editable(1)
entryHour.set_size_request(50, 25)
entryMinute = Gtk.Entry()
entryMinute.set_editable(1)
entryMinute.set_max_length(6)
entryMinute.set_size_request(50, 25)
entrySecond = Gtk.Entry()
entrySecond.set_editable(1)
entrySecond.set_max_length(9)
entrySecond.set_size_request(50, 25)

dialog.vbox.pack_start(labelKeyword, True, True, 0)
labelKeyword.show()
dialog.vbox.pack_start(entryKeyword, True, True, 0)
entryKeyword.show()
dialog.vbox.pack_start(labelDuration, True, True, 0)
labelDuration.show()

box1 = Gtk.HBox(False, 0)
dialog.vbox.pack_start(box1, True, True, 0)
box1.show()

labelHour = Gtk.Label("h")
labelMinute = Gtk.Label("m")
labelSecond = Gtk.Label("s")

box1.pack_start(entryHour, True, True, 0)
entryHour.show()
box1.pack_start(labelHour, True, True, 0)
labelHour.show()
box1.pack_start(entryMinute, True, True, 0)
entryMinute.show()
box1.pack_start(labelMinute, True, True, 0)
labelMinute.show()
box1.pack_start(entrySecond, True, True, 0)
entrySecond.show()
box1.pack_start(labelSecond, True, True, 0)
labelSecond.show()
response = dialog.run()
keyword = entryKeyword.get_text()
for i in range(0, 3):
dur.append("0")
if entryHour.get_text():
dur[0] = entryHour.get_text()
if entryMinute.get_text():
dur[1] = entryMinute.get_text()
if entrySecond.get_text():
dur[2] = entrySecond.get_text()
dialog.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response is Gtk.ResponseType.CANCEL:
return (0, 0)
else:
return (keyword, dur)

def ConvertInputToDur(self, dur):
durSecs = 0
if dur[0].isdigit():
durSecs = durSecs + int(dur[0])*3600
if dur[1].isdigit():
durSecs = durSecs + int(dur[1])*60
if dur[2].isdigit():
durSecs = durSecs + int(dur[2])
return durSecs
durSecs = 0
if dur[0].isdigit():
durSecs = durSecs + int(dur[0])*3600
if dur[1].isdigit():
durSecs = durSecs + int(dur[1])*60
if dur[2].isdigit():
durSecs = durSecs + int(dur[2])
return durSecs

## this is what actually gets called when we click our button ##
def countdown_playlist(self, event):
Expand All @@ -205,8 +197,8 @@ def countdown_playlist(self, event):
# on another note, if the request is blank, we #
# will just create a playlist using every song #

ReqKeywords = None
CountdownList = []
ReqKeywords = None
CountdownList = []

if ReqKeyword: # use booleanness of string
ReqKeywords = ReqKeyword.split(',')
Expand All @@ -226,15 +218,15 @@ def countdown_playlist(self, event):
string.find(title, keyword) is not -1 or string.find(album, keyword) is not -1 or \
string.find(album_artist, keyword) is not -1 or string.find(comment, keyword) is not -1 \
or string.find(string.lower(str(year)), keyword) is not -1:
songLocation = entry
songLocation = entry
songDuration = entry.get_ulong(RB.RhythmDBPropType.DURATION)
CountdownList.append([songLocation, songDuration])

# add all songs if query failure
if not ReqKeywords or not CountdownList:
for row in self.shell.props.library_source.props.base_query_model:
entry = row[0]
songLocation = entry
songLocation = entry
songDuration = entry.get_ulong(RB.RhythmDBPropType.DURATION)
CountdownList.append([songLocation, songDuration])

Expand Down

0 comments on commit b5af47d

Please sign in to comment.