Example #1
0
 def load_new_amz_files(self, amz_files):
     parser = AmzParser()
     for f in amz_files:
         parser.parse(f)
     objects = parser.get_parsed_objects()
     self.tree_model = TreeModel(objects)
     self.treeView.set_model(self.tree_model)
     self.treeView.expand_all()
Example #2
0
 def load_new_amz_files(self, amz_files):
     parser = AmzParser()
     for f in amz_files:
         parser.parse(f)
     objects = parser.get_parsed_objects()        
     self.tree_model = TreeModel(objects)        
     self.treeView.set_model(self.tree_model)
     self.treeView.expand_all()
Example #3
0
class MainWindow(gobject.GObject):
    def __init__(self, amzs):
        glade_fpath = os.path.join(os.path.split(__file__)[0], '_ui.glade')
        builder = gtk.Builder()
        builder.add_from_file(glade_fpath)

        self.mainWindow = builder.get_object('MainWindow')
        self.mainWindow.show()

        self.albumArtImage = builder.get_object('albumArtImage')
        self.nowDownloadingLabel = builder.get_object('nowDownloadingLabel')
        self.pythonPixbuf = gtk.gdk.pixbuf_new_from_file(python_icon_path)
        self.pymazon_text = '<span weight="bold" size="xx-large">Pymazon! w00t!</span>'
        self.reset_displaybar_info()

        self.settings_dialog = SettingsDialog(builder)

        self.treeView = builder.get_object('treeView')
        self.tree_model = None

        self.pbarRenderer = ProgressRenderer()
        self.colStatus = builder.get_object('colStatus')
        self.colStatus.clear()
        self.colStatus.pack_start(self.pbarRenderer, True)
        self.colStatus.add_attribute(self.pbarRenderer, 'value', 1)
        self.colStatus.add_attribute(self.pbarRenderer, 'text', 2)

        self.connect_signals(builder)

        self.downloader = None
        self.current_album = None
        self.old_albums = []
        if amzs:
            self.load_new_amz_files(amzs)

    def connect_signals(self, builder):
        builder.connect_signals({'on_MainWindow_destroy': self.on_destroy})
        self.actionAbout = builder.get_object('actionAbout')
        self.actionAbout.connect('activate', self.on_actionAbout_activate)
        self.actionLoadFiles = builder.get_object('actionLoadFiles')
        self.actionLoadFiles.connect('activate',
                                     self.on_actionLoadFiles_activate)
        self.actionSettings = builder.get_object('actionSettings')
        self.actionSettings.connect('activate',
                                    self.on_actionSettings_activate)
        self.actionShowDownloads = builder.get_object('actionShowDownloads')
        self.actionShowDownloads.connect('activate',
                                         self.on_actionShowDownloads_activate)
        self.actionDownload = builder.get_object('actionDownload')
        self.actionDownload.connect('activate',
                                    self.on_actionDownload_activate)
        self.actionQuit = builder.get_object('actionQuit')
        self.actionQuit.connect('activate', self.on_destroy)

    def on_actionAbout_activate(self, *args):
        webbrowser.open('http://code.google.com/p/pymazon')

    def on_actionLoadFiles_activate(self, *args):
        self.new_amz()

    def on_actionSettings_activate(self, *args):
        self.settings_dialog.launch()

    def on_actionShowDownloads_activate(self, *args):
        webbrowser.open(settings.save_dir)

    def on_actionDownload_activate(self, *args):
        self.download_tracks()

    def on_destroy(self, *arg):
        if self.downloader:
            self.downloader.kill()
        gtk.main_quit()

    def new_amz(self):
        caption = 'Choose AMZ File'
        filefilter = gtk.FileFilter()
        filefilter.add_pattern('*.amz')
        dialog = gtk.FileChooserDialog(
            caption,
            self.mainWindow,
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK,
                     gtk.RESPONSE_ACCEPT))
        dialog.set_select_multiple(True)
        dialog.set_filter(filefilter)
        res = dialog.run()
        files = dialog.get_filenames()
        dialog.destroy()
        if res == gtk.RESPONSE_REJECT:
            return
        if files:
            self.load_new_amz_files(files)

    def load_new_amz_files(self, amz_files):
        parser = AmzParser()
        for f in amz_files:
            parser.parse(f)

        objects = parser.get_parsed_objects()
        self.tree_model = TreeModel(objects)
        self.treeView.set_model(self.tree_model)
        self.treeView.expand_all()

    def download_tracks(self):
        self.num_threads = 1
        if not self.tree_model:
            return
        save_dir = settings.save_dir
        if not os.access(save_dir, os.W_OK):
            print 'here'
            msg = 'No write access to save directory. '
            msg += 'Choose a new directory with write privileges.'
            dialog = gtk.MessageDialog(self.mainWindow, buttons=gtk.BUTTONS_OK)
            dialog.set_markup(msg)
            dialog.run()
            dialog.destroy()
            return
        self.downloader = Downloader(self.tree_model, self.update_cb,
                                     self.finished_cb)
        self.actionDownload.set_sensitive(False)
        self.actionSettings.set_sensitive(False)
        self.actionLoadFiles.set_sensitive(False)
        self.downloader.start()

    def update_cb(self, node):
        if isinstance(node.elem.obj, Album):
            if not node.elem.obj is self.current_album:
                if node.elem.obj not in self.old_albums:
                    self.old_albums.append(node.elem.obj)
                    self.current_album = node.elem.obj
                    self.update_album_info()
                else:
                    pass
        self.tree_model.update_node(node)

    def finished_cb(self):
        self.downloader = None
        self.reset_displaybar_info()
        self.actionDownload.set_sensitive(True)
        self.actionSettings.set_sensitive(True)
        self.actionLoadFiles.set_sensitive(True)

    def reset_displaybar_info(self):
        self.current_album = None
        self.old_albums = []
        self.albumArtImage.set_from_pixbuf(self.pythonPixbuf)
        self.nowDownloadingLabel.set_markup(self.pymazon_text)

    def update_album_info(self):
        self.update_album_art()
        self.update_downloading_text()

    def update_album_art(self):
        img = self.current_album.image
        if img != "":
            loader = gtk.gdk.PixbufLoader()
            loader.write(img)
            loader.close()
            pb = loader.get_pixbuf()
            self.albumArtImage.set_from_pixbuf(pb)
        self.update_downloading_text()

    def update_downloading_text(self):
        name = self.current_album.artist
        title = self.current_album.title
        txt = 'Now dowloading <b>%s</b> by <b>%s</b>' % (title, name)
        self.nowDownloadingLabel.set_markup(txt)
