PyQt4 storing variable - variables

I started creating my first GUI with PyQt4 a few hours ago and I've caught a snag. I've researched all over the web and while some resources have come close they've never really answered my question.
Basically I want to know if it is possible to take user input text from a widget and store that text into a variable from a button click.
So far I have looked into QLineEdit methods but have not found what I am looking for. Is there a better way to accomplish this?

Maybe something like this?
...
def __init__(self):
...
self.button.clicked.connect(self.on_button_click)
...
def on_button_click(self):
self.variable = self.line_edit.text()
print(self.variable)
...

Related

How to use PyQt5 Multi-threading?

I know this question has been answered before, but I can't understand from those examples.
There is a file called in the backend which executes functions.
This is my code:
def execGenion(self):
#if self.CN_exec_pushButton.clicked == True:
subprocess.check_call([path,"genion","-s",cntprf,"-o",cnoutf,"-p",cntopof,"-pname",posi,"-nname",negi,"-neutral"])
#Button for this function -
self.CN_exec_pushButton.clicked.connect(self.execGenion)
Now when this button is pressed on the GUI the control is transferred to the backend file where it asks for another input. But the GUI freezes and I can't give the next input. How do I fix this?
I tried using the examples on RealPython and certain different platforms but couldn't solve my problem.

GSAP after clear timeline reverse animation not working

I am facing an issue when I clear the timeline using timeline.clear() to move back all the elements to it's original position because of immediateRenderer = true, now issue I am facing is after clear timeline revert is not working.
Please suggest a proper solution that includes immediateRenderer to true with on complete of animation elements should reset to it's original position and revert should work after clear the timeline
I have also search into GSAP forum but not get any proper solution for this issue.
When you clear() a timeline, that literally deletes all of its child animations, so it'd make sense that if you try to revert by doing something like seek(0), it would have no effect (there are no child tweens to re-render at their staring values). It sounds like maybe you just shouldn't call clear() before reverting.
If your goal is to revert the changes that a tween or timeline made, you should be able to simply seek(0) to jump back to the starting time, and if you want to pause it there so that it doesn't continue playing just pause(0) like:
var tl = new TimelineLite();
tl.to(...);
//then later...
tl.pause(0);
Is that what you're looking for?
If not, it'd be super helpful if you could provide a reduced test case in codepen or jsfiddle so that we can see what's going on.
Also, were you saying that you posted in the GreenSock forums but you didn't receive an answer? We're usually very good about answering every question, typically in less than 24 hours. Let me know if there's something we missed.

overriding matplotlib's panning tool (wx)

I'm using matplotlib housed in a wxPython panel to do some heavy duty plotting. My issues comes when using native panning tool - it's appears as though matplotlib tries to constantly redraw the canvas as you drag the pan handle around. With the amount of data I'm plotting this is getting really choppy (already optimized with Collections for data etc)
In terms of performance I think it would be much preferable for the canvas to just draw once when the mouse is released at the end of a pan. I realise this will mean I have to extend the WxAgg NavigationToolbar2 class with my own, but I'm wondering if anyone has attempted something similar to this and can advise me on which functions to override?
many thanks
I've spent a lot of time making modification on the matplotlib backends, I've never done this specific change, but I can show you one line of code to comment out that will stop the dynamic updating:
I presume you are using the WxAgg backend, if this is the case, open this file: C:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py
And comment out the line indicated here:
def dynamic_update(self):
d = self._idle
self._idle = False
if d:
#self.canvas.draw() #<--- Comment out to stop the redrawing during the Pan/Zoom
self._idle = True
I tested this and it seems to nicely solve your issue. I did some quick digging and I didn't see any other functions calling this procedure so you might even be able to just change it to:
def dynamic_update(self):
pass
...Which is the same code you'll find in the base NavigationToolbar2 class
(And of course, if you're happy with this change you can do a little more work to make your own custom backend with this kind of modification. Just to make sure you don't lose the change when upgrading matplotlib)

Simulate "Slide to Unlock" in MobileSubstrate

There is a way to simulate the Slide To Unlock in the lockscreen? I've been looked for this in SBAwayController, but without any results :( Have anyone an idea?
I believe (if I understand your question correctly) you want to have the lockbar "unlock itself". For something like that you want to look into SBAwayView, not SBAwayController. In that class there are different methods that interact with the different lockbars. You will want to specifically look at the SBAwayLockBar which is a sublcass of TPBottomLockBar (defined in <TelephonyUI/TPBottomLockBar.h>)
You will have to poke around in the headers and see if there is any way to access the lockbar's Knob position.
Hope that helped at least a bit.

PyGtk: change image after window's main() method?

I'm using a gtk.Image widget to display a picture in a gtk window. I can set the image to be displayed before I call window.main(), but after I've done that the image won't change any more. Basically:
import pygtk
pygtk.require('2.0')
import gtk
(...)
window= Window()
window.canvas= gtk.Image()
window.window.add(sprite.window.canvas)
window.canvas.show()
window.canvas.set_from_file("pic1.gif")
window.main()
window.canvas.set_from_file("pic2.gif")
pic1.gif will be displayed. Is there a proper way of changing the image (I don't care if I have to use a widget other than gtk.Image)? All I can think of is destroying the window and creating a new one.
Edit:
I realized my mistake... I called window.main() for every window and any window's destroy event called gtk.main_quit(). Had to make slight adjustments, but it works now. Even after calling window.main() :)
As Rawing hasn't yet accepted his own answer, I'll post it to get this off the top of the unanswered questions page, and to help out anyone skimming this from a search engine clickthrough by providing a comprehensive answer. (Rawing, feel free to post your answer yourself, all the same.)
In your code, you're declaring window as Window(), as opposed to gtk.Window. If you're building in one window, you should not need to do this every time. Create the window once, add what you need to it. If you need additional windows, declare them separately in this module, and call them from code (instead of from main).
Furthermore, don't name your objects with a "window." at the beginning...that just gets overly confusing. Give it a simple name, add it where you need it. Python will do the rest.
A cleaned up version of your code above would probably look like this:
window = gtk.Window()
#You may need additional arguments above, such as to make it top level.
canvas = gtk.Image()
window.add(canvas)
canvas.show()
canvas.set_from_file("pic1.gif")
Now, just change the image in an event or another "def", like this:
def ChangePicture():
canvas.set_from_file("pic2.gif")
Canvas should update the picture automatically.