X Tutup
Skip to content

Fix icon#19

Merged
pavoljuhas merged 12 commits intodiffpy:masterfrom
chiahaoliu:FIX_icon
Jun 9, 2017
Merged

Fix icon#19
pavoljuhas merged 12 commits intodiffpy:masterfrom
chiahaoliu:FIX_icon

Conversation

@chiahaoliu
Copy link
Copy Markdown
Member

This is a PR to fix invalid icon path of pdfgui when it works with matplotlib 2.0.

It addresses half of fix discussed at issue #15 by overriding toolitems class variable of NavigationToolbar2WxAgg class so that we can avoid touching private method. Here is how the toolbar looks like now:

image

@pavoljuhas since I was trying to avoid non-public API, the position of saving icon and printing icon are exchanged. The functionalities remain the same, please let me know if you are okay with that.

attn: @tacaswell

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 1, 2017

Codecov Report

Merging #19 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
- Coverage   25.67%   25.67%   -0.01%     
==========================================
  Files          90       90              
  Lines       11921    11924       +3     
==========================================
  Hits         3061     3061              
- Misses       8860     8863       +3
Impacted Files Coverage Δ
src/diffpy/pdfgui/gui/extendedplotframe.py 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38d2bb0...d88dc76. Read the comment docs.


def __init__(self, canvas):
# override class var before init
NavToolbar.toolitems = CUSTOMIZED_TOOLITEMS
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not good - this modifies the base class. Please leave it alone and just define tooltimes above as an attribute of the ExtendedToolbar class:

toolitems = tuple(ti for ti in NavToolbar.toolitems if ti[0] != 'Subplots')

#('Subplots', 'Configure subplots', 'subplots', 'configure_subplots'),
(None, None, None, None),
#('Save', 'Save the figure', 'filesave', 'save_figure')
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is better to filter the standard matplotlib toolitems instead of copying them. That way the code would be OK and up to date should matplotlib add some icon or rename handler method. See the next comment.

(None, None, None, None),
#('Save', 'Save the figure', 'filesave', 'save_figure')
('Export plot data', 'Export plot data to file',
'filesave', 'save_figure')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems to just change the tooltip of the standard MPL "Save the figure" icon to "Export plot data", but the method name is the same - this still just saves the figure.

Actually, we need 2 save icons:

  1. Save the figure - keep the standard MPL icon here
  2. Export plot data - should be a new icon with its own event which eventually needs to call ExtendedPlotFrame.savePlotData. See the MPL sources for meaning of tooltips entries and specification of their handler functions. Given the existing PDFgui code, the handler function should perhaps post the DATA_SAVE_ID wx event.

def __init__(self, canvas):
# override class var to exclude subplots
self.toolitems = tuple(el for el in NavToolbar.toolitems\
if el[0] != 'Subplots')
Copy link
Copy Markdown
Member

@pavoljuhas pavoljuhas Jun 2, 2017

Choose a reason for hiding this comment

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

Please define toolitems as class attribute above the __init__ method. Just drop the self. and move whole statement to line 37.

Also, do not use backslash continuation for expressions in parentheses. The parentheses already imply line-continuation. Make sure the 2nd line is aligned as per PEP8 (if under the el above).

Copy link
Copy Markdown
Member

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

getting closer, but not ready yet.

'Print', 'print graph')
self.AddSimpleTool(DATA_SAVE_ID,
_load_bitmap('stock_save_as.xpm'),
_load_bitmap('filesave.png'),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This produces two same-image icons with different effects and still uses non-API MPL function _load_bitmap.

Please grab the "stock_save_as.xpm" from matplotlib repo prior to matplotlib/matplotlib#5626, convert it to PNG and add it to the /icons directory in PDFgui repo. Then use the diffpy.pdfgui.gui.pdfguiglobals.iconpath function instead of _load_bitmap; you might also need wx.Bitmap call to load the PNG image.

Please test the toolbar look with both matplotlib 1 and matplotlib 2. If either looks weird, we may need 2 icon files - a colorful version for MPL-1 and a black-and-white for MPL-2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah, I just finished this modification, but I encountered something weird. iconpath actually return a path as:

/repo/location/diffpy.pdfgui/src/icons/*

but the icons/ is actually at the same level as src/ in this repo.

So by running python -m diffpy.pdfgui.gui.extendedplotframe, I would have following error:

12:50:42: can't open file '/home/timothy/Documents/Repo/diffpy.pdfgui/src/icons/stock_save_as_mpl2.png' (error 2: No such file or directory)
12:50:42: Failed to load image from file "/home/timothy/Documents/Repo/diffpy.pdfgui/src/icons/stock_save_as_mpl2.png".

that seems to be the same error when I run python.app -m diffpy.pdfgui.applications.pdfgui as mentioned in #15.

Does it come from my local configuration?

Also, since we might have to prepare two files, is matplotlib.__version__ a good approach to check?

Thanks for that comments, they are all very helpful!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

but the icons/ is actually at the same level as src/ in this repo.

Ugh, I see the same problem. Seems to happen only in development-mode installation.

I will fix it later today. In the meantime, create symbolic links src/icons --> ../icons, src/doc --> ../doc in your working directory, but make sure they are not added to git.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thanks, symlink solves the problem and here is the result of testing whole pdfgui with the grayscale icon in MPL2.0

image

and the same grayscale icon in MPL1.5.3

image

chiahaoliu and others added 7 commits June 2, 2017 12:56
Also remove the trailing toolbar separator.
Use the standard `wx.Frame.Close` method to post `wx.EVT_CLOSE`,
which is already bound to `ExtendedPlotFrame.onClose`.
- use `matplotlib.rcParamsDefault` instead of `rcParams` to get the
  same shortcuts regardless of matplotlibrc.

- rename `ExtendedPlotFrame.quit_keys` --> `close_keys`, which is
  more descriptive as for the keys function.

- rename method `closeShortcut` --> `mplKeyPress`.  Make it easier
  to add more keyboard shortcuts if needed in the future.
Switch to size and style consistent with other matplotlib 2 icons.
The old 16x16 icon looks too small.
@pavoljuhas
Copy link
Copy Markdown
Member

pavoljuhas commented Jun 9, 2017

@chiahaoliu - please check my updates and let me know if it is good to go.

The main change is the old icon looked to small - it was 16x16 whereas current matplotlib uses 24x24.
Here is the look with a new larger icon:

pdfgui-plot-mpl1

pdfgui-plot-mpl2

@pavoljuhas
Copy link
Copy Markdown
Member

NOTE: remove unused stock_save_as_mpl2.png if this is good to go.

more suitable icon file was added in previous commit 4b24ea2
@chiahaoliu
Copy link
Copy Markdown
Member Author

@pavoljuhas Thanks for the cleaning! It covers lots of aspects I didn't think of.

I pushed commit of removing unused icon file, please let me know further modification is needed.

@pavoljuhas pavoljuhas merged commit d88dc76 into diffpy:master Jun 9, 2017
@chiahaoliu chiahaoliu deleted the FIX_icon branch June 9, 2017 23:27
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

X Tutup