~ubuntu-branches/ubuntu/quantal/griffith/quantal

« back to all changes in this revision

Viewing changes to lib/initialize.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2011-12-18 21:15:25 UTC
  • mfrom: (1.1.17) (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111218211525-endbgt82m3jh9gde
Tags: 0.13-1
* New upstream release
* VCS-* fields removed (berlios will be shutdown)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: UTF-8 -*-
2
2
 
3
 
__revision__ = '$Id: initialize.py 1474 2010-10-18 20:29:45Z mikej06 $'
 
3
__revision__ = '$Id: initialize.py 1600 2011-12-02 20:30:27Z mikej06 $'
4
4
 
5
 
# Copyright © 2005-2009 Vasco Nunes, Piotr Ożarowski
 
5
# Copyright © 2005-2011 Vasco Nunes, Piotr Ożarowski
6
6
#
7
7
# This program is free software; you can redistribute it and/or modify
8
8
# it under the terms of the GNU General Public License as published by
25
25
import logging
26
26
import math
27
27
import os
28
 
import platform
29
28
import re
30
29
import sys
31
30
from glob import glob
125
124
def gui(self):
126
125
    self._ = None
127
126
 
128
 
    if platform.system() == 'Darwin':
 
127
    if os.name in ('mac') or \
 
128
            (hasattr(os, 'uname') and os.uname()[0] == 'Darwin'):
129
129
        self.mac = True
130
130
    else:
131
131
        self.mac = False
165
165
        self.widgets['extensions']['toolbar_hb'].show()
166
166
        self.widgets['menu']['ext_toolbar'].set_active(True)
167
167
 
168
 
 
169
168
def treeview(self):
 
169
    import main_treeview
 
170
    # set up the treeview to do multiple selection
 
171
    tree = self.widgets['treeview']
170
172
    self.treemodel = gtk.TreeStore(str, gtk.gdk.Pixbuf, str, str, str, str, bool, str, str, int, str, str)
171
 
    self.widgets['treeview'].set_model(self.treemodel)
172
 
    self.widgets['treeview'].set_headers_visible(True)
 
173
    tree.set_model(self.treemodel)
 
174
    tree.set_headers_visible(True)
 
175
    tree.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
 
176
    self.widgets['treeview'].get_selection().connect("changed", main_treeview.on_tree_selection, self)
 
177
    
173
178
    # number column
174
179
    renderer = gtk.CellRendererText()
175
180
    self.number_column = gtk.TreeViewColumn(_('No.'), renderer, text=0)
314
319
    self.total = self.db.session.query(db.Movie).count()
315
320
    self.widgets['treeview'].set_search_equal_func(search_func_treeview)
316
321
    self.widgets['treeview'].show()
317
 
 
 
322
    
 
323
    # adding some completion fields - TODO: move it to initialize
 
324
    self.completion = gtk.EntryCompletion()
 
325
    self.widgets['add']['o_title'].set_completion(self.completion)
 
326
    self.completion.set_model(self.treemodel)
 
327
    self.completion.set_text_column(3)
 
328
    # ... title
 
329
    self.completion_t = gtk.EntryCompletion()
 
330
    self.widgets['add']['title'].set_completion(self.completion_t)
 
331
    self.completion_t.set_model(self.treemodel)
 
332
    self.completion_t.set_text_column(4)
318
333
 
319
334
def search_func_treeview(model, column, key, iter):
320
335
    return not (str(model.get_value(iter, 0)).startswith(key) or 
508
523
        'progressbar': get('progressbar'),
509
524
        'fields': {},
510
525
    }
 
526
    w['window'].connect('delete_event', plugins.imp.on_delete_event, self)
511
527
    get('cancel_button').connect('clicked', plugins.imp.on_abort_button_clicked, self)
512
528
    get('import_button').connect('clicked', plugins.imp.on_import_button_clicked, self)
513
529
    w['plugin'].connect('changed', plugins.imp.on_import_plugin_changed, w)
546
562
            return [None, None]
547
563
        if module.toolbar_icon:
548
564
            toolbar = self.widgets['extensions']['toolbar']
549
 
            if module.toolbar_icon.endswith('.png'):
 
565
            if module.toolbar_icon.endswith(('.png', '.svg')):
550
566
                icon_path = os.path.join(os.path.dirname(module.__file__), 'data', module.toolbar_icon)
551
567
                if not os.path.isfile(icon_path):
552
568
                    icon_path = os.path.join(self.locations['images'], module.toolbar_icon)
579
595
    # extension details
580
596
    hbox = gtk.HBox()
581
597
    vbox.pack_start(hbox, expand=False)
582
 
    enabled_cb = gtk.CheckButton(label=_('enable this extension'))
 
598
    enabled_cb = gtk.CheckButton(label=_('Enable this extension'))
583
599
    enabled_cb.set_active(enabled)
584
600
    configwidgets['enabled'] = enabled_cb
585
601
    vbox.pack_start(enabled_cb, expand=False)
713
729
    i = 0
714
730
    pos_to_activate = 0
715
731
    selected_criteria = self.config.get('criteria', None, section='mainlist')
716
 
    for criteria in self.search_criteria:
717
 
        new_criteria = self.field_names[criteria]
718
 
        self.widgets['filter']['criteria'].insert_text(i, new_criteria)
719
 
        if selected_criteria == new_criteria:
 
732
    self.search_criteria_sorted = sorted((self.field_names[criteria], criteria) for criteria in self.search_criteria)
 
733
    self.search_criteria_sorted.insert( 0, ( _('Any'), 'any' ) ) 
 
734
    for (criterianame, criteria) in self.search_criteria_sorted:
 
735
        self.widgets['filter']['criteria'].insert_text(i, criterianame)
 
736
        if selected_criteria == criterianame:
720
737
            pos_to_activate = i
721
738
        i += 1
722
739
    self.widgets['filter']['criteria'].set_active(pos_to_activate)
740
757
    fill_collections_combo(self)
741
758
    fill_advfilter_combo(self)
742
759
    fill_preferences_tags_combo(self)
 
760
    fill_resolutions_combo(self)
743
761
    language_combos(self)
744
762
    acodec_combos(self)
745
763
    achannel_combos(self)
753
771
        'volume_id', 'cond', 'layers', 'region', 'movie_id']
