Changeset 11532:68ae91b09f62 in orange


Ignore:
Timestamp:
05/17/13 20:27:25 (11 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Set the application version from the package info and display it in the splash screen.

Location:
Orange/OrangeCanvas
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/application/aboutdialog.py

    r11122 r11532  
    66import pkg_resources 
    77 
    8 from PyQt4.QtGui import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QPixmap 
     8from PyQt4.QtGui import QDialog, QDialogButtonBox, QVBoxLayout, QLabel 
    99from PyQt4.QtCore import Qt 
    1010 
    11  
    12 import Orange 
    13 from Orange import OrangeCanvas 
     11from .. import config 
    1412 
    1513ABOUT_TEMPLATE = """\ 
     
    3634        label = QLabel(self) 
    3735 
    38         filename = pkg_resources.resource_filename( 
    39                         OrangeCanvas.__name__, 
    40                         "icons/orange-splash-screen.png") 
     36        pixmap, _ = config.splash_screen() 
    4137 
    42         label.setPixmap(QPixmap(filename)) 
     38        label.setPixmap(pixmap) 
     39 
    4340        layout.addWidget(label, Qt.AlignCenter) 
    4441 
  • Orange/OrangeCanvas/config.py

    r11527 r11532  
    1111import pkg_resources 
    1212 
    13 from PyQt4.QtGui import QDesktopServices 
    14 from PyQt4.QtCore import QCoreApplication 
     13from PyQt4.QtGui import ( 
     14    QDesktopServices, QPainter, QFont, QFontMetrics, QColor, QPixmap 
     15) 
     16 
     17from PyQt4.QtCore import Qt, QCoreApplication, QPoint, QRect 
    1518 
    1619from .utils.settings import Settings, config_slot 
     
    2326 
    2427def init(): 
    25     """Initialize the QCoreApplication.organizationDomain, applicationName, 
     28    """ 
     29    Initialize the QCoreApplication.organizationDomain, applicationName, 
    2630    applicationVersion and the default settings format. Will only run once. 
    2731 
     
    3034 
    3135    """ 
    32     # Set application name, version and org. domain 
     36    dist = pkg_resources.get_distribution("Orange") 
     37    version = dist.version 
     38    # Use only major.minor 
     39    version = ".".join(version.split(".", 2)[:2]) 
     40 
    3341    QCoreApplication.setOrganizationDomain("biolab.si") 
    3442    QCoreApplication.setApplicationName("Orange Canvas") 
    35     QCoreApplication.setApplicationVersion("2.6") 
     43    QCoreApplication.setApplicationVersion(version) 
    3644    QSettings.setDefaultFormat(QSettings.IniFormat) 
    3745 
     
    236244             ] 
    237245    return itertools.chain(*chain) 
     246 
     247 
     248def splash_screen(): 
     249    """ 
     250    """ 
     251    pm = QPixmap( 
     252        pkg_resources.resource_filename( 
     253            __name__, "icons/orange-splash-screen.png") 
     254    ) 
     255 
     256    version = QCoreApplication.applicationVersion() 
     257    size = 21 if len(version) < 5 else 16 
     258    font = QFont("Helvetica") 
     259    font.setPixelSize(size) 
     260    font.setBold(True) 
     261    font.setItalic(True) 
     262    font.setLetterSpacing(QFont.AbsoluteSpacing, 2) 
     263    metrics = QFontMetrics(font) 
     264    br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0) 
     265    br.moveCenter(QPoint(436, 224)) 
     266 
     267    p = QPainter(pm) 
     268    p.setRenderHint(QPainter.Antialiasing) 
     269    p.setRenderHint(QPainter.TextAntialiasing) 
     270    p.setFont(font) 
     271    p.setPen(QColor("#231F20")) 
     272    p.drawText(br, Qt.AlignCenter, version) 
     273    p.end() 
     274    return pm, QRect(88, 193, 200, 20) 
  • Orange/OrangeCanvas/main.py

    r11522 r11532  
    1616 
    1717from PyQt4.QtGui import QFont, QColor 
    18 from PyQt4.QtCore import Qt, QRect, QDir 
     18from PyQt4.QtCore import Qt, QDir 
    1919 
    2020from Orange import OrangeCanvas 
     
    2323from Orange.OrangeCanvas.application.outputview import TextStream, ExceptHook 
    2424 
    25 from Orange.OrangeCanvas.gui.splashscreen import SplashScreen, QPixmap 
     25from Orange.OrangeCanvas.gui.splashscreen import SplashScreen 
    2626from Orange.OrangeCanvas.config import cache_dir 
    2727from Orange.OrangeCanvas import config 
     
    198198 
    199199    if want_splash: 
    200         pm = QPixmap(pkg_resources.resource_filename( 
    201                         __name__, "icons/orange-splash-screen.png") 
    202                      ) 
    203         # Text rectangle in which to fit the message. 
    204         rect = QRect(88, 193, 200, 20) 
     200        pm, rect = config.splash_screen() 
    205201        splash_screen = SplashScreen(pixmap=pm, textRect=rect) 
    206202        splash_screen.setFont(QFont("Helvetica", 12)) 
Note: See TracChangeset for help on using the changeset viewer.