11import ctypes
22import tkinter as tk
33from shutil import copy
4- from subprocess import Popen
54from tkinter import messagebox , ttk
65from tkinter .filedialog import askopenfilename , asksaveasfile
76from typing import cast
1211from matplotlib .dates import DateFormatter
1312
1413from cs2tracker .app .editor_frame import ConfigEditorFrame
15- from cs2tracker .constants import (
16- CONFIG_FILE ,
17- CONFIG_FILE_BACKUP ,
18- ICON_FILE ,
19- OS ,
20- OUTPUT_FILE ,
21- POWERSHELL_COLORIZE_OUTPUT ,
22- PYTHON_EXECUTABLE ,
23- RUNNING_IN_EXE ,
24- OSType ,
25- )
14+ from cs2tracker .app .scraper_frame import ScraperFrame
15+ from cs2tracker .constants import ICON_FILE , OS , OUTPUT_FILE , OSType
2616from cs2tracker .scraper import BackgroundTask , Scraper
2717from cs2tracker .util import PriceLogs
2818
2919APPLICATION_NAME = "CS2Tracker"
30- WINDOW_SIZE = "630x380"
20+ WINDOW_SIZE = "630x335"
21+ DARK_THEME = True
22+
23+ SCRAPER_WINDOW_TITLE = "CS2Tracker Scraper"
24+ SCRAPER_WINDOW_SIZE = "900x750"
3125
3226CONFIG_EDITOR_TITLE = "Config Editor"
3327CONFIG_EDITOR_SIZE = "800x750"
3428
35- SCRAPER_WINDOW_HEIGHT = 40
36- SCRAPER_WINDOW_WIDTH = 120
37- SCRAPER_WINDOW_BACKGROUND_COLOR = "Black"
38-
3929
4030class Application :
4131 def __init__ (self ):
@@ -48,7 +38,10 @@ def run(self):
4838 """
4939 self .application_window = self ._configure_window ()
5040
51- sv_ttk .use_dark_theme ()
41+ if DARK_THEME :
42+ sv_ttk .use_dark_theme ()
43+ else :
44+ sv_ttk .use_light_theme ()
5245
5346 self .application_window .mainloop ()
5447
@@ -66,10 +59,9 @@ def _configure_button_frame(self, main_frame):
6659
6760 self ._add_button (button_frame , "Run!" , self .scrape_prices , 0 )
6861 self ._add_button (button_frame , "Edit Config" , self ._edit_config , 1 )
69- self ._add_button (button_frame , "Reset Config" , self ._reset_config , 2 )
70- self ._add_button (button_frame , "Show History" , self ._draw_plot , 3 )
71- self ._add_button (button_frame , "Export History" , self ._export_log_file , 4 )
72- self ._add_button (button_frame , "Import History" , self ._import_log_file , 5 )
62+ self ._add_button (button_frame , "Show History" , self ._draw_plot , 2 )
63+ self ._add_button (button_frame , "Export History" , self ._export_log_file , 3 )
64+ self ._add_button (button_frame , "Import History" , self ._import_log_file , 4 )
7365
7466 def _add_checkbox (
7567 self , frame , text , variable , command , row
@@ -127,9 +119,10 @@ def _configure_checkbox_frame(self, main_frame):
127119 2 ,
128120 )
129121
130- dark_theme_checkbox_value = tk .BooleanVar (value = True )
122+ # pylint: disable=attribute-defined-outside-init
123+ self .dark_theme_checkbox_value = tk .BooleanVar (value = DARK_THEME )
131124 self ._add_checkbox (
132- checkbox_frame , "Dark Theme" , dark_theme_checkbox_value , sv_ttk .toggle_theme , 3
125+ checkbox_frame , "Dark Theme" , self . dark_theme_checkbox_value , sv_ttk .toggle_theme , 3
133126 )
134127
135128 def _configure_main_frame (self , window ):
@@ -165,77 +158,32 @@ def _configure_window(self):
165158
166159 return window
167160
168- def _construct_scraper_command_windows (self ):
169- """Construct the command to run the scraper in a new window for Windows."""
170- get_size = "$size = $Host.UI.RawUI.WindowSize;"
171- set_size = "$Host.UI.RawUI.WindowSize = $size;"
172- set_window_title = f"$Host.UI.RawUI.WindowTitle = '{ APPLICATION_NAME } ';"
173- set_window_width = (
174- f"$size.Width = [Math]::Min({ SCRAPER_WINDOW_WIDTH } , $Host.UI.RawUI.BufferSize.Width);"
175- )
176- set_window_height = f"$size.Height = { SCRAPER_WINDOW_HEIGHT } ;"
177- set_background_color = (
178- f"$Host.UI.RawUI.BackgroundColor = '{ SCRAPER_WINDOW_BACKGROUND_COLOR } ';"
179- )
180- clear = "Clear-Host;"
181-
182- if RUNNING_IN_EXE :
183- # The python executable is set as the executable itself in PyInstaller
184- scraper_cmd = f"{ PYTHON_EXECUTABLE } --only-scrape | { POWERSHELL_COLORIZE_OUTPUT } "
185- else :
186- scraper_cmd = f"{ PYTHON_EXECUTABLE } -m cs2tracker --only-scrape"
187-
188- cmd = (
189- 'start powershell -NoExit -Command "& {'
190- + set_window_title
191- + get_size
192- + set_window_width
193- + set_window_height
194- + set_size
195- + set_background_color
196- + clear
197- + scraper_cmd
198- + '}"'
199- )
200- return cmd
201-
202- def _construct_scraper_command (self ):
203- """Construct the command to run the scraper in a new window."""
204- if OS == OSType .WINDOWS :
205- return self ._construct_scraper_command_windows ()
206- else :
207- # TODO: Implement for Linux
208- return ""
209-
210161 def scrape_prices (self ):
211162 """Scrape prices from the configured sources, print the total, and save the
212163 results to a file.
213164 """
214- if OS == OSType .WINDOWS :
215- scraper_cmd = self ._construct_scraper_command ()
216- Popen (scraper_cmd , shell = True )
217- else :
218- # TODO: implement external window for Linux
219- self .scraper .scrape_prices ()
165+ scraper_window = tk .Toplevel (self .application_window )
166+ scraper_window .geometry (SCRAPER_WINDOW_SIZE )
167+ scraper_window .title (SCRAPER_WINDOW_TITLE )
168+
169+ run_frame = ScraperFrame (
170+ scraper_window ,
171+ self .scraper ,
172+ sheet_size = SCRAPER_WINDOW_SIZE ,
173+ dark_theme = self .dark_theme_checkbox_value .get (),
174+ )
175+ run_frame .pack (expand = True , fill = "both" )
176+ run_frame .start ()
220177
221178 def _edit_config (self ):
222179 """Open a new window with a config editor GUI."""
223180 config_editor_window = tk .Toplevel (self .application_window )
224181 config_editor_window .geometry (CONFIG_EDITOR_SIZE )
225182 config_editor_window .title (CONFIG_EDITOR_TITLE )
226183
227- editor_frame = ConfigEditorFrame (config_editor_window , self .scraper . config )
184+ editor_frame = ConfigEditorFrame (config_editor_window , self .scraper )
228185 editor_frame .pack (expand = True , fill = "both" )
229186
230- def _reset_config (self ):
231- """Reset the configuration file to its default state."""
232- confirm = messagebox .askokcancel (
233- "Reset Config" , "Are you sure you want to reset the configuration?"
234- )
235- if confirm :
236- copy (CONFIG_FILE_BACKUP , CONFIG_FILE )
237- self .scraper .load_config ()
238-
239187 def _draw_plot (self ):
240188 """Draw a plot of the scraped prices over time."""
241189 dates , usd_prices , eur_prices = PriceLogs .read ()
@@ -258,7 +206,7 @@ def _export_log_file(self):
258206 export_path = asksaveasfile (
259207 title = "Export Log File" ,
260208 defaultextension = ".csv" ,
261- filetypes = [("CSV files " , "*.csv" )],
209+ filetypes = [("CSV File " , "*.csv" )],
262210 )
263211 if export_path :
264212 copy (OUTPUT_FILE , export_path .name )
0 commit comments