754
772
    self.search_criteria = (
755
773
        'o_title', 'title', 'number', 'director', 'plot', 'cast', 'notes', 'year',
756
 
        'runtime', 'country', 'genre', 'studio', 'media_num', 'rating')
 
774
        'runtime', 'country', 'genre', 'studio', 'media_num', 'rating', 'screenplay',
 
775
        'cameraman', 'barcode')
757
776
    self.field_names = {
758
777
        'barcode': _('Barcode'),
759
778
        'cast': _('Cast'),
804
823
        _('Region 6 (Popular Republic of China)'),
805
824
        _('Region 7 (Reserved for Unspecified Special Use)'),
806
825
        _('Region 8 (Airlines/Cruise Ships)'),
 
826
        _('Region A/1 (North and South America, Japan, Korea, Taiwan, Hong Kong, Southeast Asia)'),
 
827
        _('Region B/2 (Europe, Middle East, Africa, Australia, Oceania)'),
 
828
        _('Region C/3 (India, Nepal, China, Russia, Central and South Asia)'),
807
829
    )
808
830
 
809
831
 
840
862
                except:
841
863
                    spell_error = True
842
864
            if spell_error:
843
 
                log.info('Dictionary not available. Spellcheck will be disabled.')
 
865
                log.info('Dictionary not available. Spell check will be disabled.')
844
866
                if not self.config.get('notified', False, section='spell'):
845
867
                    gutils.info(_("Dictionary not available. Spellcheck will be disabled. \n" + \
846
 
                        "Please install the aspell-%s package or adjust the spellchekcer preferences.") % self.config.get('lang', section='spell'), \
 
868
                        "Please install the aspell-%s package or adjust the spellchecker preferences.") % self.config.get('lang', section='spell'), \
847
869
                        self.widgets['preferences']['window'])
848
870
                    self.config.set('notified', True, section='spell')
849
871
                    self.config.save()
893
915
def update_collection_combo_ids(self):
894
916
    self.collection_combo_ids = {}
895
917
    self.collection_combo_ids[0] = 0
896
 
    for i, item in enumerate(self.db.session.query(db.Collection.collection_id).all()):
 
918
    for i, item in enumerate(self.db.session.query(db.Collection.collection_id).order_by(db.Collection.name).all()):
