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.
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.