Last active
February 22, 2016 22:09
-
-
Save mottosso/970da50cfbc53a6359fd to your computer and use it in GitHub Desktop.
QML Console Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import contextlib | |
from PyQt5 import QtCore, QtGui, QtQuick | |
@contextlib.contextmanager | |
def application(): | |
app = QtGui.QGuiApplication(sys.argv) | |
yield | |
app.exec_() | |
class Model(QtCore.QAbstractListModel): | |
def __init__(self, items, parent=None): | |
super(Model, self).__init__(parent) | |
self._items = items | |
def rowCount(self, parent=None): | |
return len(self._items) | |
def data(self, index, role=QtCore.QModelIndex()): | |
if role == QtCore.Qt.UserRole + 0: | |
return self._items[index.row()] | |
def roleNames(self): | |
return { | |
QtCore.Qt.UserRole + 0: "line", | |
} | |
if __name__ == '__main__': | |
import json | |
with open("data.json") as f: | |
data = json.load(f) | |
qml = QtCore.QUrl.fromLocalFile("console.qml") | |
with application(): | |
window = QtQuick.QQuickView() | |
window.setTitle("Console") | |
window.setResizeMode(window.SizeRootObjectToView) | |
engine = window.engine() | |
context = engine.rootContext() | |
model = Model(data * 2000) # Loads of items | |
context.setContextProperty("myModel", model) | |
window.setSource(qml) | |
window.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.3 | |
Rectangle { | |
width: 500 | |
height: 300 | |
color: "steelblue" | |
ListView { | |
id: listview | |
anchors.fill: parent | |
anchors.margins: 5 | |
model: myModel | |
delegate: Text { | |
text: line | |
width: ListView.view.width | |
} | |
} | |
Scrollbar { | |
flickable: listview | |
anchors.top: parent.top | |
anchors.bottom: parent.bottom | |
anchors.right: parent.right | |
width: 25 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
"Bye bye!", | |
"rostikL Sep 02 15:36", | |
"Hello Marcus!", | |
"I have a quick question: Would it be ok for you if we postpone the start to the next Monday?", | |
"I have a deadline till Friday for a few documents and I don't think I will make it.", | |
"Would it be ok for you? Let me know. If not, i will try to move a few things around.", | |
"mottosso Sep 02 15:37", | |
"Hey Rostik", | |
"Oh, okay", | |
"Yes, sure, that's ok", | |
"rostikL Sep 02 15:37", | |
"Thanks!", | |
"mottosso Sep 02 15:38", | |
"It would be best if we could decide on 2 days up-front, so I can better manage my schedule", | |
"rostikL Sep 02 15:38", | |
"Yehh, sorry.", | |
"mottosso Sep 02 15:38", | |
"These things are probably something good for a contract of sorts", | |
"No worries, we'll work it out as we go", | |
"rostikL Sep 02 15:38", | |
"If you have already planned everything out, We can start tomorrow", | |
"but I won't be able to stay the whole day", | |
"if that's ok?", | |
"mottosso Sep 02 15:39", | |
"No that's ok, don't worry, do what you got to do", | |
"rostikL Sep 02 15:39", | |
"This way we can keep Thursday and Friday, so your schedule stays the same", | |
"mottosso Sep 02 15:40", | |
"I wouldn't want you to stress", | |
"rostikL Sep 02 15:40", | |
"That would be ok.", | |
"mottosso Sep 02 15:40", | |
"Ok, how would you like to proceed?", | |
"Thursday or Monday?", | |
"rostikL Sep 02 15:41", | |
"Monday to be honest. And from then on every Monday/Tuesday?", | |
"so, your schedule is always the same", | |
"mottosso Sep 02 15:41", | |
"Ok, let's do that", | |
"I've got lots of things to fill the comings days with, this works well for me too", | |
"rostikL Sep 02 15:42", | |
"perfekt, thanks. Sorry for the inconvinience", | |
"mottosso Sep 02 15:42", | |
"No problem, so Monday/Tuesday? Or Monday/Friday? Next week that is", | |
"rostikL Sep 02 15:42", | |
"What days are better for you?", | |
"We can do Monday/Thursday?", | |
"mottosso Sep 02 15:43", | |
"I think consecutive days would be better concentration-wise, what do you think?", | |
"rostikL Sep 02 15:43", | |
"so, during the week I can work on things and ask you on Thursday :-)", | |
"mottosso Sep 02 15:43", | |
"Ok, let's do that :)", | |
"rostikL Sep 02 15:43", | |
"ok, great.", | |
"mottosso Sep 02 15:43", | |
"Done", | |
"rostikL Sep 02 15:44", | |
"Thanks!", | |
"Till next monday then! Have a nice day", | |
"mottosso Sep 02 15:44", | |
"No problem", | |
"You too, talk soon!", | |
"rostikL Sep 02 15:44", | |
"bye!", | |
"mottosso Sep 07 09:00", | |
"Good morning @rostikL!", | |
"rostikL Sep 07 09:00", | |
"Good morning, Marcus!", | |
"Was about to write you", | |
"mottosso Sep 07 09:00", | |
"How's things?", | |
"rostikL Sep 07 09:01", | |
"but your were faster", | |
"mottosso Sep 07 09:01", | |
"Hehe", | |
"Was staring at the clock!", | |
"rostikL Sep 07 09:01", | |
"Hehe, me too :-)", | |
"How are you?", | |
"mottosso Sep 07 09:01", | |
"All good", | |
"Had a nice weekend of C++", | |
"rostikL Sep 07 09:02", | |
"So do you hate the world now? Like most people feel after c++ :-)", | |
"mottosso Sep 07 09:02", | |
"Hah, no not at all", | |
"I like it a lot", | |
"rostikL Sep 07 09:02", | |
"then you are an exception", | |
"mottosso Sep 07 09:03", | |
"Hehe, I get the feeling most of the hate comes from pre-c++11", | |
"rostikL Sep 07 09:03", | |
"possible", | |
"mottosso Sep 07 09:03", | |
"How was your weekend?", | |
"rostikL Sep 07 09:04", | |
"Ok. Had to work on a few documents", | |
"But now it's done", | |
"so i am happy", | |
"mottosso Sep 07 09:04", | |
"Documents", | |
"Sounds boring", | |
"Paperwork", | |
"rostikL Sep 07 09:04", | |
"Yes.", | |
"mottosso Sep 07 09:05", | |
"The API of humans", | |
"rostikL Sep 07 09:05", | |
"hehe", | |
"Had to be done", | |
"mottosso Sep 07 09:05", | |
"Good", | |
"Should we get right to it?", | |
"Oh actually there is one thing", | |
"rostikL Sep 07 09:06", | |
"yes", | |
"?", | |
"mottosso Sep 07 09:06", | |
"I might be heading out for a project soon", | |
"This is the part where 2 days a week serves it's purpose, it means I might be busy during weekdays", | |
"rostikL Sep 07 09:07", | |
"Ahh, so you can still work with us?", | |
"mottosso Sep 07 09:08", | |
"If it's allright with you, I could do DICE on Saturdays and Sundays", | |
"Of course", | |
"rostikL Sep 07 09:08", | |
"For me these are workdays too, so that wouldn't be a problem", | |
"mottosso Sep 07 09:08", | |
"Just that it might be difficult on weekdays", | |
"Haha", | |
"When do you take a break?", | |
"rostikL Sep 07 09:08", | |
"Next year I hope :smile:", | |
"mottosso Sep 07 09:08", | |
"Hehe, ok, perfect", | |
"Was dreading to tell you", | |
"But it's a really great project", | |
"rostikL Sep 07 09:09", | |
"No, some sundays I have to pause", | |
"mottosso Sep 07 09:09", | |
"Difficult to pass up", | |
"rostikL Sep 07 09:09", | |
"But would it be just for a month?", | |
"or longer?", | |
"mottosso Sep 07 09:09", | |
"At least a month, at most three", | |
"Expecting to hear from them tomorrow morning", | |
"rostikL Sep 07 09:10", | |
"and you will work from Monday to Friday?", | |
"mottosso Sep 07 09:10", | |
"Exactly", | |
"rostikL Sep 07 09:11", | |
"Ok, I have to discuss it with my collegues", | |
"mottosso Sep 07 09:11", | |
"Please do", | |
"rostikL Sep 07 09:11", | |
"but I think if we plan everything out, it could work", | |
"mottosso Sep 07 09:11", | |
"Me too", | |
"rostikL Sep 07 09:11", | |
"But when do you take a break?", | |
"mottosso Sep 07 09:12", | |
"Next year I hope", | |
"rostikL Sep 07 09:12", | |
"If you work from Monday till Sunday?", | |
"mottosso Sep 07 09:12", | |
";)", | |
"rostikL Sep 07 09:12", | |
"haha", | |
"mottosso Sep 07 09:12", | |
"Let's kickstart today?", | |
"rostikL Sep 07 09:12", | |
"ok", | |
"mottosso Sep 07 09:13", | |
"Were we splitting up the repo in GitHub?", | |
"rostikL Sep 07 09:13", | |
"should we do a hangout (now/later?) or do your prefer writing?", | |
"mottosso Sep 07 09:13", | |
"I figured we'd write", | |
"We could talk if you'd like", | |
"rostikL Sep 07 09:13", | |
"I think it could be faster", | |
"mottosso Sep 07 09:14", | |
"Let's do it", | |
"rostikL Sep 07 09:14", | |
"ok", | |
"I'll call you", | |
"mottosso Sep 09 09:09", | |
"Hey @rostikL, sorry for not getting back sooner, I'm still awaiting to hear back about the project.", | |
"I'll get back to you as soon as I know anything, but it's safe to say I'll be here tomorrow", | |
"rostikL Sep 09 09:12", | |
"Hi Marcus!", | |
"No problem. Thanks for the info.", | |
"rostikL 14:13", | |
"Quick question: Should we work tomorrow or move it to another day? What is best for you?", | |
"mottosso 14:14", | |
"Tomorrow works well for me", | |
"rostikL 14:14", | |
"Ok, great. Looking forward to it.", | |
"mottosso 14:14", | |
"I won't be heading anywhere until Monday, earliest", | |
"Me too", | |
"rostikL 14:15", | |
"I have already separated the repos and created submodules, looks really nice now", | |
"mottosso 14:15", | |
"Ah, that's great :smile:", | |
"mottosso 19:02", | |
"Ok, so I'm heading down on Monday, staying until 13th October, possibly but unlikely longer", | |
"Just wanted to let you know!", | |
"Working on finding a place to sleep and work with you on the weekends now, will let you know how that turns out.", | |
"rostikL 19:07", | |
"Ok. Thanks. Only until 13th October is not much anyway, only 4 weeks :smile:", | |
"Will be over before you know it", | |
"Talk to you tomorrow!", | |
"rostikL 08:57", | |
"Hi, Marcus. I'll be a little late at my PC, in about 30min.", | |
"mottosso 08:57", | |
"Hi Rostik, no problem, see you in a bit!", | |
"rostikL 09:30", | |
"Ok, i am here. Hi!", | |
"mottosso 09:30", | |
"Hey!", | |
"30 mins on the dot", | |
"I like punctuality :smile:", | |
"I'm working on a console example" | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.3 | |
Item { | |
property Flickable flickable | |
visible: flickable.visibleArea.heightRatio < 1.0 | |
MouseArea { | |
id: handle | |
Rectangle { | |
anchors.fill: parent | |
color: "yellow" | |
} | |
anchors.left: parent.left | |
anchors.right: parent.right | |
width: 20 | |
height: Math.max(30, flickable.visibleArea.heightRatio * flickable.height) | |
y: !drag.active && !isNaN(flickable.visibleArea.heightRatio) ? (drag.maximumY * flickable.contentY) / (flickable.contentHeight * (1 - flickable.visibleArea.heightRatio)) : 0 | |
drag.target: handle | |
drag.axis: Drag.YAxis | |
drag.minimumY: 0 | |
drag.maximumY: flickable.height - handle.height | |
} | |
Binding { | |
target: flickable | |
property: "contentY" | |
value: ((flickable.contentHeight * (1 - flickable.visibleArea.heightRatio)) * handle.y) / handle.drag.maximumY | |
when: !flickable.moving && handle.drag.active && flickable !== undefined | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment