Skip to content

Commit

Permalink
test7
Browse files Browse the repository at this point in the history
  • Loading branch information
amrahm committed Jan 12, 2024
1 parent 7c29380 commit f77a080
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
python-version: 3.11

- run: pip install pyinstaller
- run: pip install -r requirements.txt pyinstaller
- run: pyinstaller --clean --noconfirm --log-level=WARN src/MonitorBrightnessScheduler.spec
- uses: actions/upload-artifact@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PySimpleGUI==4.60.4
pywin32==304
monitorcontrol==3.0.1
psgtray==1.0.2
25 changes: 21 additions & 4 deletions src/settingsview.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import copy
import os
import PySimpleGUI as sg
from infrastructure import *

from src.infrastructure import (
EXIT_PROGRAM,
TIME,
TIMES,
UPDATE_FREQ,
VALUE,
WORKING_DIR,
SettingsSingleton,
position_window_on_tray,
)

CANCEL = "Cancel"
OK = "Ok"
Expand All @@ -26,7 +36,9 @@ def get_time_row(self, row, row_ind=None):
time, value = row[TIME], row[VALUE]
hrs, mins = time.split(":") if time else ("", "")
i = self.row_inc
self.row_map[i] = row_ind if row_ind is not None else len(self.new_settings[TIMES]) - 1
self.row_map[i] = (
row_ind if row_ind is not None else len(self.new_settings[TIMES]) - 1
)
self.row_inc += 1
return [
sg.Input(
Expand All @@ -52,7 +64,10 @@ def get_time_row(self, row, row_ind=None):
default_value=value,
enable_events=True,
),
sg.Button(image_filename=os.path.join(WORKING_DIR, "delete.png"), key=f"{TIME_ROW_DELETE}{i}"),
sg.Button(
image_filename=os.path.join(WORKING_DIR, "delete.png"),
key=f"{TIME_ROW_DELETE}{i}",
),
]

def get_settings_window(self):
Expand All @@ -62,7 +77,9 @@ def get_settings_window(self):

with SettingsSingleton().settings() as settings:
self.new_settings = copy.deepcopy(settings)
time_rows = [self.get_time_row(row, i) for i, row in enumerate(self.new_settings[TIMES])]
time_rows = [
self.get_time_row(row, i) for i, row in enumerate(self.new_settings[TIMES])
]
layout = [
[sg.Column(time_rows, key=TIME_COLUMN)],
[sg.Push(), sg.B(ADD_TIME), sg.Push()],
Expand Down
33 changes: 28 additions & 5 deletions src/sliderwindow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
from datetime import datetime
import PySimpleGUI as sg
from infrastructure import *

from src.infrastructure import (
HOLD_START_TIME,
HOLD_TIME,
SHOULD_HOLD,
SettingsSingleton,
get_monitor_brightness,
position_window_on_tray,
set_monitor_brightness,
)

BRIGHTNESS_SLIDER = "BRIGHTNESS_SLIDER"
CHECKBOX_HOLD = "CHECKBOX_HOLD"
Expand All @@ -15,9 +25,18 @@ def get_slider_window():
sg.Text("Set Monitor Brightness:"),
sg.Push(),
],
[sg.Slider(range=(0, 100), resolution=1, orientation="h", key=BRIGHTNESS_SLIDER)],
[
sg.Checkbox(text="Hold?", enable_events=True, key=CHECKBOX_HOLD, default=settings[SHOULD_HOLD]),
sg.Slider(
range=(0, 100), resolution=1, orientation="h", key=BRIGHTNESS_SLIDER
)
],
[
sg.Checkbox(
text="Hold?",
enable_events=True,
key=CHECKBOX_HOLD,
default=settings[SHOULD_HOLD],
),
sg.Text("for"),
sg.Input(
key=INPUT_HOLD,
Expand Down Expand Up @@ -56,10 +75,14 @@ def handle_slider_window_events(window: sg.Window, event, values):
set_monitor_brightness(int(values[BRIGHTNESS_SLIDER]))

window[CHECKBOX_HOLD].update(value=True)
SettingsSingleton().update_single_setting(HOLD_START_TIME, datetime.now().isoformat())
SettingsSingleton().update_single_setting(
HOLD_START_TIME, datetime.now().isoformat()
)
SettingsSingleton().update_single_setting(SHOULD_HOLD, True)
elif event == CHECKBOX_HOLD:
SettingsSingleton().update_single_setting(HOLD_START_TIME, datetime.now().isoformat())
SettingsSingleton().update_single_setting(
HOLD_START_TIME, datetime.now().isoformat()
)
SettingsSingleton().update_single_setting(SHOULD_HOLD, values[event])
elif event == INPUT_HOLD:
if not values[event]:
Expand Down
8 changes: 7 additions & 1 deletion src/timeloop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import time, threading
from infrastructure import *

from src.infrastructure import (
TIMES,
UPDATE_FREQ,
SettingsSingleton,
update_brightness_based_on_time,
)


class TimeLoop(threading.Thread):
Expand Down

0 comments on commit f77a080

Please sign in to comment.