Order of #animate and #layout in Julia - layout

I want to ask about the mechanism of the following errors.
The code
lay = #layout [a{0.4h}; grid(2,2)]
#animate for...
plot(..., layout = lay)
end
in Jupyter produces an animation with only one frame (the rest of frames are blank). There are no error messages in Jupyter.
The code
#animate for...
lay = #layout [a{0.4h}; grid(2,2)]
plot(..., layout = lay)
end
works fine. Why? Isn't this inefficient?

Related

Waiting Screen while data is being extracted from an API

I have created a Python Script to download data using an API. And I have put a simple GUI on top of it as well using PySimpleGUI.
However, while the data is being downloaded, I want to show a indeterminate progressbar or something like that, which will exit on its own after the download completes.
Is there any way to implement this requirement?
Two ways easily for it, element sg.ProgressBar or simple sg.Text with different length of string, maybe █, to show the state of progress.
Demo_Progress_Meters
or
from random import randint
import PySimpleGUI as sg
sg.theme('DarkBlue')
layout = [[sg.Text('', size=(50, 1), relief='sunken', font=('Courier', 11),
text_color='yellow', background_color='black',key='TEXT')]]
window = sg.Window('Title', layout, finalize=True)
text = window['TEXT']
state = 0
while True:
event, values = window.read(timeout=100)
if event == sg.WINDOW_CLOSED:
break
state = (state+1)%51
text.update('█'*state)
window.close()
Note: remember to use monospaced font, otherwise the length of sg.Text will be different as length of state string.
Depend on progress of job to set state of progress.

Adding GraphicsObject to two ViewBoxes or QGraphicsViews

Ultimately I want pyqtgraph to display a single GraphicsObject simultaneously in several ViewBoxes, sharing a single scene.
At the same time I want to have some other GraphicsObjects in a single ViewBox only.
Something like this:
vb0 = ViewBox()
vb1 = ViewBox()
# shown only in first ViewBox vb0
local_item = GraphicsObject()
# shown in all ViewBoxes
global_item = GraphicsObject()
vb0.addItem(local_item)
assert vb0.scene() is vb1.scene()
# the magic function i am looking for
vb0.scene().addItemGlobally(global_item)
So very naively I looked into the ViewBox sourcecode and reproduced the steps for addItem() like here:
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore as qc, QtGui as qg, QtWidgets as qw
class Polygon(pg.GraphicsObject):
"""Just a Triangle..."""
app = qw.QApplication([])
viewer = pg.GraphicsWindow()
vb0 = viewer.addViewBox(0, 0)
vb1 = viewer.addViewBox(0, 1)
viewer.show()
poly_yellow = Polygon((125, 125, 0, 255))
scene = vb0.scene()
added_items = vb1.addedItems = vb0.addedItems
child_group = vb1.childGroup = vb0.childGroup
child_group.setParent(scene)
child_group.itemsChangedListeners.append(vb1)
# here reproducing steps found in addItem()
if scene is not poly_yellow.scene():
scene.addItem(poly_yellow)
poly_yellow.setParentItem(child_group)
added_items.append(poly_yellow)
vb0.updateAutoRange()
# vb1.updateAutoRange()
# checking if ViewBoxes share relevant attributes
assert vb0.scene() is vb1.scene()
assert vb0.scene() is poly_yellow.scene()
assert vb0.addedItems is vb1.addedItems
assert vb0.childGroup is vb1.childGroup
app.exec_()
Running this gives me two ViewBoxes, but only vb0 showing the triangle. Also this approach would give me global only Items. Is there any way to get something like local/global items without re-implementing ViewBoxes completely?
EDIT: I think it is impossible to achieve what I want with pyqtgraph ViewBoxes. A transform of the global items must happen just before the painting.
I found it is not easily doable using ViewBox. However, it is possible to us pyqtgraphs GraphicsView, implementing a lot of functionality found in the ViewBox class already.
My approach now is to generate as many GraphicsView as I need, and set them all to one scene via GraphicsView.setScene()
The scene contains the 'global' items, displayed in every View. The Viewspecific, local Items are drawn using the GraphicsView.drawBackground() function.
I haven't tested it to much, but it seems quite good working, for the case, were several thousend items are added to the scene, but only few items are drawn to the background.

PyQt QScrollArea doesn't display widgets

