Skip to content

Commit

Permalink
Fix active users display -- now it scrolls
Browse files Browse the repository at this point in the history
Yep, never tested it with that many people.
  • Loading branch information
justinb4003 committed Jan 20, 2025
1 parent 08d96be commit 65c19ec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
26 changes: 21 additions & 5 deletions lib/tritime.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def read_punches(badge: str):
punch_data = json.loads(f.read())
else:
punch_data = []
# Sort by the ts_in property
punch_data = sorted(punch_data, key=lambda x: x['ts_in'])
return punch_data


Expand All @@ -42,17 +44,31 @@ def write_punches(badge: str, punch_data: list):
with open(datafile, 'w') as f:
f.write(json.dumps(punch_data, indent=4, sort_keys=True))

def fix_badges():
badges = get_badges()
for badge in badges.keys():
punch_data = read_punches(badge)
badges = update_badge_status(badge, badges, punch_data)
store_badges(badges)

def update_badge_status(badge: str, badges: list, punch_data: list, save_data=True):
status = 'out'
# If the last punch doesn't have a ts_out, then the badge is in
if len(punch_data) > 0 and 'ts_out' not in punch_data[-1]:
status = 'in'
badges[badge]['status'] = status
if save_data is True:
store_badges(badges)
return badges

def punch_in(badge: str, dt: datetime):
json_dt = dt.strftime(json_dt_fmt)
punch_data = read_punches(badge)
punch_data.append({'ts_in': json_dt})
write_punches(badge, punch_data)

# Change status
badges = get_badges()
badges[badge]['status'] = 'in'
store_badges(badges)
badges = update_badge_status(badge, badges, punch_data)
return badges


Expand All @@ -64,8 +80,8 @@ def punch_out(badge: str, dt: datetime):
lrec['ts_out'] = json_dt
write_punches(badge, punch_data)
badges = get_badges()
badges[badge]['status'] = 'out'
store_badges(badges)
badges = update_badge_status(badge, badges, punch_data)
print(f'punch out modify status {badge}')
return badges


Expand Down
29 changes: 16 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ def __init__(self, parent, id):
self.punch_all_out_btn.Disable()

# Create a grid that lets us show everybody punched in
self.active_badge_sizer = wx.GridSizer(4, 20, 10)
self.active_badge_sizer = wx.WrapSizer(wx.HORIZONTAL)
self.badge_scroller = wx.ScrolledWindow(self)
self.badge_scroller.SetScrollRate(10, 10)
self.badge_scroller.SetMinSize((800, 600))
self.badge_scroller.SetSizer(self.active_badge_sizer)

spacer_size = 20
# This lets us put a space to the left of everything by putting our
Expand Down Expand Up @@ -257,9 +261,10 @@ def __init__(self, parent, id):
hbox_top.AddStretchSpacer(20)
hbox_top.Add(self.export_btn)


hbox_buttons_checkgrid = wx.BoxSizer(wx.HORIZONTAL)
hbox_buttons_checkgrid.Add(vbox_buttons)
hbox_buttons_checkgrid.Add(self.active_badge_sizer)
hbox_buttons_checkgrid.Add(self.badge_scroller)

hbox_badgde_input = wx.BoxSizer(wx.HORIZONTAL)
hbox_badgde_input.Add(self.badge_num_input, 1, wx.EXPAND)
Expand Down Expand Up @@ -398,8 +403,10 @@ def create_badge_card(self, badge_num, parent=None, bind_method=None):

# Draws an individual badge on the grid with a button to punch them out
def add_badge_to_grid(self, badge_num):
vbox = self.create_badge_card(badge_num)
self.active_badge_sizer.Add(vbox)
vbox = self.create_badge_card(badge_num,
self.badge_scroller,
self.punch_out)
self.active_badge_sizer.Add(vbox, 0, wx.ALL, border=10)
self.Layout()
self.Update()

Expand Down Expand Up @@ -434,7 +441,6 @@ def on_badge_num_change(self, event):
)
badges = libtt.get_badges()
valid_badges = badges.keys()
print(f'Badge Number: {badge_num}')
if badge_num in valid_badges:
badge_data = badges[badge_num]
self.greeting_label.SetLabel(
Expand All @@ -461,6 +467,10 @@ def on_badge_num_enter(self, event, badge_num=None):
if badge_num is None:
badge_num = self.get_entered_badge()

if badge_num == 'fixbadges':
libtt.fix_badges()
return

if badge_num == 'debug':
import wx.lib.inspection
wx.lib.inspection.InspectionTool().Show()
Expand Down Expand Up @@ -498,7 +508,6 @@ def get_entered_badge(self, badge=None) -> str:
def punch_in(self, event):
badge = self.get_entered_badge()
dt = datetime.now()
print(f'Punch In {badge}')
badges = libtt.punch_in(badge, dt)
libtt.store_badges(badges)
self.add_badge_to_grid(badge)
Expand All @@ -513,7 +522,6 @@ def punch_out(self, event, badge_num=None):
badge = bni.GetValue() if badge_num is None else badge_num
badge = self.lookup_alt(libtt.get_badges(), badge)
dt = datetime.now()
print(f'Punch Out {badge}')
badges = libtt.punch_out(badge, dt)
libtt.store_badges(badges)
libtt.tabulate_badge(badge)
Expand All @@ -529,7 +537,6 @@ def check_time_dialog(self, event):
def badge_change(event):
badge = event.GetString().strip()
badge = self.lookup_alt(libtt.get_badges(), badge)
print(f'Check Time {badge}')
# Create a grid
punch_data = libtt.read_punches(badge)
punch_data.reverse()
Expand Down Expand Up @@ -610,7 +617,6 @@ def badge_change(event):

@return_focus
def add_user(self, event):
print('adding user dialog')
# Create a dialog that has inputs for a badge number, display name,
# and photo URL. When the dialog is submitted, add the user to the
# database and update the active badges grid.
Expand Down Expand Up @@ -685,15 +691,13 @@ def update_find_user_search(self, search_text):
vbox = self.create_badge_card(num,
self.scrolled_window,
self.set_badge_input)
self.find_user_badge_sizer.Add(vbox)
self.find_user_badge_sizer.AddSpacer(10)
self.find_user_badge_sizer.Add(vbox, 0, wx.ALL, border=10)
self.find_user_dlg.Fit()
self.find_user_dlg.Layout()
self.find_user_dlg.Update()

def find_user_input_change(self, event):
search_text = event.GetString().lower()
print(search_text)
self.update_find_user_search(search_text)

@return_focus
Expand Down Expand Up @@ -741,7 +745,6 @@ def submit_settings(self, event, keys: list, vfuncs: list):

@return_focus
def edit_settings(self, event):
print("editing settings")
self.settings_dlg = wx.Dialog(self, title='System Settings')
allow_all_out_chk = wx.CheckBox(self.settings_dlg,
label='Allow All Out')
Expand Down

0 comments on commit 65c19ec

Please sign in to comment.