1
0
mirror of https://github.com/thp/pyotherside.git synced 2025-02-05 08:08:23 +08:00

File browser example

This commit is contained in:
Thomas Perl 2011-05-24 05:52:05 -07:00
parent 4c2a031578
commit a8a5a71eee
2 changed files with 21 additions and 5 deletions

View File

@ -2,6 +2,6 @@
import os
import json
def demo():
return json.dumps(os.listdir('.'))
def demo(path='.'):
return json.dumps(['..'] + os.listdir(path))

View File

@ -5,14 +5,20 @@ import com.thpinfo.python 1.0
Rectangle {
width: 400
height: 400
color: 'blue'
ListView {
anchors.fill: parent
model: listModel
delegate: Text {
font.pixelSize: 30
text: pyValue
MouseArea {
anchors.fill: parent
onClicked: {
py.chdir(pyValue)
}
}
}
}
@ -22,10 +28,20 @@ Rectangle {
Python {
id: py
property string path: '.'
function chdir(newpath) {
path += '/' + newpath
listModel.clear()
var data = eval(py.evaluate('pyotherside.demo("'+path+'")'))
for (var i=0; i<data.length; i++) {
listModel.append({'pyValue': data[i]})
}
}
Component.onCompleted: {
py.importModule('pyotherside')
console.log(py.evaluate('pyotherside.demo()'))
var data = eval(py.evaluate('pyotherside.demo()'))
var data = eval(py.evaluate('pyotherside.demo("'+path+'")'))
for (var i=0; i<data.length; i++) {
listModel.append({'pyValue': data[i]})
}