Skip to content

Commit

Permalink
trying automation
Browse files Browse the repository at this point in the history
  • Loading branch information
amrahm committed Jan 12, 2024
1 parent c2a3f2d commit e01aace
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 8 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Package Application with Pyinstaller

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Package Application
uses: JackMcKew/pyinstaller-action-windows@main
with:
path: src
spec: MonitorBrightnessScheduler.spec

- uses: actions/upload-artifact@v2
with:
name: MonitorBrightnessScheduler
path: dist/windows
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ MANIFEST
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
Expand Down
45 changes: 45 additions & 0 deletions MonitorBrightnessScheduler.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['main.py'],
pathex=[],
binaries=[],
datas=[('*.png', '.'), ('*.ico', '.')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='MonitorBrightnessScheduler',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['favicon.ico'],
)
1 change: 1 addition & 0 deletions makepyspec.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyi-makespec --add-data "*.png;." --add-data "*.ico;." --icon=favicon.ico --onefile --noconsole --name=MonitorBrightnessScheduler main.py
2 changes: 1 addition & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
"UPDATE_FREQ": 30,
"SHOULD_HOLD": false,
"HOLD_TIME": 1,
"HOLD_START_TIME": "2024-01-11T19:10:35.011197"
"HOLD_START_TIME": "2024-01-11T19:33:25.842431"
}
File renamed without changes
File renamed without changes.
28 changes: 22 additions & 6 deletions infrastructure.py → src/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

Settings = Dict[str, List | int]
SETTINGS_PATH = "settings.json"
WORKING_DIR = sys._MEIPASS if getattr(sys, "frozen", False) else ""
WORKING_DIR = sys._MEIPASS if getattr(sys, "frozen", False) else "src"
print(WORKING_DIR)

EXIT_PROGRAM = "Exit Program"
OPEN_SETTINGS = "Open Settings"
Expand Down Expand Up @@ -42,7 +43,12 @@ def __init__(self):
with open(SETTINGS_PATH, "r") as jsonfile:
self._settings: Settings = json.load(jsonfile)
else:
self._settings: Settings = {TIMES: [], UPDATE_FREQ: 10, SHOULD_HOLD: False, HOLD_TIME: 60}
self._settings: Settings = {
TIMES: [],
UPDATE_FREQ: 10,
SHOULD_HOLD: False,
HOLD_TIME: 60,
}
with open(SETTINGS_PATH, "w") as jsonfile:
json.dump(self._settings, jsonfile, indent=4)

Expand Down Expand Up @@ -142,6 +148,8 @@ def __repr__(self) -> str:

def update_brightness_based_on_time():
with SettingsSingleton().settings() as settings:
if not settings[TIMES]:
return
curr_time = datetime.now()

if settings[SHOULD_HOLD]:
Expand All @@ -164,10 +172,18 @@ def update_brightness_based_on_time():

if next_time_val == prev_time_val:
next_time_val = time_vals[0]
next_time = datetime.combine(date.today() + timedelta(days=1), next_time_val.time)

ratio = 1 if next_time == prev_time else (curr_time - prev_time) / (next_time - prev_time)
new_brightness = int(next_time_val.value * ratio + prev_time_val.value * (1 - ratio))
next_time = datetime.combine(
date.today() + timedelta(days=1), next_time_val.time
)

ratio = (
1
if next_time == prev_time
else (curr_time - prev_time) / (next_time - prev_time)
)
new_brightness = int(
next_time_val.value * ratio + prev_time_val.value * (1 - ratio)
)

# print(prev_time_val, curr_time.time(), next_time_val, f"{ratio:0.5}", new_brightness)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e01aace

Please sign in to comment.