refactored applescript handeling, added horizontal resizing

This commit is contained in:
Pezz89
2015-04-06 17:20:56 +02:00
parent d7f02918c0
commit 83fc4917df
7 changed files with 74 additions and 65 deletions
+17
View File
@@ -0,0 +1,17 @@
on run(directory)
tell application "iTunes" to tell artwork 1 of current track
set d to raw data
if format is "class PNG" then
set x to "png"
else
set x to "jpg"
end if
end tell
(((directory) as text) & "cover." & x)
set b to open for access file result with write permission
set eof b to 0
write d to b
close access b
return (((directory) as text) & "cover." & x)
end run
+15
View File
@@ -0,0 +1,15 @@
on run()
tell application "iTunes"
set current_track to the current track
set track_album to the album of the current track
set track_artist to the artist of the current track
set track_comments to the comment of the current track
set track_name to the name of the current track
set track_rating to the rating of the current track
set track_duration to the duration of the current track
set track_finish to the finish of the current track
set track_start to the start of the current track
set track_position to the player position
end tell
return {album:track_album, artist:track_artist, track_name:track_name, rating:track_rating, duration:track_duration, finish:track_finish, start:track_start, position:track_position}
end run
+3
View File
@@ -0,0 +1,3 @@
on run(appName)
tell application "System Events" to (name of processes) contains appName
end run
@@ -0,0 +1,5 @@
on run(track_rating)
tell application "iTunes"
set rating of current track to track_rating
end tell
end run
+15 -11
View File
@@ -82,7 +82,8 @@ class MainWindow(wx.Frame):
super(MainWindow, self).__init__( super(MainWindow, self).__init__(
parent, parent,
title=title, title=title,
style= wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.STAY_ON_TOP style= wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.STAY_ON_TOP |
wx.RESIZE_BORDER
) )
#-------------------------------------------------------------- #--------------------------------------------------------------
#Create a file manu #Create a file manu
@@ -91,6 +92,7 @@ class MainWindow(wx.Frame):
#Create a panel #Create a panel
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.flashing_panel = False self.flashing_panel = False
self.flashbool = False
#Define menu items #Define menu items
menu_about = filemenu.Append( menu_about = filemenu.Append(
wx.ID_ABOUT, wx.ID_ABOUT,
@@ -151,8 +153,8 @@ class MainWindow(wx.Frame):
self.rating_text self.rating_text
): ):
self.text_sizer.Add(i, 1, wx.EXPAND) self.text_sizer.Add(i, 1, wx.EXPAND)
self.info_sizer.Add(self.text_sizer, 8, wx.EXPAND) self.info_sizer.Add(self.text_sizer, wx.ALIGN_LEFT)
self.info_sizer.Add(self.button_sizer, 5, wx.EXPAND) self.info_sizer.Add(self.button_sizer, wx.ALIGN_LEFT)
#-------------------------------------------------------------- #--------------------------------------------------------------
#Specify the maximum size of the album artwork #Specify the maximum size of the album artwork
@@ -162,18 +164,19 @@ class MainWindow(wx.Frame):
self.icon = wx.StaticBitmap(self, bitmap=wx.BitmapFromImage(img)) self.icon = wx.StaticBitmap(self, bitmap=wx.BitmapFromImage(img))
#Add the artwork and the information sizer to the main sizer #Add the artwork and the information sizer to the main sizer
self.main_sizer.Add(self.icon, 1, wx.EXPAND) self.main_sizer.Add(self.icon, wx.ALIGN_LEFT)
self.main_sizer.Add(self.info_sizer, 2, wx.EXPAND) self.main_sizer.Add(self.info_sizer, wx.ALIGN_LEFT)
#Select the sizer to use for the main window #Select the sizer to use for the main window
self.SetAutoLayout(1) self.SetAutoLayout(1)
#Fit sizer 1 to window #Fit sizer 1 to window
self.panel.SetSizerAndFit(self.main_sizer) self.panel.SetSizerAndFit(self.main_sizer)
sizer = wx.BoxSizer(wx.HORIZONTAL) sizer = wx.BoxSizer(wx.HORIZONTAL | wx.ALIGN_LEFT)
sizer.Add(self.panel) sizer.Add(self.panel, wx.EXPAND)
self.SetSizerAndFit(sizer) self.SetSizerAndFit(sizer)
self.SetMinSize(self.GetBestSize())
self.SetMaxSize((-1, self.GetBestSize()[1]))
#initialize comunication thread #initialize comunication thread
iTunes_com_thread() iTunes_com_thread()
@@ -226,14 +229,15 @@ class MainWindow(wx.Frame):
img = img.Scale(120,120) img = img.Scale(120,120)
self.icon = wx.StaticBitmap(self, bitmap=wx.BitmapFromImage(img)) self.icon = wx.StaticBitmap(self, bitmap=wx.BitmapFromImage(img))
if t["duration"] - t["position"] <= 30: if t["duration"] - t["position"] <= 30:
if self.panel.GetBackgroundColour() == "Yellow": if self.flashbool:
self.panel.SetBackgroundColour(wx.NullColour) self.panel.SetBackgroundColour(wx.NullColour)
self.panel.Refresh() self.panel.Refresh()
self.flashbool = False
else: else:
self.panel.SetBackgroundColour("Yellow") self.panel.SetBackgroundColour("Yellow")
self.panel.Refresh() self.panel.Refresh()
self.flashbool = True
else: else:
if self.panel.GetBackgroundColour() == "Yellow":
self.panel.SetBackgroundColour(wx.NullColour) self.panel.SetBackgroundColour(wx.NullColour)
self.panel.Refresh() self.panel.Refresh()
+19 -11
View File
@@ -4,14 +4,24 @@ import applescript
import os import os
class iTunesBridge: class iTunesBridge:
def __init__(self, script_file="./itunes_scripts.scpt"): def __init__(self):
with open("./itunes_scripts.scpt") as script_file: with open("./applescripts/is_running.scpt", 'r') as is_running_file,\
script_data = ''.join([line for line in script_file]) open("./applescripts/get_track_info.scpt", 'r') as track_info_file,\
self.as_bridge = applescript.AppleScript(script_data) open("./applescripts/set_current_track_rating.scpt", 'r') as\
set_rating_file, open("./applescripts/get_album_artwork.scpt") as\
album_artwork_file:
is_running_data = ''.join([line for line in is_running_file])
track_info_data = ''.join([line for line in track_info_file])
set_rating_data = ''.join([line for line in set_rating_file])
album_artwork_data = ''.join([line for line in album_artwork_file])
self.is_running_bridge = applescript.AppleScript(is_running_data)
self.track_info_bridge = applescript.AppleScript(track_info_data)
self.set_rating_bridge = applescript.AppleScript(set_rating_data)
self.album_artwork_bridge = applescript.AppleScript(album_artwork_data)
self.current_track = None self.current_track = None
def is_running(self): def is_running(self):
return self.as_bridge.call("is_running", "iTunes") return self.is_running_bridge.run("iTunes")
def set_current_track_rating(self, rating): def set_current_track_rating(self, rating):
""" """
@@ -19,7 +29,7 @@ class iTunesBridge:
Return True if succesful else False Return True if succesful else False
""" """
try: try:
self.as_bridge.call("set_current_track_rating", rating) self.set_rating_bridge.run(rating)
return True return True
except applescript.ScriptError: except applescript.ScriptError:
return False return False
@@ -27,7 +37,7 @@ class iTunesBridge:
def get_artwork(self, directory): def get_artwork(self, directory):
directory = os.path.realpath(directory).replace('/', ':')[1:] directory = os.path.realpath(directory).replace('/', ':')[1:]
try: try:
artwork = self.as_bridge.call("get_album_artwork", directory+':') artwork = self.album_artwork_bridge.run(directory+':')
except applescript.ScriptError: except applescript.ScriptError:
return None return None
artwork = '/'+artwork.replace(':', '/') artwork = '/'+artwork.replace(':', '/')
@@ -35,15 +45,13 @@ class iTunesBridge:
def get_current_track_info(self): def get_current_track_info(self):
try: try:
track_info = self.as_bridge.call("get_current_track_info") track_info = self.track_info_bridge.run()
except applescript.ScriptError: except applescript.ScriptError:
return None return None
return track_info return track_info
def main(): def main():
iTunes = iTunesBridge() print "Nothing in main"
print iTunes.is_running()
iTunes.get_current_track_info()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
-43
View File
@@ -1,43 +0,0 @@
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
on get_current_track_info()
tell application "iTunes"
set current_track to the current track
set track_album to the album of the current track
set track_artist to the artist of the current track
set track_comments to the comment of the current track
set track_name to the name of the current track
set track_rating to the rating of the current track
set track_duration to the duration of the current track
set track_finish to the finish of the current track
set track_start to the start of the current track
set track_position to the player position
end tell
return {album:track_album, artist:track_artist, track_name:track_name, rating:track_rating, duration:track_duration, finish:track_finish, start:track_start, position:track_position}
end get_current_track_info
on set_current_track_rating(track_rating)
tell application "iTunes"
set rating of current track to track_rating
end tell
end set_current_track_rating
on get_album_artwork(directory)
tell application "iTunes" to tell artwork 1 of current track
set d to raw data
if format is "class PNG" then
set x to "png"
else
set x to "jpg"
end if
end tell
(((directory) as text) & "cover." & x)
set b to open for access file result with write permission
set eof b to 0
write d to b
close access b
return (((directory) as text) & "cover." & x)
end get_album_artwork