Commits

Peter Hansen committed fdbddfe

first running "PyCades" experiment...

Comments (0)

Files changed (2)

LitePOC/lite/main.py

 
 from ctypes import *
 
-BBPYPATH = 'shared/misc/blackberry-py'
-# BBPYPATH = 'app/python/blackberry-py'
-
-if sys.platform == 'qnx6':
-    os.environ['LD_LIBRARY_PATH'] = os.path.join(BBPYPATH, 'lib')
-    os.environ['QT_PLUGIN_PATH'] = os.path.join(BBPYPATH, 'plugins')
-    os.environ['QML_IMPORT_PATH'] = os.path.join(BBPYPATH, 'imports')
-    os.environ['QT_QPA_PLATFORM'] = 'blackberry'
-
-# from pprint import pprint
-# pprint(dict(os.environ), stream=sys.stderr)
-# pprint(sys.path, stream=sys.stderr)
-# pprint(os.getcwd(), stream=sys.stderr)
-# pprint(sys.argv, stream=sys.stderr)
-# sys.stderr.flush()
-
 qtcore = CDLL('libQtCore.so.4')
-qtgui = CDLL('libQtGui.so.4')
+qtcascades = CDLL('libQtCascades.so')
 qtdecl = CDLL('libQtDeclarative.so.4')
-bb = CDLL(os.path.join(os.environ['QT_PLUGIN_PATH'], 'platforms/libblackberry.so'))
 
 qDebug = qtcore._Z6qDebugPKcz
 qMalloc = qtcore._Z7qMallocj
 QUrl_constructor = qtcore._ZN4QUrlC1ERK7QString
 QThread_initialize = qtcore._ZN7QThread10initializeEv
 QCoreApplication_startingUp = qtcore._ZN16QCoreApplication10startingUpEv
+QCoreApplication_exec = qtcore._ZN16QCoreApplication4execEv
 
-QApplication_constructor = qtgui._ZN12QApplicationC1ERiPPc
-QApplication_exec = qtgui._ZN12QApplication4execEv
-QWidget_setVisible = qtgui._ZN7QWidget10setVisibleEb
-QApplication_type = qtgui._ZN12QApplication4typeEv
-QWidget_showFullScreen = qtgui._ZN7QWidget14showFullScreenEv
-
-QDeclarativeView_constructor = qtdecl._ZN16QDeclarativeViewC1EP7QWidget
-QDeclarativeView_setSource = qtdecl._ZN16QDeclarativeView9setSourceERK4QUrl
-QDeclarativeView_setResizeMode = qtdecl._ZN16QDeclarativeView13setResizeModeENS_10ResizeModeE
-
-ResizeMode_SizeViewToRootObject = 0
-ResizeMode_SizeRootObjectToView = 1
+Application_constructor = qtcascades._ZN2bb8cascades11ApplicationC1ERiPPc
+Application_setScene = qtcascades._ZN2bb8cascades11Application8setSceneEPNS0_12AbstractPaneE
+QmlDocument_constructor = qtcascades._ZN2bb8cascades11QmlDocumentC1Ev
+QmlDocument_load = qtcascades._ZN2bb8cascades11QmlDocument4loadERK7QString
+QmlDocument_hasErrors = qtcascades._ZN2bb8cascades11QmlDocument9hasErrorsEv
+QmlDocument_createRootNode = qtcascades._ZN2bb8cascades11QmlDocument14createRootNodeINS0_8UIObjectEEEPT_P19QDeclarativeContext
 
 def bLog(msg):
     qDebug(msg.encode('ascii'))
             argv_0_p = c_char_p(argv_0)
             argv = pointer(argv_0_p)
 
-            bLog('gui used? {0.value}'.format(c_long.in_dll(qtgui, 'qt_is_gui_used')))
-
             # QThread_initialize()
 
             # sizeof(Qapplication) == 8
             app = qMalloc(8)
-            QApplication_constructor(app, byref(argc), argv)
+            Application_constructor(app, byref(argc), argv)
 
             bLog('starting up: {}'.format(QCoreApplication_startingUp()))
-            bLog('gui used? {0.value}'.format(c_long.in_dll(qtgui, 'qt_is_gui_used')))
-            bLog('qt_appType {}'.format(QApplication_type()))
 
-            p = os.path.join(os.path.dirname(__file__), 'main.qml')
+            # The QmlDocument.load() routine seems to insist on the file
+            # being stored in app/native/assets, which we don't have, so
+            # we have to use a relative path to get up out of there.
+            # It ignores attempts at making absolute paths.
+            p = '../../python/lite/main.qml'
 
             # Python is using 32-bit chars on QNX (UTF32) whereas
             # Qt things QChars are 16-bit, so we need some hackery
             qs1 = qMalloc(8)
             QString_QChar_p(qs1, buf)
 
-            # sizeof(QUrl) == 8
-            qurl = qMalloc(8)
-            QUrl_constructor(qurl, qs1)
+            qml = qMalloc(32)
+            QmlDocument_constructor(qml)
 
-            # sizeof(QDeclarativeView) == 20
-            view = qMalloc(20)
-            QDeclarativeView_constructor(view, None)
+            rc = QmlDocument_load(qml, qs1)
+            bLog('load rc = {}'.format(rc))
 
-            QDeclarativeView_setSource(view, qurl)
+            if not QmlDocument_hasErrors(qml):
+                page = QmlDocument_createRootNode(qml, None)
+                bLog('page = {}'.format(page))
+                if page:
+                    Application_setScene(page)
 
-            # Note: the default of SizeViewToRootObject, or using just show()
-            # or setVisible(1) instead of showFullScreen(), results in the QML
-            # root element not having a size, or being resized properly when
-            # you rotate the device
-            QDeclarativeView_setResizeMode(view, ResizeMode_SizeRootObjectToView)
-            QWidget_showFullScreen(view)
-
-            QApplication_exec(app)
+            rc = QCoreApplication_exec(app)
+            bLog('rc = {}'.format(rc))
 
         finally:
             bLog('app.run() done!')
 
 
+
 def main():
     global app # make it global so CLI can find it
     app = App()
     app.run()
 
-
-# launch telnet-based command line interface (CLI)
-# if '--cli' in sys.argv:
-#     try:
-#         import cli
-#     except ImportError:
-#         print('unable to import cli, ignoring --cli option', file=sys.stderr)
-#     else:
-#         import threading
-#         t = threading.Thread(target=cli.run)
-#         t.daemon = True
-#         t.start()

LitePOC/lite/main.qml

-import QtQuick 1.1
-Rectangle {
-    Text {
-        anchors.centerIn: parent
-        text: "This way up \u2191 (size " + parent.width + "x" + parent.height + ")"
-        font.pixelSize: parent.width * 0.05
+import bb.cascades 1.0
+
+Page {
+    id: root
+
+    content: Container {
+        layout: DockLayout {
+        }
+
+        background: Color.create("#ab8743")
+
+        TextArea {
+            text: "This way up \u2191 (size " + parent.width + "x" + parent.height + ")"
+            editable: false
+            backgroundVisible: false
+
+            layoutProperties: DockLayoutProperties {
+                horizontalAlignment: HorizontalAlignment.Fill
+                verticalAlignment: VerticalAlignment.Center
+            }
+        }
     }
 }