Changeset 7620483


Ignore:
Timestamp:
05/14/12 00:31:27 (3 years ago)
Author:
Martin Kolman <martin.kolman@…>
Branches:
master
Children:
67f4304
Parents:
28a54b8
git-author:
Martin Kolman <martin.kolman@…> (05/14/12 00:31:27)
git-committer:
Martin Kolman <martin.kolman@…> (05/14/12 00:31:27)
Message:

support for calling simple getter functions on modRana modules directly from QML

Location:
modules/gui_modules/gui_qml
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • modules/gui_modules/gui_qml/gui_qml.py

    r87cd583 r7620483  
    118118    platform = Platform(self.modrana) 
    119119    rc.setContextProperty("platform", platform) 
     120    # make the modules accessible from QML 
     121    modules = Modules(self.modrana) 
     122    rc.setContextProperty("modules", modules) 
    120123    # make tile loading accessible from QML 
    121124    tiles = MapTiles(self) 
     
    262265    """ 
    263266    version = self.modrana.paths.getVersionString() 
    264     if version == None: 
     267    if version is None: 
    265268      return "unknown" 
    266269    else: 
    267270      return version 
    268  
    269   @QtCore.Slot(result=str) 
    270   def getPayPalUrl(self): 
    271     m = self.modrana.getModule("info") 
    272     if m: 
    273       return m.getPayPalUrl() 
    274     else: 
    275       # fallback to hardwired link 
    276       return "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=martin%2ekolman%40gmail%2ecom&lc=CZ&item_name=The%20modRana%20project&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" 
    277271 
    278272  #  @QtCore.Slot() 
     
    313307    return self.modrana.dmod.getDeviceIDString() == "n900" 
    314308 
     309class Modules(QtCore.QObject): 
     310  """ 
     311  modRana module access from QML 
     312  """ 
     313  def __init__(self, modrana): 
     314    QtCore.QObject.__init__(self) 
     315    self.modrana = modrana 
     316 
     317  @QtCore.Slot(str, str, result=str) 
     318  def getS(self, moduleName, functionName): 
     319    return self._mCall(moduleName, functionName) 
     320 
     321  @QtCore.Slot(str, str, result=bool) 
     322  def getB(self, moduleName, functionName): 
     323    return self._mCall(moduleName, functionName) 
     324 
     325  @QtCore.Slot(str, str, result=int) 
     326  def getI(self, moduleName, functionName): 
     327    return self._mCall(moduleName, functionName) 
     328 
     329  @QtCore.Slot(str, str, result=float) 
     330  def getF(self, moduleName, functionName): 
     331    return self._mCall(moduleName, functionName) 
     332 
     333  def _mCall(self, moduleName, functionName): 
     334    """ 
     335    call the getter function for a given module 
     336    """ 
     337    m = self.modrana.getModule(moduleName, None) 
     338    if m: 
     339      try: 
     340        function = getattr(m, functionName) 
     341        result = function() 
     342        return result 
     343      except Exception, e: 
     344        print("QML GUI: calling function %s on module %s failed" % (functionName, moduleName)) 
     345        print(e) 
     346        return None 
     347    else: 
     348      print("QML GUI: module %s not loaded" % moduleName) 
     349      return None 
    315350 
    316351class IconImageProvider(QDeclarativeImageProvider): 
  • modules/gui_modules/gui_qml/qml/InfoPage.qml

    r87cd583 r7620483  
    4747            onClicked : { 
    4848                console.log('donation button clicked') 
    49                 Qt.openUrlExternally(platform.getPayPalUrl()) 
     49                Qt.openUrlExternally(modules.getS("info", "getPayPalUrl")) 
    5050            } 
    5151        } 
Note: See TracChangeset for help on using the changeset viewer.