8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

相同的QComboBox最大递归错误

Porcupine Andrew 2月前

35 0

def update_dropdowns(self, df): # 使用来自 DataFrame 的唯一区域更新下拉菜单 self.areas = [\'none\'] self.areas.extend( df[df.columns[1]].unique()) ...

def update_dropdowns(self, df):
        # Update dropdown menus with unique areas from the DataFrame
        self.areas = ["none"]
        self.areas.extend( df[df.columns[1]].unique())
        self.gui_components['area_dropdown_1'].clear()
        self.gui_components['area_dropdown_2'].clear()
        self.gui_components['area_dropdown_3'].clear()
        print("mitte update dropdown")
        for area in self.areas:
            print("start for loop")
            self.gui_components['area_dropdown_1'].addItem(area)
            print("after_1")
            self.gui_components['area_dropdown_2'].addItem(area)
            print("after_2")
            self.gui_components['area_dropdown_3'].addItem(area)
            print("after_3")

所有区域下拉菜单的创建方式完全相同。调用此函数时,将打印以下内容:

enter image description here

如您所见,它被多次调用,但从不打印最后一条语句,并抛出最大递归深度错误。因此,我假设错误发生在最后一次 self.gui_components 调用中。

因此我将其注释掉,它完全正常工作,只是 GUI 中缺少一个组合框。但没有错误。奇怪的是,以下所有代码都有效:

def update_dropdowns(self, df):
        # Update dropdown menus with unique areas from the DataFrame
        self.areas = ["none"]
        self.areas.extend( df[df.columns[1]].unique())
        self.gui_components['area_dropdown_1'].clear()
        self.gui_components['area_dropdown_2'].clear()
        self.gui_components['area_dropdown_3'].clear()
        print("mitte update dropdown")
        for area in self.areas:
            print("start for loop")
            self.gui_components['area_dropdown_1'].addItem(area)
            print("after_1")
            self.gui_components['area_dropdown_2'].addItem(area)
            print("after_2")
            #self.gui_components['area_dropdown_3'].addItem(area)
            print("after_3")

def update_dropdowns(self, df):
        # Update dropdown menus with unique areas from the DataFrame
        self.areas = ["none"]
        self.areas.extend( df[df.columns[1]].unique())
        self.gui_components['area_dropdown_1'].clear()
        self.gui_components['area_dropdown_2'].clear()
        self.gui_components['area_dropdown_3'].clear()
        print("mitte update dropdown")
        for area in self.areas:
            print("start for loop")
            self.gui_components['area_dropdown_1'].addItem(area)
            print("after_1")
            #self.gui_components['area_dropdown_2'].addItem(area)
            print("after_2")
            self.gui_components['area_dropdown_3'].addItem(area)
            print("after_3")

def update_dropdowns(self, df):
        # Update dropdown menus with unique areas from the DataFrame
        self.areas = ["none"]
        self.areas.extend( df[df.columns[1]].unique())
        self.gui_components['area_dropdown_1'].clear()
        self.gui_components['area_dropdown_2'].clear()
        self.gui_components['area_dropdown_3'].clear()
        print("mitte update dropdown")
        for area in self.areas:
            print("start for loop")
            #self.gui_components['area_dropdown_1'].addItem(area)
            print("after_1")
            self.gui_components['area_dropdown_2'].addItem(area)
            print("after_2")
            self.gui_components['area_dropdown_3'].addItem(area)
            print("after_3")

输出如下:

enter image description here

但最终它不起作用。我也尝试过这个:

