8000 Enabling tool positions by OceanWolf · Pull Request #7 · fariza/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Enabling tool positions #7

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

Conversation

OceanWolf
Copy link

As far as I can see, I have it working...

I found it confusing seeing in some places, end of group meant passing position as -1 and other places as None, so I went for -1 for consistency (and it allows one to set it as -2 to place it in the penultimate position in the group).

The name of the group.
position : int
The position within the group, if -1, it goes at the end.
"""
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self, need to add some more documentation here, i.e. say it returns the position that this should get inserted into the toolbar.

@fariza
Copy link
Owner
fariza commented Feb 9, 2015

@OceanWolf I am a little bit confused, as I see, you are computing the per group position inside the base clases. But there is no actually "grouping" in the implementation (GTK3). What am I missing?

The main idea of the groups, was to be able to "split" the buttons between different "toolbars" or "menus" when implementing a custom backend.
In our current implementation, was just to add a separator between the groups.

@OceanWolf
Copy link
Author

Ahh, okay, I presumed that the groups were just to make it easier to add a tool to a specific position and to do mass delete of groups.

As I understand it, you want a backend specific way to handle the grouping... do all backends support this? If not, then I guess I will leave these new methods in to get called by the specific backend if they need a fallback method... I will investigate it later this week.

@fariza
Copy link
Owner
fariza commented Feb 9, 2015

Until now, the only thing backend supported was the "spacer" and you added the tools in order.
I wanted a little bit more.
navigation opens the door to have many more tools and we might need a way to organize them. That is where the "group" idea comes from.

@fariza
Copy link
Owner
fariza commented Feb 9, 2015

I am not sure on how to do this, it is just an idea

…r a specific backend, while keeping default.
@OceanWolf
Copy link
Author

I don't know if one can do it on GTK, (I had a look but couldn't see any) but I have re-written to make it possible to override the default methods to do a backend specific implementation.

@OceanWolf
Copy link
Author

There we go, I have just reimplemented the seperators to illustrate how the backend can now decide how it wants to implement groups.

@fariza
Copy link
Owner
fariza commented Feb 13, 2015

@OceanWolf Check my approach for this https://github.com/fariza/matplotlib/compare/fariza:navigation-by-events...tool-positions?expand=1

I am not saying mine is ok and yours is wrong. I just want to compare two different understandings of "grouping"

In my view, group is completely up to the backend to implement it.

@OceanWolf
Copy link
Author

I don't know enough GTK to see what goes on, but I assume it works and I want to try. Not exactly sure what I look at though, if I read it write it says it compares this (my) branch with navigation-by-events, but I don't see any new commits in there...

P.S. Just doing my final checks on my latest branch before I PR :).

@fariza
Copy link
Owner
fariza commented Feb 13, 2015

My approach was pretty simple, I create a different toolbar for each group, and add the tools to the corresponding toolbar in it's given position (relative position).
Of course, for the default backend it is overkill to have this, but it is just to demonstrate how to separate the tools.

@fariza
Copy link
Owner
fariza commented Feb 13, 2015

make sure the comparison is between my two branches, not yours, because your navigation-by-events it's outdated, because it was created when you forked my branch, but you never push to it after that.

@OceanWolf
Copy link
Author

Yes, I agree with respect to the default backend, that's what I tried to do here, create a default implementation that allows the custom backends the flexability to override the default behaviour and do it in their own way.

For example in ToolbarBase, I added the property _groups as an ordered dict, and will contain key value pairs, where the key=group_name and the value acts as a tool container. In my default implementation, I implement this container as a simple list, but here I have the expectations that a custom backend would implement this as backend specific ToolItemGroup or in your case as mini-toolbars.

As I say, I want to grab the code, run, and perhaps merge together into mine. I understand the comparison exists between our two branches, but I don't see any of your code here https://github.com/matplotlib/matplotlib/pull/3652/files I presume this contains the most up-to-date version, what do I miss?

@fariza
Copy link
Owner
fariza commented Feb 13, 2015

My code is not merged, is in a separate branch https://github.com/fariza/matplotlib/tree/tool-positions

@fariza
Copy link
Owner
fariza commented Feb 13, 2015

by the way you can not use an ordereddict it was added in python 2.7 and mpl is officially supported from 2.5 (if I remember correctly).
This is why I didn't use an ordered dict instead of the list backend_tools.tools

@OceanWolf
Copy link
Author

Ahh yes, now I see, when you said I just want to compare two different understandings my head somehow thought that when I would click on your compare li 8000 nk, that I saw a comparison between this branch and yours (not helped that we named our branches similarly). Sorry for the confusion there. All completely obvious now I take a closer look.

So yes, I think our two approaches seem similar enough, practically identical. the only real difference lies in that your advance knowledge of GTK, i.e. knowing you can add multiple toolbars to a box, and my creation of a more uniform way to do it. But apart from that the code looks identical, the if statements, the variables used, they look exactly the same.

If I understand the benefit(s) in GTK for using toolbars in a box, it means that each individual toolbar will get those down_arrows when the toolbar_group gets full. I had tried to search for that, but I only got ToolItemGroup for ToolPalette, not quite what we wanted...

Shall I copy-paste your Gtk solution into mine, or attempt a merge? Variables different everywhere... so it may drive me crazy.

@OceanWolf
Copy link
Author

And yes, now I see the dependencies on the install page, annoying, it doesn't mention 2.5, only 2.6, so only one version out. I wonder when 2.6 support will get get dropped, given that python officially retired it over a year ago...

@fariza
Copy link
Owner
fariza commented Feb 13, 2015

The two approaches are not really compatible, in my case, the position in ToolbarBase.add_toolitem, is the position relative to the group, in yours it is the overall position. That is why I said, that my view of the problem, is to leave up to the specific backend to deal with the groups.

Sometime ago, I asked about the 2.6 vs 2.7 support and came back empty, so I wouldn't count on that, also I don't want to pollute the code with custom implementations on ordereddict

@OceanWolf
Copy link
Author

Ahh, I can see why you think that, and I did do it in my first commit, but since then I have deliberately made it more flexible then that after your first comment :). Trust me! I will go and make the changes and push it. Virtually the same :).

Did you ask about 2.6 in relation to mpl1.5? Debian currently has 2.6.6 on oldstable, I guess mpl will wait for these distros which contain python 2.6 to disappear, for debian the Long Term Support continues until February 2016.

@OceanWolf OceanWolf force-pushed the navigation-by-events-tool-positions branch from 9a6ae52 to b15d600 Compare February 14, 2015 01:15
Copy link
Author

Okay, if the mountain won't come to Muhammad...

Also added in the multi-toolbar-area, and as you see, it required no changes to ToolbarBase :) (apart from an related minor change which I will get rid of in my next PR anyway, to come tomorrow after sleep), the ToolbarBase methods I made in this PR work flexibly enough to add the tool on the way into or on the way out of add_toolitem!

@fariza
Copy link
Owner
fariza commented Feb 14, 2015

I don't know how much the mpl developer will appreciate a soon to be deprecated class in cbook. I completely understand, but still they may not like it.
And if we add it (I'm not saying we should), we can replace the backend_tools.tools list of lists for an ordered dict.

@OceanWolf
Copy link
Author

Personally I would rather start of doing it the right way, especially with something so easy to take out as this (I don't think it needs deprecation, as you just delete all references to it when once mpl no longer supports python2.6); then do it the wrong way with it embeded into a lot of code and thus will end up there for donkeys years.

If the developers don't mind this then yes, I shall alter backend_tools.tools in my next PR as I have altered it anyway. Otherwise, I shall alter this one.

I don't mind adding more of OrderedDict's methods to this one. I have coded as I have gone, and tested on a server running python2.5 (I meant to upgrade it ages ago, but I haven't got around to it).

Who should we ask about this? Where do we go from here?

@OceanWolf
Copy link
Author

Okay, I have just finished implementing a few more OD methods, and raised NotImplementedError's on the remaining ones, the ones that I really don't think anyone will use before 2.6 gets ditched, well methods that I have never used anyhow. Shall I squash into the appropriate commit above and force push?

@OceanWolf OceanWolf force-pushed the navigation-by-events-tool-positions branch from b15d600 to b6b3dfa Compare February 14, 2015 12:54
@OceanWolf OceanWolf force-pushed the navigation-by-events-tool-positions branch from 30681cd to e0f153e Compare February 15, 2015 01:49
tool, group, position = event.tool, event.data['group'], \
event.data['position']
if group is None:
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done by backend, maybe you want to create a separate menu with all the tools which group is None

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you are right, I did change the in_toolbar attribute for this and make sense. But again, the toolbar should be informed of all tools and it can decide what to include or not. The group=None is just a suggestion (implemented in the default backends)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with what you want to achieve, but I really disagree with implementing it like this. My next PR, the one that I have been talking about, will, in my opinion give a better implementation of this.

Perhaps I should push ahead and just release my next PR as a w-i-p so that you can see for yourself.

@OceanWolf OceanWolf force-pushed the navigation-by-events-tool-positions branch from e0f153e to 043d32f Compare February 17, 2015 16:03
@OceanWolf
Copy link
Author
OceanWolf commented 9E88 Feb 17, 2015

Okay, copied over the OrderedDict code. Anything else left to do here, bearing in mind I will remove the group == None bit in the other PR.

@fariza
Copy link
Owner
fariza commented Feb 17, 2015

I don't understand, I thought this one was dropped in favor of #11

@OceanWolf
Copy link
Author

I thought these PRs were doing two separate things...
This one handles groups within a single toolbar (ToolbarBase), i.e. putting separators in and other logic, in the case of GTK3, toolbar now consists of multiple sub_toolbars.

#11 allows for multiple instances of ToolbarBase, though I think we should rename ToolbarBase to ToolContainerBase or something because it can also represent menus etc. maybe have an inheritance tree like this for later on.

  • ToolContainerBase
    • ToolbarBase
    • ToolMenuBase

@fariza
Copy link
Owner
fariza commented Feb 17, 2015

I agree that the name is not really appropiate, I like ToolContainerBase.
For the moment I don't see the need for two extra subclasses.

I prefer if we go for refining #11 and for the moment we put the group/position calculations in the backend code.

@OceanWolf
Copy link
Author

Okay, though I came back to this now because I really need some of the structure from here to finish #11, namely ToolbarBase._groups and ToolbarBase._tool_items, currently GTK3 only, but I thought about moving it into ToolbarBase in #11.

I really like how ToolbarBase._groups works here. I mean standard python list methods work irresespective if groups contains just lists, or Gtk.toolbar, len(Gtk.toolbar) works, and so does tool_item in Gtk.toolbar, wonderful! :D.

And yes, I agree, no need for subclasses at the moment, I believe that that goes beyond the objectives of this MEP, I think we just want to ensure the easy creation of user-defined-tools. Adding features not currently present to toolbars and menus which don't exist at all, I think goes out of scope, just so long as our code makes it easy for these features to get added later.

@fariza
Copy link
Owner
fariza commented Feb 26, 2015

I think, I am going to go for a simpler implementation in the backend, I don't think we need to add any more methods to the base classes for this.
If we see too much repetition between different backends we can move those methods after. What do you think?

@OceanWolf
Copy link
Author

Feel free to go ahead with that, atm I have my head on the backend refactor so we can then get ToolManager cleanly rebased and integrated into the backends. The statusbar and the subplot_tool refactors (which I still have to work on, and will do after this) convinced me that I should really get those straightened out before doing any more work here.

Just waiting/working on the last little bits to get Travis to pass (which has brought to light other bugs), and then I can turn my attention to refactoring each backend in separate branches, modifying matplotlib#4143 where needed.

@fariza
Copy link
Owner
fariza commented Feb 27, 2015

@OceanWolf I was checking your refactor.
Try to split it up even further or convert it to a MEP.
For what I have seen it is going to be really hard to get it accepted, maybe I'm wrong but the more info you give the easier it is going to be.

@fariza fariza closed this Feb 27, 2015
@OceanWolf OceanWolf deleted the navigation-by-events-tool-positions branch July 25, 2015 20:20
fariza added a commit that referenced this pull request Sep 22, 2016
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.

2 participants
0