Thank you, Konstantin!
As you point out, I thoroughly confused the "statusbar" instance with the
statusBar object class itself. Once I implemented the changes you specified
(more in line with the way they were in the tutorial in the first place),
everything worked correctly, both in Spyder and from the command line.
I agree with you that the statusbar instance (or any of the Qt widgets)
should be created as a separate step before using any of their methods. I
don't know what my very initial error was, but clearly each change I made
to try to get the "View" function to work, the more I dug myself into a
hole.
Thanks for your explanations, I feel like I understand Python classes and
Qt5 that little bit much more!
Jim
On Sunday, August 27, 2017 at 1:13:36 PM UTC-7, Konstantin Krayn wrote:
>
> Jim,
>
> I have checked your "cumulative" tutorial code on my computer, and I think
> I know where the problem is. I was able to replicate the described
> misbehavior and then to make a few corrections that restore nominal
> functionality of the program both in Spyder and when run from the command
> line.
>
> The key observation is that your code does not work properly in Spyder
> either: run it and look at the effect of checking/unchecking the toggle
> menu item to make sure that there is none.
>
> I think there are two issues with your code that are responsible for this
> misbehavior, both in the definition of the toggle event handler. First, you
> omitted parentheses in your calls to self.menuBar() method that returns the
> app's menu bar object (if it has already been created, which is the case
> here). Your calls self.statusBar.showMessage() and
> self.statusBar.clearMessage() might do something weird and are unlikely to
> have the intended effect. Second, you use methods showMessage() and
> clearMessage() of the statusBar() object instead of show() and hide()
> methods recommended by the tutorial. Adding parentheses and restoring the
> tutorial-recommended methods - self.statusBar().show() and
> self.statusBar().hide() - sufficed to make the program behave properly both
> in Spyder and when run from the command line on my computer.
>
> In fact, I would think of doing this check menu item exercise more along
> line with the tutorial because their way looks more transparent to me. They
> introduce self.statusbar reference to the self.statusBar() object upon its
> creation (note 'b'/'B' alternation in the two identifiers), and then
> operate with this reference, which eliminates subsequent calls to
> statusBar() method and makes the code overall clearer and safer.
>
> So, I think here are a couple of better changes to your code that have the
> program work properly:
>
> # constructor, replaces self.statusBar().showMessage('Ready')
> self.statusbar = self.statusBar() #creates self.statusbar reference
> to fresh new self.statusBar() object
> self.statusbar.showMessage('Ready')
>
> # toggle handler definition, replaces your initial code
> if state:
> self.statusbar.show()
> else:
> self.statusbar.hide()
>
> The bottom line is that Spyder appears to be innocent with respect to this
> issue. :)
>
> Konstantin
>
> On Sun, Aug 27, 2017 at 6:43 PM, jimmott via spyder <
> [email protected] <javascript:>> wrote:
>
> [...]
>
>> def toggleMenu(self, state):
>> if state:
>> self.statusBar.showMessage()
>> else:
>> self.statusBar.clearMessage()
>>
>
--
You received this message because you are subscribed to the Google Groups
"spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.