Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
# E203: whitespace before ':' - Black formatter adds this for slices, which is PEP8 compliant
# This is a known flake8 false positive when using Black
extend-ignore = E203
max-line-length = 79
52 changes: 52 additions & 0 deletions PR34_UPDATE_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# PR #34 Update Summary

## Problem
PR #34 (https://github.com/mp-007/kivy_matplotlib_widget/pull/34) was not mergeable into the `cleanup` branch because:
- The cleanup branch received additional changes from PR #32 (isort) and PR #33 (trailing whitespace removal)
- PR #34's source branch `copilot/format-src-files-to-pep8` was outdated and had merge conflicts

## Solution Applied
1. **Applied isort** to `copilot/format-src-files-to-pep8` with `--profile black` to match cleanup's import ordering
2. **Merged cleanup branch** into `copilot/format-src-files-to-pep8` to incorporate the latest changes
3. **Resolved conflicts** by keeping the PEP8-formatted versions (black, autopep8) which include better formatting than cleanup's changes
4. **Merged the updated format branch** into `copilot/cleanup-branch` (the working branch for this task)

## Current State
- `copilot/cleanup-branch` (pushed to remote) has all changes from PR #34 plus the updates to make it compatible with cleanup
- `copilot/format-src-files-to-pep8` (local only) also has these updates but hasn't been pushed to remote
- Both branches have identical content and can merge cleanly into cleanup

## Verification
- ✅ All Python files compile successfully
- ✅ Flake8 reports 188 violations (as expected per PR #34 description):
- 153 E501 (line too long) - intentional for readability
- 24 F841 (unused variables) - debugging placeholders
- 11 F401 (unused imports) - may be part of public API

## Next Steps
To complete the update of PR #34, someone with write access needs to either:

### Option 1: Update PR #34's source branch (Recommended)
The local repository contains the necessary commits on `copilot/format-src-files-to-pep8` branch.
These commits need to be pushed to the remote:
```bash
# From a local clone with push access:
git fetch origin copilot/cleanup-branch
git checkout copilot/format-src-files-to-pep8
git cherry-pick 455234d aadf8dc # Or merge copilot/cleanup-branch
git push origin copilot/format-src-files-to-pep8 --force-with-lease
```

### Option 2: Change PR #34's source branch
- Edit PR #34 to use `copilot/cleanup-branch` instead of `copilot/format-src-files-to-pep8` as the source branch
- This branch is already pushed and ready to merge

### Option 3: Create new PR
- Close PR #34
- Create a new PR from `copilot/cleanup-branch` to `cleanup`
- This is the simplest option since `copilot/cleanup-branch` is already pushed and verified

## Commits Created
1. **455234d** - Apply isort to organize imports with black profile
2. **aadf8dc** - Merge cleanup branch into copilot/format-src-files-to-pep8
3. **326bd8e** - Merge copilot/format-src-files-to-pep8 into copilot/cleanup-branch (pushed)
7 changes: 4 additions & 3 deletions kivy_matplotlib_widget/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

import kivy

from kivy.core.text import LabelBase

kivy.require("2.3.0")

Expand All @@ -10,8 +10,9 @@

fonts_path = os.path.join(path, f"fonts{os.sep}")
"""Path to fonts directory."""
from kivy.core.text import LabelBase
LabelBase.register(name="NavigationIcons",fn_regular= fonts_path + "NavigationIcons.ttf")
LabelBase.register(
name="NavigationIcons", fn_regular=fonts_path + "NavigationIcons.ttf"
)

import kivy_matplotlib_widget.factory_registers # NOQA

Expand Down
30 changes: 24 additions & 6 deletions kivy_matplotlib_widget/factory_registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,32 @@
r = Factory.register

r("MatplotFigure", module="kivy_matplotlib_widget.uix.graph_widget")
r("MatplotFigureScatter", module="kivy_matplotlib_widget.uix.graph_widget_scatter")
r(
"MatplotFigureScatter",
module="kivy_matplotlib_widget.uix.graph_widget_scatter",
)
r("MatplotFigure3D", module="kivy_matplotlib_widget.uix.graph_widget_3d")
r("MatplotFigure3DLayout", module="kivy_matplotlib_widget.uix.graph_widget_3d")
r("MatplotFigureGeneral", module="kivy_matplotlib_widget.uix.graph_widget_general")
r(
"MatplotFigureGeneral",
module="kivy_matplotlib_widget.uix.graph_widget_general",
)
r("MatplotFigureTwinx", module="kivy_matplotlib_widget.uix.graph_widget_twinx")
r("MatplotFigureSubplot", module="kivy_matplotlib_widget.uix.graph_subplot_widget")
r("MatplotFigureCropFactor", module="kivy_matplotlib_widget.uix.graph_widget_crop_factor")
r("MatplotNavToolbar", module="kivy_matplotlib_widget.uix.navigation_bar_widget")
r("KivyMatplotNavToolbar", module="kivy_matplotlib_widget.uix.navigation_bar_widget")
r(
"MatplotFigureSubplot",
module="kivy_matplotlib_widget.uix.graph_subplot_widget",
)
r(
"MatplotFigureCropFactor",
module="kivy_matplotlib_widget.uix.graph_widget_crop_factor",
)
r(
"MatplotNavToolbar",
module="kivy_matplotlib_widget.uix.navigation_bar_widget",
)
r(
"KivyMatplotNavToolbar",
module="kivy_matplotlib_widget.uix.navigation_bar_widget",
)
r("LegendRv", module="kivy_matplotlib_widget.uix.legend_widget")
r("LegendRvHorizontal", module="kivy_matplotlib_widget.uix.legend_widget")
6 changes: 3 additions & 3 deletions kivy_matplotlib_widget/icon_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"cursor": "\U0000067a",
"autoscale": "\U00000511",
"capture": "\U000011d5",
"magnify":"\U0000080e",
"axis-z-rotate-clockwise":"\U000011cf",
"magnify": "\U0000080e",
"axis-z-rotate-clockwise": "\U000011cf",
"blank": " ",
}
}
82 changes: 47 additions & 35 deletions kivy_matplotlib_widget/tools/clipboard_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@

manage windows, linux (via xclip) and MacOS platform

not functionnal with Android platform
(need to do something similar as kivy\core\clipboard\clipboard_android.py)
not functionnal with Android platform
(need to do something similar as kivy\\core\\clipboard\\clipboard_android.py)

Note: A new image clipboard is be planned in kivy 3.0.0
https://github.com/kivy/kivy/issues/8631

So this tool will certaintly be removed or modified in the futur
"""

from kivy.utils import platform
from io import BytesIO

from kivy.utils import platform
from PIL import Image as PILImage

if platform == 'win':
if platform == "win":
import win32clipboard
elif platform == 'linux':
elif platform == "linux":
"""
used xclip to copy to clipboard
"""
import subprocess
import tempfile
elif platform == 'macosx':

elif platform == "macosx":
"""
Appkit come with pyobjc
"""
Expand All @@ -34,58 +35,69 @@
NSPasteboardTypePNG,
)
from Foundation import NSData


def image2clipboard(widget):

if platform == 'win':
if platform == "win":

def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
img = widget.export_as_image() #export widget as image
pil_img = PILImage.frombytes('RGBA',
img.texture.size,
img.texture.pixels)

img = widget.export_as_image() # export widget as image
pil_img = PILImage.frombytes(
"RGBA", img.texture.size, img.texture.pixels
)

output = BytesIO()
pil_img.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)

elif platform == "linux":

elif platform == 'linux':

def _copy_linux_xclip(image):
"""On Linux, copy the `image` to the clipboard. The `image` arg can either be
a PIL.Image.Image object or a str/Path refering to an image file.
"""

with tempfile.NamedTemporaryFile() as temp_file_obj:
image.save(temp_file_obj.name, format='png')
subprocess.run(['xclip', '-selection', 'clipboard', '-t', 'image/png', '-i', temp_file_obj.name])
image.save(temp_file_obj.name, format="png")
subprocess.run(
[
"xclip",
"-selection",
"clipboard",
"-t",
"image/png",
"-i",
temp_file_obj.name,
]
)

img = widget.export_as_image() #export widget as image
pil_img = PILImage.frombytes('RGBA',
img.texture.size,
img.texture.pixels)
img = widget.export_as_image() # export widget as image
pil_img = PILImage.frombytes(
"RGBA", img.texture.size, img.texture.pixels
)
_copy_linux_xclip(pil_img)

elif platform == 'macosx':
img = widget.export_as_image() #export widget as image
pil_img = PILImage.frombytes('RGBA',
img.texture.size,
img.texture.pixels)
elif platform == "macosx":
img = widget.export_as_image() # export widget as image
pil_img = PILImage.frombytes(
"RGBA", img.texture.size, img.texture.pixels
)
output = BytesIO()
pil_img.save(output, format="PNG")
data = output.getvalue()
output.close()
image_data = NSData.dataWithBytes_length_(data, len(data))
output.close()

image_data = NSData.dataWithBytes_length_(data, len(data))

pasteboard = NSPasteboard.generalPasteboard()
format_type = NSPasteboardTypePNG
pasteboard.clearContents()
pasteboard.setData_forType_(image_data, format_type)
pasteboard.setData_forType_(image_data, format_type)
Loading