Skip to content

Commit

Permalink
SUT-3 is done at this day
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexlep committed Jan 14, 2024
1 parent a9d56f8 commit 2479c48
Show file tree
Hide file tree
Showing 18 changed files with 856 additions and 2 deletions.
11 changes: 11 additions & 0 deletions IHL/IHL.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Metadata-Version: 2.1
Name: IHL
Version: 0.0.1
Summary: A package to make a hover window for your widgets in tkinter or ctkinter
Author: Rexlep
Author-email: [email protected]
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
License-File: LICENSE
9 changes: 9 additions & 0 deletions IHL/IHL.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LICENSE
README.md
setup.py
IHL.egg-info/PKG-INFO
IHL.egg-info/SOURCES.txt
IHL.egg-info/dependency_links.txt
IHL.egg-info/top_level.txt
hover/__init__.py
hover/option.py
1 change: 1 addition & 0 deletions IHL/IHL.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions IHL/IHL.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hover
7 changes: 7 additions & 0 deletions IHL/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 changes: 43 additions & 0 deletions IHL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# IHL (Interface Hover Library)
This is a package for tkinter or customtkinter widgets

![Untitled-1](https://github.com/Rexlep/IHL/assets/141561659/051139fa-4df1-470b-8f3c-f984b8455a71)

## Installation
```
pip install IHL
```

## Usage
```python
import customtkinter as ctk
import tkinter as tk
from IHL.hover.option import Hover

root = ctk.CTk()
root.geometry('300x400')
root.title("IHL")

tk_btn = tk.Button(root, text="Hover Me", font=("Arial", 20))
tk_btn.pack(pady=40)

ctk_btn = ctk.CTkButton(root, text="Hover Me", font=("Arial", 20))
ctk_btn.pack()

Hover(tk_btn, "I am hover", duration=1, font=("Elephant", 12))
Hover(ctk_btn, "I am hover", duration=1)

root.mainloop()
```

## Arguments
| Parameter | Description |
|-----------| ------------|
| fg | text color of hover window |
| bg | color of background |
| border_width | width of the border frame |
| font | set font and size for text |
| move_with_mouse | movement of mouse(True or False) |
| duration | change the create time of window |

Tanks for visiting i hope it was helpful for you to increase your development skill :)
Binary file added IHL/dist/IHL-0.0.1.tar.gz
Binary file not shown.
6 changes: 6 additions & 0 deletions IHL/hover/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
Hover for python interface
Author: REXLEP
"""

from .option import Hover
Binary file added IHL/hover/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added IHL/hover/__pycache__/option.cpython-311.pyc
Binary file not shown.
96 changes: 96 additions & 0 deletions IHL/hover/option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""
Hover for python interface
Author: REXLEP
"""


from tkinter import *


class HoverWindow(object):
"""This class use for hover window"""

def __init__(self, widget, duration=1, font=None, bg="#2B2B2B", fg="#ffffff", border_width=1, border_color="#000000",
move_with_mouse=True):
"""Initialize hover window elements"""
self.widget = widget
self.tipwindow = None
self.id = None
self.x = self.y = 0
self.duration = duration * 1000
self.font = font if font else ("tahoma", "12", "normal")
self.bg = bg
self.fg = fg
self.border_width = border_width
self.border_color = border_color
self.move_with_mouse = move_with_mouse

def showtip(self, text):
"""This function display text in tooltip window"""
self.text = text

# Cancel any scheduled tooltip display
if self.id:
self.widget.after_cancel(self.id)

# Schedule the tooltip to be displayed after the duration
self.id = self.widget.after(self.duration, lambda: self._showtip(text))

def _showtip(self, text):
"""This function make hover window"""
if self.tipwindow or not self.text:
return
x, y, _, cy = self.widget.bbox("insert")
x_pos, y_pos = self.widget.winfo_pointerxy() # Get current mouse position
x = x_pos + 10
y = y_pos + 10
self.tipwindow = tw = Toplevel(self.widget)
tw.wm_overrideredirect(True)
tw.wm_geometry("+%d+%d" % (x, y))
label = Label(
tw,
text=text,
justify=LEFT,
background=self.bg,
foreground=self.fg,
relief=SOLID,
borderwidth=self.border_width,
font=self.font
)
label.pack(ipadx=1)
if self.move_with_mouse:
tw.bind('<Motion>', self.on_tooltip_motion) # Bind <Motion> event

def on_tooltip_motion(self, event):
"""This function make your hover window move with your mouse movement"""
if not self.tipwindow:
return

x = event.x_root + 10
y = event.y_root + 10
self.tipwindow.wm_geometry("+%d+%d" % (x, y))

def hidetip(self):
"""This function hide the window"""
tw = self.tipwindow
self.tipwindow = None
if tw:
tw.destroy()
if self.id:
self.widget.after_cancel(self.id)
self.id = None


def Hover(widget, text, duration=0, font=None, bg="#2B2B2B", fg="#ffffff", border_width=1, move_with_mouse=True):
toolTip = HoverWindow(widget, duration, font, bg, fg, border_width, move_with_mouse)
"""This function allow you to make a hover window for your interface widget"""

def enter(event):
toolTip.showtip(text)

def leave(event):
toolTip.hidetip()

widget.bind('<Enter>', enter)
widget.bind('<Leave>', leave)
widget.bind('<Motion>', toolTip.on_tooltip_motion)
16 changes: 16 additions & 0 deletions IHL/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from setuptools import setup, find_packages

setup(
name='IHL',
version='0.0.1',
author='Rexlep',
author_email='[email protected]',
description='A package to make a hover window for your widgets in tkinter or ctkinter',
packages=find_packages(),
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
python_requires='>=3.6',
)
Loading

0 comments on commit 2479c48

Please sign in to comment.