QDockwidget closeEvent Pyqt4 - pyqt4

I am trying to catch the closeEvent of a QDockWidget in my GUI. But destroyed() doesn't work and I have tried everything else I can't seem to get it to work.
What would be the simplest solution for this. Maybe a two liner. Just to catch the Qdockwidget exit event and then print something for instance.
I have used Qt designer to create that widget.
cheers
Anns

Related

Using std::process::Command with windows_subsystem="windows" causes console flash/popup

OK, here is my situation:
I'm making a program with a GUI in rust and I don't want to show the console window to the user.
The easy solution for this is the flag (don't know if that's the actual name for those things) #![windows_subsystem = "windows"]. It works great, the console is gone. Buuut.. The std::process::Command struct is unusable because it flashes a cmd window and not actually runs the command.
So if I have a code like this, I wont be able to use it. (But i need it)
#![windows_subsystem = "windows"]
use std::process::Command;
fn main() {
// GUI stuff that at some point uses the Command like below
Command::new("runas").args(&["/user:MY-COMPANY\\Administrator", "/savecred", path]).spawn().expect("Couldnt start Installer");
}
Does anybody have any idea how I can hide the console window but still be able to use the Command?
An easy workaround for this issue is conhost.
You can use Command::new("conhost").arg("YourCommand")
Came here. Couldn't figure it out either. This is so obscure and nowhere else is there any listed solution. That conhost workaround didn't fix it at all sadly.
Anyways, here's the solution after I finally figured it out.
Import CommandExt on windows from the std library, then set command.creation_flags(CREATE_NO_WINDOW) (you can find the CREATE_NO_WINDOW constant in windows-rs or winapi)
I really don't suggest using the constant manually, but here is the value anyways:
const CREATE_NO_WINDOW: u32 = 134217728u32; (or 0x08000000)
I would like to correct something though
It does actually run the command. It just also flashes the window while doing it. But of course, with the solution above, window flashing is now gone
Here's a list of all of the process creation flags

Can anyone help me understand the problem with this code?

I am using VS studios, using python. When I try to create a function, I constantly keep getting a syntax error. I am not sure why?
def sayhi():
print("Hello User")
sayhi()
Your function should have correct indentation like so:
def sayhi():
print('Hello User')
sayhi()
Otherwise python will throw a fit as indentation is very important to python and its functions, classes, etc.
The issue in your code is the space before def sayhi(): which is going to throw an IndentationError without a doubt, remove that space and you should be much better off
do it in jupyter notebook on Visual Studio and you won't have any problems. Just make sure you're on the python interpreter

wxPython "Things are going to break" error

Ok so I'm working with wxPython with a friend of mine, now it just so happened that he implemented a new picture into the script and its working just fine for him. But if he sends the project to me I get the error:
"wx._core.wxAssertionError: C++ assertion "strcmp(setlocale(LC_ALL, NULL), "C") == 0" failed at ....\src\common\intl.cpp(1579) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a mismatch between C/C++ and Windows locale.
Things are going to break, please only change locale by creating wxLocale objects to avoid this!"
The code in the line that breaks is the following:png2 = wx.Image("BlackBorder.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap() this lies inside the __init__(self) method for wxPython
It doesnt really tell me what is wrong I feel like so I really appreciate any help.
IIRC, there are some versions of the PNG library that call setlocale in some situations. Try explicitly creating and holding a wx.Locale object at the start of your application and see if that helps.
I had exactly the same problem after updating my application from Python27 to Python3.
4 PCs worked fine but one user with French as their windows language had this error.
I solved my problem by "initialising" the wx.Locale() at the beginning of my application:
class Application(wx.Frame):
def __init__(self, parent, title):
self.locale = wx.Locale()
self.locale.Init(wx.LANGUAGE_ENGLISH)

How to Launch a function using threads in Perl

I have tried to call a function using threads using perl in my windows system.
But, during the execution, when i click the button to create a thread process, Microsoft error message is displayed as shown below,
"Perl Command Line Interpreter.
Please tell Microsoft about this problem."
Code Snippet i used in Perl:
use threads;
##### Creation of a dialog box using Tkx Module #####
$Run = $MainFrame -> new_ttk__button(
-text => TEXT,
-width => 15,
-command => sub
{
threads -> create({"stack_size" => 64*4096,
"exit" => "thread_only"},
\&CALLING_FUNCTION);
}
);
It looks like Tk having difficulties with threads: Perl Update UI on Long Thread
You need to create your thread before the Tk objects, maybe it is going to work this way.
However, using threads with Tkx may be dicey. I was getting segfaults
when I tried to join the thread rather than detach it, and I get a
segfault with the code below if I move my $t inside startWork(). This
discussion suggests that you may need to start the thread before
creating any Tk widgets for it to work reliably.
Your problem comes because you are letting Tk code get copied into
your thread, by starting it late in the script. When a thread gets
launched, a copy of the main thread is made, so if there are Tk
widgets already in existence, they get copied in. Even if you don't
use the Tk code in the thread, it can cause problems, and will be
unreliable. So...... create your thread first, before starting any Tk
widget code.

Signals and Slots PyQt

I came across some new way of connecting signals and slots in PyQt. Please have a look at this link. How to capture output of Python's interpreter and show in a Text widget?. Here the textWritten(signal)=self.normalOutputWritten(function) are connected directly. It is working. Can someone elaborate on this new way of connections.
Rephrasing the question:
How to capture output of Python's interpreter and show in a Text widget?.
In the above link, testWritten is defined as pyqtSignal and self.normalOutput is the slot function. Usually, we connect using the old or new styles but here they just used the '=' symbol. It is working. Please explain this new way.
When you create some PyQt object, you can set properties and connect signals uising keyword arguments to __init__(), e.g.:
button = QtGui.QPushButton(clicked=on_click, text='My button', checkable=True)
For more info see:
PyQt Support for Qt Properties
Frequently overlooked (and practical) PyQt4 features

Resources