I've been googling all day and can't find how to do this.
I have my main Python 3 Gtk+3 window. I want to create a overlay window (smaller than the main) that is centered on the main window. The overlay window will have focus - users cannot select the main window until the overlay is closed. The overlay window will consist of a grid container(uses entire overlay window). I will open and close the overlay as needed.
Can anyone point me in the right direction to do this? I tried a dialog but couldn't get it to accept a grid (box only?).
I have been able to insert a grid into the box on a dialog. However I cannot get it to restrict the size (window is the full width of the main window) or control its location (always on bottom).
(Oct-13-2016, 09:40 PM)DennisT Wrote: [ -> ]I have been able to insert a grid into the box on a dialog. However I cannot get it to restrict the size (window is the full width of the main window) or control its location (always on bottom).
it is always best to post the code you have so far. It makes it easier to offer suggestions based on what you have.
Please read the
Help section on how to post code.
OK, I'm trying to get dialogs to work the way I want. I have a 800x600 main window. I want to create a 400x200 dialog window in the center of the main window. I need to transfer data from the dialog back to the main window. I've been able to do this using a global. However I cannot fix the size of the dialog and center it in the main window. It appears at the bottom of the main window and covers the entire width.
Code is running on a RPi3 Raspbian w.matchbox window manager.
#!/usr/bin/python3
# Import functions
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject
PINFO = ''
#--------------------------------------------------------------------
class TestPopup(Gtk.Dialog):
def __init__(self, main_window):
global PINFO
Gtk.Dialog.__init__(self, "Popup", main_window, 0, ("Exit", Gtk.ResponseType.OK)) #create dialog window + exit button
self.set_default_size(400, 200) #control size
self.set_size_request(400, 200) #control size
self.set_border_width(9)
# self.set_decorated(0)
# self.set_resizable(False)
self.resize(400,200)
geom = Gdk.Geometry()
geom.min_width = 400
geom.max_width = 400
geom.min_height = 200
geom.max_height = 200
geom.base_width = 400
geom.base_height = 200
hints = Gdk.WindowHints.MIN_SIZE | Gdk.WindowHints.MAX_SIZE | Gdk.WindowHints.BASE_SIZE
self.set_geometry_hints(None, geom, hints)
self.resize(400,200)
W,H = self.get_size()
self.set_gravity(Gdk.Gravity.CENTER)
print ('Dialog width='+str(W)+' height='+str(H))
box = self.get_content_area() #set dialog's container
self.Titletext = Gtk.Label() #Fixed title
self.Titletext.set_text("Test Popup") #title
box.add(self.Titletext)
PINFO = 'TestPopup complete'
return
#--------------------------------------------------------------------
class MWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
global PINFO
PINFO = ''
self.set_default_size(800,600) #set window size
self.set_border_width(5)
fixed = Gtk.Fixed() #add fixed container to window
self.add(fixed)
self.ExitButton = Gtk.Button(label=" Exit ") #add reset button
fixed.put(self.ExitButton,10,600-100) #set ResetButton location
self.ExitButton.connect("clicked", self.exit_button_clicked) #set ResetButton click action
self.DiagButton = Gtk.Button(label=" Dialog ") #add button
fixed.put(self.DiagButton,180,600-100) #set Button location
self.DiagButton.connect("clicked", self.ButtonClicked) #set EmpInfo Button click action
def exit_button_clicked(self, widget): #when ResetButton is clicked
exit() #we exit. kiosk env will auto start new session
def ButtonClicked (self, widget):
W,H = self.get_size()
print ('mainwin width='+str(W)+' height='+str(H))
print ('PINFO start:'+PINFO)
dialog = TestPopup(self) #display error window
response = dialog.run()
dialog.destroy()
self.show_all()
print ('PINFO return:'+PINFO)
return True
#---------------------------------------------------------------------------------------
MainWin = MWin()
MainWin.show_all()
#cursor = Gdk.Cursor.new(Gdk.CursorType.BLANK_CURSOR) #change mouse pointer to blank (transparent)
#MainWin.get_window().set_cursor(cursor) #and set it
Gtk.main()
As you can see, there's a bunch of redundant code I've played with trying to get the dialog to the size and location I want. Interestingly. self.get_size does return the size I want. It just doesn't display that size.
I suspect this issue is with matchbox. I've been able to work around the dialog issue. Using a fixed container on my main window I can control size/location. Had to use a GObject.timeout to help emulate the focus being held to the pseudo dialog. Messy, ugly, but workable. Sure would have been a lot easier if Dialog worked as I wanted. :(