897
919
        self.collection_combo_ids[i + 1] = item.collection_id
898
920
 
899
921
 
945
967
    self.initialized = False # don't refresh main treeview
946
968
    self.widgets['filter']['advfilter'].get_model().clear()
947
969
    self.widgets['filter']['advfilter'].insert_text(0, '') # empty one
948
 
    for i, item in enumerate(self.db.session.query(db.Filter.name).all()):
 
970
    for i, item in enumerate(self.db.session.query(db.Filter.name).order_by(db.Filter.name).all()):
949
971
        # add some white spaces to prevent scrollbar hides parts of the names
950
972
        self.widgets['filter']['advfilter'].insert_text(i + 1, item.name + '   ')
951
973
    self.widgets['filter']['advfilter'].show_all()
966
988
    self.initialized = _tmp
967
989
 
968
990
 
 
991
def fill_resolutions_combo(self, default=0):
 
992
    _tmp = self.initialized
 
993
    self.initialized = False # don't refresh main treeview
 
994
    self.widgets['add']['resolution'].get_model().clear()
 
995
    #resolutions = [names[0] for names in db._movie.res_aliases.values()]
 
996
    resolutions = [names[0] for (res, names) in db._movie.res_aliases.iteritems()]
 
997
    resolutions.sort()
 
998
    i = 0
 
999
    for name in resolutions:
 
1000
        self.widgets['add']['resolution'].insert_text(i, name)
 
1001
        i = i + 1
 
1002
    self.widgets['add']['resolution'].show_all()
 
1003
    self.initialized = _tmp
 
1004
 
 
1005
 
969
1006
def language_combos(self):
970
1007
    self.widgets['preferences']['lang_name'].get_model().clear()
971
1008
    self.languages_ids = {}
973
1010
    self.lang['lang'].clear()
974
1011
    self.widgets['preferences']['lang_name'].insert_text(0, '')
975
1012
    for i, lang in enumerate(self.db.session.query(db.Lang.lang_id, db.Lang.name).all()):
976
 
        self.languages_ids[i] = lang.lang_id
 
1013
        self.languages_ids[i + 1] = lang.lang_id
977
1014
        self.widgets['preferences']['lang_name'].insert_text(i + 1, lang.name)
978
1015
        # add movie languages treeview
979
1016
        self.lang['lang'].append([lang.lang_id, lang.name])
988
1025
    self.lang['acodec'].clear()
989
1026
    self.widgets['preferences']['acodec_name'].insert_text(0, '')
990
1027
    for i, acodec in enumerate(self.db.session.query(db.ACodec.acodec_id, db.ACodec.name).all()):
991
 
        self.acodecs_ids[i] = acodec.acodec_id
 
1028
        self.acodecs_ids[i + 1] = acodec.acodec_id
992
1029
        self.widgets['preferences']['acodec_name'].insert_text(i + 1, acodec.name)
993
1030
        # add movie languages treeview
994
1031
        self.lang['acodec'].append([acodec.acodec_id, acodec.name])
1003
1040
    self.lang['achannel'].clear()
1004
1041
    self.widgets['preferences']['achannel_name'].insert_text(0, '')
1005
1042
    for i, achannel in enumerate(self.db.session.query(db.AChannel.achannel_id, db.AChannel.name).all()):
1006
 
        self.achannels_ids[i] = achannel.achannel_id
 
1043
        self.achannels_ids[i + 1] = achannel.achannel_id
1007
1044
        self.widgets['preferences']['achannel_name'].insert_text(i + 1, achannel.name)
1008
1045
        # add movie languages treeview
1009
1046
        self.lang['achannel'].append([achannel.achannel_id, achannel.name])
1018
1055
    self.lang['subformat'].clear()
1019
1056
    self.widgets['preferences']['subformat_name'].insert_text(0, '')
1020
1057
    for i, subformat in enumerate(self.db.session.query(db.SubFormat.subformat_id, db.SubFormat.name).all()):
1021
 
        self.subformats_ids[i] = subformat.subformat_id
 
1058
        self.subformats_ids[i + 1] = subformat.subformat_id
1022
1059
        self.widgets['preferences']['subformat_name'].insert_text(i + 1, subformat.name)
1023
1060
        # add movie languages treeview
1024
1061
        self.lang['subformat'].append([subformat.subformat_id, subformat.name])