~agateau/ubiquity/kde-rework-try-install-buttons

« back to all changes in this revision

Viewing changes to ubiquity/plugins/ubi-language.py

  • Committer: Aurélien Gâteau
  • Date: 2013-07-04 09:20:50 UTC
  • Revision ID: agateau@ubuntu.com-20130704092050-qqmmonamdi4r3arz
Much saner way to create big buttons.

Show diffs side-by-side

added added

removed removed

Lines of Context:
398
398
 
399
399
        try:
400
400
            from PyQt4 import uic
401
 
            from PyQt4.QtCore import Qt
402
 
            from PyQt4.QtGui import QWidget, QPixmap, QLabel, QVBoxLayout
403
 
            from PyQt4.QtGui import QSizePolicy, QLayout
 
401
            from PyQt4.QtGui import QWidget, QPixmap, QIcon
404
402
            self.page = uic.loadUi('/usr/share/ubiquity/qt/stepLanguage.ui')
405
403
            self.combobox = self.page.language_combobox
406
404
            self.combobox.currentIndexChanged[str].connect(
410
408
                self.page.oem_id_entry.hide()
411
409
 
412
410
            def init_big_button(button, image_name):
413
 
                """
414
 
                Hackishly turns an empty button into a big button, with a large
415
 
                padding.
416
 
 
417
 
                I tried to set the padding throught style.qss, but it also
418
 
                applies padding between the image and the text, which looks
419
 
                ugly.  This hackish code creates two QLabel inside the button
420
 
                and lay them out vertically. This makes it possible to define
421
 
                proper padding with setContentsMargins().
422
 
 
423
 
                It returns the text label so that its text can be updated when
424
 
                language changes.
425
 
                """
426
 
                pix = QPixmap("/usr/share/ubiquity/qt/images/" + image_name)
427
 
                img_label = QLabel()
428
 
                img_label.setPixmap(pix)
429
 
                img_label.setAlignment(Qt.AlignCenter)
430
 
                img_label.setMinimumSize(pix.size())
431
 
 
432
 
                text_label = QLabel()
433
 
                text_label.setAlignment(Qt.AlignCenter)
434
 
 
435
 
                layout = QVBoxLayout(button)
436
 
                layout.addWidget(img_label)
437
 
                layout.addWidget(text_label)
438
 
                layout.setContentsMargins(24, 24, 24, 24)
439
 
                layout.setSizeConstraint(QLayout.SetMinimumSize)
440
 
 
441
 
                return text_label
 
411
                pix = QPixmap('/usr/share/ubiquity/qt/images/' + image_name)
 
412
                icon = QIcon(pix)
 
413
                button.setIcon(icon)
 
414
                button.setIconSize(pix.size())
442
415
 
443
416
            def inst(*args):
444
 
                self.page.try_ubuntu_button.setEnabled(False)
 
417
                self.page.try_ubuntu.setEnabled(False)
445
418
                self.controller.go_forward()
446
 
 
447
 
            self.page.install_ubuntu_button.clicked.connect(inst)
448
 
            self.page.try_ubuntu_button.clicked.connect(
449
 
                self.on_try_ubuntu_clicked)
450
 
 
451
 
            self.try_ubuntu_label = init_big_button(
452
 
                self.page.try_ubuntu_button, "try.png")
453
 
            self.install_ubuntu_label = init_big_button(
454
 
                self.page.install_ubuntu_button, "install.png")
455
 
 
456
 
            self.try_ubuntu_label.setObjectName("try_ubuntu")
457
 
            self.install_ubuntu_label.setObjectName("install_ubuntu")
 
419
            self.page.install_ubuntu.clicked.connect(inst)
 
420
            self.page.try_ubuntu.clicked.connect(self.on_try_ubuntu_clicked)
 
421
            init_big_button(self.page.install_ubuntu, 'install.png')
 
422
            init_big_button(self.page.try_ubuntu, 'try.png')
458
423
 
459
424
            self.release_notes_url = ''
460
425
            self.update_installer = True
478
443
                self.page.release_notes_label.hide()
479
444
 
480
445
            if not 'UBIQUITY_GREETER' in os.environ:
481
 
                self.page.try_ubuntu_button.hide()
 
446
                self.page.try_ubuntu.hide()
482
447
                self.page.try_install_text_label.hide()
483
 
                self.page.install_ubuntu_button.hide()
 
448
                self.page.install_ubuntu.hide()
484
449
 
485
450
            if self.only:
486
451
                self.page.alpha_warning_label.hide()
508
473
        # Spinning cursor.
509
474
        self.controller.allow_change_step(False)
510
475
        # Queue quit.
511
 
        self.page.install_ubuntu_button.setEnabled(False)
 
476
        self.page.install_ubuntu.setEnabled(False)
512
477
        self.controller._wizard.current_page = None
513
478
        self.controller.dbfilter.ok_handler()
514
479
 
559
524
            self.combobox.setCurrentIndex(index)
560
525
 
561
526
        if not self.only and 'UBIQUITY_GREETER' in os.environ:
562
 
            self.page.try_ubuntu_button.setEnabled(True)
563
 
            self.page.install_ubuntu_button.setEnabled(True)
 
527
            self.page.try_ubuntu.setEnabled(True)
 
528
            self.page.install_ubuntu.setEnabled(True)
564
529
 
565
530
    def get_language(self):
566
531
        lang = self.selected_language()
585
550
            install_medium = misc.get_install_medium()
586
551
            install_medium = i18n.get_string(install_medium, lang)
587
552
            for widget in (self.page.try_install_text_label,
588
 
                           self.try_ubuntu_label,
589
 
                           self.install_ubuntu_label,
 
553
                           self.page.try_ubuntu,
 
554
                           self.page.install_ubuntu,
590
555
                           self.page.alpha_warning_label):
591
556
                text = widget.text()
592
557
                text = text.replace('${RELEASE}', release.name)