Skip to content

Commit

Permalink
Merge pull request #1 from kr1s7ian/overhaul
Browse files Browse the repository at this point in the history
Overhaul
  • Loading branch information
kr1s7ian authored Jan 30, 2023
2 parents eb452de + 701592c commit 0c3fb97
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 147 deletions.
Binary file added Assets/account_avatars/76561198180506939.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 1 addition & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
# steam-account-switcher
Gui account switcher made with customtkinter py.
Idea of the tool, and functionality of the account switching mechanics by pog
#5249, python code and implementation of UI made by me.

How To Use:
- Pressing the plus button prompts the user for a new username along with a new title, the title is the text shown on the buttons, and username is the username of the steam account the button will log into.
- Right clicking an account button will delete that entry.
- You can use keyboard keys 1 to 9 to log in in the respective accounts.

![Program Demo Image](https://i.imgur.com/Xtvrhsx.png)

Ignore if using releases:
- If you are cloning and running with python, customtkinter has a known bug with the CTkInputDialog, it shold return None when pressing cancel but the command parameter is set to the same one for the ok button, for more details on how to the issue go here https://github.com/TomSchimansky/CustomTkinter/pull/853/commits/d43cc3d6112c77db7742156198b2014ce5f56058

Other:
- Feel free to submit feedback in the issues tab, even if you feel its a minor detail or if you have any problems:

WIP
48 changes: 48 additions & 0 deletions src/accountbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import customtkinter as ck
from typing import Callable
from PIL import Image
from PIL import PngImagePlugin


def get_placeholder_image(size):
return ck.CTkImage(Image.open('Logo.png'), size=(size, size))


class AccountBox(ck.CTkFrame):
def bind(self, sequence=None, command=None, add=True):
""" called on the tkinter.Canvas """
if not (add == "+" or add is True):
raise ValueError(
"'add' argument can only be '+' or True to preserve internal callbacks")
self.button.bind(sequence, command, add=True)

def unbind(self, sequence=None, funcid=None):
""" called on the tkinter.Canvas """
if funcid is not None:
raise ValueError("'funcid' argument can only be None, because there is a bug in" +
" tkinter and its not clear whether the internal callbacks will be unbinded or not")
self.self.button.unbind(sequence, None)

def __init__(self, *args,
image_path: str = None,
title: str,
height: int,
width: int,
command: Callable = None,
avatar_size: int,
** kwargs):
super().__init__(*args, width=width, height=height, **kwargs)
if image_path == None or image_path == "":
self.avatar_image = get_placeholder_image(avatar_size)
else:
self.avatar_image = ck.CTkImage(
Image.open(image_path), size=(avatar_size, avatar_size))

self.avatar = ck.CTkLabel(self, image=self.avatar_image, text="")
self.avatar.grid(padx=5, pady=5, row=0, column=0)

button_width = (width - avatar_size) - 15

self.button = ck.CTkButton(
self, text=title, height=avatar_size, width=button_width, command=command)
self.button.grid(padx=5, pady=5, row=0, column=1)
115 changes: 78 additions & 37 deletions src/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,88 @@
from functools import partial
import os
import lib
from accountbox import AccountBox
from lib import config

ck.set_appearance_mode("dark")
ck.set_default_color_theme('Assets/Theme.json')

'''Custom tkinter main window class'''


class Gui(ck.CTk):

'''Callback for close on switch widget'''

def close_on_switch(self):
config.set_close_on_switch(not config.get_close_on_switch())
config.save()

def account_button_click(self, account_index):
lib.open_steam_in_account(account_index)
'''Callback for import button widget'''

def import_accounts_button_press(self):
lib.config.clear_accounts()
account_usernames = lib.steam.get_login_users_names()
account_steamids = lib.steam.get_login_users_steamids()
for (i, name) in enumerate(account_usernames):
steamid = account_steamids[i]
config.add_account(name, name, steamid)
config.save()
self.reload_accounts_frame()

'''Callback for clear button widget'''

def clear_accounts_button_press(self):
# unbinding account buttons
for i in range(10):
self.unbind(str(i))
config.clear_accounts()
config.save()
self.reload_accounts_frame()

'''Callback for accountbox button widget'''

def account_button_click(self, account_index=None, event=None):
lib.steam.open_steam_in_account(
account_index, lib.config.get_close_on_switch())

'''Callback for accountbox button right click'''

def account_button_right_click(self, account_index, event):
lib.config.remove_account(account_index)
lib.config.save()
self.reload_app()
self.reload_accounts_frame()

'''Method that regenerates accounts_frame with all accountboxes present in the config'''

def create_accounts_frame(self):
self.accounts_frame = ck.CTkFrame(self.bg)
self.accounts_frame.pack(padx=5, pady=5)
self.accounts_frame = ck.CTkFrame(self)
self.accounts_frame.pack(padx=10, pady=10)
if len(config.get_accounts()) == 0:
self.accounts_frame.pack_forget()

for (account_index, account_title) in enumerate(config.get_account_titles()):
callback = partial(self.account_button_click, account_index)
self.button = ck.CTkButton(
self.accounts_frame, text=account_title, command=callback)

self.button.account_index = account_index
steamid = lib.config.get_account_steamid(account_index)
user_avatar_path = lib.steam.get_user_avatar_path(
steamid=steamid)
self.account_box = AccountBox(
self.accounts_frame, width=250, height=75, title=account_title, image_path=user_avatar_path, avatar_size=34, command=callback)
self.account_box.account_index = account_index
right_click_callback = partial(
self.account_button_right_click, account_index)
self.button.bind("<ButtonRelease-3>",
command=right_click_callback)
self.button.pack(padx=5, pady=5)
self.account_box.bind("<ButtonRelease-3>",
command=right_click_callback)
self.account_box.pack(padx=5, pady=5)

key_number = account_index + 1
if key_number < 10:
self.bind(str(key_number), callback)
return self.accounts_frame

'''Prompts the user with a dialog asking Username and Title, returns a tuple containg (title, username)'''

def new_account_dialog(self):
lib.keylistener.stop()

username_dialog = ck.CTkInputDialog(
text="Insert Account Username", title='Add Account')
username = username_dialog.get_input()
Expand All @@ -55,12 +95,13 @@ def new_account_dialog(self):
if title == None:
return None

lib.keylistener.start()
return (title, username)

def reload_app(self):
'''Reloads the accounts_frame'''

def reload_accounts_frame(self):
self.accounts_frame.destroy()
self.acoounts_frame = self.create_accounts_frame()
self.accounts_frame = self.create_accounts_frame()

def add_account_button_press(self):
print("adding new account")
Expand All @@ -70,46 +111,46 @@ def add_account_button_press(self):
title = account_data[0]
username = account_data[1]

account_index = lib.config.add_account(title, username)
account_index = lib.config.add_account(title, username, "")
lib.config.save()
callback = partial(self.account_button_click, account_index)
button = ck.CTkButton(self.accounts_frame,
text=title, command=callback)
button.pack(padx=5, pady=5)
button.account_index = account_index
self.reload_app()
self.reload_accounts_frame()

'''Main window setup'''

def __init__(self):
super().__init__()
self.wm_iconbitmap('Assets/Icon.ico')
self.title("Steam Account Switcher")
self.geometry("600x500")
self.geometry("300x400")
self.resizable(0, 0)

self.bg = ck.CTkFrame(self)
self.bg.pack(padx=15, pady=15, fill="both", expand=True)
self.topbar = ck.CTkFrame(self, width=450, height=100)
self.topbar.pack(side="top", fill="x", expand=False)

self.label = ck.CTkLabel(
master=self.bg, text='Steam Account Switcher', font=('Arialbd', 40))
self.label.pack(padx=10, pady=10)
self.add_account_button = ck.CTkButton(
self.topbar, text="+", command=self.add_account_button_press, width=50)
self.add_account_button.grid(padx=10, pady=10, row=0, column=0)

self.frame = ck.CTkFrame(self.bg)
self.frame.pack(padx=5, pady=15)
self.clear_account_button = ck.CTkButton(
self.topbar, text="clear", width=80, command=self.clear_accounts_button_press)
self.clear_account_button.grid(padx=10, pady=10, row=0, column=1)

self.import_button = ck.CTkButton(
self.topbar, text="import", width=100, command=self.import_accounts_button_press)
self.import_button.grid(padx=10, pady=10, row=0, column=2)

self.close_on_switch = ck.CTkSwitch(
self.frame, text='Close on switch', progress_color=("#326da8", "#326da8"), command=self.close_on_switch)
self.close_on_switch.pack(padx=5, pady=5)
self, text='Close on switch', progress_color=("#326da8", "#326da8"), command=self.close_on_switch)
self.close_on_switch.pack(
side="bottom", padx=10, pady=10)
if config.get_close_on_switch():
self.close_on_switch.select()

self.add_account_button = ck.CTkButton(
self.frame, text="+", command=self.add_account_button_press)
self.add_account_button.pack(padx=5, pady=5)

self.accounts_frame = self.create_accounts_frame()

self.bind("<Unmap>", lambda _: lib.keylistener.stop())
self.bind("<Map>", lambda _: lib.keylistener.start())

self.mainloop()
lib.terminate_app()
39 changes: 0 additions & 39 deletions src/keylistener.py

This file was deleted.

Loading

0 comments on commit 0c3fb97

Please sign in to comment.