Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding global variable to keep track if gtkmain has been called #2604

Closed
wants to merge 1 commit into from

Conversation

fariza
Copy link
Member

@fariza fariza commented Nov 21, 2013

When embedding plot creation in gtk (see example below)
The mainloop does not call Gtk.main() because it has been called by the embedder.

But Gtk.main_quit() is called depending on is_interactive(), it doesn't take in count who called Gtk.main()

This causes that the embedder program, gets destroyed when destroying the last window of the plots.

The proposed solution is just an ugly variable added to keep track if Gtk.main() was called inside the mainloop to restrict the call of Gtk.main_quit()

This may be related to PR #2503

import matplotlib
matplotlib.use('GTK3AGG')
import matplotlib.pyplot as plt

from gi.repository import Gtk

class MyWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Hello World")
        self.button = Gtk.Button(label="Click Here")
        self.button.connect("clicked", self.on_button_clicked)
        self.add(self.button)

    def on_button_clicked(self, widget):
        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.plot([1,2,3])
        plt.show()

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

@tacaswell
Copy link
Member

I don't think this is the best way to do this.

I think it is far better to factor the pyplot dependence out of the figure_manager classes this be able to get at those with out having to import pyplot and all the state it brings with it.

@fariza
Copy link
Member Author

fariza commented Nov 21, 2013

@tacaswell I agree with you. As I said this is just a workaround the problem.

If you want I can do the removal of the dependencies in Gtk3, just to see how it goes.

At this moment, pyplot does know what figure manager and what canvas to use because pyplot calls pylab_setup to import the appropiate figure manager and canvas.

My first questions
How do we replace this functionality?
Where do we place it to be called automagically?

Another point that comes to mind, pyplot has the figure method that at the end do the assembly of the figure, canvas and manager (through new_figure_manager and new_figure_manager_given_figure).

My second question
Do we want to provide a similar method?

@fariza
Copy link
Member Author

fariza commented Nov 21, 2013

@tacaswell another question

Is there any specific reason to get rid of Gcf or even _pylab_helpers.py?
At first view I dont' see anything wrong with it and find it usefull when working with several figures.
It could be just renamed _figure_helpers.py or moved inside somewhere else

@fariza
Copy link
Member Author

fariza commented Nov 27, 2013

Hello

I have a preview working but I need some answers to know how do you want to reorganize the pyplot/pylab stuff.
I just removed everything, so there is no more Gcf, new_figure_manager_given_figure, new_figure_manager or Show inside the backend.

My little example is working calling figure, canvas and figuremanager form within my Gtk3 app, but of course without those helpers it is not of much use in scripting or interactive mode.

I don't want to be too intense with this, but if we don't clear this from here, it will be impossible to move forward with other things, because this is always first in the list of modifications that you propose.

@tacaswell
Copy link
Member

The idea is to write a second layer of classes (which keep the current names, the current classes with Gcf and company stripped need to be renamed) that sticky tape together the backend figure_manager + Gcf to be exposed back to the rest of pyplot. I suspect that this could be done with a factory method, you feed it in a backend and Gcf, and it returns a class that replicates what the figure_manager class does now. Those classes are what pyplot.figure talks to. That make sense?

@tacaswell
Copy link
Member

Also, to be clear, you don't have to listen to my suggestions, if you think I am wrong explain why (or just ignore me ;))

Sorry if I am coming across as hostile, it is not intentional.

@tacaswell
Copy link
Member

@fariza Also be aware of the changes introduced in #2588 which may or may not affect this.

@fariza
Copy link
Member Author

fariza commented Nov 27, 2013

@tacaswell I submited a first draft PR #2617 for review.
Please let me know what you think.

@fariza fariza closed this Nov 29, 2013
@fariza fariza deleted the keep_track_of_gtk_main_call branch February 11, 2015 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants