Skip to content

Commit c9f89e7

Browse files
Copilotkoderzi
andcommitted
Add browser GUI support with desktop-lite feature
Co-authored-by: koderzi <30676109+koderzi@users.noreply.github.com>
1 parent 703757d commit c9f89e7

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed

.devcontainer/cmd/setup-git

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
echo -e "\n"
4+
5+
# Check if git username is configured
6+
if [[ -z $(git config --global user.name) ]]; then
7+
read -p "Enter Git username: " username
8+
if [[ -n "$username" ]]; then
9+
git config --global user.name "$username"
10+
echo -e "Git username '$username' has been set.\n"
11+
else
12+
echo -e "Git username was not provided.\n"
13+
fi
14+
fi
15+
16+
# Check if git email is configured
17+
if [[ -z $(git config --global user.email) ]]; then
18+
read -p "Enter Git email: " email
19+
if [[ -n "$email" ]]; then
20+
git config --global user.email "$email"
21+
echo -e "Git email '$email' has been set.\n"
22+
else
23+
echo -e "Git email was not provided.\n"
24+
fi
25+
fi
26+
27+
28+
if [[ -n $(git config --global user.name) && -n $(git config --global user.email) ]]; then
29+
echo -e "\n"
30+
echo -e "Configured git.\n"
31+
fi

.devcontainer/devcontainer.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@
66
"all",
77
"--runtime=nvidia"
88
],
9+
"forwardPorts": [
10+
"0:6080"
11+
],
12+
"portsAttributes": {
13+
"0:6080": {
14+
"label": "Desktop GUI",
15+
"onAutoForward": "openBrowser"
16+
}
17+
},
18+
"features": {
19+
"ghcr.io/devcontainers/features/desktop-lite:1": {}
20+
},
921
"customizations": {
1022
"vscode": {
23+
"settings": {
24+
"git.ignoreMissingGitWarning": true
25+
},
1126
"extensions": [
1227
"ms-toolsai.jupyter",
1328
"ms-toolsai.vscode-jupyter-cell-tags",
@@ -20,5 +35,7 @@
2035
"ms-python.vscode-python-envs"
2136
]
2237
}
23-
}
38+
},
39+
"shutdownAction": "stopContainer",
40+
"postAttachCommand": "${containerWorkspaceFolder}/.devcontainer/cmd/setup-git"
2441
}

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
This repository is a lightweight template for a reproducible Python development environment using Docker and VS Code Dev Containers. It is pre-configured to optionally leverage an NVIDIA GPU when available, so you can work on data science, ML, or general Python projects without polluting your host system.
66

7+
**New Feature**: This environment now includes a browser-accessible desktop GUI, allowing you to run graphical Python applications (like matplotlib, tkinter, PyQt, etc.) directly in your browser without needing X11 forwarding or VNC clients.
8+
79
## Prerequisite
810

911
Before using this repository, you need to have the following installed on your system:
@@ -12,6 +14,14 @@ Before using this repository, you need to have the following installed on your s
1214
- VSCode with Dev Container extension installed
1315
- Alternative: Remote Repositories extension of VSCode
1416

17+
## Key Features
18+
19+
* **Browser-Based GUI**: Access a full Linux desktop environment directly in your browser for running GUI applications
20+
* **No Port Collisions**: Dynamic port mapping allows multiple instances without conflicts
21+
* **NVIDIA GPU Support**: Pre-configured for GPU acceleration when available
22+
* **Python Version Management**: Easy switching between Python versions using mise
23+
* **Isolated Environment**: All dependencies are containerized, keeping your host system clean
24+
1525
## How to use
1626

1727
To use this repository, follow the steps below:
@@ -33,3 +43,72 @@ What py-init does
3343
- Creates/updates a local mise.toml in the current directory.
3444
- Uses mise to select the requested Python version.
3545
- Configures the local virtualenv path to .venv and enables automatic creation.
46+
47+
## Browser GUI Desktop
48+
49+
This development environment includes a browser-accessible desktop GUI for running graphical Python applications.
50+
51+
### Accessing the Desktop
52+
53+
When you open the container in VS Code:
54+
55+
1. **Automatic Access**: VS Code will automatically forward port 6080 and open the desktop in your browser
56+
2. **Manual Access**:
57+
- Look at the **PORTS** tab in VS Code's bottom panel
58+
- Find port **6080** labeled **"Desktop GUI"**
59+
- Click the **globe icon** (🌐) to open it in your browser
60+
61+
### Using GUI Applications
62+
63+
The browser desktop allows you to run any graphical Python application:
64+
65+
**Example: Matplotlib**
66+
```python
67+
import matplotlib.pyplot as plt
68+
import numpy as np
69+
70+
x = np.linspace(0, 10, 100)
71+
y = np.sin(x)
72+
73+
plt.figure(figsize=(10, 6))
74+
plt.plot(x, y)
75+
plt.title('Sine Wave')
76+
plt.xlabel('X')
77+
plt.ylabel('Y')
78+
plt.grid(True)
79+
plt.show()
80+
```
81+
82+
**Example: Tkinter**
83+
```python
84+
import tkinter as tk
85+
86+
root = tk.Tk()
87+
root.title("Hello Python GUI")
88+
root.geometry("300x200")
89+
90+
label = tk.Label(root, text="Hello from Python!", font=("Arial", 16))
91+
label.pack(pady=50)
92+
93+
button = tk.Button(root, text="Click Me", command=lambda: label.config(text="Button Clicked!"))
94+
button.pack()
95+
96+
root.mainloop()
97+
```
98+
99+
Run these scripts in the VS Code terminal, and the GUI windows will appear in your browser desktop tab.
100+
101+
### Desktop Features
102+
103+
* Full Linux desktop environment (XFCE)
104+
* Window management (minimize, maximize, close)
105+
* File manager
106+
* Terminal applications
107+
* Clipboard support (with some limitations)
108+
109+
### Tips for GUI Development
110+
111+
1. **Keep Browser Tab Open**: Keep the browser desktop tab open while developing GUI applications
112+
2. **Multiple Windows**: You can open multiple application windows simultaneously
113+
3. **Full Screen Mode**: Use F11 in most browsers for full-screen mode
114+
4. **Zoom Controls**: Use browser zoom (Ctrl/Cmd + Plus/Minus) to adjust display size

0 commit comments

Comments
 (0)