Skip to content

Commit

Permalink
3.6
Browse files Browse the repository at this point in the history
- reworked structure
- better linux support
- several minor code improvements
- new wallpaper (yay)
  • Loading branch information
SirDank committed Mar 30, 2024
1 parent 48aeed2 commit 92cb14e
Show file tree
Hide file tree
Showing 17 changed files with 1,142 additions and 1,138 deletions.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ multithread(example, 10, new_list, 5, progress_bar=False) # input_two: 5 | disab

```py
import os
from dankware import export_registry_keys, is_admin
from dankware import export_registry_keys

# [NOTE]: this function requires admin privileges!

Expand All @@ -113,7 +113,9 @@ export_registry_keys(registry_root, registry_path, recursive=True, export_path=e
# 🚨 Splash Screen 🚨

```py
from dankware import splash_screen, hide_window, show_window
from dankware.pillow import splash_screen
#from dankware import hide_window, show_window

# Supports: GIFs / PNGs / JPGs / BMPs / ICOs

# hide_window()
Expand All @@ -122,7 +124,7 @@ splash_screen("D:\\splash.gif", duration=5) # runs on main thread
```

```py
from dankware import splash_screen
from dankware.pillow import splash_screen
from concurrent.futures import ThreadPoolExecutor
ThreadPoolExecutor(1).submit(splash_screen, "splash.png", 5)
# runs on separate thread
Expand Down Expand Up @@ -182,23 +184,29 @@ print(random_ip())
# 🚨 GUI File / Path Selector 🚨

```py
from dankware import file_selector
from dankware.tkinter import file_selector
path = file_selector() # opens file explorer to select a file
print(path)
```

```py
from dankware import folder_selector
from dankware.tkinter import folder_selector
path = folder_selector() # opens file explorer to select a folder
print(path)
```

# 🚨 Path Extractor 🚨

```py
import os
from dankware import get_path
for location in ["AppData", "Desktop", "Documents", "Personal", "Favorites", "Local AppData", "Pictures", "My Pictures", "Videos", "My Video", "Music", "My Music"]:
path = get_path(location) # extracts path from registry

if os.name == 'nt': # extracts path from registry
locations = ("AppData", "Desktop", "Documents", "Favorites", "Local AppData", "Pictures", "Videos", "Music")
elif os.name == 'posix':
locations = ("Desktop", "Documents", "Downloads", "Pictures", "Videos", "Music")
for location in locations:
path = get_path(location)
print(path)
```
<img width="200" alt="image" style="border-radius:5%" src="https://github.com/SirDank/dankware/assets/52797753/ee06bdd9-fbd3-4765-9450-6e2435dd6880"><br>
Expand Down Expand Up @@ -429,19 +437,19 @@ print(fade(banner, "random"))

## ♦️ Style 1 ♦️

<br><p align="center"><img width="700" alt="image" src="https://github.com/SirDank/dankware/raw/main/__wallpapers__/1.png"></p><br>
<br><p align="center"><img width="700" alt="image" src="__wallpapers__/1.png"></p><br>

## ♦️ Style 2 ♦️

<br><p align="center"><img width="700" alt="image" src="https://github.com/SirDank/dankware/raw/main/__wallpapers__/2.jpg"></p><br>
<br><p align="center"><img width="700" alt="image" src="__wallpapers__/2.png"></p><br>

## ♦️ Style 3 ♦️

<br><p align="center"><img width="700" alt="image" src="https://github.com/SirDank/dankware/raw/main/__wallpapers__/3.png"></p><br>
<br><p align="center"><img width="700" alt="image" src="__wallpapers__/3.png"></p><br>

## ♦️ Style 4 ♦️

<br><p align="center"><img width="700" alt="image" src="https://github.com/SirDank/dankware/raw/main/__wallpapers__/4.png"></p><br>
<br><p align="center"><img width="700" alt="image" src="__wallpapers__/4.png"></p><br>

<p>&nbsp;</p>

Expand Down
Binary file modified __wallpapers__/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed __wallpapers__/2.jpg
Binary file not shown.
Binary file added __wallpapers__/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,138 changes: 15 additions & 1,123 deletions dankware/__init__.py

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions dankware/ctypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import os
import time
from concurrent.futures import ThreadPoolExecutor

if os.name == 'nt':
import ctypes
elif os.name == 'posix':
import pwd # pylint: disable=import-error

def is_admin() -> bool:

"""
Checks if executed with admin privileges and returns True if found else False
"""

if os.name == 'nt':
try: return ctypes.windll.shell32.IsUserAnAdmin()
except: return False
elif os.name == 'posix':
return pwd.getpwuid(os.getuid())[0] in ('root', '0') # pylint: disable=no-member
else:
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'")

'''
def run_as_admin() -> None:
"""
Executes the script with admin privileges
"""
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
#sys.exit(clr("\n > Exiting original un-elevated script...",2))
'''

# --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def hide_window() -> None:

"""
Hides console window
Related to:
- show_window()
"""

if os.name == 'nt':
hWnd = ctypes.windll.kernel32.GetConsoleWindow()
ctypes.windll.user32.ShowWindow(hWnd, 0)
elif os.name == 'posix':
os.system("xdotool getactivewindow windowminimize")
else:
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'")

def show_window() -> None:

"""
Shows console window
Related to:
- hide_window()
"""

