GTK-Python Application Two Separate Processes

  gtk, gtk3, process, python, python-3.x

I have a simple Python 3 application and it uses GTK3 GUI. The application has an application ID and two separate processes are started when the application is started:

1) Main.py
2) test1

What can be done to start the application with a single process (test1)?

Here is the Python code (in the /usr/share/test1 folder):

Main.py:

import sys ,gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gio, Gtk
from test1 import window1

class Application(Gtk.Application):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, application_id="abcd.efgh.test1", flags=Gio.ApplicationFlags.NON_UNIQUE, **kwargs)
        self.window = None

    def do_activate(self):
        self.window = window1

if __name__ == "__main__":
    app = Application()
    app.run(sys.argv)

test1.py:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio, GLib
import os

builder = Gtk.Builder()
builder.add_from_file("/usr/share/test1/test.ui")
window1 = builder.get_object('window1')

class Signals:
    def on_window1_destroy(self, widget):
        Gtk.main_quit()

builder.connect_signals(Signals())
window1.show_all()
Gtk.main()

Here is the simple GUI file (in the /usr/share/test1 folder):
test.ui file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
  <requires lib="gtk+" version="3.24"/>
  <object class="GtkWindow" id="window1">
    <property name="can-focus">False</property>
    <child>
      <object class="GtkButton">
        <property name="label" translatable="yes">button</property>
        <property name="visible">True</property>
        <property name="can-focus">True</property>
        <property name="receives-default">True</property>
      </object>
    </child>
  </object>
</interface>

Here is the starter script (in the /bin folder):
test1 file:

#!/bin/sh
/usr/bin/python3 /usr/share/test1/Main.py

Here is the application file (in the /usr/share/applications folder):
abcd.efgh.test1.desktop file:

[Desktop Entry]
Name=Test 1
GenericName=Test 1
Comment=Comment 1
Exec=test1
Type=Application

System:

Linux x64, Python 3, GTK3

Source: Python-3x Questions

LEAVE A COMMENT