Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide critical pyqt warning when clicking a checkboc

I'm developping a GUI using PyQt4 in a Linux Ubuntu machine (XFCE desktop environement). I'm using Python 2.7.

Every thing works fine except that when I click a checkbox, this message is displayed in the console (even it doesn't affect the execution of the GUI):

(python:9482): Gtk-CRITICAL **: IA__gtk_widget_get_direction: assertion 'GTK_IS_WIDGET (widget)' failed

Here is a part from the code that displays a list of checkboxes:

def SFCheckList(self):
    groupBox = QtGui.QGroupBox("SF Functions List")
    self.grid = QtGui.QGridLayout()
    self.checkBoxList = [[], []]

    #Reading supported SF functions
    try:
        sql = "SELECT SF FROM Locators"
        cursor.execute(sql)
        results = cursor.fetchall()
    except:
        print "Error: unable to fecth data (SF Functions)"


    #Building the Checkbox List
    for SF in results:
        self.checkBoxList[0].append(QtGui.QCheckBox(SF[0])) 
        self.checkBoxList[1].append(SF[0])

    self.SFCheckListDisplay()
    groupBox.setLayout(self.grid)

    return groupBox

def SFCheckListDisplay(self):
    l = sqrt(len(self.checkBoxList[0]))
    if(l!=int(l)):
        l= int(l) + 1

    i=0
    j=0
    for cb in self.checkBoxList[0]:
        self.grid.addWidget(cb, i, j)
        j+=1
        if(j==l):
            i+=1
            j=0

I'm using the console to get some tests information. How can I prevent this message from appearing?

Thank you!

like image 751
HaTiMuX Avatar asked Sep 04 '14 08:09

HaTiMuX


1 Answers

I had similar problem with the following code on Windows 7, PyQt5:

import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class Window(QWidget):
    def __init__(self, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)
        self.stderr_backup = None

        self.label = QLabel("Test", self)

        self.layout = QHBoxLayout()
        self.layout.addWidget(self.label)

        self.setLayout(self.layout)

        self.show()

app = QApplication(sys.argv)
win = Window()
sys.exit(app.exec_())

The error message from Qt was as follows, but the application worked correctly anyway.

QWindowsWindow::setGeometry: Unable to set geometry 42x35+520+270 on QWidgetWindow/'WindowClassWindow'. Resulting geometry:  112x35+520+270 (frame: 8, 29, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 42x35, maximum size: 16777215x16777215).

I was able to disable the message by using:

def handler(msg_type, msg_log_context, msg_string):
    pass

PyQt5.QtCore.qInstallMessageHandler(handler)

However, I am not sure if that will work on PyQt4 and in your case.

like image 124
Fenikso Avatar answered Nov 07 '22 01:11

Fenikso