Python Forum
GTK main window calling a main window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GTK main window calling a main window
#1
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?).
Reply
#2
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).
Reply
#3
(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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
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.
Reply
#5
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. :(
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 348 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [Tkinter] CTkScrollableDropdown error: bad window path name ".!ctkscrollabledropdown" CopperGenie 1 221 Mar-03-2024, 04:32 AM
Last Post: deanhystad
  [Tkinter] (CLOSED) CTkScrollableDropdown error: bad window path name ".!ctkscrollabledropdown" CopperGenie 4 425 Mar-03-2024, 03:21 AM
Last Post: CopperGenie
  [PyQt] main GUI is not shown flash77 3 389 Feb-20-2024, 05:27 PM
Last Post: flash77
  Transparent window background, but not text on it muzicman0 7 2,738 Feb-02-2024, 01:28 AM
Last Post: Joically
  Tkinter multiple windows in the same window tomro91 1 790 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [Tkinter] Modal window DPaul 14 2,353 Oct-18-2023, 06:11 AM
Last Post: DPaul
  [PyQt] PyQt5 window closing when trying to display a graph bianca 4 1,622 Aug-12-2023, 03:25 PM
Last Post: bianca
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 728 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  Place QT Window in the middle AlphaInc 10 2,044 Aug-03-2023, 05:40 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020