home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1341 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  30.4 KB  |  793 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import os
  9. import traceback
  10. import re
  11. from Queue import Empty, Queue
  12. from contextlib import closing
  13. from PyQt4.Qt import QWizard, QWizardPage, QPixmap, Qt, QAbstractListModel, QVariant, QItemSelectionModel, SIGNAL, QObject, QTimer
  14. from calibre import __appname__, patheq
  15. from calibre.library.database2 import LibraryDatabase2
  16. from calibre.library.move import MoveLibrary
  17. from calibre.constants import filesystem_encoding
  18. from calibre.gui2.wizard.send_email import smtp_prefs
  19. from calibre.gui2.wizard.device_ui import Ui_WizardPage as DeviceUI
  20. from calibre.gui2.wizard.library_ui import Ui_WizardPage as LibraryUI
  21. from calibre.gui2.wizard.finish_ui import Ui_WizardPage as FinishUI
  22. from calibre.gui2.wizard.kindle_ui import Ui_WizardPage as KindleUI
  23. from calibre.gui2.wizard.stanza_ui import Ui_WizardPage as StanzaUI
  24. from calibre.gui2 import min_available_height, available_width
  25. from calibre.utils.config import dynamic, prefs
  26. from calibre.gui2 import NONE, choose_dir, error_dialog
  27. from calibre.gui2.dialogs.progress import ProgressDialog
  28.  
  29. class Device(object):
  30.     output_profile = 'default'
  31.     output_format = 'EPUB'
  32.     name = 'Default'
  33.     manufacturer = 'Default'
  34.     id = 'default'
  35.     
  36.     def set_output_profile(cls):
  37.         if cls.output_profile:
  38.             load_defaults = load_defaults
  39.             save_defaults = save_defaults
  40.             import calibre.ebooks.conversion.config
  41.             recs = load_defaults('page_setup')
  42.             recs['output_profile'] = cls.output_profile
  43.             save_defaults('page_setup', recs)
  44.         
  45.  
  46.     set_output_profile = classmethod(set_output_profile)
  47.     
  48.     def set_output_format(cls):
  49.         if cls.output_format:
  50.             prefs.set('output_format', cls.output_format)
  51.         
  52.  
  53.     set_output_format = classmethod(set_output_format)
  54.     
  55.     def commit(cls):
  56.         cls.set_output_profile()
  57.         cls.set_output_format()
  58.  
  59.     commit = classmethod(commit)
  60.  
  61.  
  62. class Kindle(Device):
  63.     output_profile = 'kindle'
  64.     output_format = 'MOBI'
  65.     name = 'Kindle 1 or 2'
  66.     manufacturer = 'Amazon'
  67.     id = 'kindle'
  68.  
  69.  
  70. class JetBook(Device):
  71.     output_profile = 'jetbook5'
  72.     output_format = 'EPUB'
  73.     name = 'JetBook'
  74.     manufacturer = 'Ectaco'
  75.     id = 'jetbook'
  76.  
  77.  
  78. class KindleDX(Kindle):
  79.     output_profile = 'kindle_dx'
  80.     output_format = 'MOBI'
  81.     name = 'Kindle DX'
  82.     id = 'kindledx'
  83.  
  84.  
  85. class Sony505(Device):
  86.     output_profile = 'sony'
  87.     name = 'All other SONY devices'
  88.     output_format = 'EPUB'
  89.     manufacturer = 'SONY'
  90.     id = 'prs505'
  91.  
  92.  
  93. class Kobo(Device):
  94.     name = 'Kobo Reader'
  95.     manufacturer = 'Kobo'
  96.     output_profile = 'kobo'
  97.     output_format = 'EPUB'
  98.     id = 'kobo'
  99.  
  100.  
  101. class Booq(Device):
  102.     name = 'Booq Reader'
  103.     manufacturer = 'Booq'
  104.     output_profile = 'sony'
  105.     output_format = 'EPUB'
  106.     id = 'booq'
  107.  
  108.  
  109. class TheBook(Device):
  110.     name = 'The Book'
  111.     manufacturer = 'Augen'
  112.     output_profile = 'sony'
  113.     output_format = 'EPUB'
  114.     id = 'thebook'
  115.  
  116.  
  117. class Avant(Booq):
  118.     name = 'Booq Avant'
  119.  
  120.  
  121. class Sony300(Sony505):
  122.     name = 'SONY Reader Pocket Edition'
  123.     id = 'prs300'
  124.     output_profile = 'sony300'
  125.  
  126.  
  127. class Sony900(Sony505):
  128.     name = 'SONY Reader Daily Edition'
  129.     id = 'prs900'
  130.     output_profile = 'sony900'
  131.  
  132.  
  133. class Nook(Sony505):
  134.     id = 'nook'
  135.     name = 'Nook'
  136.     manufacturer = 'Barnes & Noble'
  137.     output_profile = 'nook'
  138.  
  139.  
  140. class CybookG3(Device):
  141.     name = 'Cybook Gen 3'
  142.     output_format = 'MOBI'
  143.     output_profile = 'cybookg3'
  144.     manufacturer = 'Bookeen'
  145.     id = 'cybookg3'
  146.  
  147.  
  148. class CybookOpus(CybookG3):
  149.     name = 'Cybook Opus'
  150.     output_format = 'EPUB'
  151.     output_profile = 'cybook_opus'
  152.     id = 'cybook_opus'
  153.  
  154.  
  155. class PocketBook360(CybookOpus):
  156.     manufacturer = 'PocketBook'
  157.     name = 'PocketBook 360'
  158.     id = 'pocketbook360'
  159.     output_profile = 'cybook_opus'
  160.  
  161.  
  162. class PocketBook(CybookG3):
  163.     manufacturer = 'PocketBook'
  164.     name = 'PocketBook 301/302'
  165.     id = 'pocketbook'
  166.     output_profile = 'cybookg3'
  167.  
  168.  
  169. class iPhone(Device):
  170.     name = 'iPad or iPhone/iTouch + Stanza'
  171.     output_format = 'EPUB'
  172.     manufacturer = 'Apple'
  173.     id = 'iphone'
  174.  
  175.  
  176. class Android(Device):
  177.     name = 'Adroid phone + WordPlayer/Aldiko'
  178.     output_format = 'EPUB'
  179.     manufacturer = 'Android'
  180.     id = 'android'
  181.  
  182.  
  183. class HanlinV3(Device):
  184.     name = 'Hanlin V3'
  185.     output_format = 'EPUB'
  186.     output_profile = 'hanlinv3'
  187.     manufacturer = 'Jinke'
  188.     id = 'hanlinv3'
  189.  
  190.  
  191. class HanlinV5(HanlinV3):
  192.     name = 'Hanlin V5'
  193.     output_profile = 'hanlinv5'
  194.     id = 'hanlinv5'
  195.  
  196.  
  197. class BeBook(HanlinV3):
  198.     name = 'BeBook'
  199.     manufacturer = 'Endless Ideas'
  200.     id = 'bebook'
  201.  
  202.  
  203. class BeBookMini(HanlinV5):
  204.     name = 'BeBook Mini'
  205.     manufacturer = 'Endless Ideas'
  206.     id = 'bebook_mini'
  207.  
  208.  
  209. class EZReader(HanlinV3):
  210.     name = 'EZReader'
  211.     manufacturer = 'Astak'
  212.     id = 'ezreader'
  213.  
  214.  
  215. class EZReaderPP(HanlinV5):
  216.     name = 'EZReader Pocket Pro'
  217.     manufacturer = 'Astak'
  218.     id = 'ezreader_pp'
  219.  
  220.  
  221. def get_devices():
  222.     for x in globals().values():
  223.         if isinstance(x, type) and issubclass(x, Device):
  224.             yield x
  225.             continue
  226.     
  227.  
  228.  
  229. def get_manufacturers():
  230.     mans = set([])
  231.     for x in get_devices():
  232.         mans.add(x.manufacturer)
  233.     
  234.     if 'Default' in mans:
  235.         mans.remove('Default')
  236.     
  237.     return [
  238.         'Default'] + sorted(mans)
  239.  
  240.  
  241. def get_devices_of(manufacturer):
  242.     ans = _[1]
  243.     return sorted(ans, cmp = (lambda x, y: cmp(x.name, y.name)))
  244.  
  245.  
  246. class ManufacturerModel(QAbstractListModel):
  247.     
  248.     def __init__(self):
  249.         QAbstractListModel.__init__(self)
  250.         self.manufacturers = get_manufacturers()
  251.  
  252.     
  253.     def rowCount(self, p):
  254.         return len(self.manufacturers)
  255.  
  256.     
  257.     def columnCount(self, p):
  258.         return 1
  259.  
  260.     
  261.     def data(self, index, role):
  262.         if role == Qt.DisplayRole:
  263.             return QVariant(self.manufacturers[index.row()])
  264.         if role == Qt.UserRole:
  265.             return self.manufacturers[index.row()]
  266.         return NONE
  267.  
  268.     
  269.     def index_of(self, man):
  270.         for i, x in enumerate(self.manufacturers):
  271.             if x == man:
  272.                 return self.index(i)
  273.         
  274.  
  275.  
  276.  
  277. class DeviceModel(QAbstractListModel):
  278.     
  279.     def __init__(self, manufacturer):
  280.         QAbstractListModel.__init__(self)
  281.         self.devices = get_devices_of(manufacturer)
  282.  
  283.     
  284.     def rowCount(self, p):
  285.         return len(self.devices)
  286.  
  287.     
  288.     def columnCount(self, p):
  289.         return 1
  290.  
  291.     
  292.     def data(self, index, role):
  293.         if role == Qt.DisplayRole:
  294.             return QVariant(self.devices[index.row()].name)
  295.         if role == Qt.UserRole:
  296.             return self.devices[index.row()]
  297.         return NONE
  298.  
  299.     
  300.     def index_of(self, dev):
  301.         for i, device in enumerate(self.devices):
  302.             if device is dev:
  303.                 return self.index(i)
  304.         
  305.  
  306.  
  307.  
  308. class KindlePage(QWizardPage, KindleUI):
  309.     ID = 3
  310.     
  311.     def __init__(self):
  312.         QWizardPage.__init__(self)
  313.         self.setupUi(self)
  314.  
  315.     
  316.     def initializePage(self):
  317.         opts = smtp_prefs().parse()
  318.         for x in opts.accounts.keys():
  319.             if x.strip().endswith('@kindle.com'):
  320.                 self.to_address.setText(x)
  321.                 continue
  322.         
  323.         
  324.         def x():
  325.             t = unicode(self.to_address.text())
  326.             if t.strip():
  327.                 return t.strip()
  328.  
  329.         self.send_email_widget.initialize(x)
  330.  
  331.     
  332.     def commit(self):
  333.         x = unicode(self.to_address.text()).strip()
  334.         parts = x.split('@')
  335.         if len(parts) < 2 or not parts[0]:
  336.             return None
  337.  
  338.     
  339.     def nextId(self):
  340.         return FinishPage.ID
  341.  
  342.  
  343.  
  344. class StanzaPage(QWizardPage, StanzaUI):
  345.     ID = 5
  346.     
  347.     def __init__(self):
  348.         QWizardPage.__init__(self)
  349.         self.setupUi(self)
  350.         self.connect(self.content_server, SIGNAL('stateChanged(int)'), self.set_port)
  351.  
  352.     
  353.     def initializePage(self):
  354.         config = config
  355.         import calibre.gui2
  356.         yes = config['autolaunch_server']
  357.         self.content_server.setChecked(yes)
  358.         self.set_port()
  359.  
  360.     
  361.     def nextId(self):
  362.         return FinishPage.ID
  363.  
  364.     
  365.     def commit(self):
  366.         load_defaults = load_defaults
  367.         save_defaults = save_defaults
  368.         import calibre.ebooks.conversion.config
  369.         recs = load_defaults('comic_input')
  370.         recs['dont_grayscale'] = True
  371.         save_defaults('comic_input', recs)
  372.         p = self.set_port()
  373.         if p is not None:
  374.             server_config = server_config
  375.             import calibre.library.server
  376.             c = server_config()
  377.             c.set('port', p)
  378.         
  379.  
  380.     
  381.     def set_port(self, *args):
  382.         if not self.content_server.isChecked():
  383.             return None
  384.         import socket
  385.         s = socket.socket()
  386.         closing(s).__enter__()
  387.         
  388.         try:
  389.             for p in range(8080, 8100):
  390.                 
  391.                 try:
  392.                     s.bind(('0.0.0.0', p))
  393.                     t = unicode(self.instructions.text())
  394.                     t = re.sub(':\\d+', ':' + str(p), t)
  395.                     self.instructions.setText(t)
  396.                     return p
  397.                 continue
  398.                 closing(s)
  399.                 self.content_server.isChecked()
  400.                 continue
  401.                 continue
  402.  
  403.         finally:
  404.             pass
  405.  
  406.  
  407.  
  408.  
  409. class WordPlayerPage(StanzaPage):
  410.     ID = 6
  411.     
  412.     def __init__(self):
  413.         StanzaPage.__init__(self)
  414.         self.label.setText('<p>' + _('If you use the WordPlayer e-book app on your Android phone, you can access your calibre book collection directly on the device. To do this you have to turn on the content server.'))
  415.         self.instructions.setText('<p>' + _('Remember to leave calibre running as the server only runs as long as calibre is running.') + '<br><br>' + _('You have to add the URL http://myhostname:8080 as your calibre library in WordPlayer. Here myhostname should be the fully qualified hostname or the IP address of the computer calibre is running on.'))
  416.  
  417.  
  418.  
  419. class DevicePage(QWizardPage, DeviceUI):
  420.     ID = 2
  421.     
  422.     def __init__(self):
  423.         QWizardPage.__init__(self)
  424.         self.setupUi(self)
  425.         self.registerField('manufacturer', self.manufacturer_view)
  426.         self.registerField('device', self.device_view)
  427.  
  428.     
  429.     def initializePage(self):
  430.         self.man_model = ManufacturerModel()
  431.         self.manufacturer_view.setModel(self.man_model)
  432.         previous = dynamic.get('welcome_wizard_device', False)
  433.         if previous:
  434.             previous = _[1]
  435.             previous = previous[0]
  436.         else:
  437.             previous = Device
  438.         idx = self.man_model.index_of(previous.manufacturer)
  439.         if idx is None:
  440.             idx = self.man_model.index_of(Device.manufacturer)
  441.             previous = Device
  442.         
  443.         self.manufacturer_view.selectionModel().select(idx, QItemSelectionModel.Select)
  444.         self.dev_model = DeviceModel(self.man_model.data(idx, Qt.UserRole))
  445.         idx = self.dev_model.index_of(previous)
  446.         self.device_view.setModel(self.dev_model)
  447.         self.device_view.selectionModel().select(idx, QItemSelectionModel.Select)
  448.         self.connect(self.manufacturer_view.selectionModel(), SIGNAL('selectionChanged(QItemSelection,QItemSelection)'), self.manufacturer_changed)
  449.  
  450.     
  451.     def manufacturer_changed(self, current, previous):
  452.         new = list(current.indexes())[0]
  453.         man = self.man_model.data(new, Qt.UserRole)
  454.         self.dev_model = DeviceModel(man)
  455.         self.device_view.setModel(self.dev_model)
  456.         self.device_view.selectionModel().select(self.dev_model.index(0), QItemSelectionModel.Select)
  457.  
  458.     
  459.     def commit(self):
  460.         idx = list(self.device_view.selectionModel().selectedIndexes())[0]
  461.         dev = self.dev_model.data(idx, Qt.UserRole)
  462.         dev.commit()
  463.         dynamic.set('welcome_wizard_device', dev.id)
  464.  
  465.     
  466.     def nextId(self):
  467.         idx = list(self.device_view.selectionModel().selectedIndexes())[0]
  468.         dev = self.dev_model.data(idx, Qt.UserRole)
  469.         if dev in (Kindle, KindleDX):
  470.             return KindlePage.ID
  471.         if dev is iPhone:
  472.             return StanzaPage.ID
  473.         if dev is Android:
  474.             return WordPlayerPage.ID
  475.         return FinishPage.ID
  476.  
  477.  
  478.  
  479. class MoveMonitor(QObject):
  480.     
  481.     def __init__(self, worker, rq, callback, parent):
  482.         QObject.__init__(self, parent)
  483.         self.worker = worker
  484.         self.rq = rq
  485.         self.callback = callback
  486.         self.parent = parent
  487.         self.worker.start()
  488.         self.dialog = ProgressDialog(_('Moving library...'), '', max = self.worker.total, parent = parent)
  489.         self.dialog.button_box.setDisabled(True)
  490.         self.dialog.setModal(True)
  491.         self.dialog.show()
  492.         self.timer = QTimer(self)
  493.         self.connect(self.timer, SIGNAL('timeout()'), self.check)
  494.         self.timer.start(200)
  495.  
  496.     
  497.     def check(self):
  498.         if self.worker.is_alive():
  499.             self.update()
  500.         else:
  501.             self.timer.stop()
  502.             self.dialog.hide()
  503.             if self.worker.failed:
  504.                 error_dialog(self.parent, _('Failed to move library'), _('Failed to move library'), self.worker.details, show = True)
  505.                 return self.callback(None)
  506.             return self.callback(self.worker.to)
  507.         return self.worker.is_alive()
  508.  
  509.     
  510.     def update(self):
  511.         
  512.         try:
  513.             title = self.rq.get_nowait()[-1]
  514.             self.dialog.value += 1
  515.             self.dialog.set_msg(_('Copied') + ' ' + title)
  516.         except Empty:
  517.             pass
  518.  
  519.  
  520.  
  521.  
  522. class Callback(object):
  523.     
  524.     def __init__(self, callback):
  525.         self.callback = callback
  526.  
  527.     
  528.     def __call__(self, newloc):
  529.         if newloc is not None:
  530.             prefs['library_path'] = newloc
  531.         
  532.         self.callback(newloc)
  533.  
  534.  
  535. _mm = None
  536.  
  537. def move_library(oldloc, newloc, parent, callback_on_complete):
  538.     global _mm
  539.     callback = Callback(callback_on_complete)
  540.     
  541.     try:
  542.         if not os.path.exists(os.path.join(newloc, 'metadata.db')):
  543.             if oldloc and os.access(os.path.join(oldloc, 'metadata.db'), os.R_OK):
  544.                 
  545.                 try:
  546.                     db = LibraryDatabase2(oldloc)
  547.                 except:
  548.                     return move_library(None, newloc, parent, callback)
  549.  
  550.                 rq = Queue()
  551.                 m = MoveLibrary(oldloc, newloc, len(db.get_top_level_move_items()[0]), rq)
  552.                 _mm = MoveMonitor(m, rq, callback, parent)
  553.                 return None
  554.             os.access(os.path.join(oldloc, 'metadata.db'), os.R_OK)
  555.             db = LibraryDatabase2(newloc)
  556.             callback(newloc)
  557.             return None
  558.         os.path.exists(os.path.join(newloc, 'metadata.db'))
  559.         
  560.         try:
  561.             LibraryDatabase2(newloc)
  562.         except Exception:
  563.             err = None
  564.             det = traceback.format_exc()
  565.             error_dialog(parent, _('Invalid database'), _('<p>An invalid library already exists at %s, delete it before trying to move the existing library.<br>Error: %s') % (newloc, str(err)), det, show = True)
  566.             callback(None)
  567.             return None
  568.  
  569.         callback(newloc)
  570.         return None
  571.     except Exception:
  572.         err = None
  573.         det = traceback.format_exc()
  574.         error_dialog(parent, _('Could not move library'), unicode(err), det, show = True)
  575.  
  576.     callback(None)
  577.  
  578.  
  579. class LibraryPage(QWizardPage, LibraryUI):
  580.     ID = 1
  581.     
  582.     def __init__(self):
  583.         QWizardPage.__init__(self)
  584.         self.setupUi(self)
  585.         self.registerField('library_location', self.location)
  586.         self.connect(self.button_change, SIGNAL('clicked()'), self.change)
  587.         self.init_languages()
  588.         self.connect(self.language, SIGNAL('currentIndexChanged(int)'), self.change_language)
  589.         self.connect(self.location, SIGNAL('textChanged(QString)'), self.location_text_changed)
  590.  
  591.     
  592.     def location_text_changed(self, newtext):
  593.         self.emit(SIGNAL('completeChanged()'))
  594.  
  595.     
  596.     def init_languages(self):
  597.         self.language.blockSignals(True)
  598.         self.language.clear()
  599.         available_translations = available_translations
  600.         get_language = get_language
  601.         get_lang = get_lang
  602.         import calibre.utils.localization
  603.         lang = get_lang()
  604.         if lang is None or lang not in available_translations():
  605.             lang = 'en'
  606.         
  607.         self.language.addItem(get_language(lang), QVariant(lang))
  608.         items = _[1]
  609.         items.sort(cmp = (lambda x, y: cmp(x[1], y[1])))
  610.         for item in items:
  611.             self.language.addItem(item[1], QVariant(item[0]))
  612.         
  613.         self.language.blockSignals(False)
  614.         prefs['language'] = str(self.language.itemData(self.language.currentIndex()).toString())
  615.  
  616.     
  617.     def change_language(self, idx):
  618.         prefs['language'] = str(self.language.itemData(self.language.currentIndex()).toString())
  619.         import __builtin__
  620.         
  621.         __builtin__.__dict__['_'] = lambda x: x
  622.         set_translators = set_translators
  623.         import calibre.utils.localization
  624.         qt_app = qt_app
  625.         import calibre.gui2
  626.         set_translators()
  627.         qt_app.load_translations()
  628.         self.emit(SIGNAL('retranslate()'))
  629.         self.init_languages()
  630.  
  631.     
  632.     def change(self):
  633.         dir = choose_dir(self, 'database location dialog', _('Select location for books'))
  634.         if dir:
  635.             self.location.setText(dir)
  636.         
  637.  
  638.     
  639.     def initializePage(self):
  640.         lp = prefs['library_path']
  641.         self.default_library_name = None
  642.         if not lp:
  643.             fname = _('Calibre Library')
  644.             if isinstance(fname, unicode):
  645.                 
  646.                 try:
  647.                     fname = fname.encode(filesystem_encoding)
  648.                 fname = 'Calibre Library'
  649.  
  650.             
  651.             lp = os.path.expanduser('~' + os.sep + fname)
  652.             self.default_library_name = lp
  653.             if not os.path.exists(lp):
  654.                 
  655.                 try:
  656.                     os.makedirs(lp)
  657.                 traceback.print_exc()
  658.                 lp = os.path.expanduser('~')
  659.  
  660.             
  661.         
  662.         self.location.setText(lp)
  663.  
  664.     
  665.     def isComplete(self):
  666.         
  667.         try:
  668.             lp = unicode(self.location.text())
  669.             if bool(lp) and os.path.exists(lp) and os.path.isdir(lp):
  670.                 pass
  671.             ans = os.access(lp, os.W_OK)
  672.         except:
  673.             ans = False
  674.  
  675.         return ans
  676.  
  677.     
  678.     def commit(self, completed):
  679.         oldloc = prefs['library_path']
  680.         newloc = unicode(self.location.text())
  681.         
  682.         try:
  683.             newloce = newloc.encode(filesystem_encoding)
  684.             if self.default_library_name is not None and os.path.exists(self.default_library_name) and not os.listdir(self.default_library_name) and newloce != self.default_library_name:
  685.                 os.rmdir(self.default_library_name)
  686.         except:
  687.             pass
  688.  
  689.         if not os.path.exists(newloc):
  690.             os.mkdir(newloc)
  691.         
  692.         if not patheq(oldloc, newloc):
  693.             move_library(oldloc, newloc, self.wizard(), completed)
  694.             return True
  695.         return False
  696.  
  697.     
  698.     def nextId(self):
  699.         return DevicePage.ID
  700.  
  701.  
  702.  
  703. class FinishPage(QWizardPage, FinishUI):
  704.     ID = 4
  705.     
  706.     def __init__(self):
  707.         QWizardPage.__init__(self)
  708.         self.setupUi(self)
  709.  
  710.     
  711.     def nextId(self):
  712.         return -1
  713.  
  714.     
  715.     def commit(self):
  716.         pass
  717.  
  718.  
  719.  
  720. class Wizard(QWizard):
  721.     
  722.     def __init__(self, parent):
  723.         QWizard.__init__(self, parent)
  724.         self.setWindowTitle(__appname__ + ' ' + _('welcome wizard'))
  725.         p = QPixmap()
  726.         p.loadFromData(open(P('content_server/calibre.png'), 'rb').read())
  727.         self.setPixmap(self.LogoPixmap, p.scaledToHeight(80, Qt.SmoothTransformation))
  728.         self.setPixmap(self.WatermarkPixmap, QPixmap(I('welcome_wizard.svg')))
  729.         self.setPixmap(self.BackgroundPixmap, QPixmap(I('wizard.svg')))
  730.         self.device_page = DevicePage()
  731.         self.library_page = LibraryPage()
  732.         self.connect(self.library_page, SIGNAL('retranslate()'), self.retranslate)
  733.         self.finish_page = FinishPage()
  734.         bt = unicode(self.buttonText(self.FinishButton)).replace('&', '')
  735.         t = unicode(self.finish_page.finish_text.text())
  736.         self.finish_page.finish_text.setText(t % bt)
  737.         self.kindle_page = KindlePage()
  738.         self.stanza_page = StanzaPage()
  739.         self.word_player_page = WordPlayerPage()
  740.         self.setPage(self.library_page.ID, self.library_page)
  741.         self.setPage(self.device_page.ID, self.device_page)
  742.         self.setPage(self.finish_page.ID, self.finish_page)
  743.         self.setPage(self.kindle_page.ID, self.kindle_page)
  744.         self.setPage(self.stanza_page.ID, self.stanza_page)
  745.         self.setPage(self.word_player_page.ID, self.word_player_page)
  746.         self.device_extra_page = None
  747.         nh = min_available_height() - 75
  748.         nw = available_width() - 30
  749.         if nh < 0:
  750.             nh = 580
  751.         
  752.         if nw < 0:
  753.             nw = 400
  754.         
  755.         nh = min(400, nh)
  756.         nw = min(580, nw)
  757.         self.resize(nw, nh)
  758.  
  759.     
  760.     def retranslate(self):
  761.         for pid in self.pageIds():
  762.             page = self.page(pid)
  763.             page.retranslateUi(page)
  764.         
  765.  
  766.     
  767.     def accept(self):
  768.         pages = map(self.page, self.visitedPages())
  769.         for page in pages:
  770.             if page is not self.library_page:
  771.                 page.commit()
  772.                 continue
  773.         
  774.         if not self.library_page.commit(self.completed):
  775.             self.completed(None)
  776.         
  777.  
  778.     
  779.     def completed(self, newloc):
  780.         return QWizard.accept(self)
  781.  
  782.  
  783.  
  784. def wizard(parent = None):
  785.     w = Wizard(parent)
  786.     return w
  787.  
  788. if __name__ == '__main__':
  789.     from calibre.gui2 import Application
  790.     app = Application([])
  791.     wizard().exec_()
  792.  
  793.