cs2tracker 2.1.5__py3-none-any.whl → 2.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cs2tracker might be problematic. Click here for more details.

cs2tracker/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '2.1.5'
21
- __version_tuple__ = version_tuple = (2, 1, 5)
20
+ __version__ = version = '2.1.7'
21
+ __version_tuple__ = version_tuple = (2, 1, 7)
cs2tracker/application.py CHANGED
@@ -1,3 +1,4 @@
1
+ import ctypes
1
2
  import tkinter as tk
2
3
  from subprocess import Popen
3
4
  from threading import Thread
@@ -9,6 +10,7 @@ from matplotlib.dates import DateFormatter
9
10
 
10
11
  from cs2tracker.constants import (
11
12
  CONFIG_FILE,
13
+ ICON_FILE,
12
14
  OS,
13
15
  OUTPUT_FILE,
14
16
  PYTHON_EXECUTABLE,
@@ -18,8 +20,9 @@ from cs2tracker.constants import (
18
20
  )
19
21
  from cs2tracker.scraper import Scraper
20
22
 
21
- WINDOW_TITLE = "CS2Tracker"
22
- WINDOW_SIZE = "450x380"
23
+ APPLICATION_NAME = "CS2Tracker"
24
+
25
+ WINDOW_SIZE = "500x450"
23
26
  BACKGROUND_COLOR = "#1e1e1e"
24
27
  BUTTON_COLOR = "#3c3f41"
25
28
  BUTTON_HOVER_COLOR = "#505354"
@@ -27,9 +30,8 @@ BUTTON_ACTIVE_COLOR = "#5c5f61"
27
30
  FONT_STYLE = "Segoe UI"
28
31
  FONT_COLOR = "white"
29
32
 
30
- SCRAPER_WINDOW_TITLE = "CS2Tracker"
31
33
  SCRAPER_WINDOW_HEIGHT = 40
32
- SCRAPER_WINDOW_WIDTH = 80
34
+ SCRAPER_WINDOW_WIDTH = 120
33
35
  SCRAPER_WINDOW_BACKGROUND_COLOR = "Black"
34
36
 
35
37
 
@@ -58,21 +60,42 @@ class Application:
58
60
  button.bind("<Leave>", lambda _: button.config(bg=BUTTON_COLOR))
59
61
  return button
60
62
 
63
+ def _add_checkbox(self, frame, text, variable, command):
64
+ checkbox = tk.Checkbutton(
65
+ frame,
66
+ text=text,
67
+ variable=variable,
68
+ command=command,
69
+ bg=BACKGROUND_COLOR,
70
+ fg=FONT_COLOR,
71
+ selectcolor=BUTTON_COLOR,
72
+ activebackground=BACKGROUND_COLOR,
73
+ font=(FONT_STYLE, 10),
74
+ anchor="w",
75
+ padx=20,
76
+ )
77
+ checkbox.pack(fill="x", anchor="w", pady=2)
78
+
61
79
  def _configure_window(self):
62
80
  """Configure the main application window UI and add buttons for the main
63
81
  functionalities.
64
82
  """
65
83
  window = tk.Tk()
66
- window.title(WINDOW_TITLE)
84
+ window.title(APPLICATION_NAME)
67
85
  window.geometry(WINDOW_SIZE)
68
86
  window.configure(bg=BACKGROUND_COLOR)
87
+ if OS == OSType.WINDOWS:
88
+ app_id = "cs2tracker.unique.id"
89
+ ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(app_id)
90
+ icon = tk.PhotoImage(file=ICON_FILE)
91
+ window.wm_iconphoto(False, icon)
69
92
 
70
93
  frame = tk.Frame(window, bg=BACKGROUND_COLOR, padx=30, pady=30)
71
94
  frame.pack(expand=True, fill="both")
72
95
 
73
96
  label = tk.Label(
74
97
  frame,
75
- text=f"Welcome to {WINDOW_TITLE}!",
98
+ text=f"Welcome to {APPLICATION_NAME}!",
76
99
  font=(FONT_STYLE, 16, "bold"),
77
100
  fg=FONT_COLOR,
78
101
  bg=BACKGROUND_COLOR,
@@ -84,56 +107,79 @@ class Application:
84
107
  self._add_button(frame, "Show History (Chart)", self._draw_plot)
85
108
  self._add_button(frame, "Show History (File)", self._edit_log_file)
86
109
 
110
+ checkbox_frame = tk.Frame(frame, bg=BACKGROUND_COLOR)
111
+ checkbox_frame.pack(pady=(20, 0), fill="x")
112
+
87
113
  background_checkbox_value = tk.BooleanVar(value=self.scraper.identify_background_task())
88
- background_checkbox = tk.Checkbutton(
89
- frame,
90
- text="Daily Background Calculation",
91
- variable=background_checkbox_value,
92
- command=lambda: self._toggle_background_task(background_checkbox_value.get()),
93
- bg=BACKGROUND_COLOR,
94
- fg=FONT_COLOR,
95
- selectcolor=BUTTON_COLOR,
96
- activebackground=BACKGROUND_COLOR,
97
- font=(FONT_STYLE, 10),
114
+ self._add_checkbox(
115
+ checkbox_frame,
116
+ "Daily Background Calculations",
117
+ background_checkbox_value,
118
+ lambda: self._toggle_background_task(background_checkbox_value.get()),
119
+ )
120
+
121
+ discord_webhook_value = tk.BooleanVar(
122
+ value=self.scraper.config.getboolean(
123
+ "App Settings", "discord_notifications", fallback=False
124
+ )
125
+ )
126
+ self._add_checkbox(
127
+ checkbox_frame,
128
+ "Receive Discord Notifications",
129
+ discord_webhook_value,
130
+ lambda: self._toggle_discord_webhook(discord_webhook_value.get()),
131
+ )
132
+
133
+ use_proxy_checkbox_value = tk.BooleanVar(
134
+ value=self.scraper.config.getboolean("App Settings", "use_proxy", fallback=False)
135
+ )
136
+ self._add_checkbox(
137
+ checkbox_frame,
138
+ "Proxy Requests",
139
+ use_proxy_checkbox_value,
140
+ lambda: self._toggle_use_proxy(use_proxy_checkbox_value.get()),
98
141
  )
99
- background_checkbox.pack(pady=20)
100
142
 
101
143
  return window
102
144
 
145
+ def _construct_scraper_command_windows(self):
146
+ """Construct the command to run the scraper in a new window for Windows."""
147
+ get_size = "$size = $Host.UI.RawUI.WindowSize;"
148
+ set_size = "$Host.UI.RawUI.WindowSize = $size;"
149
+ set_window_title = f"$Host.UI.RawUI.WindowTitle = '{APPLICATION_NAME}';"
150
+ set_window_width = (
151
+ f"$size.Width = [Math]::Min({SCRAPER_WINDOW_WIDTH}, $Host.UI.RawUI.BufferSize.Width);"
152
+ )
153
+ set_window_height = f"$size.Height = {SCRAPER_WINDOW_HEIGHT};"
154
+ set_background_color = (
155
+ f"$Host.UI.RawUI.BackgroundColor = '{SCRAPER_WINDOW_BACKGROUND_COLOR}';"
156
+ )
157
+ clear = "Clear-Host;"
158
+
159
+ if RUNNING_IN_EXE:
160
+ # The python executable is set as the executable itself in PyInstaller
161
+ scraper_cmd = f"{PYTHON_EXECUTABLE} --only-scrape | Out-Host -Paging"
162
+ else:
163
+ scraper_cmd = f"{PYTHON_EXECUTABLE} -m cs2tracker --only-scrape"
164
+
165
+ cmd = (
166
+ 'start powershell -NoExit -Command "& {'
167
+ + set_window_title
168
+ + get_size
169
+ + set_window_width
170
+ + set_window_height
171
+ + set_size
172
+ + set_background_color
173
+ + clear
174
+ + scraper_cmd
175
+ + '}"'
176
+ )
177
+ return cmd
178
+
103
179
  def _construct_scraper_command(self):
104
180
  """Construct the command to run the scraper in a new window."""
105
181
  if OS == OSType.WINDOWS:
106
- set_utf8_encoding = "[Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8;"
107
- get_size = "$size = $Host.UI.RawUI.WindowSize;"
108
- set_size = "$Host.UI.RawUI.WindowSize = $size;"
109
- set_window_title = f"$Host.UI.RawUI.WindowTitle = '{SCRAPER_WINDOW_TITLE}';"
110
- set_window_width = f"$size.Width = {SCRAPER_WINDOW_WIDTH};"
111
- set_window_height = f"$size.Height = {SCRAPER_WINDOW_HEIGHT};"
112
- set_background_color = (
113
- f"$Host.UI.RawUI.BackgroundColor = '{SCRAPER_WINDOW_BACKGROUND_COLOR}';"
114
- )
115
- clear = "Clear-Host;"
116
-
117
- if RUNNING_IN_EXE:
118
- # The python executable is set as the executable itself in PyInstaller
119
- scraper_cmd = f"{PYTHON_EXECUTABLE} --only-scrape | Out-Host -Paging"
120
- else:
121
- scraper_cmd = f"{PYTHON_EXECUTABLE} -m cs2tracker --only-scrape"
122
-
123
- cmd = (
124
- 'start powershell -NoExit -Command "& {'
125
- + set_utf8_encoding
126
- + set_window_title
127
- + get_size
128
- + set_window_width
129
- + set_window_height
130
- + set_size
131
- + set_background_color
132
- + clear
133
- + scraper_cmd
134
- + '}"'
135
- )
136
- return cmd
182
+ return self._construct_scraper_command_windows()
137
183
  else:
138
184
  # TODO: Implement for Linux
139
185
  return ""
@@ -181,6 +227,14 @@ class Application:
181
227
  """Toggle whether a daily price calculation should run in the background."""
182
228
  self.scraper.toggle_background_task(enabled)
183
229
 
230
+ def _toggle_use_proxy(self, enabled: bool):
231
+ """Toggle whether the scraper should use proxy servers for requests."""
232
+ self.scraper.toggle_use_proxy(enabled)
233
+
234
+ def _toggle_discord_webhook(self, enabled: bool):
235
+ """Toggle whether the scraper should send notifications to a Discord webhook."""
236
+ self.scraper.toggle_discord_webhook(enabled)
237
+
184
238
 
185
239
  def _popen_and_call(popen_args, callback):
186
240
  """