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:
parent
4c2a031578
commit
a8a5a71eee
@ -2,6 +2,6 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
def demo():
|
||||
return json.dumps(os.listdir('.'))
|
||||
def demo(path='.'):
|
||||
return json.dumps(['..'] + os.listdir(path))
|
||||
|
||||
|
@ -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]})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user