-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from BlackSound1/gpu-testing
Added GPU functionality
- Loading branch information
Showing
22 changed files
with
418 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ name = "pypi" | |
textual = "*" | ||
psutil = "*" | ||
idna = "*" | ||
wmi = "*" | ||
|
||
[dev-packages] | ||
flake8 = "*" | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,75 @@ | ||
from textual.app import ComposeResult | ||
from textual.containers import VerticalScroll | ||
from textual.css.query import NoMatches | ||
from textual.reactive import reactive | ||
from textual.widgets import Static | ||
|
||
from src.utilities import get_gpu_data, RARE_INTERVAL | ||
|
||
|
||
class GPU_Usage(Static): | ||
BORDER_TITLE = "GPU Usage" | ||
BORDER_TITLE = "GPU Info" | ||
BORDER_SUBTITLE = f"Updated every {RARE_INTERVAL} seconds" | ||
|
||
gpu_data = reactive(get_gpu_data()) | ||
|
||
def update_gpu_data(self) -> None: | ||
""" | ||
Update GPU data | ||
:return: None | ||
""" | ||
self.gpu_data = get_gpu_data() | ||
|
||
def watch_gpu_data(self, gpu_data: list) -> None: | ||
""" | ||
Watch `gpu_data` and update the Static Widget with the new information | ||
:param gpu_data: The list of new GPU data | ||
:return: None | ||
""" | ||
|
||
# First, grab the Static Widget | ||
try: | ||
static = self.query_one("#gpu-static", Static) | ||
except NoMatches: | ||
return | ||
|
||
static_content = "" | ||
|
||
# Then, for each video controller, update the Static Widget with its new information | ||
for gpu in gpu_data: | ||
static_content += ( | ||
f"[green]GPU[/]: {gpu['gpu']}\n" | ||
f"[green]Driver Version[/]: {gpu['driver_version']}\n" | ||
f"[green]Resolution[/]: {gpu['resolution']}\n" | ||
f"[green]Adapter RAM[/]: {gpu['adapter_ram']}\n" | ||
f"[green]Availability[/]: {gpu['availability']}\n" | ||
f"[green]Refresh[/]: {gpu['refresh']} Hz\n" | ||
f"[green]Status[/]: {gpu['status']}\n" | ||
) | ||
|
||
static.update(static_content) | ||
|
||
def on_mount(self) -> None: | ||
self.update("This will display current GPU usage") | ||
""" | ||
Set interval to update the memory information. | ||
:return: None | ||
""" | ||
self.update_gpu_data = self.set_interval(RARE_INTERVAL, self.update_gpu_data) | ||
|
||
def on_click(self) -> None: | ||
""" | ||
When this pane is clicked, switch to the GPU screen | ||
:return: None | ||
""" | ||
self.app.switch_mode("gpu") | ||
|
||
def compose(self) -> ComposeResult: | ||
""" | ||
Generate a ComposeResult by yielding a vertically-scrolling Static widget with the GPU information. | ||
:return: The ComposeResult | ||
""" | ||
|
||
with VerticalScroll(): | ||
yield Static(id="gpu-static") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from textual.app import ComposeResult | ||
from textual.containers import Container, VerticalScroll | ||
from textual.css.query import NoMatches | ||
from textual.reactive import reactive | ||
from textual.screen import Screen | ||
from textual.widgets import Header, Footer, DataTable | ||
|
||
from src.utilities import RARE_INTERVAL, get_gpu_data | ||
|
||
|
||
class GPU_Screen(Screen): | ||
BORDER_TITLE = "GPU Info" | ||
BORDER_SUBTITLE = f"Updated every {RARE_INTERVAL} seconds" | ||
CSS_PATH = "../styles/gpu_css.tcss" | ||
BINDINGS = [ | ||
("q", "quit", "Quit"), | ||
("t", "toggle_dark", "Toggle dark mode"), | ||
("p", "switch_mode('processes')", "Processes"), | ||
("c", "switch_mode('cpu')", "CPU"), | ||
("n", "switch_mode('network')", "Network"), | ||
("d", "switch_mode('drive')", "Drives"), | ||
("m", "switch_mode('mem')", "Memory"), | ||
("v", "switch_mode('main')", "Main Screen"), | ||
] | ||
|
||
gpu_data = reactive(get_gpu_data()) | ||
|
||
def update_gpu_data(self) -> None: | ||
""" | ||
Update GPU data | ||
:return: None | ||
""" | ||
self.gpu_data = get_gpu_data() | ||
|
||
def watch_gpu_data(self, gpu_data: list) -> None: | ||
""" | ||
Watch `gpu_data` and update the Static Widget with the new information | ||
:param gpu_data: The list of new GPU data | ||
:return: None | ||
""" | ||
|
||
# First, grab the Static Widget | ||
try: | ||
table = self.query_one("#gpu-screen-table", expect_type=DataTable) | ||
except NoMatches: | ||
return | ||
|
||
# Clear the table and add the columns | ||
table.clear(columns=True) | ||
table.add_columns("GPU", "Driver Version", "Resolution", "Adapter RAM", | ||
"Availability", "Refresh", "Status") | ||
|
||
# Then, for each video controller, update the Static Widget with its new information | ||
for gpu in gpu_data: | ||
name = gpu['gpu'] | ||
version = gpu['driver_version'] | ||
resolution = gpu['resolution'] | ||
ram = gpu['adapter_ram'] | ||
availability = gpu['availability'] | ||
refresh = gpu['refresh'] | ||
status = gpu['status'] | ||
|
||
table.add_row(name, version, resolution, ram, availability, refresh, status) | ||
|
||
def on_mount(self) -> None: | ||
""" | ||
Perform initial setup for the GPU Screen | ||
:return: None | ||
""" | ||
|
||
self.update_gpu_data = self.set_interval(RARE_INTERVAL, self.update_gpu_data) | ||
|
||
try: | ||
container = self.query_one("#gpu-container", expect_type=Container) | ||
except NoMatches: | ||
return | ||
|
||
container.border_title = self.BORDER_TITLE | ||
container.border_subtitle = self.BORDER_SUBTITLE | ||
|
||
def compose(self) -> ComposeResult: | ||
""" | ||
Display the structure of the GPU Screen | ||
:return: The ComposeResult featuring the structure of the GPU Screen | ||
""" | ||
|
||
yield Header(show_clock=True) | ||
with Container(id="gpu-container"): | ||
with VerticalScroll(): | ||
yield DataTable(id="gpu-screen-table", show_cursor=False, zebra_stripes=True) | ||
yield Footer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#gpu-container { | ||
background: $panel; | ||
border: pink; | ||
border-title-color: $text; | ||
border-title-align: center; | ||
border-subtitle-color: $text; | ||
border-subtitle-align: center; | ||
} | ||
|
||
#gpu-container:light { | ||
border: deeppink; | ||
background: $boost-darken-1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.