Posts: 4
Threads: 1
Joined: Nov 2023
I am making an interface for an Unmanned Aerial Vehicle. I have a main interface that shows the data I get from the dronekit and the attitude indicator. I made this main interface using PyQt5, first I was going to add a map directly to this interface I made with PyQt5, but the map I used could not functionally work on the interface I made over PyQt5. So I decided to separate the main interface and the map. I made the map using "tkintermapwiever". When I run the two separately, it works smoothly and stably. But since we have a single tool and we will connect through the same server, both programs need to run simultaneously, my research has not yielded any results. I have tried Threading and Processing methods, but they work sequentially, not at the same time. So for example, my main interface opens first, and after I close my interface, my map application opens. It shouldn't be like this, both should open side by side at the same time.I would be very grateful if you can help. Thank you..
Posts: 6,240
Threads: 16
Joined: Feb 2020
Nov-07-2023, 01:53 AM
(This post was last modified: Nov-07-2023, 01:54 AM by deanhystad.)
Posts: 4
Threads: 1
Joined: Nov 2023
(Nov-07-2023, 01:53 AM)deanhystad Wrote: Show what you have tried
And there's this extra problem: in the code snippet below, as soon as I import root.tk, the map opens automatically.
block of code where I call two different files and try multiprocessing:
from multiprocessing import Process
from mainMap import root_tk
from mainarayüz import main
def arayuz() :
p1 = Process(target= main())
p2 = Process(root_tk.mainloop())
p1.start()
p2.start()
p1.join()
p2.join()
if __name__ == '__main__' :
arayuz()
`
Posts: 6,240
Threads: 16
Joined: Feb 2020
A couple problems. When you import a module the first time, Python executes the module code. If you don't want to draw the map you must put that code inside a function or hide it behind if __name__ == '__main__' :. The bigger problem is it sounds like you are running tk in one process and mainloop in another. That will not work. You must create your windows and run mainloop in the same process.
Posts: 4
Threads: 1
Joined: Nov 2023
(Nov-09-2023, 08:27 PM)deanhystad Wrote: A couple problems. When you import a module the first time, Python executes the module code. If you don't want to draw the map you must put that code inside a function or hide it behind if __name__ == '__main__' :. The bigger problem is it sounds like you are running tk in one process and mainloop in another. That will not work. You must create your windows and run mainloop in the same process.
from multiprocessing import Process
def ana() :
from mainMap import root_tk
from mainarayüz import main
p1 = Process(target=(root_tk, main))
p1.start()
ana() like this?
Posts: 6,240
Threads: 16
Joined: Feb 2020
Nov-09-2023, 09:37 PM
(This post was last modified: Nov-09-2023, 09:37 PM by deanhystad.)
What benefit are you getting from running everything in a separate process?
You don't have to use mainloop(). Is there a way you could periodically call window.update() for the tk root window? I've never tried running Qt and Tk in the same process like this, but it is worth a try.
If this was me, I would drop either Qt or Tkinter and do everything using one GUI toolkit. Since it sounds like the map is the most complicated thing, I would say bye bye Qt py.
Posts: 4
Threads: 1
Joined: Nov 2023
(Nov-09-2023, 09:37 PM)deanhystad Wrote: What benefit are you getting from running everything in a separate process?
You don't have to use mainloop(). Is there a way you could periodically call window.update() for the tk root window? I've never tried running Qt and Tk in the same process like this, but it is worth a try.
If this was me, I would drop either Qt or Tkinter and do everything using one GUI toolkit. Since it sounds like the map is the most complicated thing, I would say bye bye Qt py. You are right, but for now I need to solve this problem, because it is urgent. After that, I'll put the two together via Qt or Tkinter. At first I tried using the folium library in Qt5, but it was technically impossible to update the marker in folium, and I didn't want to develop the interface in Tkinter. So I came up with this solution, but I can't make it work. I just managed to run both apps together, but after 1 second both apps froze and didn't update themselves.
I will post the code:
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
from sarsgui_taslak import Ui_MainWindow
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtCore import QTimer
from geopy.geocoders import OpenCage
from PyQt5.QtGui import QFont, QColor
from connecBaglanti import connect, connection_string, vehicle , VehicleMode, LocationLocal
from attitude_indicator import AttitudeIndicator
import datetime
import time
import math
import tkinter as tk
import tkintermapview
import time
import threading
import os
from PIL import Image, ImageTk
from connecBaglanti import connect, connection_string, vehicle, lat, lon
from multiprocessing import Process
# print("Simülatör başlatılıyor (SITL)")
# connection_string = "tcp:127.0.0.1:5762"
# print("Araç şurada bağlanıyor: %s" % (connection_string,))
# vehicle = connect(connection_string, wait_ready=False)
# # lat = vehicle.lsocation.global_relative_frame.lat
# lon = vehicle.location.global_relative_frame.lon
opencage_api_key = "52a.........................0"
class MainPage(QMainWindow):
def __init__(self):
super().__init__()
######MAIN INTERFACE STUFFFFFFFFFFFFFFFFFFFFFFFF
####################################MAP WITH TKINTER##############################################
def mapgui() :
lat = vehicle.location.global_relative_frame.lat
lon = vehicle.location.global_relative_frame.lon
# create tkinter window
root_tk = tk.Tk()
root_tk.geometry(f"{1000}x{700}")
root_tk.title("SarsGUI Map")
###MAP STUFFFF
root_tk.mainloop()
def maingui():
uygulama = QApplication([])
pencere = MainPage()
pencere.show()
sys.exit(uygulama.exec_())
if __name__ == '__main__':
pyqt_process = Process(target=maingui)
tkinter_process = Process(target=mapgui)
pyqt_process.start()
tkinter_process.start()
pyqt_process.join()
tkinter_process.join()
|