[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Working example of QMenuBar on OSX? Examples don't work
From: Marcel_Maré <list () webtothemax ! com>
Date: 2016-06-06 7:20:28
Message-ID: 35E0AC0E-8FDD-4462-B5AF-177200F6CB2B () webtothemax ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hi Dave,
No, no, I'm running either from the IDE (PyCharm) or the command line (Python \
menus.py).
Met vriendelijke groet,
Marcel
> On 5 jun. 2016, at 22:01, David Cortesi <davecortesi@gmail.com> wrote:
>
> Ah. How are you running this program? e.g. from a command line, python myscript.py \
> , or how?
> What you describe sounds like a problem with an app after it was bundled by \
> PyInstaller. Owing to the lack of some magical incantation in the app's info.plist, \
> the app's menus would not appear when it was launched, but if it was hidden (or if \
> another app was made active), when it came again to the front, its menus did \
> appear.
> That has been fixed for PyInstaller with the latest (3.2) version. Anyway, the code \
> I showed you should work.
>
> > On Sun, Jun 5, 2016 at 11:57 AM, Marcel Maré <list@webtothemax.com> wrote:
> > Hi
> >
> > Think I found out some more.
> >
> > To rule out a programming error on my part (bering new to Qt) I only looked at \
> > the menus.py example (Qt/examples/mainwindows/menus.py).
> > The relevant menu definition sections is like this:
> >
> > def createMenus(self):
> > self.fileMenu = self.menuBar().addMenu("&File")
> > self.fileMenu.addAction(self.newAct)
> > self.fileMenu.addAction(self.openAct)
> > self.fileMenu.addAction(self.saveAct)
> > self.fileMenu.addAction(self.printAct)
> > self.fileMenu.addSeparator()
> > self.fileMenu.addAction(self.exitAct)
> >
> > self.editMenu = self.menuBar().addMenu("&Edit")
> > self.editMenu.addAction(self.undoAct)
> > self.editMenu.addAction(self.redoAct)
> > self.editMenu.addSeparator()
> > self.editMenu.addAction(self.cutAct)
> > self.editMenu.addAction(self.copyAct)
> > self.editMenu.addAction(self.pasteAct)
> > self.editMenu.addSeparator()
> >
> > So, since it uses self.menuBar() it should not be compatible with the system menu \
> > on OSX, since it does not use QMenuBar().
> > Wat I found out that is that when I run the program the menu is visible but \
> > unclickable (as reported earlier). However, when I switch to some other program \
> > and then back to the menus.py program the menu works! Looks like a bug to me.
> >
> > Marcel
> >
> >
> >
> > > On 05 Jun 2016, at 18:42, David Cortesi <davecortesi@gmail.com> wrote:
> > >
> > > I have a PyQt5 app that works well in Mac OS, Linux and Windows. The only \
> > > difference I see in the setup of my QMainWindow is this:
> > > import platform
> > > if platform.uname().system.startswith('Darw') :
> > > self._menu_bar = QMenuBar() # parentless menu bar for Mac OS
> > > else :
> > > self._menu_bar = self.menuBar() # refer to the default one
> > >
> > > and then it proceeds to initialize self._menu_bar with menus, e.g.
> > >
> > > self.file_menu = self._menu_bar.addMenu(_TR('Menu name', '&File'))
> > > work = self.file_menu.addAction( _TR('File menu command','&New') )
> > > work.setShortcut(QKeySequence.New)
> > > work.setToolTip( _TR('File:New tooltip','Create a new, empty document') )
> > > work.triggered.connect(self._new)
> > >
> > > and so forth. The above test of platform.uname() is about the only platform \
> > > difference in the whole app...
>
[Attachment #5 (text/html)]
<html><head><meta http-equiv="content-type" content="text/html; \
charset=utf-8"></head><body dir="auto"><div>Hi Dave,</div><div \
id="AppleMailSignature"><br></div><div id="AppleMailSignature">No, no, I'm running \
either from the IDE (PyCharm) or the command line (Python menus.py). <br><br>Met \
vriendelijke groet,<div><br></div><div>Marcel</div></div><div><br>On 5 jun. 2016, at \
22:01, David Cortesi <<a \
href="mailto:davecortesi@gmail.com">davecortesi@gmail.com</a>> \
wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div><div>Ah. How are \
you running this program? e.g. from a command line, python myscript.py , or \
how?<br><br></div>What you describe sounds like a problem with an app after it \
was bundled by PyInstaller. Owing to the lack of some magical incantation in the \
app's info.plist, the app's menus would not appear when it was launched, but if it \
was hidden (or if another app was made active), when it came again to the front, its \
menus did appear.<br><br></div>That has been fixed for PyInstaller with the latest \
(3.2) version. Anyway, the code I showed you should work.<br><br></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 5, 2016 at 11:57 AM, \
Marcel Maré <span dir="ltr"><<a href="mailto:list@webtothemax.com" \
target="_blank">list@webtothemax.com</a>></span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div style="word-wrap:break-word">Hi<div><br></div><div>Think \
I found out some more. </div><div><br></div><div>To rule out a programming error \
on my part (bering new to Qt) I only looked at the menus.py example \
(Qt/examples/mainwindows/menus.py). </div><div><br></div><div>The relevant menu \
definition sections is like this:</div><div><br></div><div><pre \
style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Menlo';font-size:10.5pt"><span \
style="color:#cc7832;font-weight:bold">def </span><span \
style="font-weight:bold">createMenus</span>(<span \
style="color:#94558d">self</span>):<br> <span \
style="color:#94558d">self</span>.fileMenu = <span \
style="color:#94558d">self</span>.menuBar().addMenu(<span \
style="color:#008080">"&File"</span>)<br> <span \
style="color:#94558d">self</span>.fileMenu.addAction(<span \
style="color:#94558d">self</span>.newAct)<br> <span \
style="color:#94558d">self</span>.fileMenu.addAction(<span \
style="color:#94558d">self</span>.openAct)<br> <span \
style="color:#94558d">self</span>.fileMenu.addAction(<span \
style="color:#94558d">self</span>.saveAct)<br> <span \
style="color:#94558d">self</span>.fileMenu.addAction(<span \
style="color:#94558d">self</span>.printAct)<br> <span \
style="color:#94558d">self</span>.fileMenu.addSeparator()<br> <span \
style="color:#94558d">self</span>.fileMenu.addAction(<span \
style="color:#94558d">self</span>.exitAct)<br><br> <span \
style="color:#94558d">self</span>.editMenu = <span \
style="color:#94558d">self</span>.menuBar().addMenu(<span \
style="color:#008080">"&Edit"</span>)<br> <span \
style="color:#94558d">self</span>.editMenu.addAction(<span \
style="color:#94558d">self</span>.undoAct)<br> <span \
style="color:#94558d">self</span>.editMenu.addAction(<span \
style="color:#94558d">self</span>.redoAct)<br> <span \
style="color:#94558d">self</span>.editMenu.addSeparator()<br> <span \
style="color:#94558d">self</span>.editMenu.addAction(<span \
style="color:#94558d">self</span>.cutAct)<br> <span \
style="color:#94558d">self</span>.editMenu.addAction(<span \
style="color:#94558d">self</span>.copyAct)<br> <span \
style="color:#94558d">self</span>.editMenu.addAction(<span \
style="color:#94558d">self</span>.pasteAct)<br> <span \
style="color:#94558d">self</span>.editMenu.addSeparator()<br></pre><div><br></div></div><div>So, \
since it uses self.menuBar() it should not be compatible with the system menu on OSX, \
since it does not use QMenuBar(). </div><div><br></div><div>Wat I found out that \
is that when I run the program the menu is visible but unclickable (as reported \
earlier). However, when I switch to some other program and then back to the menus.py \
program the menu works!</div><div>Looks like a bug to me.</div><span \
class="HOEnZb"><font \
color="#888888"><div><br></div><div>Marcel </div></font></span><div><div \
class="h5"><div><br></div><div><br></div><div><br><div><blockquote \
type="cite"><div>On 05 Jun 2016, at 18:42, David Cortesi <<a \
href="mailto:davecortesi@gmail.com" target="_blank">davecortesi@gmail.com</a>> \
wrote:</div><br><div><div dir="ltr"><div><div>I have a PyQt5 app that works well in \
Mac OS, Linux and Windows. The only difference I see in the setup of my QMainWindow \
is this:<br><br> import \
platform<br> if \
platform.uname().system.startswith('Darw') \
:<br> \
self._menu_bar = QMenuBar() # parentless menu bar for Mac \
OS<br> else \
:<br> \
self._menu_bar = self.menuBar() # refer to the default one<br><br></div>and then it \
proceeds to initialize self._menu_bar with menus, \
e.g.<br><br> self.file_menu = \
self._menu_bar.addMenu(_TR('Menu name', \
'&File'))<br> work = \
self.file_menu.addAction( _TR('File menu command','&New') \
)<br> \
work.setShortcut(QKeySequence.New)<br> \
work.setToolTip( _TR('File:New tooltip','Create a new, empty document') \
)<br> \
work.triggered.connect(self._new)<br><br></div>and so forth. The above test of \
platform.uname() is about the only platform difference in the whole app...<br></div> \
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div> \
</div></blockquote></body></html>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic