wxWidgets dialog doesn't get a maximize box - user-interface

I've got a wxPython (via wxGlade) app with a dialog that has wx.MAXIMIZE_BOX set in the style, but the maximize box doesn't appear when I run the app.
Here's a minimal program that exhibits the behavior:
#!/usr/bin/env python
import wx
class MyDialog(wx.Dialog):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_DIALOG_STYLE|wx.MAXIMIZE_BOX
wx.Dialog.__init__(self, *args, **kwds)
self.SetTitle("dialog_1")
self.Layout()
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
dialog_1 = MyDialog(None, -1, "")
app.SetTopWindow(dialog_1)
dialog_1.Show()
app.MainLoop()
Note that wx.MAXIMIZE_BOX is set, but when I run this program I don't get a maximize box on the dialog:
Is this a window manager issue?
Is there something I can do to make the maximize box show up? (My real dialog has a bunch of scrolled text from a log file and it's easier to click maximize than it is to manually resize to fill the screen.)
I'm using:
Linux (Ubuntu 10.04 LTS)
python-wxgtk, libwxgtk2.8-0, libwxbase2.8-0: 2.8.10.1-0ubuntu1.2
metacity: 1:2.30.1-0ubuntu1.1

I found this in the wxWidgets docs:
"Under Unix or Linux, MWM (the Motif Window Manager) or other window managers recognizing the MHM hints should be running for any of these styles ( including wxMAXIMIZE_BOX ) to have an effect."
So it sounds like it might well be a window manager issue.

Related

QDialog not centered on parent QMainWindow on Ubuntu 22.04

I encountered a strange situation on Ubuntu 22.04, using PySide6 when spawning a QDialog from a QMainWindow parent via menu action, like with the sample code below:
from PySide6.QtWidgets import QApplication, QMainWindow, QDialog
from PySide6.QtGui import QAction
class Dialog(QDialog):
def __init__(self, parent):
QDialog.__init__(self, parent)
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setGeometry(0, 0, 500, 500)
menu = self.menuBar()
submenu = menu.addMenu("Submenu")
self.action_open_dialog = QAction("Open Dialog", self)
self.action_open_dialog.setCheckable(False)
self.action_open_dialog.triggered.connect(self.open_dialog)
submenu.addAction(self.action_open_dialog)
def open_dialog(self):
dialog = Dialog(self)
dialog.exec()
if __name__ == '__main__':
app = QApplication()
w = MainWindow()
w.show()
app.exec()
The position of the dialog should be centered on the main window as parent, according to the documentation, but this is not the case. In fact, the dialogs initial position can even be outside the main window when the latter is moved before spawning the dialog, and appears to be located at some fixed screen position on the upper left. Curiously, the dialog is properly appearing in the center of the main window when executing on a Windows system.
Is this a known issue with Linux systems and is there some way to force the dialog to appear in the main windows center?
PS: The Ubuntu OS is executed as a VM on VirtualBox, in case this is relevant.
PPS: As requested, the exact Ubuntu version is 22.04.1 and the Wayland (ie. mutter) version is 42.0-3ubuntu2 - this is really just a stock install straight from the downloaded ISO without any modifications.
With Glade 3.38.2 "Centre on Parent" for modal popup gtkWindows works perfect in XORG, but not in Wayland.
In Wayland you have to select Toplevel as type under Window Attributes. With popup only position = mouse works.
As this is a Wayland problem, the same may be the case for QT.

Gtk+3 Grid Blocking Background Image In Overlay

I've been trying to get into GUI programming with Python on Xubuntu 14.04 by following a few guides like this one here. I wanted to have a background image in my GUI with whatever buttons on top of it. I searched on stackoverflow and came across a person having a similar issue. His solution worked, but the grid filled up the entire window and I can no longer see the background image. How do I fix this? Here is my code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-:
from gi.repository import Gtk #Here we are importing the GTK3 library to use in our program
class mywindow(Gtk.Window):
def __init__(self):
#In the class's constructor, we have to call the constructor of the super class. In addition, we tell it to set
#the value of the property title to Media Manager v1.0
Gtk.Window.__init__(self, title="Media Manager v1.0") #Creates an Empty Window
#use an overlay for the background image
self.overlay = Gtk.Overlay()
self.add(self.overlay)
self.background = Gtk.Image.new_from_file('Background.jpg')
self.overlay.add(self.background)
self.grid = Gtk.Grid()
self.button1 = Gtk.Button(label="Hello")
self.button1.connect("clicked", self.on_button1_clicked)
self.grid.add(self.button1)
self.overlay.add_overlay(self.grid)
#Gtk.Window.set_default_size(self, 400,325)
Gtk.Window.set_position(self, Gtk.WindowPosition.CENTER)
def on_button1_clicked(self, button):
print "Hello"
def on_button2_clicked(self, button):
print "Exiting..."
def main():
window = mywindow()
#connect to the window's delete event to ensure that the application is terminated if we click on the x to close the window
window.connect("delete-event", Gtk.main_quit)
#Display the window
window.show_all()
#Finally, start the GTK+ processing loop which we quit when the winndow is closed.
Gtk.main()
return 0
if __name__ == '__main__':
main()
Pass values for the valign and halign properties when creating the grid and/or the button. The default for these properties is Gtk.Align.FILL which causes them to cover all the space given to them. Instead, pick Gtk.Align.START, Gtk.Align.END, or Gtk.Align.CENTER.

PyQt QtDesigner lost of the windows minimize buttons

My problem is only in Qtdesigner.
I am using QtDesigner v4.8.4 to define my HMI for a pyqt project. In this editor the window I have drown, has got a reduce and a close button in right up corner. I am sorry I wanted to show it to you with screenshots but I don't have enough reputation.
When I use it or previsualize it (with Ctrl + R), I lose the "minimize button" of the window and its functionnality.
Do you have the same behavior?
I have a useless ? button instead and the close button. How could I keep it to minimize my window ?
Thanks a lot for any advice!
When I use it or previsualize it (with Ctrl + R), I lose the "minimize button" of the window and its functionnality.
Answer : This is not bug, I just preview your widget only. If your implement in pyqt can see all button for windows.
Picture: Show previsualize of Qt4 Designer doesn't have "minimize button"
Picture: Show running of PyQt4 (It default have "minimize button")"
Can you please show an example of implementation of the minimize button of the up right corner because for my script
OK, Keyword is implement event in widget by this method QWidget.changeEvent (self, QEvent)
, Please see my example code, Hope is helps;
import sys
from PyQt4 import QtCore, QtGui, uic
(loadUserInterface, loadQWidget) = uic.loadUiType('QWelcomeWidget.ui')
class QWelcomeWidget (loadQWidget):
def __init__ (self, parent = None):
loadQWidget.__init__(self, parent)
self.ui = loadUserInterface()
self.ui.setupUi(self)
def changeEvent (self, eventQEvent):
if eventQEvent.type() == QtCore.QEvent.WindowStateChange:
if self.windowState() & QtCore.Qt.WindowMinimized:
print 'Window Minimized'
QtGui.QWidget.changeEvent(self, eventQEvent)
if __name__ == '__main__':
appQApplication = QtGui.QApplication(sys.argv)
mainQWidget = QWelcomeWidget()
mainQWidget.show()
# Start Application
sys.exit(appQApplication.exec_())
References : http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#changeEvent
Regards,
convert your .ui file to (.py)python file using
pyuic4 filename.ui
sudo pyuic4 -x ptqt_filename.ui -o python_file_name.py
Now run that python file,you will be able to see all controls
python pyqt_first_ui.py

Run thread in main window for both Windows and Linux

I am creating a game to run inside a GUI (text area, button, menu etc) I've created a GUI with wxpython. I create a panel inside the main window, which runs a pygame thread.
Problem:
On Windows, the pygame thread runs perfectly inside the main window. But on Linux, the pygame pop up on a new window. How can I set this such that both windows and Linux run the thread in the main window?
Code:
class SDLPanel(wx.Panel):
def __init__(self,parent,ID,tplSize):
global pygame
global pygame_init_flag
wx.Panel.__init__(self, parent, ID, size=tplSize)
self.Fit()
if (sys.platform == 'win32'):
os.environ['SDL_WINDOWID'] = str(self.GetHandle())
os.environ['SDL_VIDEODRIVER'] = 'windib'
else:
os.environ['SDL_VIDEODRIVER'] = 'x11'
#here is where things change if pygame has already been initialized
#we need to do so again
if pygame_init_flag:
#call pygame.init() on subsaquent windows
pygame.init()
else:
#import if this is the first time
import pygame
pygame_init_flag = True #make sure we know that pygame has been imported
pygame.display.init()
window = pygame.display.set_mode(tplSize)
self.thread = SDLThread(window)
self.thread.Start()
def __del__(self):
self.thread.Stop()
print "thread stoped"
#very important line, this makes sure that pygame exits before we
#reinitialize it other wise we get errors
pygame.quit()
Solved problem.
In main window we must self.Show()
Idk why in linux the main window must be showed . Same code.
Tks all
This is a disclaimer alert, according to https://forums.libsdl.org/viewtopic.php?p=39332, the solution works only with SDL 1.2 and not 2.0.

wxPython Mouse Entering/Leaving event methods don't work on Linux

I am trying to provide a custom button class that needs a hover for it to work properly. I am therefore using StaticBitmap and extending it. But I am finding differences between Windows and Linux using the same exact code between both. The following small simple example doesn't work properly in Linux, but works fine in Windows:
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Test")
panel = wx.Panel(self, wx.ID_ANY, size=(200,100))
panel.SetBackgroundColour("Black")
# create a normal bitmap button
bitmap = wx.Bitmap("images/power.png", wx.BITMAP_TYPE_ANY)
self.image1 = wx.StaticBitmap(panel, bitmap=bitmap, size=bitmap.GetSize())
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.image1)
panel.SetSizer(sizer)
# This works on Windows, but not on Linux
#self.image1.Bind(wx.EVT_ENTER_WINDOW, self.OnHover)
#self.image1.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveHover)
# This (used by itself) gets events for both Linux/Win, but
# doesn't find e.Entering() or e.Leaving() on Linux!
self.image1.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvents)
def OnHover(self, e):
print "Hover"
def OnLeaveHover(self,e):
print "Leaving Hover"
def OnMouseEvents(self,e):
print "Mouse event"
#print dir(e)
if e.Entering():
print "Hover"
elif e.Leaving():
print "Leaving Hover"
else:
e.Skip()
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
Is this a known issue? Is there some other way to bind the event to get the mouseover/hover operation to work properly in Linux?
Also, no forms of self.Bind() work here on Linux or Windows. Why? i.e.:
self.Bind(wx.EVT_ENTER_WINDOW, self.OnHover, self.image1)
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveHover, self.image1)
Hmmm..., all I can tell you is what I experienced with your code when using it in Ubuntu 12.04
1) My picture never shows up (i.e. a grey window nothing more)
2) when binding the EVT_ENTER/LEAVE_WINDOW to self and not to image1 (see below), it works
# This now works on Linux
#self.Bind(wx.EVT_ENTER_WINDOW, self.OnHover)
#self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveHover)
I hope this helps you in some form. Also I would like to add that I have made many a bad experience with cross-platform compatibility of wxpython unfortunately. I like the library a lot, but once it delves into more obscure widgets, the behaviour may differ wildly between Windows and Linux.
I remember trying to use the MPlayerCtrl once and for the same method in Windows it would return 0 while in Linux it would return -1 (can't mind exactly which method it was, that project got dumped once I noticed it)
Maybe, this is another one of those strange behaviours...
Having thought about it some more.
instead of binding the event to the picture, you could bind it to the widget it is displayed in, such as your panel.
self.panel = wx.Panel(self, wx.ID_ANY, size=(200,100))
self.panel.SetBackgroundColour("Black")
...
#self.panel.Bind(wx.EVT_ENTER_WINDOW, self.OnHover)
#self.pane.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveHover)
you should bind the wx.EVT_ENTER_WINDOW/wx.EVT_LEAVE_WINDOW event to self.panel. that works.
wx.EVT_ENTER_WINDOW/wx.EVT_LEAVE_WINDOW is not the subclass of wx.CommandEvent class. It isn't thrown up to the parent window to process.

Resources