Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Connect menu action from importet modul (GUI startet via function)
QtWS25 Last Chance

Connect menu action from importet modul (GUI startet via function)

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 3 Posters 331 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nietzsche
    wrote on last edited by
    #1

    Hello,

    I have the following issue and I hope someone can help me. I have the following scripts:

    1.) Main script (Imports df from script 2, starts the plotter function from script 3, and passes df to it)
    2.) Script for BLE communication (creates a Pandas DataFrame, df, and passes df to script 1 by importing the variable from it)
    3.) Script for plotter window (plots the data from df using an integrated plotter function, to which the main script passes the data from df when it starts)

    So far, everything is working fine. The plotter window was implemented using pyqtgraph. First, a GUI window was designed in QT Designer, then the widget was promoted, and the corresponding class was assigned. In the script, the UI was imported using the following line:

    "uiclass, baseclass = pg.Qt.loadUiType("plotter_window.ui")"

    A MainWindow was created from the uiclass, and in this class, the plotting function was defined. So far, so good. It works, and my data is plotted. However, I can only plot all the data or the first data points. When I try to plot the last data points, I get an error saying that the index was not found. Here is the code:

    Works: "spo2_list = df['Red'].astype(float)"
    Doesn't work: "spo2_list = df['Red'].tail(100).astype(float)"

    Can someone possibly help me with this?

    However, my main problem is that I don't know how to update the plotter when I click on File > Refresh in the menu at the top of the window (a menu was created using qt Designer). Can someone help me with that? I have tried various approaches, but nothing has worked so far.

    jsulmJ 1 Reply Last reply
    0
    • N Nietzsche

      Hello,

      I have the following issue and I hope someone can help me. I have the following scripts:

      1.) Main script (Imports df from script 2, starts the plotter function from script 3, and passes df to it)
      2.) Script for BLE communication (creates a Pandas DataFrame, df, and passes df to script 1 by importing the variable from it)
      3.) Script for plotter window (plots the data from df using an integrated plotter function, to which the main script passes the data from df when it starts)

      So far, everything is working fine. The plotter window was implemented using pyqtgraph. First, a GUI window was designed in QT Designer, then the widget was promoted, and the corresponding class was assigned. In the script, the UI was imported using the following line:

      "uiclass, baseclass = pg.Qt.loadUiType("plotter_window.ui")"

      A MainWindow was created from the uiclass, and in this class, the plotting function was defined. So far, so good. It works, and my data is plotted. However, I can only plot all the data or the first data points. When I try to plot the last data points, I get an error saying that the index was not found. Here is the code:

      Works: "spo2_list = df['Red'].astype(float)"
      Doesn't work: "spo2_list = df['Red'].tail(100).astype(float)"

      Can someone possibly help me with this?

      However, my main problem is that I don't know how to update the plotter when I click on File > Refresh in the menu at the top of the window (a menu was created using qt Designer). Can someone help me with that? I have tried various approaches, but nothing has worked so far.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Nietzsche said in Connect menu action from importet modul (GUI startet via function):

      I get an error saying that the index was not found

      So, did you check how many entries you actually have there?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Nietzsche said in Connect menu action from importet modul (GUI startet via function):

        I get an error saying that the index was not found

        So, did you check how many entries you actually have there?

        N Offline
        N Offline
        Nietzsche
        wrote on last edited by Nietzsche
        #3

        @jsulm Hi, i have fixed the problem. But now i want to plot an live chart via pglive, maybe someone can help ?

        Here my code:

        import pyqtgraph as pg
        from PyQt6.QtWidgets import QMainWindow
        from PyQt6 import uic
        import numpy as np
        from PySide6.QtGui import Qt
        
        
        uiclass, baseclass = uic.loadUiType("plotter_window.ui")
        
        class PlotterWindow(QMainWindow, uiclass):
            def __init__(self, df):
                super().__init__()
                self.plot_item = None
                self.setupUi(self)
                self.actionAktualisieren.triggered.connect(self.update_button_plotter)
        
            def plot(self, df):
                print("Daten des DF in Plotter Modul")
                print(df)
                spo2_list = df['Red'].astype(float) # Gibt alle Werte aus
        
                # spo2_list = df['Red'][:100].astype(float) #gibt die ersten 100 Werte aus
                # spo2_list = df['Red'].tail(100).astype(float) # gibt die letzten 100 Werte aus, klappt nicht
        
                print("spo2_list = ")
                print(spo2_list)
                print("letzte 100 Werte")
                letzte_werte = df['Red'].tail(50).astype(float)
                print(letzte_werte)
                self.plot_item = self.graphWidget.plot() # Erstellen des Graphen
                self.plot_item .setData(spo2_list)  # Aktualisieren der Daten des Graphen
                self.plot_item.setData(y=spo2_list)  # Aktualisiere die Daten des Graphen
        
        
            def update_button_plotter(self):
        
                # Aktualisiere den Plot mit den neuen Daten
                from safe_to_excel import df
                spo2_list = df['Red'].tail(50).astype(float)  # Gibt die letzten 100 Werte aus
                spo2_list.reset_index(drop=True, inplace=True)  # Setze den Index zurück
                self.plot_item.setData(y=np.array(spo2_list))  # Aktualisiere die Daten des Graphen
                print(df)
        
            def keyPressEvent(self, event):
                if event.key() == Qt.Key.Key_F5:
                    self.update_button_plotter()
                else:
                    super().keyPressEvent(event)
        
        
        

        Regards

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nafi Ullah
          wrote on last edited by
          #4

          Regarding the issue with plotting the last data points from the DataFrame in Python:

          Check if the column exists in the DataFrame using 'Red' in df.columns.
          Handle the case when the column doesn't exist.
          You can follow this pattern:

          if 'Red' in df.columns:
              spo2_list = df['Red'].tail(100).astype(float)
          else:
              # Handle the case when the column doesn't exist
              spo2_list = None  # or any other desired handling
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved