Add icon to Qdialogs

2,718 views
Skip to first unread message

Davy Cottet

unread,
Dec 14, 2014, 7:00:59 AM12/14/14
to leo-e...@googlegroups.com
Hi,
I would like to add the ability to set icon for g.app.gui.run... Qdialogs.
Actually, some of them have no icon set so an ugly system fallback icon is shown...
I thought it would be nice to set default Qdialog icon to leo's app one and even the ability to set a custom one.

That would mean to add some changes to leo/plugins/qt_gui.py.
To achieve that, I wonder if there is a special function to get default app icon, or if we have to specify icon name (leoapp32.png).

For example

def runAskOkCancelStringDialog(self,c,title,message,cancelButtonText=None,
                               okButtonText
=None, icon=None,default=""):

   
"""Create and run askOkCancelString dialog ."""

   
if g.unitTesting: return None

    d
= QtWidgets.QInputDialog()
    d
.setWindowTitle(title)
    d
.setLabelText(message)
    d
.setTextValue(default)
   
if icon:
        d
.setWindowIcon(icon)
   
else:
        d
.setWindowIcon(g.app.gui.getIconImage ('leoapp32.png'))
   
if cancelButtonText:
        d
.setCancelButtonText(cancelButtonText)
   
if okButtonText:
        d
.setOkButtonText(okButtonText)
    ok
= d.exec_()
   
return str(d.textValue()) if ok else None



Davy Cottet

unread,
Dec 14, 2014, 10:17:51 AM12/14/14
to leo-e...@googlegroups.com
Finally, I abandonned the idea of custom icons, since I though it was better for users to know that new dialogs are from Leo.

So I just modified a bit leo/plugins/leo_qt.py to attach Leo's app icons to dialogs without one.

I just realize that it only work for g.app.gui.runAskOkCancelStringDialog and  g.app.gui.runAskOkCancelNumberDialog
but not for runOpenFileDialog, runOpenDirectoryDialog & runSaveFileDialog...

I've to say that I've no idea why this difference...
Does anyone have any clue ?

Edward K. Ream

unread,
Dec 15, 2014, 5:40:49 AM12/15/14
to leo-editor
On Sun, Dec 14, 2014 at 9:17 AM, Davy Cottet <cotte...@gmail.com> wrote:


I just realize that it only work for g.app.gui.runAskOkCancelStringDialog and  g.app.gui.runAskOkCancelNumberDialog
but not for runOpenFileDialog, runOpenDirectoryDialog & runSaveFileDialog...

I've to say that I've no idea why this difference...
Does anyone have any clue ?

Various dialogs work differently and return different values.  Look at the code: these g.app.gui methods​
 
​call different Qt dialog methods, as would be expected.

EKR

Davy Cottet

unread,
Dec 15, 2014, 8:54:39 AM12/15/14
to leo-e...@googlegroups.com
Various dialogs work differently and return different values.  Look at the code: these g.app.gui methods​
 ​call different Qt dialog methods, as would be expected.
Yes, precisely the ones in question are  QInputDialog and QFileDialog. From what I've experimented, the others dialogs does not generate new tabs so no doesn't need icons.
I first worked with native QinputDialogs and then see that Leo embed those functions in Qt-Gui so better to use them.
The mods I've done work well for QinputDialogs, so I've done the same for QFileDialog since they both have a setWindowIcon function and child of Qdialog class.
But no way to make this work with QFileDialog ! I've googled a lot but not found any clue on this very specific issue.
Maybe someone on this forum have an answer..

Davy Cottet

unread,
Dec 15, 2014, 9:03:38 AM12/15/14
to leo-e...@googlegroups.com

Here is a screen shot of Leo main tab and "Save as.." dialog for you to see what I'm talking about :

leo-icon.png

Chris George

unread,
Dec 15, 2014, 11:25:32 AM12/15/14
to leo-e...@googlegroups.com
On Linux Mint 17 KDE I get the X windows icon on the task bar and the Leo icon on the actual Save As dialogue window.

Chris

Davy Cottet

unread,
Dec 15, 2014, 11:39:23 AM12/15/14
to leo-e...@googlegroups.com
Interesting... so that behavior is desktop dependent...
Is your version before or after rev e4b24d9526b60c3f04cedef9df673f263d70a7fd ?
I'm actually running under xfce.
I've another machine with Debian & KDE, I'll try to install Leo and run some tests on it if I've time tomorrow.
What about the behaviour on windows ?

Chris George

unread,
Dec 15, 2014, 7:30:54 PM12/15/14
to leo-e...@googlegroups.com
I use the latest version from git, downloaded by 7am Pacific daily.


Leo Log Window

Leo 5.0-final, build 20141214175420, Sun Dec 14 17:54:20 CST 2014

Git repo info: branch = master, commit = 861bce9f9855

Python 2.7.6, PyQt version 4.8.6
linux2


I use Linux Mint 17 KDE (Ubuntu based).


Chris 

Davy Cottet

unread,
Dec 16, 2014, 2:51:45 AM12/16/14
to leo-e...@googlegroups.com
I didn't take time to try on other system, but think I found a potential workaround for these not Leo's default x icons.

I didn't really understand why QInputDialog and QfileDialogs have different behaviours regarding to setWindowIcon...
I've read that since it has no parent, a Qwidget should be considered as a window...
Maybe one have to deal with setAttribute or setWindowsFlags... but I didn't work on this way.

Actually, a simple workaround is to define a "parent" attribute for every Dialog in order to get rid of new windows tab/icons.
In fact, that the case for some functions in plugins/qt_gui.py :

Those have "c.frame.top" defined as parent so do not generate a new windows tab in your desktop
runAboutLeoDialog
runAskDateTimeDialog
runAskOkDialog
runAskYesNoCancelDialog
runAskYesNoDialog

But those one specified parent=None, so a new tab is generated with an default x icon
alert
runAskLeoIDDialog
runOpenDirectoryDialog
runOpenFileDialog
runSaveFileDialog

As I said before, runOpenDirectoryDialog, runOpenFileDialog, runSaveFileDialog rely on QFileDialog on which setWindowIcon is actually not working.
I try to apply setWindowIcon on runAskLeoIDDialog which is a QMessageBox and it worked;

Finally those ones fallback on parent=None as well and i've modified them in rev e4b24d9526b60c3f04cedef9df673f263d70a7fd to display Leo's icon.
runAskOkCancelNumberDialog
runAskOkCancelStringDialog


So my question is : what about setting parent=c.frame.top for all of them  ?
By the way, some of these functions request c but don't use it.


PS : what is c.in_qt_dialog for ?

Message has been deleted

Davy Cottet

unread,
Dec 16, 2014, 3:34:07 AM12/16/14
to leo-e...@googlegroups.com
Here a simple example of what I'm talking about :
from  leo.core.leoQt import QtWidgets

b
= QtWidgets.QMessageBox

def independantBox():
   
"""This box is independant from Leo
    You can keep working without closing it
    It have its own tab on your desktop app panel"""
 
   
# For no new app tab
    box
=b()
   
#Equivalent to
   
#box=b(None)
   
#box=b(parent=None)
    box
.setWindowIcon(g.app.gui.appIcon)
    box
.exec_()



def childBox():
   
"""This box is attached to Leo
    Leo is frozen until you close it
    It have no tab on your panel"""

    box
=b(c.frame.top)
   
#Equivalent to
   
#box=b(parent=c.frame.top)
   
# Set tabs icon
    box
.exec_()


Davy Cottet

unread,
Dec 16, 2014, 9:44:11 AM12/16/14
to leo-e...@googlegroups.com
Finally I think I find out the origin of this icon problem !

I was trying to play with  evens of qFileDialog... and that was not working too.
I found this thread  where it is advised not using native dialogs in order to avoid some bugs and be faster.
That was the problem so I directly try to add an icon to this damned dialog (I know I a bit obsessed :p)

And that worked, the dialog look a bit different but personally I'm fine with that. You can have a shot with this code :

from  leo.core.leoQt import QtWidgets

def onDirEntered():
        g
.es("Entered in a new directory")
       
dialog
= QtWidgets.QFileDialog(None, 'Select directory')
dialog
.setDirectory(os.getenv('HOME'))
dialog
.setFileMode(QtWidgets.QFileDialog.Directory)
dialog
.directoryEntered.connect(onDirEntered)
# Try with and without this option :
dialog
.setOption(QtWidgets.QFileDialog.DontUseNativeDialog)
dialog
.setWindowIcon(g.app.gui.appIcon)
dialog
.exec_()


Reply all
Reply to author
Forward
0 new messages