if os.name == 'nt':
hWnd = ctypes.windll.kernel32.GetConsoleWindow()
ctypes.windll.user32.ShowWindow(hWnd, 1)
elif os.name == 'posix':
os.system("xdotool getactivewindow windowactivate")
else:
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'")

def hide_window_for(duration: int = 3) -> None:

"""
Hides console window for the given duration
Related to:
- hide_window()
- show_window()
"""

def tmp():
hide_window()
time.sleep(duration)
show_window()

ThreadPoolExecutor(1).submit(tmp)

def minimise_window() -> None:

"""
Minimises console window
Related to:
- maximise_window()
- restore_window()
"""

if os.name == 'nt':
user32 = ctypes.WinDLL('user32')
user32.ShowWindow(user32.GetForegroundWindow(), 6)
elif os.name == 'posix':
os.system("xdotool getactivewindow windowminimize")
else:
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'")

def maximise_window() -> None:

"""
Maximises console window
Related to:
- minimise_window()
- restore_window()
"""

if os.name == 'nt':
user32 = ctypes.WinDLL('user32')
user32.ShowWindow(user32.GetForegroundWindow(), 3)
elif os.name == 'posix':
os.system("xdotool getactivewindow windowactivate windowmaximize")
else:
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'")

def restore_window() -> None:

"""
Restores console window to its original size
Related to:
- minimise_window()
- maximise_window()
"""

if os.name == 'nt':
user32 = ctypes.WinDLL('user32')
user32.ShowWindow(user32.GetForegroundWindow(), 9)
elif os.name == 'posix':
os.system("xdotool getactivewindow windowactivate windowrestore")
else:
raise ValueError(f"Unsupported Operating System: {os.name} | Supported: 'nt', 'posix'")
105 changes: 105 additions & 0 deletions dankware/datetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from datetime import datetime

def get_duration(then: datetime, now: datetime = None, interval: str = "default") -> int | str:

"""
Returns a duration as specified by the 'interval' variable
__________________________________________________________
valid intervals:
- year -> int
- month -> int
- week -> int
- day -> int
- hour -> int
- minute -> int
- second -> int
- dynamic -> str
- dynamic-mini -> str
- default -> str
- default-mini -> str
"""

if not now: now = datetime.now()
interval = interval.lower()
duration = now - then

if "year" in interval: return int(duration.days / 365)
if "month" in interval: return int(duration.days / 30)
if "week" in interval: return int(duration.days / 7)
if "day" in interval: return duration.days
if "hour" in interval: return int(duration.total_seconds() / 3600)
if "minute" in interval: return int(duration.total_seconds() / 60)
if "second" in interval: return int(duration.total_seconds())
if "dynamic" in interval:

mini = bool(interval == "dynamic-mini")
seconds = duration.total_seconds()

if seconds < 60:
if mini: return f"{int(seconds)}s"
return f"{int(seconds)} second{'s' if seconds > 1 else ''}"

if seconds < 3600:
minutes = int(seconds / 60)
if mini: return f"{minutes}m"
return f"{minutes} minute{'s' if minutes > 1 else ''}"

if seconds < 86400:
hours = int(seconds / 3600)
if mini: return f"{hours}h"
return f"{hours} hour{'s' if hours > 1 else ''}"

if seconds < 604800:
days = int(seconds / 86400)
if mini: return f"{days}d"
return f"{days} day{'s' if days > 1 else ''}"

if seconds < 2592000:
weeks = int(seconds / 604800)
if mini: return f"{weeks}w"
return f"{weeks} week{'s' if weeks > 1 else ''}"

if seconds < 31536000:
months = int(seconds / 2592000)
if mini: return f"{months}m"
return f"{months} month{'s' if months > 1 else ''}"

years = int(seconds / 31536000)
if mini: return f"{years}y"
return f"{years} year{'s' if years > 1 else ''}"

if "default" in interval:

seconds = duration.total_seconds()
years = int(seconds / 31536000)
months = int((seconds % 31536000) / 2592000)
weeks = int((seconds % 2592000) / 604800)
days = int((seconds % 604800) / 86400)
hours = int((seconds % 86400) / 3600)
minutes = int((seconds % 3600) / 60)
seconds = int(seconds % 60)

parts = []
if interval == "default":
if years: parts.append(f"{years} year{'s' if years > 1 else ''}")
if months: parts.append(f"{months} month{'s' if months > 1 else ''}")
if weeks: parts.append(f"{weeks} week{'s' if weeks > 1 else ''}")
if days: parts.append(f"{days} day{'s' if days > 1 else ''}")
if hours: parts.append(f"{hours} hour{'s' if hours > 1 else ''}")
if minutes: parts.append(f"{minutes} minute{'s' if minutes > 1 else ''}")
if seconds: parts.append(f"{seconds} second{'s' if seconds > 1 else ''}")

elif interval == "default-mini":
if years: parts.append(f"{years}y")
if months: parts.append(f"{months}mo")
if weeks: parts.append(f"{weeks}w")
if days: parts.append(f"{days}d")
if hours: parts.append(f"{hours}h")
if minutes: parts.append(f"{minutes}m")
if seconds: parts.append(f"{seconds}s")

return ", ".join(parts)

raise ValueError(f"Invalid Interval: {interval} | Valid Intervals: year, month, week, day, hour, minute, second, dynamic, dynamic-mini, default, default-mini")
Loading

0 comments on commit 92cb14e

Please sign in to comment.