Master PyQt5 part 10: Make responsive GUIs with Threads

  Рет қаралды 19,503

Alan D Moore Codes

Alan D Moore Codes

Күн бұрын

Пікірлер: 57
@rwbazillion
@rwbazillion 3 жыл бұрын
Thanks for the tutorials, I have bought the book and this will be good to look at for reference as a code in PyQT5.
@joshuakornblum6341
@joshuakornblum6341 4 жыл бұрын
The Norm McDonald of Python GUI coding! Love it.
@xllvr
@xllvr 4 жыл бұрын
This and the analogies within helped a lot with understanding threading better. It's quite difficult to wrap your mind around the concept and how it's implemented, but this helped to clarify quite a bit which I needed for a major project.
@DA_CSF
@DA_CSF 2 жыл бұрын
Thanks for the explanation. I came in time before I was about to give up and accept a freezing GUI. If only I had stubbled on this earlier, might have saved a ton of time.
@Soljarag5
@Soljarag5 4 жыл бұрын
whooohoo! I got threads working in my project! Thanks man!!!
@Lucas-br3fn
@Lucas-br3fn 3 жыл бұрын
Man, i'm new to python and you helped me SO much! Ty mate, keep the great work
@codenio
@codenio 4 жыл бұрын
Thanks for this wonder tutorial series. How could we stop QThread safely from GUI on demand?
@Shizostereo
@Shizostereo 4 жыл бұрын
Up this question
@beaujamie2661
@beaujamie2661 3 жыл бұрын
a tip: you can watch series on Flixzone. I've been using them for watching lots of of movies during the lockdown.
@tonyfox1316
@tonyfox1316 3 жыл бұрын
@Beau Jamie Yea, been using Flixzone} for since november myself :D
@aneesch6908
@aneesch6908 4 жыл бұрын
Thanks for your lesson it's really helpful and very easy to follow you, awesome 10/10
@Grlypyt
@Grlypyt 4 жыл бұрын
Great video, super helpful thanks for your hard work in making this!
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
Thanks!
@weekendprogrammer7545
@weekendprogrammer7545 4 жыл бұрын
Your way of teaching is dam good, best programming video explanation I have seen. That too on threads. Amazing sir, I'm looking forward to buying your book. Please continue doing video on pyqt. I'm a freelancer and this particular video helped me through threading, and also your signals ans slots video. Thank you for your videos.
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
Thanks! Hope the book helps too.
@ak47-hz4fq4np3z
@ak47-hz4fq4np3z Ай бұрын
Thanks a million man, great video!
@VAN_production.mp4
@VAN_production.mp4 3 жыл бұрын
That story time got me 😄😄😄😄😄 subscribed just because of it! 😂😂
@alandmoorecodes3585
@alandmoorecodes3585 3 жыл бұрын
Thanks!
@pabloparada636
@pabloparada636 3 жыл бұрын
So very well explained! you didn't miss a beat in the whole video; please go into teaching :)
@mahmoudali1660
@mahmoudali1660 3 жыл бұрын
Thank you so much! You’ve helped me a lot❤️
@mohamedsaidi5375
@mohamedsaidi5375 4 жыл бұрын
Hey Man thinks to you I learned , many PyQt concepts in no time. keep up !
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
Thanks!
@johnnytoobad7785
@johnnytoobad7785 3 жыл бұрын
I recently implemented a Prod-Cons (I/O bound) thread pool using Python threading and tkinter (using "after"). The tk version seems simpler but not as versatile since tk is not "thread aware". Basically I just used ".after" in tk as a timer-interrupt to launch and monitor the back-end threads. Eventually I would like to translate that app to Qt5. I love the "Mr 5-bags" analogy.
@Soljarag5
@Soljarag5 4 жыл бұрын
ha, this is pretty much exactly what I needed... thanks!!!!!!
@PythonisLove
@PythonisLove 4 жыл бұрын
Thanks for the video...
@thghtfl
@thghtfl 4 жыл бұрын
this is just brilliant
@siddharthchabukswar2
@siddharthchabukswar2 4 жыл бұрын
Hi! Great tutorial, explained the concepts quite well. The Worker threads are not terminating after exiting the main window(By Clicking the 'X'). The Console says 'QThread: Destroyed while thread is still running'. Please help.
@ShnitzenGiggles
@ShnitzenGiggles 4 жыл бұрын
Hey man, just want to say your vids are extremely helpful, the metaphor was supremely welcome, can't stand "Mr. 5 Carts". With that, if I could make a request. The internet is throughout lacking for people who have a hard time sifting through documentation and stack overflow posts that go off on a tangent or are titled ambiguously and the body is too specific. One thing that I've been doing, and using your videos, I've been piecing things together. I've only been programming since may and I've become a little ambitious. However, I'm not letting the wall of plethora of knowledge stand in my way. Though I lack some crucial and fundamental things. Software engineering and application engineering best practices. Incorporating design patterns into a gui application. The dos and don't's if you will. If a very basic theory crafted video (I know very conflicting ideas) were to be made that outlines how one should approach a multievent and multitasked application I'd venture to say it would be a boon to those who have taken on programming to enhance their current career, such as myself being a network engineer. Qthreading is something I've taken on, though I'm experiencing some things that I don't know if it's something I'm doing or just an inherent problem (lag in the gui, not locking up, when I run a background task that doesn't require sending data back to the gui.
@rebelScience
@rebelScience 4 жыл бұрын
Awesome video. I am wondering if I should use PyQT or PySide2. Can' find a definitive answer online. I am developing (adding a UI to my huge set of Bioinformatics classes) a tool and it will be 100% free and open-source.
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
Well, I have to admit I'm a bit biased towards PyQt. Functionally, it makes very little difference. There are few differences in the code, and in fact I've made projects that supported both. I will say in PyQt's favor that it has been steadily turning out releases for over 13 years, whereas the PySide project died out for several years before being recently revived. So I'm a little leery about trusting its longevity. To be fair, I'm not sure how many people apart from Phil Thompson actually develop PyQt, so there's maybe a bus factor involved there (I may be wrong). Speculations aside, the biggest difference right now is licensing, which is moot in your case.
@tom_p6430
@tom_p6430 3 жыл бұрын
Great video. I have a specific question, maybe you will take the time to answer here. Let's say I have a main window and I want to write a function that do things. But that function at some point needs input from the user, and this input is asked in the form of a setting window where numerical fields have to be filled. My question is: how to make the function wait for the setting window to be close (meaning that the numerical values are submitted). The only way I could come up with is to split my function in two functions, and play with signals and slots to first emit a signal at the end of the first function to open the setting window, that itself emit a signal upon closing for processing the second function with the values submitted. I am certain there is a better way of doing that. Thank you.
@alandmoorecodes3585
@alandmoorecodes3585 3 жыл бұрын
Offhand i feel like you're on the right track there. Signals and slots are the most appropriate way to communicate between your backend and a pyqt gui.
@tom_p6430
@tom_p6430 3 жыл бұрын
@@alandmoorecodes3585 Thanks. Now that I went this way, my code looks more modular, and I can reuse the individual split functions for different purposes.
@johanocop
@johanocop 4 жыл бұрын
Hi Alan, I bought a few books about PyQt5, and yours is by far the on that I got the best understanding from, so a big thanks for your good work.. I have two question regarding Qthread that I hope you can help me with. I have made a program with 10 threads, each thread updates different locations in a Qtable at 10Hz in the main GUI(it works but I use python thread) I need an example of how to make multiple Qthreads, I cant figure out if I need one "worker" for each "worker_thread" and is each of my 10 Objects(that needs to run individual) actually the "worker" ?
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
That might be a good case QRunnable workers controlled by a QThreadPool. Then have a single QThread that manages those and communicates updates the GUI. Hard to say without knowing more about the code. You may have trouble keeping it realtime at 10Hz.
@ryadorexy
@ryadorexy 3 жыл бұрын
I tried the code but AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'emit', can anyone help with this?
@alandmoorecodes3585
@alandmoorecodes3585 3 жыл бұрын
IIRC, for some reason emit does not exist until a signal has been bound to something. You just need to make sure to connect the signal before referencing emit.
@billcolak5253
@billcolak5253 3 жыл бұрын
skip to 21:30 to get to the point.
@thestigster
@thestigster 4 жыл бұрын
I have a question about the worker class: You construct it as a QObject; why not as a QRunnable? What is the difference between the two? (I am very much a PyQt5-apprentice trying to understand this mighty powerhouse.)
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
QRunnable isn't able to send signals; they're more useful in a high-concurrency situation where you want to distribute a load among a lot of workers. If you just have one process that needs to run independently of the GUI, a QObject moved to a different thread is simpler, since we can use signals and slots to communicate with it.
@thestigster
@thestigster 4 жыл бұрын
Alan D Moore Codes Aha! I see. Sounds like more of a ”fire and forget”-ish thing. Thanks for the swift reply, by the way. This was very helpful.
@TheTrainWatch
@TheTrainWatch 3 жыл бұрын
@@alandmoorecodes3585 what about inheriting from QThread? I’ve seen someone do that before and it didn’t need the move to thread call and signals and slots worked.
@saidshaban389
@saidshaban389 4 жыл бұрын
Hey! Thank you very much for your videos, they're a great help for newcomers! I have a rather tricky question, I hope you can help me with! I am trying to do realtime data in my GUI from data I collect from another thread. How am i supposed to do that? I have been working on Qobjects and Qthreads, but they do not seem to be the solution.
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
Without knowing more about why QObjects and QThreads didn't work for you, it's hard to say. They can definitely be difficult to work with, though.
@neobyte999
@neobyte999 4 жыл бұрын
I'm confused about the hash_gen = recursive_hashes(Path(root)). How is that utilizing the recursive_hashes function above? To be specific, I'm pointing more towards the "Path(root)" portion of it. What does that mean?
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
Because it uses yield rather than return, recursive_hashes() returns a generator. Hard to explain generators in a single comment, maybe start here: wiki.python.org/moin/Generators
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
What PyQt topics do you want next? Let me know here!
@haydenhoodless2055
@haydenhoodless2055 4 жыл бұрын
Event handlers in PyQT. mousePressEvent, mouseMoveEvent etc.
@cro9364
@cro9364 4 жыл бұрын
could you show us how to structure our projects
@NphiniT
@NphiniT 4 жыл бұрын
Connecting to and interacting with Databases (MySQL or similar)
@hackpiece3094
@hackpiece3094 4 жыл бұрын
Sir can you please guide me over a threading issue? I have a main widget with a Find button and a QtableWidget. I want to traverse a given directory path And make corresponding Qwidgets from that path to be shown in QtableWidget. I am following the way its recommended to use threads...ie. Using generator to traverse subdirectory and emiting signals from a worker thread and connecting slots to the mainWidget as you too have done. However due to the Qwidget creation in the main widget for each time the signal is emited by the worker thread for the purpose of adding the qwidget to the QtableWidget, the Gui Freezes. I guess the rate of emitting the signals from the worker thread is higher than the rate at which the main Qwidget is making the sub- widgets and adding them to the QtableWidget as using sleep for 1 sec after emiting the signal has prevented the gui being frozen. I would like a more event driven approach... something like the signal once emited should wait until its corresponding slot has completed its job.Only then should it be emiting another signal.
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
If you want one thread to wait on the other, it seems to me that doesn't really make sense to use threads. You would be better off just calling your generator's next value, then creating the widget, all in the main thread, would you not?
@hackpiece3094
@hackpiece3094 4 жыл бұрын
@@alandmoorecodes3585 Hi Sir , I did that previously but the Gui was freezing...However I solved the mess by using other thread to get emit me a signal along with the details from a generator with next. I then made an object, added to the table and again requested the thread to emit me another signal along with the details. On StopIteraton exception, the thread emits a stop signal and i show the table. I am using thread because before getting the details, i am performing a lengthy check over each path...That was making the Gui Sluggish. Thank You So much for getting time out of your day to reply.
@bennguyen1313
@bennguyen1313 4 жыл бұрын
I've run into a situation where I need to update my MainWindow's gui elements (label, etc), from another class (thread). Is there a pythonic way to get access to the gui objects in another class?
@alandmoorecodes3585
@alandmoorecodes3585 4 жыл бұрын
Generally, you don't want to do that. What you should do instead is use signals and slots to trigger class methods that manipulate the classes's gui elements.
@Soljarag5
@Soljarag5 4 жыл бұрын
@@alandmoorecodes3585 hmmm.. I guess i should change my "MainWindow.statusbar.showMessage(filename) " to a signal/slot?
Master PyQt5 part 11:  Application Infrastructure and Communication
33:51
Alan D Moore Codes
Рет қаралды 4,6 М.
Master PyQt5 part 1:  Hello World and Template
27:48
Alan D Moore Codes
Рет қаралды 19 М.
My Daughter's Dumplings Are Filled With Coins #funny #cute #comedy
00:18
Funny daughter's daily life
Рет қаралды 13 МЛН
Kỹ thuật vi xử lý, GPIO, bài tập 1
9:02
Become a shell wizard in ~12 mins
12:25
CODE IS EVERYTHING
Рет қаралды 251 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,7 МЛН
Master PyQt5 part 6:  QMainWindow for easy apps
27:05
Alan D Moore Codes
Рет қаралды 12 М.
When you Accidentally Compromise every CPU on Earth
15:59
Daniel Boctor
Рет қаралды 835 М.
Why Isn't Functional Programming the Norm? - Richard Feldman
46:09
Tkinter vs. PyQt:  Which Python GUI framework is right for you?
38:11
Alan D Moore Codes
Рет қаралды 64 М.
Harder Drive: Hard drives we didn't want or need
36:47
suckerpinch
Рет қаралды 1,7 МЛН
WHY IS THE HEAP SO SLOW?
17:53
Core Dumped
Рет қаралды 229 М.
QtDesigner and PyQt5:  The right and wrong way to use them together
37:16
Alan D Moore Codes
Рет қаралды 108 М.