PyQt5 control windows - windows

In the above imange the background window is the main window of the screen. Then follows one Form that opens from the menu of the Main Window
and at the top you can see a QMessageBox like this:
box = QMessageBox()
box.setIcon(QMessageBox.Question)
box.setWindowTitle('Αποθήκευση αλλαγών')
box.setText('Θέλετε να αποθηκεύσετε τις αλλαγές σας;')
box.setStandardButtons(QMessageBox.Yes|QMessageBox.No|QMessageBox.Cancel)
buttonY = box.button(QMessageBox.Yes)
buttonY.setText('Ναι')
buttonN = box.button(QMessageBox.No)
buttonN.setText('Οχι')
buttonC = box.button(QMessageBox.Cancel)
buttonC.setText('Ακύρωση')
box.exec_()
if box.clickedButton() == buttonY:
self.save_and_close(True)
self.main_self.manage_microphone_window_is_open = False
event.accept()
elif box.clickedButton() == buttonN:
self.main_self.manage_microphone_window_is_open = False
event.accept()
elif box.clickedButton() == buttonC:
event.ignore()
I want in the bottom the Windows (bottom bottom there that start menu of windows and clock are) to show only one program.
Any ideas?

With the help of musicmante i did the following:
I change Form Window to QDialog and set MainWindow as parent
I set a parent to box: box = QMessageBox(dlg)
Note than in step 1 when you copy paste the QWidgets from Form to new Dialog (in QtDesigner), you may change the title of window the icon of window the style of the window and perhaps any other window settings.

Related

How to make Qt app visible on top on all screens?

How can I make a Qt window (keyboard launcher) show up on all spaces like e.g. Spotlight or iterm2 hotkey window.
I need to achieve the following: The launcher window has to be able to show up on every screen, even full screen apps, no dock item, not window switcher item, no main menu, this should work without any further implications (see below). Nice to have would be if the settings window would be still a regular window.
I tried to use qputenv("QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM", "1"); but using this the window accepts no keyboard input anymore. I also tried
WId windowObject = this->winId();
objc_object * nsviewObject = reinterpret_cast<objc_object *>(windowObject);
objc_object * nsWindowObject = ((objc_object* (*)(id, SEL))objc_msgSend)(nsviewObject, sel_registerName("window"));
int NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1;
int NSWindowCollectionBehaviorTransient = 1 << 3;
int NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8;
int total = NSWindowCollectionBehaviorMoveToActiveSpace
|NSWindowCollectionBehaviorTransient
| NSWindowCollectionBehaviorFullScreenAuxiliary;
((objc_object* (*)(id, SEL, int))objc_msgSend)(nsWindowObject, sel_registerName("setCollectionBehavior:"), total);
but this way the window does not show over fullscreen apps and also has still a dock item and main menu.

Xamarin Forms for Mac runModalForWindow doesn't starting window as modal

In my Xamarin Forms for Mac I have 2 windows:
A - main window
B - window that I want to open as modal.
Window B I opening using function RunModalForWindow.
Problem is that window B opening as common window and when I click on main window A the modal loses focus and goes out of the foreground.
How I can fix this problem?
Here is my code how I open my modal window:
this.window = new NSWindow(this.windowRect, NSWindowStyle.Closable, NSBackingStore.Buffered, false)
{
Title = "Pick install path",
TitleVisibility = NSWindowTitleVisibility.Hidden,
};
PickInstallPath pickInstallPath = new();
this.window.ContentViewController = pickInstallPath.CreateViewController();
this.window.ContentViewController.PreferredContentSize = this.windowRect.Size;
NSApplication.SharedApplication.RunModalForWindow(this.window);

Dialog window positioning

I'm creating a small non-modal dialog in TornadoFX like this:
find<Grib>(scope).apply { openModal(block = true,
owner = FX.primaryStage,
stageStyle = StageStyle.UTILITY,
modality = Modality.NONE) }
How do I go about setting (and retrieving) it's window position for later? That is, I have a preferences object for the window location and I want to update it so that the next time the user opens the window, it opens in the same place they last closed it.
I was able to mostly solve my problem by digging through some of the TornadoFX source code.
I added this to my init{} function:
Platform.runLater {
root.scene.window.x = Main.preferences.getDouble(GRIB_WINDOW_X, 400.0)
root.scene.window.y = Main.preferences.getDouble(GRIB_WINDOW_Y, 400.0)
}
And then adding this to my close() function:
Main.preferences.putDouble(GRIB_WINDOW_X, root.scene.window.x)
Main.preferences.putDouble(GRIB_WINDOW_Y, root.scene.window.y)
This "mostly" solves the problem in that it does save/restore the window position, however the window flickers when it is created as it moves from some default position to the newly set position.

Add Scrollbar to popup table in Tkinter

I have a menu button in a GUI I am making that displays a popup containing a CSV file, using pd.read_csv through pandas. However, there is a lot of data, and when the popup is displayed, pandas cuts off a lot of the data, only displaying the data in the beginning and in the end of the file.
I want to be able to scroll through all the data in my popup window. Any suggestions?
Here is the code for the popup command:
def popuptable():
popup = tk.Tk()
popup.wm_title("!")
label = ttk.Label(popup, text=(pd.read_csv('NameofCSVFile.csv')), font=NORM_FONT)
label.pack(side="top", fill="x", pady=10)
popup.mainloop()
I give you an example of how to do a scrollable text widget that looks like a label. I put it in the main window for this example, but you just have to replace root by a toplevel to adapt it to your case.
from tkinter import Tk, Text, Scrollbar
root = Tk()
# only the column containing the text is resized when the window size changes:
root.columnconfigure(0, weight=1)
# resize row 0 height when the window is resized
root.rowconfigure(0, weight=1)
txt = Text(root)
txt.grid(row=0, column=0, sticky="eswn")
scroll_y = Scrollbar(root, orient="vertical", command=txt.yview)
scroll_y.grid(row=0, column=1, sticky="ns")
# bind txt to scrollbar
txt.configure(yscrollcommand=scroll_y.set)
very_long_list = "\n".join([str(i) for i in range(100)])
txt.insert("1.0", very_long_list)
# make the text look like a label
txt.configure(state="disabled", relief="flat", bg=root.cget("bg"))
root.mainloop()
Screenshot:

Toolbar TBSTYLE_FLAT issue

If I create a toolbar and add the TBSTYLE_FLAT flag my toolbar ends up with a black background and the buttons behave funny, without the flag all is well except the separators don't show so the question is how do I use the TBSTYLE_FLAT properly so that the separators show but the background behaves as it should?
dwExStyle = nul
dwStyle = WS_CHILD + TBSTYLE_LIST + TBSTYLE_TOOLTIPS + CCS_NODIVIDER + TBSTYLE_FLAT
Edit: If I take out the TBSTYLE_FLAT and then send a TB_SETSTYLE message with TBSTYLE_FLAT before the window is shown then everything looks OK but the toolbar places itself at the bottom of the window and clicking a button shows the button rec to still be at the top of the window?
TBSTYLE_FLAT = 0x0800;
TB_SETSTYLE = 0x438;

Resources