Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

added wx hello world sample #142

Closed
wants to merge 2 commits into from

2 participants

@schuster-rainer

added a basic example app of how to use wx from clojure-py

@anntzer

Fine for me but we can probably do a single merge with both the wx and the qml examples.
Also, while you're at it, can you have a look at pyside/tutorial/t1.clj? I think it got broken when I changed the import semantics some time ago :-)

Rainer Schuster added pyside qml hello world and fixed t1.clj
imports of examples/pyside/tutorial/t1.clj where broken
97cc12a
@anntzer anntzer commented on the diff
examples/pyside/qml/helloqml.clj
@@ -0,0 +1,14 @@
+; sample taken from http://doc.qt.nokia.com/4.7-snapshot/qml-tutorial2.html
+(ns exampes.pyside.qml.helloqml
+ (:require [PySide.QtGui :as gui]
+ [PySide.QtDeclarative :as decl]
+ [PySide.QtCore :as core]))
+
+
+(let [app (gui/QApplication sys/argv)
+ view (decl/QDeclarativeView)]
+ (.setWindowTitle view "PySide/QML/clojure-py")
+ (.setSource view (.fromLocalFile core/QUrl "helloqml.qml"))
@anntzer
anntzer added a note

Can you use the absolute path (ie using __file__) here, to allow running the example from any folder?

__file__ doesn't work on my machine (win7 x64). getting "<interactive namespace>" as filename. Have to figure out what's wrong here.

tried this code:

(ns pathtest
  (:require [os.path]))

; that's the approach I'm normally used to take
; os.path.dirname(os.path.abspath(__file__))
(defn -main [& args]
  (->> __file__
    ; (.dirname os/path)
    prn))

(-main)
@anntzer
anntzer added a note

Oops. I think I know what is wrong: __file__ is simply never set for clojure namespaces to the right value. Will have to work on that as well (or you can have a look at namespace.py and main.py (the import hook part), where the culprit is (I think)).
Can you open a bug for that?

I'll open a bug. Already had a quick look at it, but couldn't figure it out. Will have a look into later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@anntzer anntzer closed this pull request from a commit
@anntzer anntzer Fix equality between {} and [], fix #169.
(closes #142 at the same time.)
60689b4
@anntzer anntzer closed this in 60689b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 30, 2012
  1. added wx hello world sample

    Rainer Schuster authored
Commits on Oct 31, 2012
  1. added pyside qml hello world and fixed t1.clj

    Rainer Schuster authored
    imports of examples/pyside/tutorial/t1.clj where broken
This page is out of date. Refresh to see the latest.
View
20 examples/pyside/qml/Cell.qml
@@ -0,0 +1,20 @@
+import QtQuick 1.1
+
+Item {
+ id: container
+ property alias cellColor: rectangle.color
+ signal clicked(color cellColor)
+
+ width: 40; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: container.clicked(container.cellColor)
+ }
+}
View
14 examples/pyside/qml/helloqml.clj
@@ -0,0 +1,14 @@
+; sample taken from http://doc.qt.nokia.com/4.7-snapshot/qml-tutorial2.html
+(ns exampes.pyside.qml.helloqml
+ (:require [PySide.QtGui :as gui]
+ [PySide.QtDeclarative :as decl]
+ [PySide.QtCore :as core]))
+
+
+(let [app (gui/QApplication sys/argv)
+ view (decl/QDeclarativeView)]
+ (.setWindowTitle view "PySide/QML/clojure-py")
+ (.setSource view (.fromLocalFile core/QUrl "helloqml.qml"))
@anntzer
anntzer added a note

Can you use the absolute path (ie using __file__) here, to allow running the example from any folder?

__file__ doesn't work on my machine (win7 x64). getting "<interactive namespace>" as filename. Have to figure out what's wrong here.

tried this code:

(ns pathtest
  (:require [os.path]))

; that's the approach I'm normally used to take
; os.path.dirname(os.path.abspath(__file__))
(defn -main [& args]
  (->> __file__
    ; (.dirname os/path)
    prn))

(-main)
@anntzer
anntzer added a note

Oops. I think I know what is wrong: __file__ is simply never set for clojure namespaces to the right value. Will have to work on that as well (or you can have a look at namespace.py and main.py (the import hook part), where the culprit is (I think)).
Can you open a bug for that?

I'll open a bug. Already had a quick look at it, but couldn't figure it out. Will have a look into later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ (.setResizeMode view (.-SizeRootObjectToView decl/QDeclarativeView))
+ (.show view)
+ (sys/exit (.exec_ app)))
View
49 examples/pyside/qml/helloqml.qml
@@ -0,0 +1,49 @@
+import QtQuick 1.1
+
+Rectangle {
+ id: page
+ width: 500; height: 200
+ color: "lightgray"
+
+ Text {
+ id: helloText
+ text: "Hello world!"
+ y: 30
+ anchors.horizontalCenter: page.horizontalCenter
+ font.pointSize: 24; font.bold: true
+
+ MouseArea {
+ id: mouseArea;
+ anchors.fill: parent;
+ onClicked: {
+ console.log("Mouse clicked!", parent.color)
+ }
+ }
+
+ states: State {
+ name: "down"; when: mouseArea.pressed == true
+ PropertyChanges { target: helloText; y: 160; rotation: 180; color: "red" }
+ }
+
+ transitions: Transition {
+ from: ""; to: "down"; reversible: true
+ ParallelAnimation {
+ NumberAnimation { properties: "y,rotation"; duration: 500; easing.type: Easing.InOutQuad }
+ ColorAnimation { duration: 500 }
+ }
+ }
+ }
+
+ Grid {
+ id: colorPicker
+ x: 4; anchors.bottom: page.bottom; anchors.bottomMargin: 4
+ rows: 2; columns: 3; spacing: 3
+
+ Cell { cellColor: "red"; onClicked: helloText.color = cellColor }
+ Cell { cellColor: "green"; onClicked: helloText.color = cellColor }
+ Cell { cellColor: "blue"; onClicked: helloText.color = cellColor }
+ Cell { cellColor: "yellow"; onClicked: helloText.color = cellColor }
+ Cell { cellColor: "steelblue"; onClicked: helloText.color = cellColor }
+ Cell { cellColor: "black"; onClicked: helloText.color = cellColor }
+ }
+}
View
6 examples/pyside/tutorial/t1.clj
@@ -1,11 +1,11 @@
(ns examples.pyside.tutorial.t1
- (:require [PySide.QtGui :only [QApplication QPushButton]]))
+ (:require [PySide.QtGui :as gui]))
-(let [app (QApplication sys/argv)
- hello (QPushButton "Hello world!")]
+(let [app (gui/QApplication sys/argv)
+ hello (gui/QPushButton "Hello world!")]
(.resize hello 100 30)
(.show hello)
(sys/exit (.exec_ app)))
View
16 examples/wx/hello-wx.clj
@@ -0,0 +1,16 @@
+(ns hello-wx
+ (:require [wx]))
+
+(let [app (wx/App.)
+ frame (wx/Frame. nil wx/ID_ANY "hello world!")
+ txt (wx/TextCtrl. frame
+ wx/ID_ANY
+ wx/EmptyString
+ wx/DefaultPosition
+ [300 200]
+ (or wx/TE_AUTO_URL
+ wx/TE_CHARWRAP
+ wx/TE_MULTILINE))]
+ (.SetValue txt "clojure-py says hello to wx.Python")
+ (.Show frame)
+ (.MainLoop app))
Something went wrong with that request. Please try again.