~ackondro/aniworld/0.2

« back to all changes in this revision

Viewing changes to bin/aniworld

  • Committer: Andrew Sellers
  • Date: 2009-12-26 23:19:22 UTC
  • Revision ID: ackondro@gmail.com-20091226231922-l22e0pf0f95tefxn
documentation done, time to release 0.2.beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
288
288
    Actions: scans for the correct record then adds it to the treemodel
289
289
    '''
290
290
    def add_row(self,aid):
 
291
        #retrieve series data from the database
291
292
        results=self.database.get_records(record_type=series_rec,create_view=True)
292
293
        for x in results:
 
294
            #if we found our anime, add it to the treestore
293
295
            if x.value['AID']==aid:
294
 
                break
295
 
        self.episode_view.get_model().append(None,[x.value['Title'],'0 Episodes','',x.value['AID']])
 
296
                self.episode_view.get_model().append(None,[x.value['Title'],'0 Episodes','',x.value['AID']])
 
297
 
296
298
        
297
299
    
298
300
    '''
300
302
    Actions: scans for a row, then deletes it
301
303
    '''
302
304
    def remove_row(self,aid):
 
305
        # get the nescessry information, then start looking through the treestore for the correct row
303
306
        model=self.episode_view.get_model()
304
307
        anime_iter=model.get_iter_root()
305
308
        while anime_iter != None:
 
309
            #if we find our record, delete it
306
310
            if model.get_value(anime_iter,3)==aid:
307
311
                model.remove(anime_iter)
308
312
                return False
309
313
            anime_iter=model.iter_next(anime_iter)
 
314
        #if we can't find a good entry in the treestore, just forget it
310
315
        return False
311
316
        
312
317
    '''
314
319
    Actions: resets the record_type to force a refresh of the queue CouchGrid
315
320
    '''
316
321
    def refresh_queue(self):
 
322
        #set the record_type
317
323
        self.queue_grid.record_type=queue_rec
318
324
        return False
319
325
 
377
383
    Actions: Spawns a message box that has an error with the passed text
378
384
    '''
379
385
    def error_box(self,text=None):
380
 
        silly=gtk.MessageDialog(self,0,gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE,text)
381
 
        silly.run()
382
 
        silly.destroy()
 
386
        boxer=gtk.MessageDialog(self,0,gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE,text)
 
387
        boxer.run()
 
388
        boxer.destroy()
383
389
        return False
384
390
#end UI functions
385
391
 
393
399
    Actions: Spawns dialog for user to enjoy
394
400
    '''
395
401
    def about(self, widget, data=None):
396
 
        """about - display the about box for aniworld """
 
402
        #spawn and run a AboutDialog
397
403
        about = AboutAniworldDialog.NewAboutAniworldDialog()
398
404
        response = about.run()
399
405
        about.destroy()
457
463
 
458
464
    '''
459
465
    view_episode: Spawns a player for the current file, linked to double clicking in the episode grid, sets the watched status
460
 
    Actions: TODO
 
466
    Actions: finds the selected entry, then spawns a player window for it, then marks it as watched
461
467
    '''
462
468
    def view_episode(self,widget,*params):
 
469
        #get the selected row
463
470
        selector=self.episode_grid.get_selection()
464
471
        (model,rows)=selector.get_selected_rows()
465
472
        if rows==[]:
466
473
            return
467
474
        iterr=model.get_iter(rows[0])
 
475
        #get the record key, and look up the record using it
468
476
        record_key=model.get_value(iterr,3)
469
477
        record=self.database.get_record(record_key)
470
478
        self.net_scan.set_viewed(record_key)
 
479
        #get the file uri and mark the episode as watched
471
480
        file_uri=record['uri']
472
481
        self.database.update_fields(record_key,{'watched':'Watched'})
473
482
        model.set(iterr,2,'Watched')
474
483
        if model.iter_parent(iterr):
475
484
            if os.path.isfile(file_uri):
 
485
                #close out the old player
476
486
                if self.player == None:
477
487
                    pass
478
488
                elif self.player.returncode == None:
479
489
                    self.player.terminate()
 
490
                #load the player from the preferences and play the file
480
491
                player=self.preferences['player']
481
492
                self.player=subprocess.Popen([player,file_uri])
 
493
        #this needs to be fixed
 
494
        #it depends on what is calling this, it will call view_series if the row is an anime and not an episode
 
495
        #it means that the user double clicked on the episode view, and when the series CouchGrid got merged in,
 
496
        #this method ended up doing three diffferent things. It will be fixed by 0.2.0
482
497
        elif params !=():
483
498
            self.view_series(widget)
484
499
 
585
600
    Actions: calls a function in the net_scan thread
586
601
    '''
