-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathteradicislider.py
More file actions
174 lines (153 loc) · 6.62 KB
/
teradicislider.py
File metadata and controls
174 lines (153 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import tkinter as tk
from tkinter import messagebox
import subprocess
import os
class PCoIPImageQualityApp:
def __init__(self, root, config_file="/etc/pcoip-agent/pcoip-agent.conf"):
self.root = root
self.config_file = config_file
self.root.overrideredirect(True) # Remove window title bar and decorations
self.root.title("Teradici Quality") # Title won't be visible
# Set window to always stay on top
self.root.attributes('-topmost', True)
# Variables for dragging
self.drag_start_x = 0
self.drag_start_y = 0
# Define colors
self.dark_grey = "#333333" # Background color
self.text_grey = "#A6A6A6" # 65% grey for text and slider number
# Create a background frame for dragging
self.drag_frame = tk.Frame(self.root, bg=self.dark_grey, width=250, height=110)
self.drag_frame.pack(fill="both", expand=True)
self.drag_frame.pack_propagate(False) # Prevent frame from resizing
# Bind drag events to the background frame
self.drag_frame.bind("<Button-1>", self.start_drag)
self.drag_frame.bind("<B1-Motion>", self.on_drag)
# Check if crudini is installed
if not self.check_crudini():
messagebox.showerror("Error", "crudini is not installed. Please install it using 'sudo dnf install crudini'.")
self.root.destroy()
return
# Check if config file exists
if not os.path.exists(self.config_file):
messagebox.showerror("Error", f"Configuration file {self.config_file} not found.")
self.root.destroy()
return
# Get initial value
self.current_quality = self.get_current_quality()
# Create and configure the label
self.label = tk.Label(
self.drag_frame,
text="Teradici Quality",
font=("Helvetica", 10), # 10-point font
bg=self.dark_grey, # Match background
fg=self.text_grey # 65% grey text
)
self.label.pack(pady=(5, 0)) # Reduced padding
# Create and configure the slider
self.slider = tk.Scale(
self.drag_frame,
from_=0,
to=100,
orient=tk.HORIZONTAL,
length=235,
width=15,
sliderlength=40,
resolution=5, # Move in increments of 5
command=self.update_quality,
bg=self.dark_grey, # Background of slider
fg=self.text_grey, # 65% grey for tick mark labels
troughcolor=self.dark_grey, # Slider track color
highlightthickness=0 # Remove border highlight
)
self.slider.set(self.current_quality)
self.slider.pack(pady=(2, 5)) # Reduced padding
# Create a frame for buttons
self.button_frame = tk.Frame(self.drag_frame, bg=self.dark_grey)
self.button_frame.pack(pady=5) # Reduced padding
# Default button
self.default_button = tk.Button(
self.button_frame,
text="Default",
font=("Helvetica", 10), # 10-point font
command=self.set_default_quality,
bg=self.dark_grey, # Button background
fg=self.text_grey, # 65% grey text
activebackground="#555555", # Slightly lighter grey when clicked
highlightthickness=0 # Remove border highlight
)
self.default_button.pack(side=tk.LEFT, padx=5)
# Exit button
self.exit_button = tk.Button(
self.button_frame,
text="Exit",
font=("Helvetica", 10), # 10-point font
command=self.root.destroy,
bg=self.dark_grey, # Button background
fg=self.text_grey, # 65% grey text
activebackground="#555555", # Slightly lighter grey when clicked
highlightthickness=0 # Remove border highlight
)
self.exit_button.pack(side=tk.LEFT, padx=5)
def start_drag(self, event):
self.drag_start_x = event.x_root - self.root.winfo_x()
self.drag_start_y = event.y_root - self.root.winfo_y()
def on_drag(self, event):
x = event.x_root - self.drag_start_x
y = event.y_root - self.drag_start_y
self.root.geometry(f"+{x}+{y}")
def check_crudini(self):
try:
subprocess.run(["crudini", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
return False
def get_current_quality(self):
try:
result = subprocess.run(
["crudini", "--get", self.config_file, "quality", "pcoip.maximum_initial_image_quality"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
return int(result.stdout.strip())
except (subprocess.CalledProcessError, ValueError):
return 85
def update_quality(self, value):
try:
quality = int(value)
subprocess.run(
["sudo", "crudini", "--set", self.config_file, "quality", "pcoip.maximum_initial_image_quality", str(quality)],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
except subprocess.CalledProcessError as e:
messagebox.showerror("Error", f"Failed to update quality: {e.stderr}")
def set_default_quality(self):
try:
quality = 80
subprocess.run(
["sudo", "crudini", "--set", self.config_file, "quality", "pcoip.maximum_initial_image_quality", str(quality)],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
self.slider.set(quality)
except subprocess.CalledProcessError as e:
messagebox.showerror("Error", f"Failed to set default quality: {e.stderr}")
if __name__ == "__main__":
root = tk.Tk()
# Center the window
window_width = 250
window_height = 110
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
root.geometry(f"{window_width}x{window_height}+{x}+{y}")
app = PCoIPImageQualityApp(root)
root.mainloop()