I am somewhat new to GUI programming and very new to PyQt, and I'm trying to build a GUI that displays a list of questions. I have created a QuestionBank class that subclasses QWidget and overrides the .show() method to display the list properly. I have tested this alone and it works correctly. However, the list of questions can be quite long, so I've been trying to make it scrollable. Rather than add a QScrollBar to the widget and then set up the event triggers by hand, I've been trying to my QuestionBank widget in a QScrollArea based on the syntax I've seen in examples online. While the scroll area shows up fine, it does not at all display the question bank but rather just shows a blank outline.
The QuestionBank class looks like this:
class QuestionBank(QWidget):
BUFFER = 10 # space between questions (can be modified)
def __init__(self, parent, questions):
# `parent` should be the QWidget that contains the QuestionBank, or None if
# QuestionBank is top level
# `questions` should be a list of MasterQuestion objects (not widgets)
QWidget.__init__(self, parent)
self.questions = [MasterQuestionWidget(self, q) for q in questions]
self.bottomEdge = 0
def show(self, y=BUFFER):
QWidget.show(self)
for q in self.questions:
# coordinates for each each question
q.move(QuestionBank.BUFFER, y)
q.show()
# update y-coordinate so that questions don't overlap
y += q.frameGeometry().height() + QuestionBank.BUFFER
self.bottomEdge = y + 3 * QuestionBank.BUFFER
# ... other methods down here
My code for showing the scroll bar looks like this:
app = QApplication(sys.argv)
frame = QScrollArea()
qs = QuestionBank(None, QFileManager.importQuestions())
qs.resize(350, 700)
frame.setGeometry(0, 0, 350, 300)
frame.setWidget(qs)
frame.show()
sys.exit(app.exec_())
I have tried many variants of this, including calling resize on frame instead of qs, getting rid of setGeometry, and setting the parent of qs to frame instead of None and I have no idea where I'm going wrong.
If it helps, I'm using PyQt5
Here is the question bank without the scroll area, to see what it is supposed to look like:
Here is the output of the code above with the scroll area:
This variation on the code is the only one that produces any output whatsoever, the rest just have blank windows. I'm convinced its something simple I'm missing, as the frame is obviously resizing correctly and it obviously knows what widget to display but its not showing the whole thing.
Any help is much appreciated, thank you in advance.

How to specify borders in urwid?

I am new to urwid and think I missunderstood something. I don't see why this doesn't work. And I don't understand the error message.
#!/usr/bin/env python3
import urwid
def show_or_exit(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
txt.set_text(repr(key))
txt = urwid.Text('FooBar')
fil = urwid.Filler(txt, valign='middle', height=('relative', 70))
box = urwid.LineBox(fil)
pad = urwid.Padding(box, align='center', width=('relative', 85))
loop = urwid.MainLoop(pad, unhandled_input=show_or_exit)
loop.run()
I've also had problems like this, to get a better grasp of what's going on you probably should read the documentation section about widgets sizing modes. Basically, this has to do with the way the widgets rendering work, which is different for each widget depending on its "sizing mode". This is one of the trickiest things to understand about Urwid, once you get that then you're able to be more productive with it. :)
Here is a working version of the code you provided:
#!/usr/bin/env python3
import urwid
def show_or_exit(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
txt.set_text(repr(key))
txt = urwid.Text('FooBar')
widget = urwid.LineBox(txt)
widget = urwid.Padding(widget, align='center', width=('relative', 85))
widget = urwid.Filler(widget, 'middle')
loop = urwid.MainLoop(widget, unhandled_input=show_or_exit)
loop.run()

Scale not updating during key inputs

I am currently working on scales using tkinter. I have gotten the code to work except one thing. I have bound keys to the motion of a servo motor. When I press the keys however the scale does not follow what the key bindings do.How can I get the scale to follow the key bindings?
Please see code below
....GPIO setup code above not shown...
def fMin(event):
iDCServo = 2.5
pServo.ChangeDutyCycle(iDCServo) #this is pwm code for the servo motor
def fMin2(event):
iDCServo = 7.5
pServo.ChangeDutyCycle(iDCServo)
def fMax(event):
iDCServo = 12.5
pServo.ChangeDutyCycle(iDCServo)
def fMax2(event):
iDCServo = 7.5
pServo.ChangeDutyCycle(iDCServo)
def fOperation():
global guiSliderServo1, iLoop
while True:
win = Tk()
win.wm_title(">>>Servo Slider<<<")
win.geometry("800x100+0+0")
guiSliderServo1 = Scale(win, from_=-45, to_=45, orient=HORIZONTAL, length_=700, sliderlength_=10, tickinterval_=5, command=fSliderServo1)
guiSliderServo1.set(0)
guiSliderServo1.grid(row=0)
guiSliderServo1.pack(side=TOP)
guiSliderServo1.bind('<Key-q>', fMin)
guiSliderServo1.bind('<KeyRelease-q>', fMin2)
guiSliderServo1.bind('<Key-e>', fMax)
guiSliderServo1.bind('<KeyRelease-e>', fMax2)
guiSliderServo1.focus_set()
guiButtonExit = Button(win, text="Exit Slider", command=quit)
guiButtonExit.pack(side=BOTTOM)
win.mainloop()
...there is some remaining code regarding looks, functions and imports not shown, not sure, but probably would just clutter the real question.
Thank you
The while True hogs the computer so there is no time left for Tkinter to update the widget. You should be able to just delete the while True in the above code and be fine because Tkinter's mainloop() essentially does the same thing, i.e. continually checks for a keypress. Also mixing grid and pack, you use both, yields unknown results. Settle on one and use it. Note that this code does not change the scale, and the Button command should be win.quit.

Resources