587
602
    def pause_queue(self,widget,data=None):
 
603
        #tell the scanner thread to stop, which will cascade
588
604
        self.net_scan.pause()
589
605
 
590
606
 
593
609
    Actions: spawns a gtk.FileChooseDialog, then gets back what is nescessary to add to the queue using the __add_file function
594
610
    '''
595
611
    def new_file(self,widget,data=None):
 
612
        #make a file add dialog
596
613
        dialogger=gtk.FileChooserDialog("Please Select File",None,gtk.FILE_CHOOSER_ACTION_OPEN,(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,gtk.STOCK_OK,gtk.RESPONSE_ACCEPT),None)
597
614
        result=dialogger.run()
 
615
        #get the selected file
598
616
        get_file=dialogger.get_filename()
599
617
        dialogger.destroy()
600
618
        if (result != gtk.RESPONSE_ACCEPT):
601
619
            return
 
620
        #send the selected file to the __add_file funcion
602
621
        self.__add_file(get_file,get_file.rsplit('/',1)[1])
 
622
        #refresh_queue to reflect the new file
603
623
        self.refresh_queue()
604
624
        return
605
625
 
610
630
    Actions: spawns a choose folder dialog, processes the files using the os.walk function, then refreshes the queue grid
611
631
    '''
612
632
    def new_folder(self,widget,data=None):
 
633
        #make a select folder dialog, run it then get the filename
613
634
        dialogger=gtk.FileChooserDialog("Please Select Folder",None,gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,gtk.STOCK_OK,gtk.RESPONSE_ACCEPT),None)
614
635
        result=dialogger.run()
615
636
        get_folder=dialogger.get_filename()
616
637
        dialogger.destroy()
617
638
        if (result != gtk.RESPONSE_ACCEPT):
618
639
            return
 
640
        #iterate over the possible files, feed each one to __add_file
619
641
        iterator = os.walk(get_folder)
620
642
        for x,y,z in iterator:
621
643
            for a in z:
622
644
                self.__add_file(x+'/'+a,a)
 
645
        #refresh the queue CouchGrid
623
646
        self.refresh_queue()
624
647
        return
625
648
 
630
653
    Actions: add the passed file to the database, with the nescessary queue info
631
654
    '''
632
655
    def __add_file(self,file_path,file_name):
 
656
        #check to see if the file extension is in the file type dictionary
633
657
        if(file_types.has_key(file_name.rsplit('.',1).pop(1))):
634
658
 
635
659
            y=time.localtime()
636
 
            #this next bit looks ugly, but most of it is making a nice timestamp
637
 
            self.database.put_record(Record({'record_type':queue_rec,'Status':'Waiting', 'Filename':file_name, 'File Path':file_path, 'Time Added':str(y.tm_mday)+'-'+str(y.tm_mon)+'-'+str(y.tm_year)+' '+str(y.tm_hour)+':'+str(y.tm_min)+':'+str(y.tm_sec), 'File Size':str(os.stat(file_path).st_size), 'Location':os.uname()[1]}))
 
660
            #I made a custom timestamp, and this code formats it right
 
661
            time_stamp=str(y.tm_mday)+'-'+str(y.tm_mon)+'-'+str(y.tm_year)+' '+str(y.tm_hour)+':'+str(y.tm_min)+':'+str(y.tm_sec)
 
662
            #put a record in that is ready to be picked up by the scanner
 
663
            self.database.put_record(Record({'record_type':queue_rec,'Status':'Waiting', 'Filename':file_name, 'File Path':file_path, 'Time Added':time_stamp, 'File Size':str(os.stat(file_path).st_size), 'Location':os.uname()[1]}))
638
664
 
639
665
 
640
666
 
643
669
    Actions: gets the selected file, removes it from the database, then resets the queue grid
644
670
    '''
645
671
    def remove_file(self,widget,data=None):
 
672
        #get the selected records 
646
673
        ids = self.queue_grid.selected_record_ids
 
674
        #for all selected ids, delete them
647
675
        for x in range(0,len(ids)):
648
676
            self.database.delete_record(ids[x])
649
677
        self.queue_grid.record_type=queue_rec
651
679
#end queue functions
652
680
 
653
681
 
654
 
 
655
 
 
656
 
 
657
 
 
658
 
 
659
 
 
660
 
 
661
 
 
662
 
 
663
 
 
664
 
 
665
 
 
666
 
 
667
 
 
668
 
 
669
 
 
670
 
 
671
 
 
672
682
def NewAniworldWindow():
673
683
    """NewAniworldWindow - returns a fully instantiated
674
684
    AniworldWindow object. Use this function rather than