home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1309 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  11.8 KB  |  260 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. import functools
  8. import sys
  9. import os
  10. from PyQt4.Qt import Qt, QStackedWidget, QMenu, QSize, QSizePolicy, QStatusBar, QLabel, QFont
  11. from calibre.utils.config import prefs
  12. from calibre.constants import isosx, __appname__, preferred_encoding, __version__
  13. from calibre.gui2 import config, is_widescreen, gprefs
  14. from calibre.gui2.library.views import BooksView, DeviceBooksView
  15. from calibre.gui2.widgets import Splitter
  16. from calibre.gui2.tag_view import TagBrowserWidget
  17. from calibre.gui2.book_details import BookDetails
  18. from calibre.gui2.notify import get_notifier
  19. _keep_refs = []
  20.  
  21. def partial(*args, **kwargs):
  22.     ans = functools.partial(*args, **kwargs)
  23.     _keep_refs.append(ans)
  24.     return ans
  25.  
  26.  
  27. class LibraryViewMixin(object):
  28.     
  29.     def __init__(self, db):
  30.         self.library_view.files_dropped.connect(self.iactions['Add Books'].files_dropped, type = Qt.QueuedConnection)
  31.         self.library_view.add_column_signal.connect(partial(self.iactions['Preferences'].do_config, initial_plugin = ('Interface', 'Custom Columns')), type = Qt.QueuedConnection)
  32.         for func, args in [
  33.             ('connect_to_search_box', (self.search, self.search_done)),
  34.             ('connect_to_book_display', (self.book_details.show_data,))]:
  35.             for view in (self.library_view, self.memory_view, self.card_a_view, self.card_b_view):
  36.                 getattr(view, func)(*args)
  37.             
  38.         
  39.         self.memory_view.connect_dirtied_signal(self.upload_booklists)
  40.         self.memory_view.connect_upload_collections_signal(func = self.upload_collections, oncard = None)
  41.         self.card_a_view.connect_dirtied_signal(self.upload_booklists)
  42.         self.card_a_view.connect_upload_collections_signal(func = self.upload_collections, oncard = 'carda')
  43.         self.card_b_view.connect_dirtied_signal(self.upload_booklists)
  44.         self.card_b_view.connect_upload_collections_signal(func = self.upload_collections, oncard = 'cardb')
  45.         self.book_on_device(None, reset = True)
  46.         db.set_book_on_device_func(self.book_on_device)
  47.         self.library_view.set_database(db)
  48.         self.library_view.model().set_book_on_device_func(self.book_on_device)
  49.         prefs['library_path'] = self.library_path
  50.         for view in ('library', 'memory', 'card_a', 'card_b'):
  51.             view = getattr(self, view + '_view')
  52.             view.verticalHeader().sectionDoubleClicked.connect(self.iactions['View'].view_specific_book)
  53.         
  54.         self.build_context_menus()
  55.  
  56.     
  57.     def build_context_menus(self):
  58.         lm = QMenu(self)
  59.         
  60.         def populate_menu(m, items):
  61.             for what in items:
  62.                 if what is None:
  63.                     m.addSeparator()
  64.                     continue
  65.                 if what in self.iactions:
  66.                     m.addAction(self.iactions[what].qaction)
  67.                     continue
  68.             
  69.  
  70.         populate_menu(lm, gprefs['action-layout-context-menu'])
  71.         dm = QMenu(self)
  72.         populate_menu(dm, gprefs['action-layout-context-menu-device'])
  73.         ec = self.iactions['Edit Collections'].qaction
  74.         self.library_view.set_context_menu(lm, ec)
  75.         for v in (self.memory_view, self.card_a_view, self.card_b_view):
  76.             v.set_context_menu(dm, ec)
  77.         
  78.  
  79.     
  80.     def search_done(self, view, ok):
  81.         if view is self.current_view():
  82.             self.search.search_done(ok)
  83.             self.set_number_of_books_shown()
  84.         
  85.  
  86.  
  87.  
  88. class LibraryWidget(Splitter):
  89.     
  90.     def __init__(self, parent):
  91.         orientation = Qt.Vertical
  92.         if config['gui_layout'] == 'narrow':
  93.             orientation = None if is_widescreen() else Qt.Vertical
  94.         
  95.         idx = None if orientation == Qt.Vertical else 1
  96.         size = None if orientation == Qt.Vertical else 550
  97.         Splitter.__init__(self, 'cover_browser_splitter', _('Cover Browser'), I('cover_flow.png'), orientation = orientation, parent = parent, connect_button = not config['separate_cover_flow'], side_index = idx, initial_side_size = size, initial_show = False, shortcut = _('Shift+Alt+B'))
  98.         parent.library_view = BooksView(parent)
  99.         parent.library_view.setObjectName('library_view')
  100.         self.addWidget(parent.library_view)
  101.  
  102.  
  103.  
  104. class Stack(QStackedWidget):
  105.     
  106.     def __init__(self, parent):
  107.         QStackedWidget.__init__(self, parent)
  108.         parent.cb_splitter = LibraryWidget(parent)
  109.         self.tb_widget = TagBrowserWidget(parent)
  110.         parent.tb_splitter = Splitter('tag_browser_splitter', _('Tag Browser'), I('tags.png'), parent = parent, side_index = 0, initial_side_size = 200, shortcut = _('Shift+Alt+T'))
  111.         parent.tb_splitter.addWidget(self.tb_widget)
  112.         parent.tb_splitter.addWidget(parent.cb_splitter)
  113.         parent.tb_splitter.setCollapsible(parent.tb_splitter.other_index, False)
  114.         self.addWidget(parent.tb_splitter)
  115.         for x in ('memory', 'card_a', 'card_b'):
  116.             name = x + '_view'
  117.             w = DeviceBooksView(parent)
  118.             setattr(parent, name, w)
  119.             self.addWidget(w)
  120.             w.setObjectName(name)
  121.         
  122.  
  123.  
  124.  
  125. class StatusBar(QStatusBar):
  126.     
  127.     def __init__(self, parent = None):
  128.         QStatusBar.__init__(self, parent)
  129.         self.default_message = __appname__ + ' ' + _('version') + ' ' + self.get_version() + ' ' + _('created by Kovid Goyal')
  130.         self.device_string = ''
  131.         self.update_label = QLabel('')
  132.         self.update_label.setOpenExternalLinks(True)
  133.         self.addPermanentWidget(self.update_label)
  134.         self.update_label.setVisible(False)
  135.         self._font = QFont()
  136.         self._font.setBold(True)
  137.         self.setFont(self._font)
  138.         self.defmsg = QLabel(self.default_message)
  139.         self.defmsg.setFont(self._font)
  140.         self.addWidget(self.defmsg)
  141.  
  142.     
  143.     def initialize(self, systray = None):
  144.         self.systray = systray
  145.         self.notifier = get_notifier(systray)
  146.  
  147.     
  148.     def device_connected(self, devname):
  149.         self.device_string = _('Connected ') + devname
  150.         self.defmsg.setText(self.default_message + ' ..::.. ' + self.device_string)
  151.         self.clearMessage()
  152.  
  153.     
  154.     def device_disconnected(self):
  155.         self.device_string = ''
  156.         self.defmsg.setText(self.default_message)
  157.         self.clearMessage()
  158.  
  159.     
  160.     def new_version_available(self, ver, url):
  161.         msg = u'<span style="color:red; font-weight: bold">%s: <a href="%s">%s<a></span>' % (_('Update found'), url, ver)
  162.         self.update_label.setText(msg)
  163.         self.update_label.setCursor(Qt.PointingHandCursor)
  164.         self.update_label.setVisible(True)
  165.  
  166.     
  167.     def get_version(self):
  168.         dv = os.environ.get('CALIBRE_DEVELOP_FROM', None)
  169.         v = __version__
  170.         if getattr(sys, 'frozen', False) and dv and os.path.abspath(dv) in sys.path:
  171.             v += '*'
  172.         
  173.         return v
  174.  
  175.     
  176.     def show_message(self, msg, timeout = 0):
  177.         self.showMessage(msg, timeout)
  178.         if self.notifier is not None and not config['disable_tray_notification']:
  179.             if isosx and isinstance(msg, unicode):
  180.                 
  181.                 try:
  182.                     msg = msg.encode(preferred_encoding)
  183.                 except UnicodeEncodeError:
  184.                     msg = msg.encode('utf-8')
  185.                 except:
  186.                     None<EXCEPTION MATCH>UnicodeEncodeError
  187.                 
  188.  
  189.             None<EXCEPTION MATCH>UnicodeEncodeError
  190.             self.notifier(msg)
  191.         
  192.  
  193.     
  194.     def clear_message(self):
  195.         self.clearMessage()
  196.  
  197.  
  198.  
  199. class LayoutMixin(object):
  200.     
  201.     def __init__(self):
  202.         if config['gui_layout'] == 'narrow':
  203.             self.book_details = BookDetails(False, self)
  204.             self.stack = Stack(self)
  205.             self.bd_splitter = Splitter('book_details_splitter', _('Book Details'), I('book.png'), orientation = Qt.Vertical, parent = self, side_index = 1, shortcut = _('Alt+D'))
  206.             self.bd_splitter.addWidget(self.stack)
  207.             self.bd_splitter.addWidget(self.book_details)
  208.             self.bd_splitter.setCollapsible(self.bd_splitter.other_index, False)
  209.             self.centralwidget.layout().addWidget(self.bd_splitter)
  210.         else:
  211.             self.bd_splitter = Splitter('book_details_splitter', _('Book Details'), I('book.png'), initial_side_size = 200, orientation = Qt.Horizontal, parent = self, side_index = 1, shortcut = _('Shift+Alt+D'))
  212.             self.stack = Stack(self)
  213.             self.bd_splitter.addWidget(self.stack)
  214.             self.book_details = BookDetails(True, self)
  215.             self.bd_splitter.addWidget(self.book_details)
  216.             self.bd_splitter.setCollapsible(self.bd_splitter.other_index, False)
  217.             self.bd_splitter.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
  218.             self.centralwidget.layout().addWidget(self.bd_splitter)
  219.         self.status_bar = StatusBar(self)
  220.         for x in ('cb', 'tb', 'bd'):
  221.             button = getattr(self, x + '_splitter').button
  222.             button.setIconSize(QSize(24, 24))
  223.             self.status_bar.addPermanentWidget(button)
  224.         
  225.         self.status_bar.addPermanentWidget(self.jobs_button)
  226.         self.setStatusBar(self.status_bar)
  227.  
  228.     
  229.     def finalize_layout(self):
  230.         self.status_bar.initialize(self.system_tray_icon)
  231.         self.book_details.show_book_info.connect(self.iactions['Show Book Details'].show_book_info)
  232.         self.book_details.files_dropped.connect(self.iactions['Add Books'].files_dropped_on_book)
  233.         self.book_details.open_containing_folder.connect(self.iactions['View'].view_folder_for_id)
  234.         self.book_details.view_specific_format.connect(self.iactions['View'].view_format_by_id)
  235.         m = self.library_view.model()
  236.         if m.rowCount(None) > 0:
  237.             self.library_view.set_current_row(0)
  238.             m.current_changed(self.library_view.currentIndex(), self.library_view.currentIndex())
  239.         
  240.         self.library_view.setFocus(Qt.OtherFocusReason)
  241.  
  242.     
  243.     def save_layout_state(self):
  244.         for x in ('library', 'memory', 'card_a', 'card_b'):
  245.             getattr(self, x + '_view').save_state()
  246.         
  247.         for x in ('cb', 'tb', 'bd'):
  248.             s = getattr(self, x + '_splitter')
  249.             s.update_desired_state()
  250.             s.save_state()
  251.         
  252.  
  253.     
  254.     def read_layout_settings(self):
  255.         for x in ('cb', 'tb', 'bd'):
  256.             getattr(self, x + '_splitter').restore_state()
  257.         
  258.  
  259.  
  260.