# Initialization of the controller with the view, file dialog, and optional CSV file path and displayed table name

        self.table_names = []  # List to store table names
        super().__init__()  
        self.view = view  # Reference to the view component
        self.file_dialog = file_dialog  # Reference to the file dialog component
        self.displayed_table_name = displayed_table_name  # Name of the table currently displayed
        self.displayed_df = pd.DataFrame()  # DataFrame for the displayed table
        self.indicator_flag = True 
        self.updated_df = pd.DataFrame()  # DataFrame for the updated table
        self.source_df = pd.DataFrame() # Dataframe for the source table
        self.indicator_df = pd.DataFrame() #Dataframe for the indicatior table
        self.clicked_cells = []  # Set to keep track of clicked cells
        self.indicator_path = None
        self.source_path = None
        self.indicator_name = None
        self.source_name = None
        self.areas = ["none"]

        # GUI components and their corresponding view elements
        self.gui_components = {
            
            "main_table": self.view.main_table,
            "updated_table": self.view.updated_table,
            "substring_input":self.view.substring_input,
            "area_dropdown_1": self.view.area_dropdown_1,
            "area_dropdown_2": self.view.area_dropdown_2,
            "area_dropdown_3": self.view.area_dropdown_3,
            }


        # Event handler for cell editing
        def cell_edited(item):
            if (item.row(),item.column()) in self.clicked_cells:
                print("wuhu")
                self.displayed_df.iloc[item.row(), item.column()] = item.text()
                print("hello")
                # Update the dropdown menus with the updated DataFrame
                self.update_dropdowns(self.displayed_df)
                print("qewrqewrqwerqrew")
                
                #TODO: indicator source check


        # Event handler for cell activation
        def cell_activated(row,column):
            self.clicked_cells.append((row,column))
            
        # Event handler for table button clicks
        def table_button_handler(item,name,bool):
            
            if item.column() == 2 and self.indicator_flag:
                self.open_information(str(name)) 
            elif item.column() == 3 and self.indicator_flag:
                self.open_source(str(name))
            elif bool:
                self.add_to_calc_tool(name)

        # Connect buttons to their respective handlers
        self.gui_components['delete_row_button'].clicked.connect(lambda: self.delete_row())
        self.gui_components['export_button'].clicked.connect(lambda: self.export_filtered_table())
        self.gui_components['import_button'].clicked.connect(lambda: self.import_data())
        self.gui_components['main_table'].itemChanged.connect(cell_edited)  ##
        self.gui_components['main_table'].cellClicked.connect(cell_activated) ##
        self.gui_components['main_table'].itemDoubleClicked.connect(lambda item:table_button_handler(item,self.gui_components['main_table'].item(item.row(), 0).text(),False))

self.gui_components['area_dropdown_1'].currentTextChanged.connect(lambda: self.apply_filters())
        self.gui_components['area_dropdown_2'].currentTextChanged.connect(lambda: self.apply_filters())
        self.gui_components['area_dropdown_3'].currentTextChanged.connect(lambda: self.apply_filters())
        self.gui_components['substring_input'].textChanged.connect(lambda: self.apply_filters())
        

    def update_dropdowns(self, df):
        # Update dropdown menus with unique areas from the DataFrame
        self.areas = ["none"]
        self.areas.extend( df[df.columns[1]].unique())
        self.gui_components['area_dropdown_1'].clear()
        self.gui_components['area_dropdown_2'].clear()
        self.gui_components['area_dropdown_3'].clear()
        print("mitte update dropdown")
        for area in self.areas:
            print("start for loop")
            self.gui_components['area_dropdown_1'].addItem(area)
            print("after_1")
            self.gui_components['area_dropdown_2'].addItem(area)
            print("after_2")
            self.gui_components['area_dropdown_3'].addItem(area)
            print("after_3")
        #self.update_last_dropdown(self.areas)



    #def update_last_dropdown(self,areas):
    #    for area in areas:
    #        self.gui_components['area_dropdown_3'].addItem(area)

    def apply_filters(self):
        # Apply filters to the displayed DataFrame based on user input

        # Get the user input from the GUI componentsa
        substring = self.gui_components['substring_input'].text()
        area_1 = self.gui_components['area_dropdown_1'].currentText()
        area_2 = self.gui_components['area_dropdown_2'].currentText()
        area_3 = self.gui_components['area_dropdown_3'].currentText()

        
        # Filter by substring if provided
        if substring != "":
            updated_df = self.displayed_df[self.displayed_df['name'].str.contains(substring, case=False, na=False)]
        
        # Filter by areas if selected
        selected_areas = [area for area in [area_1, area_2, area_3] if area != "none"]
        if selected_areas: #["economic","ecological"]
            
            updated_df = self.displayed_df[self.displayed_df['area'].isin(selected_areas)]
        else:
            updated_df = self.displayed_df
        
        # Update the controller's updated DataFrame
        self.updated_df = updated_df.copy().drop_duplicates(inplace=True)
        
        # Display the filtered DataFrame in the updated table
        self.display_table(table_to_display_to = "updated_table", dataframe = updated_df)

这将会引发与开始时相同的错误。

帖子版权声明 1、本帖标题:相同的QComboBox最大递归错误
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由Porcupine Andrew在本站《python》版块原创发布, 转载请注明出处!
最新回复 (0)
  • @musicamante 希望这能有所帮助,遗憾的是我没有足够的时间按照 MRE 的建议从头开始。这是函数范围内的全部代码。

  • @jasonharper 不,在我展示的第二个代码片段中,每个函数都有效。这让我相信 area_dropdown_3 没有问题,因为只有当所有 3 个都被调用时它才会失败

返回
作者最近主题: