├── .editorconfig
├── .flake8
├── .github
├── CODEOWNERS
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ ├── config.yml
│ └── feature_request.yml
├── PULL_REQUEST_TEMPLATE.md
├── SUPPORT.md
└── workflows
│ ├── build.yml
│ └── release.yml
├── .gitignore
├── .prettierrc
├── CHANGELOG.md
├── LICENSE
├── Pipfile
├── README.md
├── __init__.py
├── assets
├── demo.gif
├── preferences
│ ├── directory.png
│ ├── filename.png
│ ├── image-type.png
│ └── subdirectory.png
└── ui
│ ├── 3d-viewport.png
│ ├── image-editor.png
│ ├── shader-editor.png
│ └── video-sequencer.png
├── imagepaste
├── clipboard
│ ├── clipboard.py
│ ├── darwin
│ │ ├── darwin.py
│ │ └── pasteboard
│ │ │ ├── _native.cpython-310-darwin.so
│ │ │ ├── _native.cpython-311-darwin.so
│ │ │ ├── _native.cpython-37m-darwin.so
│ │ │ └── _native.cpython-39-darwin.so
│ ├── linux
│ │ ├── bin
│ │ │ └── xclip
│ │ └── linux.py
│ └── windows
│ │ └── windows.py
├── image.py
├── metadata.py
├── operators.py
├── preferences.py
├── process.py
├── report.py
└── tree.py
└── script
├── bootstrap.cmd
├── bootstrap.sh
├── build.cmd
├── build.sh
├── setup.cmd
└── setup.sh
/.editorconfig:
--------------------------------------------------------------------------------
1 | # This file is for unifying the coding style for different editors and IDEs
2 | # editorconfig.org
3 |
4 | # Ignore any other files further up in the file system
5 | root = true
6 |
7 | # Configuration for all files
8 | [*]
9 | indent_style = space
10 | indent_size = 4
11 | charset = utf-8
12 | insert_final_newline = true
13 | trim_trailing_whitespace = true
14 |
15 | # Configuration for YAML and Markdown
16 | [**.{yml,md}]
17 | indent_size = 2
18 |
--------------------------------------------------------------------------------
/.flake8:
--------------------------------------------------------------------------------
1 | [flake8]
2 | extend-ignore =
3 | E203,
4 | W503,
5 | F821,
6 | F722
7 |
8 | exclude =
9 | bin/
10 |
11 | max-line-length = 88
12 |
13 | per-file-ignores =
14 | __init__.py:E402
15 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @thanhph111
2 | /__init__.py @Yeetus3141 @thanhph111
3 |
--------------------------------------------------------------------------------
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | binitnew@gmail.com.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Contributing to ImagePaste
4 |
5 | First of all, thank you for taking the time to support us. Every change, no matter how small, helps us grow further. Your contributions here are our starting point.
6 |
7 | ## How do I…
8 |
9 | - 🐛 [Report a bug](#-reporting-a-bug)
10 | - 🚀 [Request a feature](#-requesting-a-feature)
11 | - 💬 [Open a discussion](#-opening-a-discussion)
12 | - 🎉 [Create a pull request](#-creating-a-pull-request)
13 |
14 | Or you can take a look at [our development guide](#-development-guide).
15 |
16 | ## Code of Conduct
17 |
18 | This project and everyone participating in it are governed by [the Code of Conduct](CODE_OF_CONDUCT.md) which is adapted from the [_Contributor Covenant_](https://www.contributor-covenant.org), version 2.0. By participating, you are expected to uphold this code.
19 |
20 | ## 🐛 Reporting a bug
21 |
22 | A great way to contribute to the add-on is to send a detailed report when you encounter an issue. We always appreciate a well-written, thorough bug report, and will thank you for it!
23 |
24 | 1. **Avoid walls of text**: It's very helpful to attach a log file to your report, which helps us quickly triage the bugs ([learn how to open a terminal](https://docs.blender.org/manual/en/latest/advanced/command_line/launch/index.html) to collect logs). When sending lengthy log files, consider posting them as a [_GitHub Gist_](https://gist.github.com). Don't forget to remove sensitive data from your log files before posting (you can replace those parts with "REDACTED").
25 |
26 | 2. **Avoid duplication**: Make sure [the issue database](https://github.com/Yeetus3141/ImagePaste/issues) doesn't already include that problem or suggestion before submitting an issue. If you find a match, you can use the **Subscribe** button to get notified of updates. Do not leave random "+1" or "I have this too" comments, as they only clutter the discussion. However, if you have ways to reproduce the issue or have additional information that may help to resolve the issue, please leave a comment.
27 |
28 | 3. **Simplify**: First try to simplify the process that triggers the bug, so that it is reproducible in the least amount of steps. The fewer steps there are, the easier it is for us to spot the problem in the code. Typically if you have a complex .blend file, it is possible to keep removing objects, modifiers, nodes, and other data until the problem has been isolated to a simple setup.
29 |
30 | Finally, you can [create a new issue](https://github.com/Yeetus3141/ImagePaste/issues/new/choose) by choosing the **Bug report** template or creating a blank one.
31 |
32 | ## 🚀 Requesting a feature
33 |
34 | If the add-on doesn't do something you need, [open an issue](https://github.com/Yeetus3141/ImagePaste/issues/new/choose) and provide as much context as you can about what you're running into. Please try to be clear about why existing features and alternatives would not work for you. This project is very small, and this makes it flexible, your idea is much more likely to come true. If it isn't accepted, don't have a cow. Sometimes, it's our job to keep the project on the right track.
35 |
36 | ## 💬 Opening a discussion
37 |
38 | We’re using [_Discussions_](https://github.com/Yeetus3141/ImagePaste/discussions) as a place to connect with other members of our community. You can:
39 |
40 | - Ask questions you’re wondering about.
41 | - Share ideas.
42 | - Engage with other community members.
43 | - Welcome others and be open-minded. Remember that this is a community we build muscle together.
44 |
45 | ## 🎉 Creating a pull request
46 |
47 | We like code commits a lot! They're super handy, and they keep the project going and doing the work it needs to do to be useful to others.
48 |
49 | Code contributions of just about any size of any things in this repository (even the lines you're reading) are acceptable! However, before contributing large or high-impact changes, make the effort to coordinate with the maintainers of the project before submitting a pull request. This prevents you from doing extra work that may or may not be merged.
50 |
51 | To contribute code:
52 |
53 | - Read the [development guide](#development-guide) and [set up the project](#setup-environment-for-development).
54 | - Make any necessary changes to the source code.
55 | - Include any additional documentation the changes might need.
56 | - Test and verify that your contribution works as expected.
57 | - Write clear, concise commit messages using [the conventional format](#git-commit).
58 | - [Open a new pull request](https://github.com/Yeetus3141/ImagePaste/compare) with your changes.
59 |
60 | We are always thrilled to receive pull requests. We will do our best to process them quickly. If your pull request is not accepted on the first try, don't get discouraged! Keep trying, we're sure you will learn a lot from these.
61 |
62 | ## 📃 Development guide
63 |
64 | ### Design decision
65 |
66 | #### Architecture and method
67 |
68 | The add-on code is divided into several modules to make it easier to maintain and extend. In [`__init__.py`](../__init__.py), we only keep the `bl_info` metadata and the `register`, `unregister` functions to register and unregister other modules. The main processing code of the add-on is located in [`imagepaste/`](../imagepaste/), which includes:
69 |
70 | - [`process.py`](../imagepaste/process.py): The module holds the `Process` class, which is the utility class that handles the communication with commands or shells.
71 | - [`image.py`](../imagepaste/image.py): The module contains the `Image` class, whose instances hold image information.
72 | - [`report.py`](../imagepaste/report.py): The module for the `Report` class that creates objects containing operations status.
73 | - [`clipboard/`](../imagepaste/clipboard/): The folder that contains all processes related to clipboard, which includes these modules:
74 | - [`clipboard.py`](../imagepaste/clipboard/clipboard.py): The module with the abstract `Clipboard` class, which all platform-specific clipboard classes inherit from must perform two important class methods - `push` and `pull` - with different appropriate approaches described below.
75 | - [`windows/windows.py`](../imagepaste/clipboard/windows/windows.py): The module contains the concrete `WindowsClipboard` class of the `Clipboard` for the _Windows_ platform. Used to rely on _Pillow_ library to handle the clipboard but because of some drawbacks, from [version 1.5](https://github.com/Yeetus3141/ImagePaste/compare/v1.4.0...v1.5.0) we replace it with the _PowerShell_ 5.1 scripts which is pre-installed from _Windows_ version 1607 (see pull request [#8](https://github.com/Yeetus3141/ImagePaste/pull/8)).
76 | - [`linux/linux.py`](../imagepaste/clipboard/linux/linux.py): The module contains the concrete `LinuxClipboard` class of the `Clipboard` for the _Linux_ platform. We currently use _xclip_ to manipulate clipboard on _X11_. _Wayland_ hasn't been tested and done the research yet (see pull request [#4](https://github.com/Yeetus3141/ImagePaste/pull/4)).
77 | - [`darwin/darwin.py`](../imagepaste/clipboard/darwin/darwin.py): The module contains the concrete `DarwinClipboard` class of the `Clipboard` for the _macOS_ platform. [_Pasteboard_](https://pypi.org/project/pasteboard/) is shipped with the add-on to be responsible for the clipboard (see pull request [#6](https://github.com/Yeetus3141/ImagePaste/pull/6)).
78 | - [`operators.py`](../imagepaste/operators.py): The module with the core operators for main functionalities (copy/paste images from/to the _Blender_ editors), which depend mostly on clipboard instances created from `WindowsClipboard`, `LinuxClipboard` and `DarwinClipboard` classes.
79 | - [`preferences.py`](../imagepaste/preferences.py): The module contains the add-on preferences class, all keymaps and UI-related functions.
80 | - [`tree.py`](../imagepaste/tree.py): The module contains the utilities to work with files, folders, and paths.
81 | - [`metadata.py`](../imagepaste/metadata.py): The module will cover the add-on metadata related operations.
82 |
83 | The docstring in each module is also very helpful to understand what the module does and how to use it. Open the module you need and check them.
84 |
85 | #### Naming
86 |
87 | To be consistent, anything related to the code or the core system of the platform, we use `darwin` to refer to the _macOS_ platform. For _Windows_ and _Linux_ platforms, they are `windows` and `linux` respectively.
88 |
89 | #### Branches
90 |
91 | We currently use the _Centralized Workflow_ as the official _Git_ workflow, which `main` is the central branch where you can merge from and create pull requests to.
92 |
93 | ### Style guides
94 |
95 | #### Git commit
96 |
97 | Example of good commit:
98 |
99 | ```text
100 | Summarize changes in around 50 characters or less
101 |
102 | More detailed explanatory text. Wrap it to 72 characters. The blank
103 | line separating the summary from the body is critical (unless you omit
104 | the body entirely).
105 |
106 | Write your commit message in the imperative: "Fix bug" and not "Fixed
107 | bug" or "Fixes bug." But if your commit solves an issue, use "Fixes #1"
108 | as described below.
109 |
110 | Explain the problem that this commit is solving. Focus on why you
111 | are making this change as opposed to how (the code explains that).
112 | Are there side effects or other unintuitive consequences of this
113 | change? Here's the place to explain them.
114 |
115 | Further paragraphs come after blank lines. A list would be like this:
116 | - Bullet points are okay, too, end with a period.
117 | - Typically a hyphen or asterisk is used for the bullet, followed by a
118 | single space. Use a hanging indent.
119 |
120 | If the commit is related to an issue or pull request, put references to
121 | them at the bottom. Links can be inserted if it's necessary, like this:
122 | https://github.blog/2013-01-22-closing-issues-via-commit-messages/.
123 |
124 | See more at #123.
125 | Fixes #456.
126 | ```
127 |
128 | #### Python
129 |
130 | We follow the [recommended _Blender_ add-ons style guide](https://wiki.blender.org/wiki/Style_Guide/Python) for all _Python_ files in this repository with these tools:
131 |
132 | - Linter: [_Flake8_](https://flake8.pycqa.org/en/latest/) (latest version, which is configured in [`.flake8`](../.flake8)).
133 | - Formatter: [_Black_](https://black.readthedocs.io/en/stable/) (latest version with default settings).
134 |
135 | #### Other files
136 |
137 | All other files (including _YAML_ and _Markdown_) will be formatted with [_Prettier_](https://prettier.io/), which is configured in [`.prettierrc`](../.prettierrc).
138 |
139 | ### Set up a development environment
140 |
141 | If this is your first pull request, you just need to fork the repository and do whatever you need to do. If you have already forked it before, make sure you are on the latest commit before you make any changes, this will prevent some unnecessary conflicts when you request merging into the upstream.
142 |
143 | We use [_Pipenv_](https://pipenv.pypa.io/en/latest/) as an environment manager, which is configured in [`Pipfile`](../Pipfile). To set up your development environment, simply run [`script\setup.cmd`](script\setup.cmd) (on _Windows_) or [`script\setup.sh`](script\setup.sh) (on _Linux_) and the script will do the rest for you. When it's done, you can get in the virtual environment using `pipenv shell` and get out with `exit`. Once activated, you will have all packages you need.
144 |
145 | Some editor configurations are also defined in [`.editorconfig`](.editorconfig). You can read more on the [EditorConfig website](https://editorconfig.org/) about how to set up your IDE/editor to read the file.
146 |
147 | We recommend using [_Visual Studio Code_](https://code.visualstudio.com/) as an official editor for this project, although we decided to ignore its `.vscode` folder as it may contain some personal configuration that you would not want to commit. If you also use it, you should have these configurations in your workspace settings:
148 |
149 | ```jsonc
150 | {
151 | // Python language configuration
152 | "[python]": {
153 | "editor.rulers": [88],
154 | "editor.wordWrap": "wordWrapColumn",
155 | "editor.wordWrapColumn": 88
156 | },
157 | // Enable and overwrite Flake8 user settings (if any) to be accepted in `.flake8`
158 | "python.linting.flake8Enabled": true,
159 | "python.linting.flake8Args": [],
160 | // Set default Python formatter and reset it to default settings
161 | "python.formatting.provider": "black",
162 | "python.formatting.blackArgs": []
163 | }
164 | ```
165 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | custom: ['https://www.paypal.me/b1n1t']
4 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.yml:
--------------------------------------------------------------------------------
1 | # @format
2 |
3 | name: Bug Report
4 | description: Create a report to help us improve
5 | title: "BUG: "
6 | labels:
7 | - bug
8 | assignees:
9 | - thanhph111
10 | - b-init
11 | body:
12 | - type: textarea
13 | id: description
14 | attributes:
15 | label: Describe the bug
16 | description: Tell us what annoys you. Include the picture of the ugly bug if you can.
17 | validations:
18 | required: true
19 | - type: textarea
20 | id: steps_to_reproduce
21 | attributes:
22 | label: Step to reproduce
23 | description: How we make the bug reveals?
24 | placeholder: |
25 | 1. Go to …
26 | 2. Click on …
27 | 3. Get a Kit Kat
28 | 4. Scroll down to …
29 | 5. See error
30 | validations:
31 | required: true
32 | - type: textarea
33 | id: logs
34 | attributes:
35 | label: Relevant log output
36 | description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
37 | render: shell
38 | - type: textarea
39 | id: expected_behavior
40 | attributes:
41 | label: Expected behavior
42 | description: What it should actually be?
43 | validations:
44 | required: true
45 | - type: dropdown
46 | id: platform
47 | attributes:
48 | label: Platform
49 | description: What OS you running on?
50 | multiple: true
51 | options:
52 | - Windows
53 | - macOS
54 | - Linux
55 | validations:
56 | required: true
57 | - type: input
58 | id: platform_version
59 | attributes:
60 | label: Platform version
61 | description: What version of the above platform?
62 | placeholder: 20H2
63 | validations:
64 | required: true
65 | - type: dropdown
66 | id: blender_version
67 | attributes:
68 | label: Blender version
69 | description: What version of Blender are you using?
70 | multiple: true
71 | options:
72 | - "2.83"
73 | - "2.90"
74 | - "2.91"
75 | - "2.92"
76 | - "2.93"
77 | - "3.0"
78 | - Other
79 | validations:
80 | required: true
81 | - type: input
82 | id: imagepaste_version
83 | attributes:
84 | label: ImagePaste Version
85 | description: What version of ImagePaste are you using?
86 | validations:
87 | required: true
88 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | # @format
2 |
3 | blank_issues_enabled: true
4 | contact_links:
5 | - name: 📥 Download the latest version
6 | url: https://github.com/Yeetus3141/ImagePaste/releases/latest
7 | about: Make sure you're running the latest version, your bugs may already be fixed.
8 | - name: 📢 Open a new discussion
9 | url: https://github.com/Yeetus3141/ImagePaste/discussions/new
10 | about: If you haven't ready to open an issue yet, question here.
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.yml:
--------------------------------------------------------------------------------
1 | # @format
2 |
3 | name: Feature Request
4 | description: Suggest an idea for this add-on
5 | title: "FEATURE: "
6 | labels:
7 | - enhancement
8 | assignees:
9 | - thanhph111
10 | - Yeetus3141
11 | body:
12 | - type: textarea
13 | id: problem
14 | attributes:
15 | label: Problem
16 | description: Is your feature request related to a problem?
17 | - type: textarea
18 | id: idea
19 | attributes:
20 | label: Idea
21 | description: And you've got an idea to make it change?
22 | validations:
23 | required: true
24 | - type: textarea
25 | id: images
26 | attributes:
27 | label: Images
28 | description: We know the feature's not presented yet but if you have any images to help us imagine, please paste them here.
29 | - type: textarea
30 | id: additional_context
31 | attributes:
32 | label: Additional context
33 | description: And you want to tell us more?
34 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Proposed changes
4 |
5 |
6 |
7 | ## Screenshots/Screencasts
8 |
9 |
10 | | Original | Updated |
11 | | ----------------- | -------------------- |
12 | | | |
13 |
14 |
15 | ## Further comments
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.github/SUPPORT.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Other ways to get support
4 |
5 | For any questions, suggestions or bug reports:
6 |
7 | - 📢 Join [my discord server](https://discord.gg/G8ajxwQuYT).
8 | - 🐦 Contact me via twitter [@YeetusBlenditus](https://twitter.com/YeetusBlenditus).
9 | - 📬 E-mail me at [binitnew@gmail.com](mailto:binitnew@gmail.com).
10 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # @format
2 |
3 | name: Build
4 |
5 | on:
6 | push:
7 | branches:
8 | - "**"
9 | paths:
10 | - "**.py"
11 | pull_request:
12 | workflow_dispatch:
13 |
14 | jobs:
15 | build:
16 | runs-on: ubuntu-latest
17 | steps:
18 | - name: Checkout the project
19 | uses: actions/checkout@v3
20 | - name: Upload artifacts
21 | uses: actions/upload-artifact@v3
22 | with:
23 | name: ImagePaste
24 | path: |
25 | __init__.py
26 | imagepaste
27 | LICENSE
28 | retention-days: 1
29 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | # @format
2 |
3 | name: Release
4 |
5 | on:
6 | push:
7 | tags:
8 | - v[0-9]+.[0-9]+.[0-9]+
9 |
10 | jobs:
11 | release:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - name: Checkout the repository
15 | uses: actions/checkout@v2
16 | - name: Get pushed tag
17 | run: echo "TAG=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
18 | - name: Build and get file name
19 | run: echo "ZIP_FILE=$(./script/build.sh $TAG)" >> $GITHUB_ENV
20 | - name: Get release body
21 | id: get_release_body
22 | run: |
23 | IFS=$'\n'
24 | URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}"
25 | latest_tag=$(curl --url "${URL}/releases/latest" | jq -r '.tag_name')
26 | commits=($(curl --url "${URL}/compare/${latest_tag}...${GITHUB_SHA}" |
27 | jq -r '.commits[] | [.commit.message, .sha, .author.login] | @tsv' |
28 | while IFS=$'\t' read -r message sha author; do
29 | echo "- ${message%\\n\\n*} (${sha} by @${author})"
30 | done))
31 | body=$(echo "${commits[*]:0:${#commits[@]}-1}" | sed ':a; N; $!ba; s/\n/%0A/g')
32 | echo "::set-output name=body::$body"
33 | - name: Create a release
34 | id: create_release
35 | uses: actions/create-release@v1
36 | with:
37 | tag_name: ${{ github.ref }}
38 | release_name: ImagePaste ${{ env.TAG }}
39 | body: ${{ steps.get_release_body.outputs.body }}
40 | draft: true
41 | prerelease: false
42 | env:
43 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44 | - name: Upload release asset
45 | uses: actions/upload-release-asset@v1
46 | with:
47 | upload_url: ${{ steps.create_release.outputs.upload_url }}
48 | asset_path: ${{ env.ZIP_FILE }}
49 | asset_name: ${{ env.ZIP_FILE }}
50 | asset_content_type: application/zip
51 | env:
52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Linux ###
2 | *~
3 |
4 | # temporary files which can be created if a process still has a handle open of a deleted file
5 | .fuse_hidden*
6 |
7 | # KDE directory preferences
8 | .directory
9 |
10 | # Linux trash folder which might appear on any partition or disk
11 | .Trash-*
12 |
13 | # .nfs files are created when an open file is removed but is still being accessed
14 | .nfs*
15 |
16 | ### macOS ###
17 | # General
18 | .DS_Store
19 | .AppleDouble
20 | .LSOverride
21 |
22 | # Icon must end with two \r
23 | Icon
24 |
25 |
26 | # Thumbnails
27 | ._*
28 |
29 | # Files that might appear in the root of a volume
30 | .DocumentRevisions-V100
31 | .fseventsd
32 | .Spotlight-V100
33 | .TemporaryItems
34 | .Trashes
35 | .VolumeIcon.icns
36 | .com.apple.timemachine.donotpresent
37 |
38 | # Directories potentially created on remote AFP share
39 | .AppleDB
40 | .AppleDesktop
41 | Network Trash Folder
42 | Temporary Items
43 | .apdisk
44 |
45 | ### Python ###
46 | # Byte-compiled / optimized / DLL files
47 | __pycache__/
48 | *.py[cod]
49 | *$py.class
50 |
51 | # C extensions
52 | *.so
53 |
54 | # Darwin pasteboard modules
55 | !_native.cpython-37m-darwin.so
56 | !_native.cpython-39-darwin.so
57 | !_native.cpython-310-darwin.so
58 | !_native.cpython-311-darwin.so
59 |
60 | # Distribution / packaging
61 | .Python
62 | build/
63 | develop-eggs/
64 | dist/
65 | downloads/
66 | eggs/
67 | .eggs/
68 | parts/
69 | sdist/
70 | var/
71 | wheels/
72 | pip-wheel-metadata/
73 | share/python-wheels/
74 | *.egg-info/
75 | .installed.cfg
76 | *.egg
77 | MANIFEST
78 |
79 | # PyInstaller
80 | # Usually these files are written by a python script from a template
81 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
82 | *.manifest
83 | *.spec
84 |
85 | # Installer logs
86 | pip-log.txt
87 | pip-delete-this-directory.txt
88 |
89 | # Unit test / coverage reports
90 | htmlcov/
91 | .tox/
92 | .nox/
93 | .coverage
94 | .coverage.*
95 | .cache
96 | nosetests.xml
97 | coverage.xml
98 | *.cover
99 | *.py,cover
100 | .hypothesis/
101 | .pytest_cache/
102 | pytestdebug.log
103 |
104 | # Translations
105 | *.mo
106 | *.pot
107 |
108 | # Django stuff:
109 | *.log
110 | local_settings.py
111 | db.sqlite3
112 | db.sqlite3-journal
113 |
114 | # Flask stuff:
115 | instance/
116 | .webassets-cache
117 |
118 | # Scrapy stuff:
119 | .scrapy
120 |
121 | # Sphinx documentation
122 | docs/_build/
123 | doc/_build/
124 |
125 | # PyBuilder
126 | target/
127 |
128 | # Jupyter Notebook
129 | .ipynb_checkpoints
130 |
131 | # IPython
132 | profile_default/
133 | ipython_config.py
134 |
135 | # pyenv
136 | .python-version
137 |
138 | # pipenv
139 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
140 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
141 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
142 | # install all needed dependencies.
143 | Pipfile.lock
144 |
145 | # poetry
146 | #poetry.lock
147 |
148 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
149 | __pypackages__/
150 |
151 | # Celery stuff
152 | celerybeat-schedule
153 | celerybeat.pid
154 |
155 | # SageMath parsed files
156 | *.sage.py
157 |
158 | # Environments
159 | .env
160 | .env/
161 | .venv/
162 | env/
163 | venv/
164 | ENV/
165 | env.bak/
166 | venv.bak/
167 | pythonenv*
168 |
169 | # Spyder project settings
170 | .spyderproject
171 | .spyproject
172 |
173 | # Rope project settings
174 | .ropeproject
175 |
176 | # mkdocs documentation
177 | /site
178 |
179 | # mypy
180 | .mypy_cache/
181 | .dmypy.json
182 | dmypy.json
183 |
184 | # Pyre type checker
185 | .pyre/
186 |
187 | # pytype static type analyzer
188 | .pytype/
189 |
190 | # operating system-related files
191 | # file properties cache/storage on macOS
192 | *.DS_Store
193 | # thumbnail cache on Windows
194 | Thumbs.db
195 |
196 | # profiling data
197 | .prof
198 |
199 |
200 | ### Windows ###
201 | # Windows thumbnail cache files
202 | Thumbs.db:encryptable
203 | ehthumbs.db
204 | ehthumbs_vista.db
205 |
206 | # Dump file
207 | *.stackdump
208 |
209 | # Folder config file
210 | [Dd]esktop.ini
211 |
212 | # Recycle Bin used on file shares
213 | $RECYCLE.BIN/
214 |
215 | # Windows Installer files
216 | *.cab
217 | *.msi
218 | *.msix
219 | *.msm
220 | *.msp
221 |
222 | # Windows shortcuts
223 | *.lnk
224 |
225 | ### VisualStudioCode ###
226 | .vscode/*
227 | *.code-workspace
228 |
229 | ### User preferences ###
230 | # Blender files
231 | *.blend
232 | *.blend[0-9]
233 | *.blend[12][0-9]
234 | *.blend3[0-2]
235 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "overrides": [
3 | {
4 | "files": "**",
5 | "options": {
6 | "requirePragma": true,
7 | "insertPragma": true
8 | }
9 | },
10 | {
11 | "files": [
12 | "**.yml",
13 | "**.md"
14 | ],
15 | "options": {
16 | "tabWidth": 2,
17 | "embeddedLanguageFormatting": "off"
18 | }
19 | }
20 | ]
21 | }
22 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Changelog
4 |
5 | ## [1.8.2](https://github.com/b-init/ImagePaste/compare/v1.8.1...v1.8.2) (2024-03-08)
6 |
7 | - Add pasteboard module for python 3.11 ([#53](https://github.com/b-init/ImagePaste/commit/050a8aa5324f36ea9a031f5d63132e583862da45))
8 |
9 | ## [1.8.1](https://github.com/b-init/ImagePaste/compare/v1.8.0...v1.8.1) (2022-09-21)
10 |
11 | - Now works with both `PNG` and `DIB` formats on _Windows_ ([#33](https://github.com/b-init/ImagePaste/pull/33) by [@teetow](https://github.com/teetow)).
12 |
13 | ## [1.8.0](https://github.com/b-init/ImagePaste/compare/v1.7.1...v1.8.0) (2021-10-15)
14 |
15 | - Now works with transparent images without losing alpha data while pasting or copying. Alpha copying only supported as `PNG` (not `DIB`) [#22](https://github.com/b-init/ImagePaste/pull/22)
16 |
17 | ## [1.7.1](https://github.com/b-init/ImagePaste/compare/v1.7.0...v1.7.1) (2021-10-02)
18 |
19 | - Unicode filepaths or filenames such as `👉👈.jpg` or `测试图像.png` should be valid for pasting on _Windows_ ([#21](https://github.com/b-init/ImagePaste/pull/21) by [@atticus-lv](https://github.com/atticus-lv)).
20 |
21 | ## [1.7.0](https://github.com/b-init/ImagePaste/compare/v1.6.1...v1.7.0) (2021-09-01)
22 |
23 | - Now you can customize the filename of the pasted images ([#18](https://github.com/b-init/ImagePaste/pull/18) by [@thanhph111](https://github.com/thanhph111)).
24 | - You can paste the images anytime you want, then save the file and all images you need will be in the target folder ([#17](https://github.com/b-init/ImagePaste/pull/17) by [@thanhph111](https://github.com/thanhph111)).
25 | - The folder in your `.blend` file will be removed automatically when you quit _Blender_ if it's empty (by [@thanhph111](https://github.com/thanhph111)).
26 | - Copying images in the **Image Editor** won't save it to your folder anymore.
27 |
28 | ## [1.6.1](https://github.com/b-init/ImagePaste/compare/v1.6.0...v1.6.1) (2021-08-01)
29 |
30 | - Fix the logic of getting the save directory.
31 |
32 | ## [1.6.0](https://github.com/b-init/ImagePaste/compare/v1.5.1...v1.6.0) (2021-07-27)
33 |
34 | - Now you can paste your image to the _Video Sequence Editor_ as an image strip with a button in the context menu, thanks to [@tin2tin](https://github.com/tin2tin) (read more at [#16](https://github.com/b-init/ImagePaste/pull/16)).
35 | - The add-on now stores the pasted images in a temporary folder by default, they will be deleted after _Blender_ is closed, but from the time you save your session, they will be saved under the `ImagePaste` folder in the same directory as the `.blend` file ([#14](https://github.com/b-init/ImagePaste/pull/14) by [@thanhph111](https://github.com/thanhph111)).
36 | - Redesigned preferences UI with an option to change the name of the default folder and another option to force the add-on to use a different folder for your temporary images ([#14](https://github.com/b-init/ImagePaste/pull/14) by [@thanhph111](https://github.com/thanhph111)).
37 | - All operators now only run if they are in their context so you never have to worry about annoying errors (even they're now more friendly) ([#14](https://github.com/b-init/ImagePaste/pull/14) by [@thanhph111](https://github.com/thanhph111)).
38 | - We also want to thank [@williamchange](https://github.com/williamchange) for helping us to implement new code architecture on _macOS_.
39 |
40 | ## [1.5.1](https://github.com/b-init/ImagePaste/compare/v1.5.0...v1.5.1) (2021-06-30)
41 |
42 | - Fix the crash that occurred when undoing after inserting an image ([#13](https://github.com/b-init/ImagePaste/issues/13) by [@thanhph111](https://github.com/thanhph111)).
43 |
44 | ## [1.5.0](https://github.com/b-init/ImagePaste/compare/v1.4.0...v1.5.0) (2021-06-22)
45 |
46 | - Now works on _macOS_ (by [@celestialmaze](https://twitter.com/cmzw_)).
47 | - Standardized _Github_ repository (by [@thanhph111](https://github.com/thanhph111)).
48 | - Excluded the use of _Pillow_ module for _Windows_, now works natively (by [@thanhph111](https://github.com/thanhph111)).
49 | - Minor fixes and improvements.
50 |
51 | ## [1.4.0](https://github.com/b-init/ImagePaste/compare/v1.3.2...v1.4.0) (2021-06-10)
52 |
53 | - Now supports _X11_ clipboard on _Linux_ platform, (by [@thanhph111](https://github.com/thanhph111)).
54 |
55 | ## [1.3.2](https://github.com/b-init/ImagePaste/compare/v1.3.1...v1.3.2) (2021-04-16)
56 |
57 | - Updated image naming scheme, now with timestamps, preventing overwriting of saved images.
58 | - Merged separate build versions of _ImagePaste_ for _Blender_ version below 2.93a and above into one.
59 |
60 | ## [1.3.1](https://github.com/b-init/ImagePaste/compare/v1.3.0...v1.3.1) (2021-03-14)
61 |
62 | - Fixed issue with the **Copy to clipboard** feature where it didn't work as intended for certain cases.
63 |
64 | ## [1.3.0](https://github.com/b-init/ImagePaste/compare/v1.1.0...v1.3.0) (2021-03-12)
65 |
66 | - Images can be pasted directly into the **Node Editor** as **Image Texture Nodes**, using Context Menu|Paste Images from Clipboard or Ctrl+Shift+V.
67 | - Images can now be copied to the clipboard in the **Image Editor**: Image|Copy To Clipboard or Ctrl+Shift+C. These images are also saved along with other images in the set directory.
68 |
69 | ## 1.2.0 (2021-02-06)
70 |
71 | - Paste images from clipboard directly as a plane onto the viewport: Ctrl+Shift+Alt+V.
72 | - Support images copied from file explorer in _Windows_.
73 | - Multiple images can now be pasted at the same time if multiple images are copied from the file explorer (only for _Windows_).
74 | - Fixed an issue where images were saved with the same name in the default directory even with different _Blender_ sessions and led to different images being loaded from what was pasted.
75 | - Added icons for the buttons.
76 |
77 | ## [1.1.0](https://github.com/b-init/ImagePaste/compare/v1.0.0...v1.1.0) (2021-01-06)
78 |
79 | - Improved error management.
80 | - The images are now saved in the same folder as the `.blend` file, in a newly created subfolder. If the blend file is not saved, it uses the directory set in preferences or the default temp directory, which might raise permission errors. This feature can be toggled via add-on preferences.
81 | - Improved the UI in preferences.
82 |
83 | ## [1.0.0](https://github.com/b-init/ImagePaste/releases/tag/v1.0.0) (2021-01-04)
84 |
85 | - Initial release.
86 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | ImagePaste Copyright (C) 2022 Binit
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Pipfile:
--------------------------------------------------------------------------------
1 | [[source]]
2 | url = "https://pypi.org/simple"
3 | verify_ssl = true
4 | name = "pypi"
5 |
6 | [dev-packages]
7 | black = "*"
8 | flake8 = "*"
9 | "fake-bpy-module-2.83" = "*"
10 | "fake-bpy-module-2.93" = "*"
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # ImagePaste
4 |
5 | A simple _Blender_ add-on to paste images from the clipboard to various places in _Blender_ and copy them to the clipboard to be pasted anywhere. Works with _Blender_ 2.80 and above.
6 |
7 | **This Addon is soon to be deprecated as the functionality is being integrated into Blender itself!**
8 |
9 | ## Installing
10 |
11 | 1. Download [the latest release](https://github.com/b-init/ImagePaste/releases/latest) (you can also view the changelog on [the release page](https://github.com/b-init/ImagePaste/releases)).
12 | 2. Go to Edit|Preferences. On the Add-ons tab, choose Install and select the downloaded `.zip` file.
13 | 3. Tick the box beside the add-on name.
14 |
15 | ## Using
16 |
17 | 
18 |
19 | The add-on supports copying images to the clipboard and pasting them from various places:
20 |
21 | ### Image Editor
22 |
23 | 
24 |
25 | **Copy Image**:
26 |
27 | - Keyboard shortcut: Ctrl+Shift+C
28 | - UI: Image|Copy to Clipboard
29 |
30 | **Paste as Images**:
31 |
32 | - Keyboard shortcut: Ctrl+Shift+V
33 | - UI: Image|Paste from Clipboard
34 |
35 | ### Video Sequencer
36 |
37 | 
38 |
39 | **Paste as Image Strips**:
40 |
41 | - Keyboard shortcut: Ctrl+Shift+Alt+V
42 | - UI: Sequencer Context Menu|Paste from Clipboard
43 |
44 | ### Shader Editor
45 |
46 | 
47 |
48 | **Paste as Image Textures**:
49 |
50 | - Keyboard shortcut: Ctrl+Shift+V
51 | - UI: Node Context Menu|Paste from Clipboard
52 |
53 | ### 3D Viewport
54 |
55 | 
56 |
57 | **Paste as Planes**:
58 |
59 | - Keyboard shortcut: Ctrl+Shift+Alt+V
60 | - UI: Add|Image|Paste from Clipboard as Plane
61 |
62 | **Paste as References**:
63 |
64 | - Keyboard shortcut: Ctrl+Shift+V
65 | - UI: Add|Image|Paste from Clipboard as Reference
66 |
67 | ## Configuring
68 |
69 | ### Customizing the save folder
70 |
71 | By default, pasted images will be stored in a temporary folder, this one will be deleted when you close _Blender_. If you want, you can redirect these images to a different directory.
72 | 
73 |
74 | On the other hand, after you save the `.blend` file, these pasted images will be saved where the `.blend` file is located - in the `ImagePaste` folder. This folder can also be customized in the preferences.
75 | 
76 |
77 | ### Customizing the image filename
78 |
79 | 
80 |
81 | You can customize the filename of the pasted image with the help of some predefined variables:
82 |
83 | | Variable | Description | Example |
84 | | --------------------- | ---------------------------------------------------- | ------------------------------ |
85 | | `${addonName}` | Name of the add-on | _ImagePaste_ |
86 | | `${yearLong}` | Year with the century | 2021, 2022, … |
87 | | `${yearShort}` | Year without the century | 21, 22, … |
88 | | `${monthNumber}` | Month as a zero-padded decimal number | 01, 02, …, 12 |
89 | | `${monthNameLong}` | Full month name | January, February, …, December |
90 | | `${monthNameShort}` | Abbreviated month name | Jan, Feb, …, Dec |
91 | | `${day}` | Day of the month as a zero-padded decimal number | 01, 02, …, 31 |
92 | | `${weekdayNumber}` | Weekday as a decimal number | 0, 1, …, 6 |
93 | | `${weekdayNameLong}` | Full weekday name | Sunday, Monday, …, Saturday |
94 | | `${weekdayNameShort}` | Abbreviated weekday name | Sun, Mon, …, Sat |
95 | | `${hour24}` | Hour (24-hour clock) as a zero-padded decimal number | 00, 01, …, 23 |
96 | | `${hour12}` | Hour (12-hour clock) as a zero-padded decimal number | 01, 02, …, 12 |
97 | | `${minute}` | Minute as a zero-padded decimal number | 00, 01, …, 59 |
98 | | `${second}` | Second as a zero-padded decimal number | 00, 01, …, 59 |
99 | | `${index}` | Order of the image | 1, 2, … |
100 | | `${index:N}` | N-digits image order number with zero padding | `${index:2}` gives 01, 02, … |
101 |
102 | The default filename is `${addonName}-${yearShort}${monthNumber}${day}-${hour24}${minute}${second}`.
103 |
104 | ### Choosing the image type to move when saving the file
105 |
106 | 
107 |
108 | This feature will move (actually copy) images into the save directory after you save the file, so you can paste images anytime, no need to save it first. There's also an option in the add-on preferences you can choose the type of images to move:
109 |
110 | - **Pasted images**: Only images that were pasted using the add-on would be moved to the save directory.
111 | - **All images**: Images existing in the `.blend` file will be moved.
112 | - **No moving**: Don't do anything when saving the file.
113 |
114 | ## Troubleshooting
115 |
116 | If ImagePaste doesn't work, try:
117 | - Running Blender as adminstrator
118 | - Using an earlier version of ImagePaste, particularly [v1.4.0](https://github.com/b-init/ImagePaste/releases/tag/v1.4.0) and [v1.3.2](https://github.com/b-init/ImagePaste/releases/tag/v1.3.2) (Windows 7 doesn't seem to work with the newer versions)
119 |
120 | ## Contributing and getting support
121 |
122 | This is only a small project and we're happy to know it helped some of you. I just want to say that all this wouldn't have been possible without these [great contributors](https://github.com/b-init/ImagePaste/graphs/contributors) and everybody who comes with new ideas and bug reports! So thank you all!
123 |
124 | It will be great if you have an idea and turn it into visible. Tell us how amazing they are by [suggesting a feature](https://github.com/b-init/ImagePaste/issues/new/choose), or you can make it yourself by creating [a pull request](https://github.com/b-init/ImagePaste/compare). And if you encounter a problem, let us know by [opening an issue](https://github.com/b-init/ImagePaste/issues/new/choose). But before doing anything, let's take a look at [our contributing guide](.github/CONTRIBUTING.md), it will show you how to start with all of that.
125 |
--------------------------------------------------------------------------------
/__init__.py:
--------------------------------------------------------------------------------
1 | bl_info = {
2 | "name": "ImagePaste",
3 | "author": "Binit",
4 | "blender": (2, 80, 0),
5 | "version": (1, 8, 2),
6 | "category": "Import-Export",
7 | "support": "COMMUNITY",
8 | "doc_url": "https://github.com/b-init/ImagePaste#readme",
9 | "tracker_url": "https://github.com/b-init/ImagePaste/issues",
10 | "description": "Copy and paste your images with the clipboard in various places",
11 | "location": "Image Editor, Video Sequencer, Shader Editor, 3D Viewport",
12 | }
13 |
14 | from .imagepaste import preferences
15 | from .imagepaste import operators
16 |
17 |
18 | def register():
19 | preferences.register()
20 | operators.register()
21 |
22 |
23 | def unregister():
24 | operators.unregister()
25 | preferences.unregister()
26 |
--------------------------------------------------------------------------------
/assets/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/demo.gif
--------------------------------------------------------------------------------
/assets/preferences/directory.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/preferences/directory.png
--------------------------------------------------------------------------------
/assets/preferences/filename.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/preferences/filename.png
--------------------------------------------------------------------------------
/assets/preferences/image-type.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/preferences/image-type.png
--------------------------------------------------------------------------------
/assets/preferences/subdirectory.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/preferences/subdirectory.png
--------------------------------------------------------------------------------
/assets/ui/3d-viewport.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/ui/3d-viewport.png
--------------------------------------------------------------------------------
/assets/ui/image-editor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/ui/image-editor.png
--------------------------------------------------------------------------------
/assets/ui/shader-editor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/ui/shader-editor.png
--------------------------------------------------------------------------------
/assets/ui/video-sequencer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/assets/ui/video-sequencer.png
--------------------------------------------------------------------------------
/imagepaste/clipboard/clipboard.py:
--------------------------------------------------------------------------------
1 | from __future__ import annotations
2 | from abc import ABC
3 | from abc import abstractmethod
4 | from abc import abstractclassmethod
5 |
6 | from ..image import Image
7 | from ..report import Report
8 |
9 |
10 | class Clipboard(ABC):
11 | """An abstract class for clipboard operations."""
12 |
13 | @abstractmethod
14 | def __init__(self, report: Report, images: list[Image] = None) -> None:
15 | """Require subclasses to provide implementation for this method.
16 |
17 | Args:
18 | report (Report): Mandatory parameter, to be used to report status of result.
19 | images (list[Image], optional): List of returned images. Defaults to None.
20 | """
21 | self.report = report
22 | self.images = images
23 |
24 | @abstractclassmethod
25 | def push(cls, save_directory: str) -> Clipboard:
26 | """Push images information from the clipboard.
27 |
28 | Subclasses must implement this method to return a new instance of the class.
29 | 'Push' keyword mean that the clipboard is giving (pushing) the images to us.
30 |
31 | Args:
32 | save_directory (str): a path of the directory where images should be saved.
33 |
34 | Returns:
35 | Clipboard: an instance of the class, which contains a Report object showing
36 | the status of the operation and a list of Image objects that holds
37 | information of images were copied in the clipboard.
38 | """
39 | pass
40 |
41 | @abstractclassmethod
42 | def pull(cls, image_path: str) -> Clipboard:
43 | """Pull images information to the clipboard.
44 |
45 | Subclasses must implement this method to return a new instance of the class.
46 | 'Pull' keyword mean that the clipboard is getting (pulling) data from us.
47 |
48 | Args:
49 | image_path (str): a path of an image to be copied to the clipboard.
50 |
51 | Returns:
52 | Clipboard: an instance of the class, which contains a Report object showing
53 | the status of the operation and a list of one Image object that hold
54 | information of the image we put its path to the input.
55 | """
56 | pass
57 |
58 | @staticmethod
59 | def get_filename() -> str:
60 | """Get a string representation of the current time in the filename format.
61 |
62 | Returns:
63 | str: a string representing the current time in the filename format.
64 | """
65 | from time import strftime
66 | from ..metadata import get_addon_preferences
67 | from ..tree import populate_filename
68 | from ..tree import is_valid_filename
69 |
70 | preferences = get_addon_preferences()
71 | filename = (
72 | populate_filename(preferences.image_filename_pattern)
73 | + preferences.image_extension
74 | )
75 | if is_valid_filename(filename):
76 | return filename
77 | return strftime(f"ImagePaste-%y%m%d-%H%M%S{preferences.image_extension}")
78 |
79 | def __repr__(self) -> str:
80 | """Representation of the object.
81 |
82 | Returns:
83 | str: a string showing a brief information about the report and images.
84 | """
85 | return "{}({!r})".format(self.__class__.__name__, self.__dict__)
86 |
--------------------------------------------------------------------------------
/imagepaste/clipboard/darwin/darwin.py:
--------------------------------------------------------------------------------
1 | from __future__ import annotations
2 |
3 | from ..clipboard import Clipboard
4 | from ...image import Image
5 | from ...report import Report
6 | from ...process import Process
7 |
8 |
9 | class DarwinClipboard(Clipboard):
10 | """A Clipboard implementation for macOS."""
11 |
12 | def __init__(self, report: Report, images: list[Image] = None) -> None:
13 | """Initialize the Darwin Clipboard.
14 |
15 | Args:
16 | report (Report): A Report object to hold operation results.
17 | images (list[Image], optional): A list of Image objects. Default: None.
18 | """
19 | super().__init__(report, images)
20 |
21 | @classmethod
22 | def push(cls, save_directory: str) -> DarwinClipboard:
23 | """Push the current image information from the clipboard.
24 |
25 | Args:
26 | save_directory (str): A path to a directory to save the image.
27 |
28 | Returns:
29 | DarwinClipboard: A new instance of the DarwinClipboard, with a Report
30 | object containing the operation results and a list of Image objects
31 | holding the images information.
32 | """
33 | from os.path import join
34 | from os.path import isfile
35 | from .pasteboard import _native as pasteboard
36 |
37 | pb = pasteboard.Pasteboard()
38 |
39 | # Use Pasteboard to get file URLs from the clipboard
40 | urls = pb.get_file_urls()
41 | if urls is not None:
42 | filepaths = list(urls)
43 | images = [Image(filepath, pasted=True) for filepath in filepaths]
44 | return cls(Report(6, f"Pasted {len(images)} image files: {images}"), images)
45 |
46 | # Save an image if it is in the clipboard
47 | contents = pb.get_contents(type=pasteboard.TIFF)
48 | if contents is not None:
49 | filename = cls.get_filename()
50 | filepath = join(save_directory, filename)
51 | commands = [
52 | "set pastedImage to "
53 | f'(open for access POSIX file "{filepath}" with write permission)',
54 | "try",
55 | " write (the clipboard as «class PNGf») to pastedImage",
56 | "end try",
57 | "close access pastedImage",
58 | ]
59 | process = Process.execute(cls.get_osascript_args(commands))
60 | if not isfile(filepath):
61 | image = Image(filepath)
62 | return cls(Report(3, f"Cannot save image: {image} ({process.stderr})"))
63 | image = Image(filepath, pasted=True)
64 | if process.stderr:
65 | report = Report(6, f"Saved 1 image: {image} (WARN: {process.stderr})")
66 | return cls(report, [image])
67 | return cls(Report(6, f"Saved and pasted 1 image: {image}"), [image])
68 | return cls(Report(2))
69 |
70 | @classmethod
71 | def pull(cls, image_path: str) -> DarwinClipboard:
72 | """Pull the image to the clipboard from its path.
73 |
74 | Args:
75 | image_path (str): A path to an image to be pulled to the clipboard.
76 |
77 | Returns:
78 | DarwinClipboard: A new instance of the DarwinClipboard, with a Report
79 | object containing the operation results and a list of one Image object
80 | holding information of the pulled image we put its path to the input.
81 | """
82 | commands = [
83 | "set the clipboard to "
84 | f'(read file POSIX file "{image_path}" as «class PNGf»)'
85 | ]
86 | process = Process.execute(cls.get_osascript_args(commands))
87 | if process.stderr:
88 | return cls(Report(4, f"Process failed ({process.stderr})"))
89 | image = Image(image_path)
90 | return cls(Report(5, f"Copied 1 image: {image}"), [image])
91 |
92 | @staticmethod
93 | def get_osascript_args(commands: list[str]) -> list[str]:
94 | """Get the arguments for osascript command.
95 |
96 | Args:
97 | commands (list[str]): A list of commands to be executed.
98 |
99 | Returns:
100 | list[str]: A list of arguments for osascript command ready to be executed.
101 | """
102 | args = ["osascript"]
103 | for command in commands:
104 | args += ["-e", command]
105 | return args
106 |
--------------------------------------------------------------------------------
/imagepaste/clipboard/darwin/pasteboard/_native.cpython-310-darwin.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/imagepaste/clipboard/darwin/pasteboard/_native.cpython-310-darwin.so
--------------------------------------------------------------------------------
/imagepaste/clipboard/darwin/pasteboard/_native.cpython-311-darwin.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/imagepaste/clipboard/darwin/pasteboard/_native.cpython-311-darwin.so
--------------------------------------------------------------------------------
/imagepaste/clipboard/darwin/pasteboard/_native.cpython-37m-darwin.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/imagepaste/clipboard/darwin/pasteboard/_native.cpython-37m-darwin.so
--------------------------------------------------------------------------------
/imagepaste/clipboard/darwin/pasteboard/_native.cpython-39-darwin.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/imagepaste/clipboard/darwin/pasteboard/_native.cpython-39-darwin.so
--------------------------------------------------------------------------------
/imagepaste/clipboard/linux/bin/xclip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/b-init/ImagePaste/26f1db90c0c4c1f14ebd641068645af5e15be3d0/imagepaste/clipboard/linux/bin/xclip
--------------------------------------------------------------------------------
/imagepaste/clipboard/linux/linux.py:
--------------------------------------------------------------------------------
1 | from __future__ import annotations
2 | from enum import Enum
3 |
4 | from ...image import Image
5 | from ...process import Process
6 | from ...report import Report
7 | from ..clipboard import Clipboard
8 |
9 |
10 | class XclipTarget(Enum):
11 | """Enum for xclip target types."""
12 |
13 | ALL = "TARGETS"
14 | IMAGE = "image/png"
15 | URI = "text/uri-list"
16 |
17 |
18 | class LinuxClipboard(Clipboard):
19 | """A Clipboard implementation for Linux."""
20 |
21 | def __init__(self, report: Report, images: list[Image] = None) -> None:
22 | """Initialize LinuxClipboard instance.
23 |
24 | Args:
25 | report (Report): a Report object to show status of operation results.
26 | images (list[Image], optional): a list of Image objects. Defaults to None.
27 | """
28 | super().__init__(report, images)
29 |
30 | @classmethod
31 | def push(cls, save_directory: str) -> LinuxClipboard:
32 | """Clipboard pushes images information.
33 |
34 | Args:
35 | save_directory (str): a directory to save images.
36 |
37 | Returns:
38 | LinuxClipboard: a LinuxClipboard instance, which contains a Report object
39 | showing the status of the operation and a list of Image objects that
40 | holds information of images were copied in the clipboard.
41 | """
42 | from os.path import join
43 | from urllib.parse import urlparse
44 | from urllib.request import url2pathname
45 |
46 | # Get all available targets
47 | process = Process.execute(cls.get_xclip_args())
48 | if process.stderr:
49 | return cls(Report(1, f"Process failed ({process.stderr})"))
50 |
51 | # If there is an image in clipboard, save the image and send its path
52 | if XclipTarget.IMAGE.value in process.stdout:
53 | filename = cls.get_filename()
54 | filepath = join(save_directory, filename)
55 | process = Process.execute(
56 | cls.get_xclip_args(XclipTarget.IMAGE.value), outpath=filepath
57 | )
58 | if process.stderr:
59 | image = Image(filepath)
60 | return cls(Report(3, f"Cannot save image: {image} ({process.stderr})"))
61 | image = Image(filepath, pasted=True)
62 | return cls(Report(6, f"Saved and pasted 1 image: {image}"), [image])
63 |
64 | # If copying from files, just send their paths
65 | if XclipTarget.URI.value in process.stdout:
66 | uris = Process.execute(cls.get_xclip_args(XclipTarget.URI.value)).stdout
67 | filepaths = [url2pathname((urlparse(uri).path)) for uri in uris]
68 | # TODO: Check if files are images
69 | images = [Image(filepath, pasted=True) for filepath in filepaths]
70 | return cls(Report(6, f"Pasted {len(images)} image files: {images}"), images)
71 | return cls(Report(2))
72 |
73 | @classmethod
74 | def pull(cls, image_path: str) -> LinuxClipboard:
75 | """Clipboard pulls image information.
76 |
77 | Args:
78 | image_path (str): a path to image to be copied to clipboard.
79 |
80 | Returns:
81 | LinuxClipboard: a LinuxClipboard instance, which contains a Report object
82 | showing the status of the operation and a list of one Image object that
83 | holds information of the image we put its path to the input.
84 | """
85 | from mimetypes import guess_type
86 |
87 | mime_type = guess_type(image_path)[0]
88 | if not mime_type:
89 | return Report(4, f"Cannot guess MIME type from {image_path}")
90 | args = LinuxClipboard.get_xclip_args(mime_type, image_path, out=False)
91 | # If capture stdout/stderr, popen will hang as xclip runs in the background
92 | process = Process.execute(args, capture_output=False)
93 | if process.returncode != 0:
94 | return cls(Report(4, f"Popen failed with code {process.returncode}"))
95 | image = Image(image_path)
96 | return cls(Report(5, f"Copied 1 image: {image}"), [image])
97 |
98 | @staticmethod
99 | def get_xclip_args(
100 | target: XclipTarget = XclipTarget.ALL.value, *suffix: str, out=True
101 | ) -> list[str]:
102 | """Get arguments for xclip command.
103 |
104 | Args:
105 | target (XclipTarget, optional): a XclipTarget enum value, which specifies
106 | what to capture. Defaults to XclipTarget.ALL.value.
107 | suffix (str, optional): a list of suffixes to be added to the command.
108 | Defaults to empty list.
109 | out (bool, optional): a flag to request xclip to output to stdout.
110 | Defaults to True.
111 |
112 | Returns:
113 | list[str]: a list of arguments for xclip command.
114 | """
115 | from os import chmod
116 | from os.path import dirname
117 | from os.path import realpath
118 | from stat import S_IXUSR
119 |
120 | XCLIP_PATH = f"{dirname(realpath(__file__))}/bin/xclip"
121 | # TODO: Move to higher level
122 | chmod(XCLIP_PATH, S_IXUSR)
123 | args = [
124 | XCLIP_PATH,
125 | "-rmlastnl",
126 | "-selection",
127 | "clipboard",
128 | "-target",
129 | f"{target}",
130 | ]
131 | if out:
132 | args += ["-out"]
133 | args += suffix
134 | return args
135 |
--------------------------------------------------------------------------------
/imagepaste/clipboard/windows/windows.py:
--------------------------------------------------------------------------------
1 | from __future__ import annotations
2 |
3 | from ..clipboard import Clipboard
4 | from ...report import Report
5 | from ...image import Image
6 | from ...process import Process
7 |
8 |
9 | class WindowsClipboard(Clipboard):
10 | """A concrete implementation of Clipboard for Windows."""
11 |
12 | def __init__(self, report: Report, images: list[Image] = None) -> None:
13 | """A concreate implementation of Clipboard for Windows.
14 |
15 | Args:
16 | report (Report): A Report instance to which results should be reported.
17 | images (list[Image], optional): A list of Images objects. Defaults to None.
18 | """
19 | super().__init__(report, images)
20 |
21 | @classmethod
22 | def push(cls, save_directory: str) -> WindowsClipboard:
23 | """A class method for pushing images from the Windows Clipboard.
24 |
25 | Args:
26 | save_directory (str): A path to a directory to save the pushed images.
27 |
28 | Returns:
29 | WindowsClipboard: A WindowsClipboard instance, which contains status of
30 | operations under Report object and a list of Image objects holding
31 | pushed images information.
32 | """
33 | from os.path import join
34 |
35 | filename = cls.get_filename()
36 | filepath = join(save_directory, filename)
37 |
38 | image_script = (
39 | "Add-Type -AssemblyName System.Windows.Forms; "
40 | "Add-Type -AssemblyName System.Drawing; "
41 | "$clipboard = [System.Windows.Forms.Clipboard]::GetDataObject(); "
42 | "$imageStream = $clipboard.GetData('PNG'); "
43 | "if ($null -eq $imageStream) { $imageStream = $clipboard.GetData('image/png') }; "
44 | "if ($null -eq $imageStream) { $imageStream = $clipboard.GetData('System.Drawing.Bitmap') }; "
45 | "if ($imageStream) {"
46 | "$bitmap = New-Object System.Drawing.Bitmap($imageStream); "
47 | f"$bitmap.Save('{filepath}', [System.Drawing.Imaging.ImageFormat]::Png); "
48 | "Write-Output 0"
49 | "}"
50 | )
51 | process = Process.execute(cls.get_powershell_args(image_script), split=False)
52 | if process.stderr:
53 | image = Image(filepath)
54 | return cls(Report(3, f"Cannot save image: {image} ({process.stderr})"))
55 | if process.stdout == "0":
56 | image = Image(filepath, pasted=True)
57 | return cls(Report(6, f"Saved and pasted 1 image: {image}"), [image])
58 |
59 | file_script = (
60 | "$files = Get-Clipboard -Format FileDropList; "
61 | "if ($files) { $files.fullname }"
62 | )
63 | process = Process.execute(cls.get_powershell_args(file_script))
64 | if process.stdout[0] != "":
65 | images = [Image(filepath) for filepath in process.stdout]
66 | return cls(Report(6, f"Pasted {len(images)} image files: {images}"), images)
67 | return cls(Report(2))
68 |
69 | @classmethod
70 | def pull(cls, image_path: str) -> WindowsClipboard:
71 | """A class method for pulling images to the Windows Clipboard.
72 |
73 | Args:
74 | image_path (str): A path to an image to be pulled to the clipboard.
75 |
76 | Returns:
77 | WindowsClipboard: A WindowsClipboard instance, which contains status of
78 | operations under Report object and a list of one Image object that holds
79 | information of the pulled image we put its path to the input.
80 | """
81 | # Script that supports transparency. Save images to clipboard as PNG and Bitmap.
82 | # Populating the clipboard with Bitmap data which is equivalent to using the
83 | # `Clipboard.SetImage` method.
84 | script = (
85 | "Add-Type -Assembly System.Windows.Forms; "
86 | "Add-Type -Assembly System.Drawing; "
87 | f"$image = [Drawing.Image]::FromFile('{image_path}'); "
88 | "$imageStream = New-Object System.IO.MemoryStream; "
89 | "$image.Save($imageStream, [System.Drawing.Imaging.ImageFormat]::Png); "
90 | "$dataObj = New-Object System.Windows.Forms.DataObject('Bitmap', $image); "
91 | "$dataObj.SetData('PNG', $imageStream); "
92 | "[System.Windows.Forms.Clipboard]::SetDataObject($dataObj, $true); "
93 | )
94 |
95 | process = Process.execute(cls.get_powershell_args(script))
96 | if process.stderr:
97 | return cls(Report(4, f"Cannot load image: {image_path} ({process.stderr})"))
98 | image = Image(image_path)
99 | return cls(Report(5, f"Copied 1 image: {image}"), [image])
100 |
101 | @staticmethod
102 | def get_powershell_args(script: str) -> list[str]:
103 | """A static method to get PowerShell arguments from a script for a process.
104 |
105 | Args:
106 | script (str): A script to be executed.
107 |
108 | Returns:
109 | list[str]: A list of PowerShell arguments for operating a process.
110 | """
111 | from os import getenv
112 | from os.path import join
113 |
114 | powershell_args = [
115 | join(
116 | getenv("SystemRoot"),
117 | "System32",
118 | "WindowsPowerShell",
119 | "v1.0",
120 | "powershell.exe",
121 | ),
122 | "-NoProfile",
123 | "-NoLogo",
124 | "-NonInteractive",
125 | "-WindowStyle",
126 | "Hidden",
127 | ]
128 | script = (
129 | "$OutputEncoding = "
130 | "[System.Console]::OutputEncoding = "
131 | "[System.Console]::InputEncoding = "
132 | "[System.Text.Encoding]::UTF8; "
133 | + "$PSDefaultParameterValues['*:Encoding'] = 'utf8'; "
134 | + script
135 | )
136 | args = powershell_args + ["& { " + script + " }"]
137 | return args
138 |
--------------------------------------------------------------------------------
/imagepaste/image.py:
--------------------------------------------------------------------------------
1 | class Image:
2 | """A class to represent an image file."""
3 |
4 | pasted_images = {}
5 | image_index = 0
6 |
7 | def __init__(self, filepath: str, pasted: bool = False) -> None:
8 | """Constructor for the Image class.
9 |
10 | Args:
11 | filepath (str): The path to the image file.
12 | filename (str, optional): The name of the image file.
13 | pasted (bool, optional): Whether the image is pasted.
14 | """
15 | self.filepath = filepath
16 | if pasted:
17 | Image.pasted_images[self.filepath] = self
18 | Image.image_index += 1
19 |
20 | @property
21 | def filepath(self) -> str:
22 | """Get the path to the image file."""
23 | return self._filepath
24 |
25 | @filepath.setter
26 | def filepath(self, filepath: str) -> None:
27 | """Set the path to the image file.
28 |
29 | Args:
30 | filepath (str): The path to the image file.
31 | """
32 | from os.path import basename
33 | from os.path import dirname
34 |
35 | self._filepath = filepath
36 | self.filename = basename(filepath)
37 | self.filebase = dirname(filepath)
38 |
39 | def __repr__(self) -> str:
40 | """Return a string representation of the Image class.
41 |
42 | Returns:
43 | str: A string representation of the Image class.
44 | """
45 | return f"{self.filename}<{self.filepath}>"
46 |
--------------------------------------------------------------------------------
/imagepaste/metadata.py:
--------------------------------------------------------------------------------
1 | import bpy
2 |
3 |
4 | ADDON_NAME = __package__.split(".")[0]
5 |
6 |
7 | def get_addon_preferences() -> bpy.types.AddonPreferences:
8 | """Get the addon preferences.
9 |
10 | Returns:
11 | bpy.types.AddonPreferences: The addon preferences.
12 | """
13 | return bpy.context.preferences.addons[ADDON_NAME].preferences
14 |
15 |
16 | def get_addon_bl_info() -> dict:
17 | """Get add-on bl_info defined in __init__.py.
18 |
19 | Returns:
20 | dict: a dictionary containing add-on info.
21 | """
22 | from importlib import import_module
23 |
24 | return import_module(ADDON_NAME).bl_info
25 |
--------------------------------------------------------------------------------
/imagepaste/operators.py:
--------------------------------------------------------------------------------
1 | from __future__ import annotations
2 | import sys
3 |
4 | if sys.platform == "win32":
5 | from .clipboard.windows.windows import WindowsClipboard as Clipboard
6 | elif sys.platform == "linux":
7 | from .clipboard.linux.linux import LinuxClipboard as Clipboard
8 | elif sys.platform == "darwin":
9 | from .clipboard.darwin.darwin import DarwinClipboard as Clipboard
10 | else:
11 | raise RuntimeError(f"Unsupported platform '{sys.platform}'.")
12 |
13 |
14 | import bpy
15 |
16 |
17 | class IMAGEPASTE_OT_imageeditor_copy(bpy.types.Operator):
18 | """Copy image to the clipboard"""
19 |
20 | bl_idname = "imagepaste.imageeditor_copy"
21 | bl_label = "Copy to Clipboard"
22 | bl_options = {"UNDO_GROUPED"}
23 |
24 | def execute(self, context):
25 | from os.path import join
26 | from .metadata import get_addon_preferences
27 |
28 | active_image = context.area.spaces.active.image
29 | # If active image is render result, save it first
30 | if active_image.filepath != "":
31 | image_path = active_image.filepath
32 | else:
33 | image_extension = get_addon_preferences().image_extension
34 | image_path = join(bpy.app.tempdir, active_image.name + image_extension)
35 | bpy.ops.image.save_as(save_as_render=True, copy=True, filepath=image_path)
36 | # Report and log the result
37 | clipboard = Clipboard.pull(image_path)
38 | clipboard.report.log(self)
39 | if clipboard.report.type != "INFO":
40 | return {"CANCELLED"}
41 | return {"FINISHED"}
42 |
43 | @classmethod
44 | def poll(_cls, context):
45 | return (
46 | context.area.type == "IMAGE_EDITOR"
47 | and context.area.spaces.active.image is not None
48 | and context.area.spaces.active.image.has_data is True
49 | )
50 |
51 |
52 | class IMAGEPASTE_OT_imageeditor_paste(bpy.types.Operator):
53 | """Paste images from the clipboard"""
54 |
55 | bl_idname = "imagepaste.imageeditor_paste"
56 | bl_label = "Paste from Clipboard"
57 | bl_options = {"UNDO_GROUPED"}
58 |
59 | def execute(self, context):
60 | from .tree import get_save_directory
61 |
62 | clipboard = Clipboard.push(get_save_directory())
63 | clipboard.report.log(self)
64 | if clipboard.report.type != "INFO":
65 | return {"CANCELLED"}
66 | for image in clipboard.images:
67 | bpy.data.images.load(image.filepath)
68 | last_image_name = clipboard.images[-1].filename
69 | context.area.spaces.active.image = bpy.data.images[last_image_name]
70 | return {"FINISHED"}
71 |
72 | @classmethod
73 | def poll(_cls, context):
74 | return context.area.type == "IMAGE_EDITOR"
75 |
76 |
77 | class IMAGEPASTE_OT_sequenceeditor_paste(bpy.types.Operator):
78 | """Paste images from the clipboard"""
79 |
80 | bl_idname = "imagepaste.sequenceeditor_paste"
81 | bl_label = "Paste from Clipboard"
82 | bl_options = {"UNDO_GROUPED"}
83 |
84 | def execute(self, context):
85 | from .tree import get_save_directory
86 |
87 | clipboard = Clipboard.push(get_save_directory())
88 | clipboard.report.log(self)
89 | if clipboard.report.type != "INFO":
90 | return {"CANCELLED"}
91 | sequences = context.scene.sequence_editor.sequences
92 | current_frame = context.scene.frame_current
93 | for image in clipboard.images:
94 | image_strip = sequences.new_image(
95 | name=image.filename,
96 | filepath=image.filepath,
97 | channel=1,
98 | frame_start=current_frame,
99 | )
100 | image_strip.frame_final_end = current_frame + 50
101 | return {"FINISHED"}
102 |
103 | @classmethod
104 | def poll(_cls, context):
105 | return context.area.type == "SEQUENCE_EDITOR"
106 |
107 |
108 | class IMAGEPASTE_OT_shadereditor_paste(bpy.types.Operator):
109 | """Paste images from the clipboard as image texture nodes"""
110 |
111 | bl_idname = "imagepaste.shadereditor_paste"
112 | bl_label = "Paste from Clipboard"
113 | bl_options = {"UNDO_GROUPED"}
114 |
115 | def execute(self, context):
116 | from .tree import get_save_directory
117 |
118 | clipboard = Clipboard.push(get_save_directory())
119 | clipboard.report.log(self)
120 | if clipboard.report.type != "INFO":
121 | return {"CANCELLED"}
122 | tree = context.space_data.edit_tree
123 | location_X, location_Y = context.space_data.cursor_location
124 | for image in clipboard.images:
125 | node_image = tree.nodes.new("ShaderNodeTexImage")
126 | node_image.location = location_X, location_Y
127 | # Offset location for next node
128 | location_Y += 300
129 | image_data = bpy.data.images.load(filepath=image.filepath)
130 | node_image.image = image_data
131 | return {"FINISHED"}
132 |
133 | @classmethod
134 | def poll(_cls, context):
135 | return (
136 | context.area.type == "NODE_EDITOR"
137 | and context.area.ui_type == "ShaderNodeTree"
138 | and context.space_data.edit_tree is not None
139 | )
140 |
141 |
142 | class IMAGEPASTE_OT_view3d_paste_plane(bpy.types.Operator):
143 | """Paste images from the clipboard as planes"""
144 |
145 | bl_idname = "imagepaste.view3d_paste_plane"
146 | bl_label = "Paste from Clipboard as Plane"
147 | bl_options = {"UNDO_GROUPED"}
148 |
149 | def execute(self, _context):
150 | from addon_utils import enable
151 | from .tree import get_save_directory
152 |
153 | # Enable the "Import Images as Planes" add-on to be used here
154 | enable("io_import_images_as_planes")
155 |
156 | clipboard = Clipboard.push(get_save_directory())
157 | clipboard.report.log(self)
158 | if clipboard.report.type != "INFO":
159 | return {"CANCELLED"}
160 | for image in clipboard.images:
161 | bpy.ops.import_image.to_plane(files=[{"name": image.filepath}])
162 | return {"FINISHED"}
163 |
164 | @classmethod
165 | def poll(_cls, context):
166 | return (
167 | context.area.type == "VIEW_3D"
168 | and context.area.ui_type == "VIEW_3D"
169 | and context.mode == "OBJECT"
170 | )
171 |
172 |
173 | class IMAGEPASTE_OT_view3d_paste_reference(bpy.types.Operator):
174 | """Paste images from the clipboard as references"""
175 |
176 | bl_idname = "imagepaste.view3d_paste_reference"
177 | bl_label = "Paste from Clipboard as Reference"
178 | bl_options = {"UNDO_GROUPED"}
179 |
180 | def execute(self, _context):
181 | from .tree import get_save_directory
182 |
183 | clipboard = Clipboard.push(get_save_directory())
184 | clipboard.report.log(self)
185 | if clipboard.report.type != "INFO":
186 | return {"CANCELLED"}
187 | for image in clipboard.images:
188 | bpy.ops.object.load_reference_image(filepath=image.filepath)
189 | return {"FINISHED"}
190 |
191 | @classmethod
192 | def poll(_cls, context):
193 | return (
194 | context.area.type == "VIEW_3D"
195 | and context.area.ui_type == "VIEW_3D"
196 | and context.mode == "OBJECT"
197 | )
198 |
199 |
200 | class IMAGEPASTE_OT_move_to_save_directory(bpy.types.Operator):
201 | """Move images to a target directory"""
202 |
203 | bl_idname = "imagepaste.move_to_save_directory"
204 | bl_label = "Move to Target Directory"
205 | bl_options = {"UNDO_GROUPED"}
206 |
207 | def __init__(self) -> None:
208 | from .tree import get_save_directory
209 |
210 | super().__init__()
211 | self.save_directory = get_save_directory()
212 | self.orphaned_images = self.get_orphaned_images(self.save_directory)
213 |
214 | def execute(self, _context):
215 | from .image import Image
216 | from .report import Report
217 |
218 | pasted_images = Image.pasted_images
219 | orphaned_image_filepaths = []
220 | # Change the paths the images refers to with the new one
221 | for orphaned_image in self.orphaned_images:
222 | old_filepath = self.get_abspath(orphaned_image.filepath)
223 | self.change_image_directory(orphaned_image, self.save_directory)
224 | new_filepath = self.get_abspath(orphaned_image.filepath)
225 | # Also change in the dictionary
226 | if old_filepath in pasted_images:
227 | pasted_images[new_filepath] = pasted_images.pop(old_filepath)
228 | pasted_images[new_filepath].filepath = new_filepath
229 | orphaned_image_filepaths.append(old_filepath)
230 | # Remove pasted images which are not in `.blend` file (pasted but then undone)
231 | existing_images = [
232 | self.get_abspath(image.filepath)
233 | for image in bpy.data.images
234 | if image.filepath
235 | ]
236 | for filepath in list(pasted_images.keys()):
237 | if filepath not in existing_images:
238 | del pasted_images[filepath]
239 | Report(7, f"Pasted images after: {list(pasted_images.keys())}").log(self)
240 | Report.console_log(f"Blend images after: {existing_images}")
241 | return {"FINISHED"}
242 |
243 | def invoke(self, context, _event):
244 | if self.orphaned_images:
245 | self.execute(context)
246 | return {"CANCELLED"}
247 |
248 | @classmethod
249 | def poll(_cls, _context):
250 | return bool(bpy.data.filepath)
251 |
252 | def get_abspath(self, path: str) -> str:
253 | """Get the absolute path of a file or directory.
254 |
255 | Args:
256 | path (str): The path to get the absolute path of.
257 |
258 | Returns:
259 | str: The absolute path of the file or directory.
260 | """
261 | from os.path import abspath
262 |
263 | return abspath(bpy.path.abspath(path))
264 |
265 | def get_orphaned_images(self, save_directory: str) -> list[bpy.types.Image]:
266 | """Get images that are not in the target directory.
267 |
268 | Args:
269 | save_directory (str): The target directory.
270 |
271 | Returns:
272 | list[bpy.types.Image]: A list of orphaned images.
273 | """
274 | from os.path import dirname
275 | from .image import Image
276 | from .metadata import get_addon_preferences
277 | from .report import Report
278 |
279 | preferences = get_addon_preferences()
280 | if preferences.image_type_to_move == "no_moving":
281 | return []
282 | pasted_images = Image.pasted_images
283 | orphaned_images = []
284 | orphaned_image_paths = []
285 | existing_images = []
286 | for image in bpy.data.images:
287 | # Example: 'Render Result'
288 | if not image.filepath:
289 | continue
290 | filepath = self.get_abspath(image.filepath)
291 | existing_images.append(filepath)
292 | if dirname(filepath) == save_directory:
293 | continue
294 | if preferences.image_type_to_move == "all_images":
295 | orphaned_images.append(image)
296 | orphaned_image_paths.append(filepath)
297 | continue
298 | if filepath in pasted_images:
299 | orphaned_images.append(image)
300 | orphaned_image_paths.append(filepath)
301 | Report.console_log(f"Pasted images before: {list(pasted_images.keys())}")
302 | Report.console_log(f"Blend images before: {existing_images}")
303 | Report.console_log(f"Orphaned images: {orphaned_image_paths}")
304 | return orphaned_images
305 |
306 | def change_image_directory(
307 | self, orphaned_image: bpy.types.Image, save_directory: str
308 | ) -> None:
309 | """Change the directory of an orphaned image.
310 |
311 | Args:
312 | orphaned_image (bpy.types.Image): An orphaned image.
313 | save_directory (str): The target directory.
314 | """
315 | from os.path import join
316 | from shutil import copyfile
317 |
318 | new_filepath = join(save_directory, bpy.path.basename(orphaned_image.filepath))
319 | copyfile(bpy.path.abspath(orphaned_image.filepath), new_filepath)
320 | orphaned_image.filepath = new_filepath
321 | orphaned_image.reload()
322 |
323 |
324 | classes = (
325 | IMAGEPASTE_OT_imageeditor_copy,
326 | IMAGEPASTE_OT_imageeditor_paste,
327 | IMAGEPASTE_OT_sequenceeditor_paste,
328 | IMAGEPASTE_OT_shadereditor_paste,
329 | IMAGEPASTE_OT_view3d_paste_plane,
330 | IMAGEPASTE_OT_view3d_paste_reference,
331 | IMAGEPASTE_OT_move_to_save_directory,
332 | )
333 |
334 |
335 | def register():
336 | for cls in classes:
337 | bpy.utils.register_class(cls)
338 |
339 |
340 | def unregister():
341 | for cls in reversed(classes):
342 | bpy.utils.unregister_class(cls)
343 |
--------------------------------------------------------------------------------
/imagepaste/preferences.py:
--------------------------------------------------------------------------------
1 | import bpy
2 |
3 | from .metadata import ADDON_NAME
4 | from .operators import (
5 | IMAGEPASTE_OT_imageeditor_copy,
6 | IMAGEPASTE_OT_imageeditor_paste,
7 | IMAGEPASTE_OT_sequenceeditor_paste,
8 | IMAGEPASTE_OT_shadereditor_paste,
9 | IMAGEPASTE_OT_view3d_paste_plane,
10 | IMAGEPASTE_OT_view3d_paste_reference,
11 | )
12 | from .tree import remove_empty_subdirectory
13 |
14 |
15 | def get_subdirectory_name(self):
16 | """Get the subdirectory name."""
17 | return self.get("subdirectory_name", ADDON_NAME)
18 |
19 |
20 | def set_subdirectory_name(self, value):
21 | """Set the subdirectory name."""
22 | from .tree import remove_empty_subdirectory
23 |
24 | # Remove the old subdirectory before setting the new one
25 | remove_empty_subdirectory(self.subdirectory_name)
26 | self["subdirectory_name"] = value
27 |
28 |
29 | class IMAGEPASTE_AddonPreferences(bpy.types.AddonPreferences):
30 | """Add-on preferences for ImagePaste"""
31 |
32 | bl_idname = ADDON_NAME
33 |
34 | is_use_another_directory: bpy.props.BoolProperty(
35 | name="Use a directory",
36 | description=(
37 | "Save images to another directory instead of temporary directory"
38 | " when the file is not saved"
39 | ),
40 | default=False,
41 | )
42 | another_directory: bpy.props.StringProperty(
43 | name="Saving directory",
44 | description="A path to directory where images saved to",
45 | subtype="DIR_PATH",
46 | )
47 | is_force_use_another_directory: bpy.props.BoolProperty(
48 | name="Force use another directory",
49 | description="Save images to above directory even when the file is saved or not",
50 | default=False,
51 | )
52 | is_use_subdirectory: bpy.props.BoolProperty(
53 | name="Use subdirectory",
54 | description="Save images to a subdirectory where the file is saved",
55 | default=True,
56 | )
57 | subdirectory_name: bpy.props.StringProperty(
58 | name="Sub directory name",
59 | description="A name for subdirectory",
60 | default=ADDON_NAME,
61 | get=get_subdirectory_name,
62 | set=set_subdirectory_name,
63 | )
64 | image_filename_pattern: bpy.props.StringProperty(
65 | name="Image filename",
66 | description=(
67 | "A name for pasted images\n"
68 | "Go to the Documentation to read more about the variables\n"
69 | "Warning: Images can be overwritten if they have the same name"
70 | ),
71 | default=(
72 | "${addonName}"
73 | "-${yearShort}${monthNumber}${day}"
74 | "-${hour24}${minute}${second}"
75 | ),
76 | subtype="FILE_NAME",
77 | )
78 | image_extension: bpy.props.StringProperty(
79 | name="Image extension",
80 | description="A file extension for pasted images",
81 | get=lambda _: ".png",
82 | )
83 | image_type_to_move: bpy.props.EnumProperty(
84 | name="Image type to move",
85 | description="Which type of image will be moved",
86 | items=[
87 | ("pasted_images", "Pasted images", "Only pasted images will be moved"),
88 | ("all_images", "All images", "All images will be moved"),
89 | ("no_moving", "No moving", "Don't move anything when saving"),
90 | ],
91 | default="pasted_images",
92 | )
93 | is_disable_debug: bpy.props.BoolProperty(
94 | name="Disable debug message",
95 | description="Debug message will not printed in console",
96 | default=False,
97 | )
98 |
99 | def draw(self, _context):
100 | from .tree import populate_filename
101 | from .tree import is_valid_filename
102 |
103 | split_ratio = 0.3
104 | layout = self.layout.column(align=True)
105 |
106 | # New box
107 | box = layout.box().column()
108 | box.label(
109 | text="Specify a different directory for images when the file is not saved"
110 | )
111 |
112 | # New property
113 | prop = box.row(align=True)
114 | split = prop.split(factor=split_ratio)
115 | # First column
116 | column_1 = split.column()
117 | column_1.alignment = "RIGHT"
118 | column_1.label(text="Use a directory")
119 | # Second column
120 | column_2 = split.column().row(align=True)
121 | column_2.prop(self, "is_use_another_directory", text="")
122 | column_2_sub = column_2.column()
123 | column_2_sub.active = self.is_use_another_directory
124 | column_2_sub.prop(self, "another_directory", text="")
125 |
126 | # New property
127 | prop = box.row(align=True)
128 | split = prop.split(factor=split_ratio)
129 | # First column
130 | split.column()
131 | # Second column
132 | column_2 = split.column().row(align=True)
133 | column_2.active = self.is_use_another_directory
134 | column_2.prop(self, "is_force_use_another_directory", text="Force use")
135 |
136 | # New box
137 | box = layout.box().column()
138 | box.label(text="Specify a subdirectory for images when the file is saved")
139 |
140 | # New property
141 | prop = box.row(align=True)
142 | prop.active = not (
143 | self.is_force_use_another_directory and self.is_use_another_directory
144 | )
145 | split = prop.split(factor=split_ratio)
146 | # First column
147 | column_1 = split.column()
148 | column_1.alignment = "RIGHT"
149 | column_1.label(text="Use subdirectory")
150 | # Second column
151 | column_2 = split.column().row(align=True)
152 | column_2.prop(self, "is_use_subdirectory", text="")
153 | column_2_sub = column_2.column()
154 | column_2_sub.active = self.is_use_subdirectory
155 | column_2_sub.prop(self, "subdirectory_name", text="")
156 |
157 | # New box
158 | box = layout.box().column()
159 | box.label(text="Customize image filename")
160 |
161 | # New property
162 | prop = box.row(align=True)
163 | split = prop.split(factor=split_ratio)
164 | # First column
165 | column_1 = split.column()
166 | column_1.alignment = "RIGHT"
167 | column_1.label(text="Image filename")
168 | # Second column
169 | column_2 = split.column().row(align=True)
170 | filename = populate_filename(self.image_filename_pattern) + self.image_extension
171 | column_2.alert = not is_valid_filename(filename)
172 | column_2.prop(self, "image_filename_pattern", text="")
173 | column_2_sub = column_2.column(align=True)
174 | column_2_sub.alignment = "RIGHT"
175 | column_2_sub.prop(self, "image_extension", text="")
176 |
177 | # New box
178 | box = layout.box().column()
179 | box.label(
180 | text=("Choose the type of images that will be moved when saving the file")
181 | )
182 |
183 | # New property
184 | prop = box.row(align=True)
185 | split = prop.split(factor=split_ratio)
186 | # First column
187 | column_1 = split.column()
188 | column_1.alignment = "RIGHT"
189 | column_1.label(text="Image type to move")
190 | # Second column
191 | column_2 = split.row()
192 | column_2.prop(self, "image_type_to_move", expand=True)
193 |
194 | # New box
195 | box = layout.box().column()
196 | box.label(text="Miscellaneous")
197 |
198 | # New property
199 | prop = box.row(align=True)
200 | split = prop.split(factor=split_ratio)
201 | # First column
202 | column_1 = split.column()
203 | column_1.alignment = "RIGHT"
204 | column_1.label(text="Disable debug message")
205 | # Second column
206 | column_2 = split.row()
207 | column_2.prop(self, "is_disable_debug", text="")
208 |
209 |
210 | def imageeditor_copy_imagemenu_draw(self, _context):
211 | """Draw the Copy operator in the Image Editor toolbar."""
212 | self.layout.operator(
213 | IMAGEPASTE_OT_imageeditor_copy.bl_idname,
214 | icon="COPYDOWN",
215 | )
216 |
217 |
218 | def imageeditor_paste_imagemenu_draw(self, _context):
219 | """Draw the Paste operator in the Image Editor toolbar."""
220 | self.layout.operator(
221 | IMAGEPASTE_OT_imageeditor_paste.bl_idname,
222 | icon="FILE_IMAGE",
223 | )
224 |
225 |
226 | def sequenceeditor_paste_contextmenu_draw(self, _context):
227 | """Draw the Paste operator in the Sequence Editor context menu."""
228 | self.layout.separator()
229 | self.layout.operator(
230 | IMAGEPASTE_OT_sequenceeditor_paste.bl_idname,
231 | icon="IMAGE_PLANE",
232 | )
233 |
234 |
235 | def shadereditor_paste_contextmenu_draw(self, _context):
236 | """Draw the Paste operator in the Shader Editor context menu."""
237 | self.layout.operator(
238 | IMAGEPASTE_OT_shadereditor_paste.bl_idname,
239 | icon="FILE_IMAGE",
240 | )
241 |
242 |
243 | def view3d_paste_plane_imageaddmenu_draw(self, _context):
244 | """Draw the Paste as Plane operator in the 3D View Add Image menu."""
245 | self.layout.operator(
246 | IMAGEPASTE_OT_view3d_paste_plane.bl_idname,
247 | icon="IMAGE_PLANE",
248 | )
249 |
250 |
251 | def view3d_paste_reference_imageaddmenu_draw(self, _context):
252 | """Draw the Paste as Reference operator in the 3D View Add Image menu."""
253 | self.layout.operator(
254 | IMAGEPASTE_OT_view3d_paste_reference.bl_idname,
255 | icon="FILE_IMAGE",
256 | )
257 |
258 |
259 | @bpy.app.handlers.persistent
260 | def move_to_save_directory_handler(_self, _context):
261 | """Handler to move the images to the save directory after the file is saved."""
262 | bpy.ops.imagepaste.move_to_save_directory("INVOKE_DEFAULT")
263 |
264 |
265 | addon_keymaps = []
266 |
267 |
268 | def register_keymaps():
269 | """Register the keymaps."""
270 | kc = bpy.context.window_manager.keyconfigs.addon
271 | if not kc:
272 | return
273 |
274 | km = kc.keymaps.new(name="Image Generic", space_type="IMAGE_EDITOR")
275 | kmi = km.keymap_items.new(
276 | IMAGEPASTE_OT_imageeditor_copy.bl_idname,
277 | type="C",
278 | value="PRESS",
279 | ctrl=True,
280 | shift=True,
281 | )
282 | addon_keymaps.append((km, kmi))
283 |
284 | km = kc.keymaps.new(name="Image Generic", space_type="IMAGE_EDITOR")
285 | kmi = km.keymap_items.new(
286 | IMAGEPASTE_OT_imageeditor_paste.bl_idname,
287 | type="V",
288 | value="PRESS",
289 | ctrl=True,
290 | shift=True,
291 | )
292 | addon_keymaps.append((km, kmi))
293 |
294 | km = kc.keymaps.new(name="Sequencer", space_type="SEQUENCE_EDITOR")
295 | kmi = km.keymap_items.new(
296 | IMAGEPASTE_OT_sequenceeditor_paste.bl_idname,
297 | type="V",
298 | value="PRESS",
299 | ctrl=True,
300 | shift=True,
301 | alt=True,
302 | )
303 | addon_keymaps.append((km, kmi))
304 |
305 | km = kc.keymaps.new(name="Node Editor", space_type="NODE_EDITOR")
306 | kmi = km.keymap_items.new(
307 | IMAGEPASTE_OT_shadereditor_paste.bl_idname,
308 | type="V",
309 | value="PRESS",
310 | ctrl=True,
311 | shift=True,
312 | )
313 | addon_keymaps.append((km, kmi))
314 |
315 | km = kc.keymaps.new(name="3D View", space_type="VIEW_3D")
316 | kmi = km.keymap_items.new(
317 | IMAGEPASTE_OT_view3d_paste_plane.bl_idname,
318 | type="V",
319 | value="PRESS",
320 | ctrl=True,
321 | shift=True,
322 | alt=True,
323 | )
324 | addon_keymaps.append((km, kmi))
325 |
326 | km = kc.keymaps.new(name="3D View", space_type="VIEW_3D")
327 | kmi = km.keymap_items.new(
328 | IMAGEPASTE_OT_view3d_paste_reference.bl_idname,
329 | type="V",
330 | value="PRESS",
331 | ctrl=True,
332 | shift=True,
333 | )
334 | addon_keymaps.append((km, kmi))
335 |
336 |
337 | def unregister_keymaps():
338 | """Unregister the keymaps."""
339 | for km, kmi in addon_keymaps:
340 | km.keymap_items.remove(kmi)
341 | addon_keymaps.clear()
342 |
343 |
344 | def register():
345 | bpy.utils.register_class(IMAGEPASTE_AddonPreferences)
346 | bpy.types.IMAGE_MT_image.append(imageeditor_copy_imagemenu_draw)
347 | bpy.types.IMAGE_MT_image.append(imageeditor_paste_imagemenu_draw)
348 | bpy.types.SEQUENCER_MT_context_menu.append(sequenceeditor_paste_contextmenu_draw)
349 | bpy.types.NODE_MT_context_menu.append(shadereditor_paste_contextmenu_draw)
350 | bpy.types.VIEW3D_MT_image_add.append(view3d_paste_plane_imageaddmenu_draw)
351 | bpy.types.VIEW3D_MT_image_add.append(view3d_paste_reference_imageaddmenu_draw)
352 | bpy.app.handlers.save_post.append(move_to_save_directory_handler)
353 | register_keymaps()
354 |
355 |
356 | def unregister():
357 | unregister_keymaps()
358 | remove_empty_subdirectory()
359 | bpy.app.handlers.save_post.remove(move_to_save_directory_handler)
360 | bpy.types.VIEW3D_MT_image_add.remove(view3d_paste_reference_imageaddmenu_draw)
361 | bpy.types.VIEW3D_MT_image_add.remove(view3d_paste_plane_imageaddmenu_draw)
362 | bpy.types.NODE_MT_context_menu.remove(shadereditor_paste_contextmenu_draw)
363 | bpy.types.SEQUENCER_MT_context_menu.remove(sequenceeditor_paste_contextmenu_draw)
364 | bpy.types.IMAGE_MT_image.remove(imageeditor_paste_imagemenu_draw)
365 | bpy.types.IMAGE_MT_image.remove(imageeditor_copy_imagemenu_draw)
366 | bpy.utils.unregister_class(IMAGEPASTE_AddonPreferences)
367 |
--------------------------------------------------------------------------------
/imagepaste/process.py:
--------------------------------------------------------------------------------
1 | from __future__ import annotations
2 |
3 |
4 | class Process:
5 | """A helper class for executing a command line process."""
6 |
7 | def __init__(self) -> None:
8 | """Initialize a Process instance."""
9 | self.parameters = {
10 | "encoding": "utf-8",
11 | "text": True,
12 | }
13 | self.stdout = None
14 | self.stderr = None
15 | self.returncode = None
16 |
17 | @classmethod
18 | def execute(
19 | cls,
20 | args: list[str],
21 | shell: bool = False,
22 | capture_output: bool = True,
23 | split: bool = True,
24 | outpath: str = None,
25 | ) -> Process:
26 | """Execute a command line process.
27 |
28 | Args:
29 | args (list[str]): The command line arguments to execute.
30 | shell (bool, optional): If True, execute the command line using the shell.
31 | Defaults to False.
32 | capture_output (bool, optional): If True, capture the output of the command
33 | line. Defaults to True.
34 | outpath (str, optional): The path to write the output to. If not provided,
35 | the output will be returned as a string. Defaults to None.
36 | split (bool, optional): If True, split the output `stderr` into a list of
37 | lines. If False, it will be returned as a single string. The `stderr`
38 | is passed without any modifications. Defaults to True.
39 |
40 | Returns:
41 | Process: A Process instance with the output of the command line.
42 | """
43 | from subprocess import (
44 | DEVNULL,
45 | PIPE,
46 | Popen,
47 | STDOUT,
48 | )
49 |
50 | def comunicate(parameters):
51 | popen = Popen(**parameters)
52 | stdout, stderr = popen.communicate()
53 | return popen, stdout, stderr
54 |
55 | process = cls()
56 | process.parameters.update(
57 | {
58 | "args": args,
59 | "shell": shell,
60 | "stdout": PIPE if capture_output else DEVNULL,
61 | "stderr": PIPE if capture_output else STDOUT,
62 | }
63 | )
64 | if outpath:
65 | with open(outpath, "w") as file:
66 | process.parameters.update({"stdout": file})
67 | popen, stdout, stderr = comunicate(process.parameters)
68 | else:
69 | popen, stdout, stderr = comunicate(process.parameters)
70 |
71 | # Postprocess output
72 | if capture_output:
73 | if not outpath:
74 | process.stdout = stdout.strip().split("\n") if split else stdout.strip()
75 | process.stderr = stderr.strip()
76 | process.returncode = popen.returncode
77 | return process
78 |
--------------------------------------------------------------------------------
/imagepaste/report.py:
--------------------------------------------------------------------------------
1 | import bpy
2 |
3 |
4 | class Report:
5 | """A class to hold information about a report."""
6 |
7 | REPORT_TABLE = {
8 | 1: ["ERROR", "Process failed"],
9 | 2: ["ERROR", "No image found on clipboard"],
10 | 3: ["ERROR", "Unable to save image"],
11 | 4: ["ERROR", "Unable to copy image"],
12 | 5: ["INFO", "Copied image"],
13 | 6: ["INFO", "Pasted image"],
14 | 7: ["INFO", "Moved images"],
15 | }
16 |
17 | def __init__(self, code: int, verbose: str = None) -> None:
18 | """Initialize the Report object.
19 |
20 | Args:
21 | code (int): The code of the report.
22 | verbose (str, optional): The verbose message for the debugging. Defaults to
23 | None.
24 | """
25 | self.code = code
26 | self.type = Report.REPORT_TABLE[self.code][0]
27 | self.message = Report.REPORT_TABLE[self.code][1]
28 | self.verbose = verbose or self.message
29 |
30 | def log(self, operator: bpy.types.Operator) -> None:
31 | """Log the report to the Blender UI and console.
32 |
33 | Args:
34 | operator (bpy.types.Operator): The operator calling the report. If the
35 | method is called from a Blender operator method, it is usually `self`.
36 | """
37 | operator.report({self.type}, self.message)
38 | Report.console_log(self.verbose)
39 |
40 | @staticmethod
41 | def console_log(message: str) -> None:
42 | """Log the message to the console.
43 |
44 | Args:
45 | message (str): The message to be printed to the console.
46 | """
47 | from .metadata import get_addon_preferences
48 |
49 | preferences = get_addon_preferences()
50 | if not preferences.is_disable_debug:
51 | print(f"ImagePaste: {message}")
52 |
53 | def __repr__(self) -> str:
54 | """Return the string representation of the report.
55 |
56 | Returns:
57 | str: The string representation of the report.
58 | """
59 | return f"({self.code}:{self.type})<{self.message}>"
60 |
--------------------------------------------------------------------------------
/imagepaste/tree.py:
--------------------------------------------------------------------------------
1 | import bpy
2 |
3 |
4 | def get_save_directory() -> str:
5 | """Get the path to the directory where the images are saved.
6 |
7 | Returns:
8 | str: The path to the directory where the images are saved.
9 | """
10 | from os import makedirs
11 | from os.path import exists
12 | from os.path import dirname
13 | from os.path import join
14 | from .metadata import get_addon_preferences
15 |
16 | preferences = get_addon_preferences()
17 |
18 | if not bpy.data.filepath:
19 | if preferences.is_use_another_directory and preferences.another_directory:
20 | return preferences.another_directory
21 | return bpy.app.tempdir
22 |
23 | if (
24 | preferences.is_use_another_directory
25 | and preferences.is_force_use_another_directory
26 | and preferences.another_directory
27 | ):
28 | return preferences.another_directory
29 |
30 | directory_path = dirname(bpy.data.filepath)
31 | if not preferences.is_use_subdirectory or not preferences.subdirectory_name:
32 | return directory_path
33 | subdirectory_path = join(directory_path, preferences.subdirectory_name)
34 | if not exists(subdirectory_path):
35 | makedirs(subdirectory_path)
36 | return subdirectory_path
37 |
38 |
39 | def is_valid_filename(filename: str) -> bool:
40 | """Check if the filename is valid.
41 |
42 | Args:
43 | filename (str): a string representing the filename.
44 |
45 | Returns:
46 | bool: True if the filename is valid, False otherwise.
47 | """
48 |
49 | def is_general_valid_filename(filename: str) -> bool:
50 | """Check if the filename is valid.
51 |
52 | Args:
53 | filename (str): a string representing the filename.
54 |
55 | Returns:
56 | bool: True if the filename is valid, False otherwise.
57 | """
58 | if not filename:
59 | return False
60 | if len(filename) > 255:
61 | return False
62 | if filename in (".", ".."):
63 | return False
64 | return True
65 |
66 | def is_windows_valid_filename(filename: str) -> bool:
67 | """Check if the filename is valid on Windows.
68 |
69 | Args:
70 | filename (str): a string representing a filename.
71 |
72 | Returns:
73 | bool: True if the filename is valid on Windows, False otherwise.
74 | """
75 | # Check if the filename does not end with a dot or a space
76 | if filename[-1] in (".", " "):
77 | return False
78 | # Check if the filename is a reserved name
79 | windows_reserved_filenames = (
80 | "CON",
81 | "PRN",
82 | "AUX",
83 | "NUL",
84 | "COM1",
85 | "COM2",
86 | "COM3",
87 | "COM4",
88 | "COM5",
89 | "COM6",
90 | "COM7",
91 | "COM8",
92 | "COM9",
93 | "LPT1",
94 | "LPT2",
95 | "LPT3",
96 | "LPT4",
97 | "LPT5",
98 | "LPT6",
99 | "LPT7",
100 | "LPT8",
101 | "LPT9",
102 | )
103 | if filename.upper() in windows_reserved_filenames:
104 | return False
105 | # Check if the filename contains any invalid characters
106 | windows_invalid_characters = ("/", "\\", ":", "*", "?", '"', "<", ">", "|")
107 | for character in windows_invalid_characters:
108 | if character in filename:
109 | return False
110 | # Check if the filename contains any unprintable characters
111 | for index in range(31):
112 | if chr(index) in filename:
113 | return False
114 | return True
115 |
116 | def is_linux_valid_filename(filename: str) -> bool:
117 | """Check if the filename is valid on Linux.
118 |
119 | Args:
120 | filename (str): a string representing a filename.
121 |
122 | Returns:
123 | bool: True if the filename is valid on Linux, False otherwise.
124 | """
125 | # The "\" character is valid in Linux but Blender does not support it
126 | invalid_characters = ["/", "\\"]
127 | for invalid_character in invalid_characters:
128 | if invalid_character in filename:
129 | return False
130 | return True
131 |
132 | def is_darwin_valid_filename(filename: str) -> bool:
133 | """Check if the filename is valid on macOS.
134 |
135 | Args:
136 | filename (str): a string representing a filename.
137 |
138 | Returns:
139 | bool: True if the filename is valid on macOS, False otherwise.
140 | """
141 | return is_linux_valid_filename(filename)
142 |
143 | import sys
144 |
145 | if not is_general_valid_filename(filename):
146 | return False
147 | if sys.platform == "win32":
148 | return is_windows_valid_filename(filename)
149 | elif sys.platform == "linux":
150 | return is_linux_valid_filename(filename)
151 | elif sys.platform == "darwin":
152 | return is_darwin_valid_filename(filename)
153 | return False
154 |
155 |
156 | def populate_filename(filename_pattern: str) -> str:
157 | """Populate a filename with a pattern.
158 |
159 | Args:
160 | pattern (str): a string representing a pattern.
161 |
162 | Returns:
163 | str: a string representing a filename.
164 | """
165 | from re import sub
166 | from time import strftime
167 | from .image import Image
168 | from .metadata import ADDON_NAME
169 |
170 | image_index = str(Image.image_index + 1)
171 | # Replace normal variables
172 | VARIABLES_TABLE = [
173 | ("${addonName}", ADDON_NAME),
174 | ("${yearLong}", strftime("%Y")),
175 | ("${yearShort}", strftime("%y")),
176 | ("${monthNumber}", strftime("%m")),
177 | ("${monthNameLong}", strftime("%B")),
178 | ("${monthNameShort}", strftime("%b")),
179 | ("${day}", strftime("%d")),
180 | ("${weekdayNumber}", strftime("%w")),
181 | ("${weekdayNameLong}", strftime("%A")),
182 | ("${weekdayNameShort}", strftime("%a")),
183 | ("${hour24}", strftime("%H")),
184 | ("${hour12}", strftime("%I")),
185 | ("${minute}", strftime("%M")),
186 | ("${second}", strftime("%S")),
187 | ("${index}", image_index),
188 | ]
189 | for pattern_key, pattern_value in VARIABLES_TABLE:
190 | filename_pattern = filename_pattern.replace(pattern_key, pattern_value)
191 | # Replace dynamic variables ${index:N}
192 | # Produce an N-digits-with-zeros-padded number
193 | filename_pattern = sub(
194 | r"\${index\:(\d+)}",
195 | lambda match: image_index.zfill(int(match.group(1))),
196 | filename_pattern,
197 | )
198 | return filename_pattern
199 |
200 |
201 | def remove_empty_subdirectory(subdirectory_name: str = None) -> None:
202 | """Remove empty subdirectories.
203 |
204 | Args:
205 | subdirectory_name (str, optional): a string representing a subdirectory name.
206 | Defaults to None.
207 | """
208 | from os import listdir
209 | from os import rmdir
210 | from os.path import (
211 | dirname,
212 | join,
213 | isdir,
214 | )
215 | from .report import Report
216 | from .metadata import get_addon_preferences
217 |
218 | if not subdirectory_name:
219 | preferences = get_addon_preferences()
220 | if not preferences.subdirectory_name:
221 | return
222 | subdirectory_name = preferences.subdirectory_name
223 | directory_path = dirname(bpy.data.filepath)
224 | subdirectory_path = join(directory_path, subdirectory_name)
225 | if not isdir(subdirectory_path):
226 | return
227 | if listdir(subdirectory_path):
228 | return
229 | rmdir(subdirectory_path)
230 | Report.console_log(f"Empty subdirectory '{subdirectory_path}' was removed")
231 |
--------------------------------------------------------------------------------
/script/bootstrap.cmd:
--------------------------------------------------------------------------------
1 | @REM script/bootstrap: Resolve all dependencies the application requires to run.
2 |
3 | @ECHO OFF
4 |
5 | CD %~dp0..
6 |
7 | WHERE pipenv >nul 2>nul
8 | IF %ERRORLEVEL% NEQ 0 (
9 | ECHO Command 'pipenv' not found. Aborting.
10 | EXIT 1
11 | )
12 |
13 | SET PIPENV_VENV_IN_PROJECT=1
14 | pipenv install --dev --skip-lock
15 |
--------------------------------------------------------------------------------
/script/bootstrap.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # script/bootstrap: Resolve all dependencies the application requires to run.
4 |
5 | set -e
6 |
7 | cd "$(dirname "$BASH_SOURCE")/.."
8 |
9 | hash pipenv 2>/dev/null || {
10 | echo >&2 "Command 'pipenv' not found. Aborting."
11 | exit 1
12 | }
13 |
14 | PIPENV_VENV_IN_PROJECT=1 pipenv install --dev --skip-lock
15 |
--------------------------------------------------------------------------------
/script/build.cmd:
--------------------------------------------------------------------------------
1 | @REM script/build: Packaging the required components for release.
2 | @REM Designed to run on the continuous integration server.
3 | @REM
4 | @REM INPUT
5 | @REM %1: The version number of the release.
6 | @REM
7 | @REM OUTPUT
8 | @REM Name of the release ZIP file.
9 |
10 |
11 | @REM Disable the command prompt
12 | @ECHO OFF
13 |
14 | @REM Set some variables
15 | SET version=%1
16 | SET components=__init__.py imagepaste LICENSE
17 | SET addon_name=ImagePaste
18 | SET temp=temp
19 | IF "%version%"=="" (
20 | SET zip_file=%addon_name%.zip
21 | ) ELSE (
22 | SET zip_file=%addon_name%-%version%.zip
23 | )
24 |
25 | @REM Move to the root and make directories
26 | CD %~dp0..
27 | IF EXIST %temp% RMDIR /S /Q %temp%
28 | MKDIR %temp%\%addon_name%
29 |
30 | @REM Copy the files and folders
31 | FOR %%G IN (%components%) DO (
32 | IF EXIST %%G\NUL (
33 | ROBOCOPY %%G %temp%\%addon_name%\%%G /E >NUL
34 | ) ELSE (
35 | ROBOCOPY . %temp%\%addon_name% %%G >NUL
36 | )
37 | )
38 |
39 | @REM Create the ZIP file
40 | tar -C %temp% -acf %zip_file% %addon_name%
41 |
42 | @REM Remove the temporary directory and return the ZIP file name
43 | RMDIR /S /Q %temp%
44 | IF EXIST %zip_file% ECHO %zip_file%
45 |
--------------------------------------------------------------------------------
/script/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # script/build: Packaging the required components for release.
4 | # Designed to run on the continuous integration server.
5 | #
6 | # INPUT
7 | # $1: The suffix for the ZIP file name.
8 | #
9 | # OUTPUT
10 | # Name of the release ZIP file.
11 |
12 | # Exit immediately if an error occurs
13 | set -e
14 |
15 | # Go to the project directory
16 | cd "$(dirname "$BASH_SOURCE")/.."
17 |
18 | # Set some variables for ZIP file name
19 | components=("__init__.py" "imagepaste" "LICENSE")
20 |
21 | suffix="$1"
22 | addon_name="ImagePaste"
23 | if [[ -z "$suffix" ]]; then
24 | zip_name=$addon_name
25 | else
26 | zip_name="$addon_name-$suffix.zip"
27 | fi
28 |
29 | # Create a temporary directories
30 | temporary_directory="$(mktemp -d)"
31 | addon_directory="$temporary_directory/$addon_name"
32 | mkdir "$addon_directory"
33 |
34 | # Copy the required components to the created directory
35 | for component in "${components[@]}"; do
36 | cp -r "$component" "$addon_directory"
37 | done
38 |
39 | # Generate ZIP file
40 | root_directory="$(pwd)"
41 | cd "$temporary_directory"
42 | zip -rmqq "$root_directory/$zip_name" "$addon_name"
43 | rm -rf "$temporary_directory"
44 |
45 | # Return the name of the ZIP file
46 | echo "$zip_name"
47 |
--------------------------------------------------------------------------------
/script/setup.cmd:
--------------------------------------------------------------------------------
1 | @REM script/setup: Set up application for the first time after cloning, or set
2 | @REM it back to the initial first unused state.
3 |
4 | @ECHO OFF
5 |
6 | CD %~dp0..
7 |
8 | .\script\bootstrap.cmd
9 |
--------------------------------------------------------------------------------
/script/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # script/setup: Set up application for the first time after cloning, or set it
4 | # back to the initial first unused state.
5 |
6 | set -e
7 |
8 | cd "$(dirname "$BASH_SOURCE")/.."
9 |
10 | ./script/bootstrap.sh
11 |
--------------------------------------------------------------------------------