fastshot 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fastshot-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.1
2
+ Name: fastshot
3
+ Version: 0.1.0
4
+ Summary: A versatile screen capturing tool with annotation and OCR features
5
+ Home-page: https://github.com/yourusername/fastshot
6
+ Author: Your Name
7
+ Author-email: your-email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: pyautogui
15
+ Requires-Dist: pynput
16
+ Requires-Dist: pillow
17
+ Requires-Dist: screeninfo
18
+ Requires-Dist: mss
19
+ Requires-Dist: Pillow
20
+ Requires-Dist: pyperclip
21
+ Requires-Dist: pywin32
22
+ Requires-Dist: paddleocr
23
+ Requires-Dist: paddlepaddle
24
+
25
+ # Fastshot
26
+
27
+ Fastshot is a versatile screen capturing tool that allows users to take screenshots, annotate them with paint and text tools, and perform OCR (Optical Character Recognition) to extract text from images. The application provides an intuitive interface and can be extended with plugins.
28
+
29
+ ## Features
30
+
31
+ - **Screen Capturing**: Capture any part of your screen using a customizable hotkey.
32
+ - **Annotation Tools**: Use paint and text tools to annotate your screenshots.
33
+ - **OCR Integration**: Extract text from images using the built-in OCR plugin powered by PaddleOCR.
34
+ - **Plugin System**: Easily extend the functionality with plugins.
35
+
36
+ ## Installation
37
+
38
+ You can install Fastshot from PyPI:
39
+
40
+ ```sh
41
+ pip install fastshot
42
+ ```
43
+
44
+
45
+ ## Usage
46
+ Once installed, you can start Fastshot from the command line:
47
+
48
+ ```sh
49
+ fastshot
50
+ ```
51
+
52
+ ## Hotkeys
53
+ F1: Activate screen capturing mode.
54
+
55
+ Ctrl+P: Activate paint mode.
56
+
57
+ Ctrl+T: Activate text mode.
58
+
59
+ Esc: Exit the current mode.
60
+
61
+ ## Right-Click Menu
62
+
63
+ Close: Close the current window.
64
+
65
+ Save As...: Save the current screenshot.
66
+
67
+ Paint: Activate paint mode.
68
+
69
+ Undo: Undo the last action.
70
+
71
+ Exit Edit: Exit paint or text mode.
72
+
73
+ Copy: Copy the current screenshot to the clipboard.
74
+
75
+ Text: Activate text mode.
76
+
77
+ OCR: Perform OCR on the current screenshot and copy the result to the clipboard.
78
+
79
+
80
+ ## Development
81
+ Setting Up the Development Environment
82
+ 1. Clone the repository:
83
+
84
+ ```sh
85
+ git clone https://github.com/yourusername/fastshot.git
86
+ cd fastshot
87
+ ```
88
+
89
+ 2. Install the dependencies:
90
+ ```sh
91
+ pip install -r requirements.txt
92
+ ```
93
+
94
+ ## Running Tests
95
+ You can run the tests using:
96
+
97
+ ```sh
98
+ pytest tests/
99
+ ```
100
+
101
+ ## Contributing
102
+ We welcome contributions! Please read our Contributing Guidelines for more details.
103
+
104
+ ## License
105
+ This project is licensed under the Apache License - see the LICENSE file for details.
106
+
107
+
108
+
109
+
110
+
@@ -0,0 +1,86 @@
1
+ # Fastshot
2
+
3
+ Fastshot is a versatile screen capturing tool that allows users to take screenshots, annotate them with paint and text tools, and perform OCR (Optical Character Recognition) to extract text from images. The application provides an intuitive interface and can be extended with plugins.
4
+
5
+ ## Features
6
+
7
+ - **Screen Capturing**: Capture any part of your screen using a customizable hotkey.
8
+ - **Annotation Tools**: Use paint and text tools to annotate your screenshots.
9
+ - **OCR Integration**: Extract text from images using the built-in OCR plugin powered by PaddleOCR.
10
+ - **Plugin System**: Easily extend the functionality with plugins.
11
+
12
+ ## Installation
13
+
14
+ You can install Fastshot from PyPI:
15
+
16
+ ```sh
17
+ pip install fastshot
18
+ ```
19
+
20
+
21
+ ## Usage
22
+ Once installed, you can start Fastshot from the command line:
23
+
24
+ ```sh
25
+ fastshot
26
+ ```
27
+
28
+ ## Hotkeys
29
+ F1: Activate screen capturing mode.
30
+
31
+ Ctrl+P: Activate paint mode.
32
+
33
+ Ctrl+T: Activate text mode.
34
+
35
+ Esc: Exit the current mode.
36
+
37
+ ## Right-Click Menu
38
+
39
+ Close: Close the current window.
40
+
41
+ Save As...: Save the current screenshot.
42
+
43
+ Paint: Activate paint mode.
44
+
45
+ Undo: Undo the last action.
46
+
47
+ Exit Edit: Exit paint or text mode.
48
+
49
+ Copy: Copy the current screenshot to the clipboard.
50
+
51
+ Text: Activate text mode.
52
+
53
+ OCR: Perform OCR on the current screenshot and copy the result to the clipboard.
54
+
55
+
56
+ ## Development
57
+ Setting Up the Development Environment
58
+ 1. Clone the repository:
59
+
60
+ ```sh
61
+ git clone https://github.com/yourusername/fastshot.git
62
+ cd fastshot
63
+ ```
64
+
65
+ 2. Install the dependencies:
66
+ ```sh
67
+ pip install -r requirements.txt
68
+ ```
69
+
70
+ ## Running Tests
71
+ You can run the tests using:
72
+
73
+ ```sh
74
+ pytest tests/
75
+ ```
76
+
77
+ ## Contributing
78
+ We welcome contributions! Please read our Contributing Guidelines for more details.
79
+
80
+ ## License
81
+ This project is licensed under the Apache License - see the LICENSE file for details.
82
+
83
+
84
+
85
+
86
+
File without changes
@@ -0,0 +1,196 @@
1
+ import tkinter as tk
2
+ from tkinter import filedialog
3
+ from PIL import Image, ImageTk, ImageDraw, ImageFont
4
+ import io
5
+ import win32clipboard
6
+ from pynput import keyboard
7
+ from .paint_tool import PaintTool
8
+ from .text_tool import TextTool
9
+
10
+ class ImageWindow:
11
+ def __init__(self, app, img):
12
+ self.app = app
13
+ self.root = app.root
14
+ self.img_window = tk.Toplevel(self.root)
15
+ self.img_window.overrideredirect(True)
16
+ self.img_window.attributes('-topmost', True)
17
+ self.img_window.bind('<ButtonPress-1>', self.start_move)
18
+ self.img_window.bind('<B1-Motion>', self.do_move)
19
+ self.img_window.bind('<Button-3>', self.show_context_menu)
20
+ self.img_window.bind('<MouseWheel>', self.zoom)
21
+ self.img_window.bind('<Enter>', self.activate_window)
22
+
23
+ self.img_label = tk.Label(self.img_window, borderwidth=1, relief="solid")
24
+ self.img_label.pack()
25
+ self.update_image(img)
26
+
27
+ self.paint_tool = PaintTool(self)
28
+ self.text_tool = TextTool(self)
29
+ self.draw_history = []
30
+
31
+ self.setup_hotkey_listener()
32
+
33
+ def setup_hotkey_listener(self):
34
+ def on_activate_paint():
35
+ self.app.exit_all_modes()
36
+ if self.img_window.winfo_exists():
37
+ self.paint_tool.enable_paint_mode()
38
+
39
+ def on_activate_text():
40
+ self.app.exit_all_modes()
41
+ if self.img_window.winfo_exists():
42
+ self.text_tool.enable_text_mode()
43
+
44
+ def for_canonical(f):
45
+ return lambda k: f(self.listener.canonical(k))
46
+
47
+ hotkey_paint = keyboard.HotKey(keyboard.HotKey.parse('<ctrl>+p'), on_activate_paint)
48
+ hotkey_text = keyboard.HotKey(keyboard.HotKey.parse('<ctrl>+t'), on_activate_text)
49
+
50
+ self.listener = keyboard.Listener(
51
+ on_press=for_canonical(hotkey_paint.press),
52
+ on_release=for_canonical(hotkey_paint.release))
53
+
54
+ self.listener.start()
55
+
56
+ self.listener_text = keyboard.Listener(
57
+ on_press=for_canonical(hotkey_text.press),
58
+ on_release=for_canonical(hotkey_text.release))
59
+
60
+ self.listener_text.start()
61
+
62
+ def set_paint_tool(self, paint_tool):
63
+ if self.paint_tool and self.paint_tool != paint_tool:
64
+ self.paint_tool.disable_paint_mode()
65
+ self.paint_tool = paint_tool
66
+
67
+ def set_text_tool(self, text_tool):
68
+ if self.text_tool and self.text_tool != text_tool:
69
+ self.text_tool.disable_text_mode()
70
+ self.text_tool = text_tool
71
+
72
+ def update_image(self, img):
73
+ self.img_label.original_image = img
74
+ self.img_label.zoomed_image = img.copy()
75
+ self.img_label.scale = 1.0
76
+ self.img_label.image = ImageTk.PhotoImage(img)
77
+ self.img_label.config(image=self.img_label.image)
78
+
79
+ def start_move(self, event):
80
+ if not self.paint_tool.painting and not self.text_tool.text_mode:
81
+ self.img_window._drag_data = {"x": event.x, "y": event.y}
82
+
83
+ def do_move(self, event):
84
+ if not self.paint_tool.painting and not self.text_tool.text_mode:
85
+ x = self.img_window.winfo_x() + event.x - self.img_window._drag_data["x"]
86
+ y = self.img_window.winfo_y() + event.y - self.img_window._drag_data["y"]
87
+ self.img_window.geometry(f"+{x}+{y}")
88
+
89
+ def show_context_menu(self, event):
90
+ menu = tk.Menu(self.img_window, tearoff=0)
91
+
92
+ # 使用 Unicode 字符作为图标
93
+ icons = {
94
+ "Close": "❌",
95
+ "Save As...": "💾",
96
+ "Paint": "🖌️",
97
+ "Undo": "↩️",
98
+ "Exit Edit": "🚪",
99
+ "Copy": "📋",
100
+ "Text": "🔤",
101
+ "OCR": "🔍"
102
+ }
103
+
104
+ commands = {
105
+ "Close": self.close,
106
+ "Save As...": self.save_as,
107
+ "Paint": self.paint,
108
+ "Undo": self.undo,
109
+ "Exit Edit": self.exit_edit_mode,
110
+ "Copy": self.copy,
111
+ "Text": self.text,
112
+ "OCR": self.ocr
113
+ }
114
+
115
+ for label, icon in icons.items():
116
+ menu.add_command(label=f"{icon} {label}", command=commands[label])
117
+
118
+ menu.post(event.x_root, event.y_root)
119
+
120
+ def close(self):
121
+ self.img_window.destroy()
122
+ self.app.windows.remove(self)
123
+
124
+ def save_as(self):
125
+ file_path = filedialog.asksaveasfilename(
126
+ defaultextension=".png",
127
+ filetypes=[("PNG files", "*.png"), ("All files", "*.*")])
128
+ if file_path:
129
+ self.img_label.zoomed_image.save(file_path)
130
+
131
+ def paint(self):
132
+ self.paint_tool.enable_paint_mode()
133
+
134
+ def undo(self):
135
+ self.paint_tool.undo_last_draw()
136
+
137
+ def exit_edit_mode(self):
138
+ if self.img_window.winfo_exists():
139
+ self.paint_tool.disable_paint_mode()
140
+ self.text_tool.disable_text_mode()
141
+
142
+ def copy(self):
143
+ output = io.BytesIO()
144
+ self.img_label.zoomed_image.save(output, format='BMP')
145
+ data = output.getvalue()[14:]
146
+ output.close()
147
+
148
+ win32clipboard.OpenClipboard()
149
+ win32clipboard.EmptyClipboard()
150
+ win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
151
+ win32clipboard.CloseClipboard()
152
+
153
+ def text(self):
154
+ self.text_tool.enable_text_mode()
155
+
156
+ def ocr(self):
157
+ plugin = self.app.plugins.get('fastshot.plugin_ocr')
158
+ if plugin:
159
+ img_path = 'temp.png'
160
+ self.img_label.zoomed_image.save(img_path)
161
+ result = plugin.ocr(img_path)
162
+ plugin.show_message("OCR result updated in clipboard", self.img_window)
163
+
164
+ def zoom(self, event):
165
+ scale_factor = 1.1 if event.delta > 0 else 0.9
166
+ self.img_label.scale *= scale_factor
167
+ new_width = int(self.img_label.original_image.width * self.img_label.scale)
168
+ new_height = int(self.img_label.original_image.height * self.img_label.scale)
169
+ self.img_label.zoomed_image = self.img_label.original_image.resize((new_width, new_height), Image.LANCZOS)
170
+ self.redraw_image()
171
+
172
+ def redraw_image(self):
173
+ self.img_label.zoomed_image = self.img_label.original_image.resize(
174
+ (int(self.img_label.original_image.width * self.img_label.scale),
175
+ int(self.img_label.original_image.height * self.img_label.scale)),
176
+ Image.LANCZOS
177
+ )
178
+ draw = ImageDraw.Draw(self.img_label.zoomed_image)
179
+ for item in self.draw_history:
180
+ if isinstance(item, list): # 画线的历史记录
181
+ for (x1, y1, x2, y2) in item:
182
+ scaled_x1 = int(x1 * self.img_label.scale)
183
+ scaled_y1 = int(y1 * self.img_label.scale)
184
+ scaled_x2 = int(x2 * self.img_label.scale)
185
+ scaled_y2 = int(y2 * self.img_label.scale)
186
+ draw.line((scaled_x1, scaled_y1, scaled_x2, scaled_y2), fill="red", width=3)
187
+ elif isinstance(item, tuple) and item[0] == 'text': # 文字的历史记录
188
+ _, scaled_x, scaled_y, text = item
189
+ font = ImageFont.truetype("arial", size=int(28 * self.img_label.scale))
190
+ draw.text((int(scaled_x * self.img_label.scale), int(scaled_y * self.img_label.scale)),
191
+ text, fill="red", font=font)
192
+ self.img_label.image = ImageTk.PhotoImage(self.img_label.zoomed_image)
193
+ self.img_label.config(image=self.img_label.image)
194
+
195
+ def activate_window(self, event):
196
+ self.app.exit_all_modes()
@@ -0,0 +1,71 @@
1
+ import tkinter as tk
2
+ from pynput import keyboard
3
+ from screeninfo import get_monitors
4
+ import ctypes
5
+ import importlib
6
+
7
+ from fastshot.snipping_tool import SnippingTool
8
+ from fastshot.image_window import ImageWindow
9
+
10
+ class SnipasteApp:
11
+ def __init__(self):
12
+ self.root = tk.Tk()
13
+ self.root.withdraw()
14
+ self.monitors = get_monitors()
15
+ self.snipping_tool = SnippingTool(self.root, self.monitors, self.on_screenshot)
16
+ self.windows = []
17
+ self.plugins = {}
18
+ self.load_plugins()
19
+ self.setup_hotkey_listener()
20
+
21
+ def load_plugins(self):
22
+ plugin_modules = ['fastshot.plugin_ocr'] # 可以在此添加更多插件模块
23
+ for module_name in plugin_modules:
24
+ module = importlib.import_module(module_name)
25
+ plugin_class = getattr(module, 'PluginOCR')
26
+ self.plugins[module_name] = plugin_class()
27
+
28
+ def setup_hotkey_listener(self):
29
+ def on_activate_snip():
30
+ print("Hotkey activated")
31
+ self.snipping_tool.start_snipping()
32
+
33
+ def on_escape():
34
+ self.exit_all_modes()
35
+
36
+ def for_canonical(f):
37
+ return lambda k: f(self.listener.canonical(k))
38
+
39
+ hotkey_snip = keyboard.HotKey(keyboard.HotKey.parse('<f1>'), on_activate_snip)
40
+
41
+ ctypes.windll.user32.RegisterHotKey(None, 1, 0, 0x70) # 0x70 is the virtual key code for F1
42
+
43
+ self.listener = keyboard.Listener(
44
+ on_press=for_canonical(hotkey_snip.press),
45
+ on_release=for_canonical(hotkey_snip.release))
46
+
47
+ self.listener.start()
48
+
49
+ self.listener_escape = keyboard.Listener(
50
+ on_press=for_canonical(lambda key: on_escape() if key == keyboard.Key.esc else None))
51
+
52
+ self.listener_escape.start()
53
+
54
+ def on_screenshot(self, img):
55
+ window = ImageWindow(self, img)
56
+ self.windows.append(window)
57
+
58
+ def exit_all_modes(self):
59
+ for window in self.windows:
60
+ if window.img_window.winfo_exists(): # 检查窗口是否存在
61
+ window.exit_edit_mode()
62
+
63
+ def run(self):
64
+ self.root.mainloop()
65
+
66
+ def main():
67
+ app = SnipasteApp()
68
+ app.run()
69
+
70
+ if __name__ == "__main__":
71
+ main()
@@ -0,0 +1,58 @@
1
+
2
+ import tkinter as tk
3
+ from PIL import ImageDraw
4
+
5
+ class PaintTool:
6
+ def __init__(self, image_window):
7
+ self.image_window = image_window
8
+ self.painting = False
9
+ self.last_x = self.last_y = None
10
+
11
+ def enable_paint_mode(self):
12
+ if self.image_window.text_tool:
13
+ self.image_window.text_tool.disable_text_mode()
14
+ self.painting = True
15
+ img_label = self.image_window.img_label
16
+ if img_label:
17
+ img_label.bind('<B1-Motion>', self.paint)
18
+ img_label.bind('<ButtonPress-1>', self.on_mouse_down)
19
+ if self.image_window.root:
20
+ self.image_window.root.bind_all('<Escape>', self.disable_paint_mode)
21
+ self.image_window.root.bind_all('<Control-z>', self.undo_last_draw)
22
+ img_label.config(cursor="pencil")
23
+ self.image_window.set_paint_tool(self) # 设置当前 PaintTool 实例为活动的绘图工具
24
+
25
+ def disable_paint_mode(self, event=None):
26
+ self.painting = False
27
+ img_label = self.image_window.img_label
28
+ if img_label:
29
+ img_label.unbind('<B1-Motion>')
30
+ img_label.unbind('<ButtonPress-1>')
31
+ if self.image_window.root:
32
+ self.image_window.root.unbind_all('<Escape>')
33
+ self.image_window.root.unbind_all('<Control-z>')
34
+ img_label.config(cursor="arrow")
35
+
36
+ def on_mouse_down(self, event):
37
+ self.last_x, self.last_y = event.x, event.y
38
+ # 检查最后一项是否为列表,如果不是则添加一个新列表
39
+ if not self.image_window.draw_history or not isinstance(self.image_window.draw_history[-1], list):
40
+ self.image_window.draw_history.append([])
41
+
42
+ def paint(self, event):
43
+ if self.painting:
44
+ img_label = self.image_window.img_label
45
+ x, y = event.x, event.y
46
+ scaled_last_x = self.last_x / img_label.scale
47
+ scaled_last_y = self.last_y / img_label.scale
48
+ scaled_x = x / img_label.scale
49
+ scaled_y = y / img_label.scale
50
+ self.image_window.draw_history[-1].append((scaled_last_x, scaled_last_y, scaled_x, scaled_y))
51
+ self.last_x, self.last_y = x, y
52
+ self.image_window.redraw_image()
53
+
54
+ def undo_last_draw(self, event=None):
55
+ if self.image_window.draw_history:
56
+ self.image_window.draw_history.pop()
57
+ self.image_window.redraw_image()
58
+
@@ -0,0 +1,25 @@
1
+ from paddleocr import PaddleOCR
2
+ from PIL import Image
3
+ import win32clipboard
4
+ import tkinter as tk
5
+
6
+ class PluginOCR:
7
+ def __init__(self):
8
+ self.ocr_engine = PaddleOCR(use_angle_cls=True, lang='ch')
9
+
10
+ def ocr(self, image):
11
+ result = self.ocr_engine.ocr(image, cls=True)
12
+ ocr_text = "\n".join([line[1][0] for res in result for line in res])
13
+ self.copy_to_clipboard(ocr_text)
14
+ return ocr_text
15
+
16
+ def copy_to_clipboard(self, text):
17
+ win32clipboard.OpenClipboard()
18
+ win32clipboard.EmptyClipboard()
19
+ win32clipboard.SetClipboardText(text, win32clipboard.CF_UNICODETEXT)
20
+ win32clipboard.CloseClipboard()
21
+
22
+ def show_message(self, message, parent):
23
+ label = tk.Label(parent, text=message, bg="yellow", fg="black", font=("Helvetica", 10))
24
+ label.pack(side="bottom", fill="x")
25
+ parent.after(3000, label.destroy)
@@ -0,0 +1,97 @@
1
+ import tkinter as tk
2
+ from PIL import Image
3
+ import mss
4
+ import mss.tools
5
+ import io
6
+
7
+ class SnippingTool:
8
+ def __init__(self, root, monitors, on_screenshot):
9
+ self.root = root
10
+ self.monitors = monitors
11
+ self.on_screenshot = on_screenshot
12
+ self.overlays = []
13
+ self.canvases = []
14
+ self.rects = []
15
+
16
+ def start_snipping(self):
17
+ self.snipping = True
18
+ self.overlays = []
19
+ self.canvases = []
20
+ self.rects = []
21
+
22
+ for monitor in self.monitors:
23
+ overlay = tk.Toplevel(self.root)
24
+ overlay.geometry(f"{monitor.width}x{monitor.height}+{monitor.x}+{monitor.y}")
25
+ overlay.configure(bg='blue')
26
+ overlay.attributes('-alpha', 0.3)
27
+ overlay.bind('<Escape>', self.exit_snipping)
28
+
29
+ canvas = tk.Canvas(overlay, cursor="cross")
30
+ canvas.pack(fill=tk.BOTH, expand=tk.TRUE)
31
+ canvas.bind('<ButtonPress-1>', self.on_mouse_down)
32
+ canvas.bind('<B1-Motion>', self.on_mouse_drag)
33
+ canvas.bind('<ButtonRelease-1>', self.on_mouse_up)
34
+
35
+ self.overlays.append(overlay)
36
+ self.canvases.append(canvas)
37
+ self.rects.append(None)
38
+
39
+ self.root.update_idletasks()
40
+ self.root.update()
41
+
42
+ self.start_x = self.start_y = self.end_x = self.end_y = 0
43
+
44
+ def exit_snipping(self, event=None):
45
+ self.snipping = False
46
+ for overlay in self.overlays:
47
+ overlay.destroy()
48
+
49
+ def on_mouse_down(self, event):
50
+ self.start_x = event.x_root
51
+ self.start_y = event.y_root
52
+ for i in range(len(self.rects)):
53
+ self.rects[i] = None
54
+
55
+ def on_mouse_drag(self, event):
56
+ for i, canvas in enumerate(self.canvases):
57
+ if self.rects[i]:
58
+ canvas.delete(self.rects[i])
59
+ self.rects[i] = canvas.create_rectangle(
60
+ self.start_x - canvas.winfo_rootx(),
61
+ self.start_y - canvas.winfo_rooty(),
62
+ event.x_root - canvas.winfo_rootx(),
63
+ event.y_root - canvas.winfo_rooty(),
64
+ outline='red'
65
+ )
66
+
67
+ def on_mouse_up(self, event):
68
+ self.end_x = event.x_root
69
+ self.end_y = event.y_root
70
+ self.take_screenshot()
71
+ self.exit_snipping()
72
+
73
+ def take_screenshot(self):
74
+ x1 = min(self.start_x, self.end_x)
75
+ y1 = min(self.start_y, self.end_y)
76
+ x2 = max(self.start_x, self.end_x)
77
+ y2 = max(self.start_y, self.end_y)
78
+
79
+ for overlay in self.overlays:
80
+ overlay.withdraw()
81
+
82
+ with mss.mss() as sct:
83
+ monitor = {
84
+ "top": y1,
85
+ "left": x1,
86
+ "width": x2 - x1,
87
+ "height": y2 - y1
88
+ }
89
+ screenshot = sct.grab(monitor)
90
+ img = mss.tools.to_png(screenshot.rgb, screenshot.size)
91
+
92
+ for overlay in self.overlays:
93
+ overlay.deiconify()
94
+
95
+ img = Image.open(io.BytesIO(img))
96
+ img = img.convert('RGB')
97
+ self.on_screenshot(img)
@@ -0,0 +1,60 @@
1
+
2
+ import tkinter as tk
3
+ from PIL import ImageDraw, ImageFont
4
+
5
+ class TextTool:
6
+ def __init__(self, image_window):
7
+ self.image_window = image_window
8
+ self.text_mode = False
9
+
10
+ def enable_text_mode(self):
11
+ if self.image_window.paint_tool:
12
+ self.image_window.paint_tool.disable_paint_mode()
13
+ self.text_mode = True
14
+ img_label = self.image_window.img_label
15
+ if img_label:
16
+ img_label.bind('<Button-1>', self.add_text_entry)
17
+ if self.image_window.root:
18
+ self.image_window.root.bind_all('<Escape>', self.disable_text_mode)
19
+ self.image_window.root.bind_all('<Control-z>', self.undo_last_text)
20
+ img_label.config(cursor="xterm")
21
+ self.image_window.set_text_tool(self) # 设置当前 TextTool 实例为活动的文字工具
22
+
23
+ def disable_text_mode(self, event=None):
24
+ self.text_mode = False
25
+ img_label = self.image_window.img_label
26
+ if img_label:
27
+ img_label.unbind('<Button-1>')
28
+ if self.image_window.root:
29
+ self.image_window.root.unbind_all('<Escape>')
30
+ self.image_window.root.unbind_all('<Control-z>')
31
+ img_label.config(cursor="arrow")
32
+
33
+ def add_text_entry(self, event):
34
+ if self.text_mode:
35
+ x, y = event.x, event.y
36
+ entry = tk.Entry(self.image_window.img_window, font=("Arial", 28), fg="red", bd=0, highlightthickness=0, insertbackground="red")
37
+ entry.place(x=x, y=y)
38
+ entry.bind('<Return>', lambda e: self.save_text(entry, x, y))
39
+ entry.bind('<FocusOut>', lambda e: self.save_text(entry, x, y))
40
+ entry.focus()
41
+ self.text_entry = entry
42
+
43
+ def save_text(self, entry, x, y):
44
+ text = entry.get()
45
+ entry.destroy()
46
+ if text:
47
+ scaled_x = x / self.image_window.img_label.scale
48
+ scaled_y = y / self.image_window.img_label.scale
49
+ self.image_window.draw_history.append(('text', scaled_x, scaled_y, text))
50
+ self.image_window.redraw_image()
51
+
52
+ def undo_last_text(self, event=None):
53
+ if self.image_window.draw_history:
54
+ for i in range(len(self.image_window.draw_history) - 1, -1, -1):
55
+ if isinstance(self.image_window.draw_history[i], tuple) and self.image_window.draw_history[i][0] == 'text':
56
+ del self.image_window.draw_history[i]
57
+ break
58
+ self.image_window.redraw_image()
59
+
60
+
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.1
2
+ Name: fastshot
3
+ Version: 0.1.0
4
+ Summary: A versatile screen capturing tool with annotation and OCR features
5
+ Home-page: https://github.com/yourusername/fastshot
6
+ Author: Your Name
7
+ Author-email: your-email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: pyautogui
15
+ Requires-Dist: pynput
16
+ Requires-Dist: pillow
17
+ Requires-Dist: screeninfo
18
+ Requires-Dist: mss
19
+ Requires-Dist: Pillow
20
+ Requires-Dist: pyperclip
21
+ Requires-Dist: pywin32
22
+ Requires-Dist: paddleocr
23
+ Requires-Dist: paddlepaddle
24
+
25
+ # Fastshot
26
+
27
+ Fastshot is a versatile screen capturing tool that allows users to take screenshots, annotate them with paint and text tools, and perform OCR (Optical Character Recognition) to extract text from images. The application provides an intuitive interface and can be extended with plugins.
28
+
29
+ ## Features
30
+
31
+ - **Screen Capturing**: Capture any part of your screen using a customizable hotkey.
32
+ - **Annotation Tools**: Use paint and text tools to annotate your screenshots.
33
+ - **OCR Integration**: Extract text from images using the built-in OCR plugin powered by PaddleOCR.
34
+ - **Plugin System**: Easily extend the functionality with plugins.
35
+
36
+ ## Installation
37
+
38
+ You can install Fastshot from PyPI:
39
+
40
+ ```sh
41
+ pip install fastshot
42
+ ```
43
+
44
+
45
+ ## Usage
46
+ Once installed, you can start Fastshot from the command line:
47
+
48
+ ```sh
49
+ fastshot
50
+ ```
51
+
52
+ ## Hotkeys
53
+ F1: Activate screen capturing mode.
54
+
55
+ Ctrl+P: Activate paint mode.
56
+
57
+ Ctrl+T: Activate text mode.
58
+
59
+ Esc: Exit the current mode.
60
+
61
+ ## Right-Click Menu
62
+
63
+ Close: Close the current window.
64
+
65
+ Save As...: Save the current screenshot.
66
+
67
+ Paint: Activate paint mode.
68
+
69
+ Undo: Undo the last action.
70
+
71
+ Exit Edit: Exit paint or text mode.
72
+
73
+ Copy: Copy the current screenshot to the clipboard.
74
+
75
+ Text: Activate text mode.
76
+
77
+ OCR: Perform OCR on the current screenshot and copy the result to the clipboard.
78
+
79
+
80
+ ## Development
81
+ Setting Up the Development Environment
82
+ 1. Clone the repository:
83
+
84
+ ```sh
85
+ git clone https://github.com/yourusername/fastshot.git
86
+ cd fastshot
87
+ ```
88
+
89
+ 2. Install the dependencies:
90
+ ```sh
91
+ pip install -r requirements.txt
92
+ ```
93
+
94
+ ## Running Tests
95
+ You can run the tests using:
96
+
97
+ ```sh
98
+ pytest tests/
99
+ ```
100
+
101
+ ## Contributing
102
+ We welcome contributions! Please read our Contributing Guidelines for more details.
103
+
104
+ ## License
105
+ This project is licensed under the Apache License - see the LICENSE file for details.
106
+
107
+
108
+
109
+
110
+
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ fastshot/__init__.py
6
+ fastshot/image_window.py
7
+ fastshot/main.py
8
+ fastshot/paint_tool.py
9
+ fastshot/plugin_ocr.py
10
+ fastshot/snipping_tool.py
11
+ fastshot/text_tool.py
12
+ fastshot.egg-info/PKG-INFO
13
+ fastshot.egg-info/SOURCES.txt
14
+ fastshot.egg-info/dependency_links.txt
15
+ fastshot.egg-info/entry_points.txt
16
+ fastshot.egg-info/requires.txt
17
+ fastshot.egg-info/top_level.txt
18
+ tests/test_main.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ fastshot = fastshot.main:main
@@ -0,0 +1,10 @@
1
+ pyautogui
2
+ pynput
3
+ pillow
4
+ screeninfo
5
+ mss
6
+ Pillow
7
+ pyperclip
8
+ pywin32
9
+ paddleocr
10
+ paddlepaddle
@@ -0,0 +1 @@
1
+ fastshot
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,37 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='fastshot',
5
+ version='0.1.0',
6
+ packages=find_packages(),
7
+ include_package_data=True,
8
+ install_requires=[
9
+ "pyautogui",
10
+ "pynput",
11
+ "pillow",
12
+ "screeninfo",
13
+ "mss",
14
+ "Pillow",
15
+ "pyperclip",
16
+ "pywin32",
17
+ "paddleocr",
18
+ "paddlepaddle"
19
+ ],
20
+ entry_points={
21
+ 'console_scripts': [
22
+ 'fastshot = fastshot.main:main',
23
+ ],
24
+ },
25
+ author='Your Name',
26
+ author_email='your-email@example.com',
27
+ description='A versatile screen capturing tool with annotation and OCR features',
28
+ long_description=open('README.md').read(),
29
+ long_description_content_type='text/markdown',
30
+ url='https://github.com/yourusername/fastshot',
31
+ classifiers=[
32
+ 'Programming Language :: Python :: 3',
33
+ 'License :: OSI Approved :: MIT License',
34
+ 'Operating System :: OS Independent',
35
+ ],
36
+ python_requires='>=3.6',
37
+ )
File without changes