~nataliabidart/ubuntuone-windows-installer/stable-3-0-update-2.99.2

« back to all changes in this revision

Viewing changes to ubuntuone_installer/gui/qt/main/windows.py

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart
  • Date: 2011-11-12 02:00:31 UTC
  • mfrom: (85.1.5 import-qt4reactor)
  • Revision ID: tarmac-20111112020031-gvj3ise8dpm2xs7g
- Import qt4reactor properly (LP: #888722).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
 
3
 
# Authors: Manuel de la Pena <manuel@canonical.com>
4
 
#          Roberto Alsina <roberto.alsina@canonical.com>
5
2
#
6
3
# Copyright 2011 Canonical Ltd.
7
4
#
16
13
#
17
14
# You should have received a copy of the GNU General Public License along
18
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
"""Reactor installation for windows."""
20
 
 
21
 
# pylint: disable=E1101, F0401, W0404
22
 
 
23
 
import sys
 
16
 
 
17
"""Main method to be used on windows."""
24
18
 
25
19
from PyQt4 import QtGui, QtCore
26
 
from twisted.internet import defer
27
 
 
28
 
# Module used to include the resources into this file
29
 
# pylint: disable=W0611
30
 
from ubuntuone_installer.gui.qt.ui import images_rc
31
 
# pylint: enable=W0611
32
 
 
33
 
 
34
 
def stop(*args):
35
 
    """End the process."""
36
 
    from twisted.internet import reactor
37
 
    reactor.stop()
38
 
 
39
 
 
40
 
def error_cb(exc, logger):
41
 
    """Handle credentials errors."""
42
 
    logger.error(
43
 
    'Error while getting the credentials: %r', exc)
44
 
    stop()
45
 
 
46
 
 
47
 
@defer.inlineCallbacks
48
 
def success_cb(creds, gui, installing, logger, start_control_panel,
49
 
               check_updates):
50
 
    """Handle credentials success."""
51
 
    logger.debug('Got back from sso.')
52
 
    if creds:  # Have credentials already
53
 
        logger.debug('Already got credentials.')
54
 
        logger.info('Starting control panel.')
55
 
        start_control_panel(with_icon=False)
56
 
        logger.info('Checking updates.')
57
 
        yield check_updates(gui, logger)
58
 
        logger.info('Stopping.')
59
 
        stop()
60
 
    else:  # No credentials
61
 
        logger.debug('Did got connections.')
62
 
        window = gui.MainWindow(close_callback=stop, installing=installing)
63
 
        # Set Application Style Sheet
64
 
        app = QtGui.QApplication.instance()
65
 
        qss = QtCore.QResource(":/ubuntuone.qss")
66
 
        app.setStyleSheet(QtCore.QString(qss.data()))
67
 
        # Apply font to the entire application
68
 
        QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-R.ttf')
69
 
        QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-B.ttf')
70
 
        # Set Application Icon
71
 
        app.setWindowIcon(QtGui.QIcon(":/ubuntu_one_favicon.png"))
72
 
        window.show()
73
 
 
74
 
 
75
 
def main(installing=False):
76
 
    """Perform a client request to be logged in."""
77
 
    # pylint: disable=W0612
78
 
    app = QtGui.QApplication(sys.argv)
79
 
    # pylint: enable=W0612
80
 
    import qtreactor.qt4reactor
81
 
    qtreactor.qt4reactor.install()
82
 
    from ubuntuone_installer.gui.qt import gui
83
 
    from twisted.internet import reactor
84
 
    # All this has to be imported here because it installs a reactor
85
 
    from ubuntuone_installer.logger import setup_logging
86
 
    from ubuntuone_installer.gui.qt.utils import check_credentials
87
 
 
88
 
    logger = setup_logging('qt.gui')
89
 
    check_credentials(gui, logger, success_cb,
90
 
                      error_cb, installing)
91
 
    reactor.run()
 
20
 
 
21
 
 
22
def main(app):
 
23
    """Apply style sheet and fonts."""
 
24
    # Apply font to the entire application
 
25
    QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-R.ttf')
 
26
    QtGui.QFontDatabase.addApplicationFont(':/Ubuntu-B.ttf')
 
27
 
 
28
    # Set Application Icon
 
29
    app.setWindowIcon(QtGui.QIcon(":/ubuntu_one_favicon.png"))
 
30
 
 
31
    # Apply Style Sheet -- The windows version may be different
 
32
    qss = QtCore.QResource(":/ubuntuone.qss")
 
33
    app.setStyleSheet(qss.data())