Example #4
0
class MainWindow(gobject.GObject):    
    def __init__(self, amzs):
        glade_fpath = os.path.join(os.path.split(__file__)[0], '_ui.glade')
        builder = gtk.Builder()
        builder.add_from_file(glade_fpath)            
        
        self.mainWindow = builder.get_object('MainWindow')
        self.mainWindow.show()
          
        self.albumArtImage = builder.get_object('albumArtImage')
        self.nowDownloadingLabel = builder.get_object('nowDownloadingLabel')
        self.pythonPixbuf = gtk.gdk.pixbuf_new_from_file(python_icon_path)
        self.pymazon_text = '<span weight="bold" size="xx-large">Pymazon! w00t!</span>'
        self.reset_displaybar_info()        
        
        self.settings_dialog = SettingsDialog(builder)             

        self.treeView = builder.get_object('treeView')
        self.tree_model = None 
        
        self.pbarRenderer = ProgressRenderer()       
        self.colStatus = builder.get_object('colStatus')
        self.colStatus.clear()
        self.colStatus.pack_start(self.pbarRenderer, True)
        self.colStatus.add_attribute(self.pbarRenderer, 'value', 1)
        self.colStatus.add_attribute(self.pbarRenderer, 'text', 2)
        
        self.connect_signals(builder)
        
        self.downloader = None
        self.current_album = None
        self.old_albums = []
        if amzs:
            self.load_new_amz_files(amzs)
        
    def connect_signals(self, builder):
        builder.connect_signals({'on_MainWindow_destroy': self.on_destroy})
        self.actionAbout = builder.get_object('actionAbout')
        self.actionAbout.connect('activate', self.on_actionAbout_activate)
        self.actionLoadFiles = builder.get_object('actionLoadFiles')
        self.actionLoadFiles.connect('activate', self.on_actionLoadFiles_activate)
        self.actionSettings = builder.get_object('actionSettings')
        self.actionSettings.connect('activate', self.on_actionSettings_activate)
        self.actionShowDownloads = builder.get_object('actionShowDownloads')
        self.actionShowDownloads.connect('activate', self.on_actionShowDownloads_activate)
        self.actionDownload = builder.get_object('actionDownload')
        self.actionDownload.connect('activate', self.on_actionDownload_activate)      
        self.actionQuit = builder.get_object('actionQuit')
        self.actionQuit.connect('activate', self.on_destroy)        
        
    def on_actionAbout_activate(self, *args):
        webbrowser.open('http://code.google.com/p/pymazon')

    def on_actionLoadFiles_activate(self, *args):
        self.new_amz()

    def on_actionSettings_activate(self, *args):
        self.settings_dialog.launch()

    def on_actionShowDownloads_activate(self, *args):
        webbrowser.open(settings.save_dir)

    def on_actionDownload_activate(self, *args):
        self.download_tracks()

    def on_destroy(self, *arg):
        if self.downloader:
            self.downloader.kill()
        gtk.main_quit()    

    def new_amz(self):
        caption = 'Choose AMZ File'
        filefilter = gtk.FileFilter()        
        filefilter.add_pattern('*.amz')        
        dialog = gtk.FileChooserDialog(caption, self.mainWindow,                                       
                                       buttons=(gtk.STOCK_CANCEL,
                                                gtk.RESPONSE_REJECT,
                                                gtk.STOCK_OK,
                                                gtk.RESPONSE_ACCEPT))
        dialog.set_select_multiple(True)
        dialog.set_filter(filefilter)
        res = dialog.run()
        files = dialog.get_filenames()
        dialog.destroy()
        if res == gtk.RESPONSE_REJECT:
            return
        if files:
            self.load_new_amz_files(files)

    def load_new_amz_files(self, amz_files):
        parser = AmzParser()
        for f in amz_files:
            parser.parse(f)
        objects = parser.get_parsed_objects()        
        self.tree_model = TreeModel(objects)        
        self.treeView.set_model(self.tree_model)
        self.treeView.expand_all()

    def download_tracks(self):
        self.num_threads = 1        
        if not self.tree_model:
            return
        save_dir = settings.save_dir               
        if not os.access(save_dir, os.W_OK):
            print 'here'
            msg = 'No write access to save directory. '
            msg += 'Choose a new directory with write privileges.'
            dialog = gtk.MessageDialog(self.mainWindow, 
                                       buttons=gtk.BUTTONS_OK)
            dialog.set_markup(msg)
            dialog.run()
            dialog.destroy()
            return        
        self.downloader = Downloader(self.tree_model, self.update_cb, 
                                     self.finished_cb)
        self.actionDownload.set_sensitive(False)
        self.actionSettings.set_sensitive(False)
        self.actionLoadFiles.set_sensitive(False)        
        self.downloader.start()            

    def update_cb(self, node):
        if isinstance(node.elem.obj, Album):
            if not node.elem.obj is self.current_album:
                if node.elem.obj not in self.old_albums:
                    self.old_albums.append(node.elem.obj)
                    self.current_album = node.elem.obj
                    self.update_album_info()
                else:
                    pass     
        self.tree_model.update_node(node)
    
    def finished_cb(self):
        self.downloader = None
        self.reset_displaybar_info()
        self.actionDownload.set_sensitive(True)
        self.actionSettings.set_sensitive(True)
        self.actionLoadFiles.set_sensitive(True)
        
    def reset_displaybar_info(self):
        self.current_album = None
        self.old_albums = []        
        self.albumArtImage.set_from_pixbuf(self.pythonPixbuf)
        self.nowDownloadingLabel.set_markup(self.pymazon_text)
        
    def update_album_info(self):
        self.update_album_art()
        self.update_downloading_text()
        
    def update_album_art(self):
        img = self.current_album.image
        loader = gtk.gdk.PixbufLoader()
        loader.write(img)
        loader.close()
        pb = loader.get_pixbuf()
        self.albumArtImage.set_from_pixbuf(pb)
        self.update_downloading_text()
        
    def update_downloading_text(self):
        name = self.current_album.artist
        title = self.current_album.title
        txt = 'Now dowloading <b>%s</b> by <b>%s</b>' % (title, name)
        self.nowDownloadingLabel.set_markup(txt)