Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

fariza
Copy link
Member

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

ButGtk.main_quit() is called depending onis_interactive(), it doesn't take in count who calledGtk.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 ifGtk.main() was called inside the mainloop to restrict the call ofGtk.main_quit()

This may be related to PR#2503

import matplotlibmatplotlib.use('GTK3AGG')import matplotlib.pyplot as pltfrom gi.repository import Gtkclass 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 thepyplot dependence out of thefigure_manager classes this be able to get at those with out having to importpyplot and all the state it brings with it.

@fariza
Copy link
MemberAuthor

@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 becausepyplot callspylab_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 thefigure method that at the end do the assembly of the figure, canvas and manager (throughnew_figure_manager andnew_figure_manager_given_figure).

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

@fariza
Copy link
MemberAuthor

@tacaswell another question

Is there any specific reason to get rid ofGcf 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
MemberAuthor

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 moreGcf,new_figure_manager_given_figure,new_figure_manager orShow 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 backendfigure_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 whatpyplot.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
MemberAuthor

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

@farizafariza closed thisNov 29, 2013
@farizafariza deleted the keep_track_of_gtk_main_call branchFebruary 11, 2015 18:09
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@fariza@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp