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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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) 
Note: See TracChangeset for help on using the changeset viewer.