changes for initial gui setup and discovery of the terminal program to use, avoid using TERM env variable
This commit is contained in:
parent
fd2a5ec290
commit
34895c1f9c
3 changed files with 30 additions and 34 deletions
|
@ -25,17 +25,16 @@ LOCAL_XMLS_PATH = DATA_PATH.joinpath("xmls").absolute()
|
||||||
LOCAL_MOBILITY_PATH = DATA_PATH.joinpath("mobility").absolute()
|
LOCAL_MOBILITY_PATH = DATA_PATH.joinpath("mobility").absolute()
|
||||||
|
|
||||||
# configuration data
|
# configuration data
|
||||||
TERMINALS = [
|
TERMINALS = {
|
||||||
"$TERM",
|
"xterm": "xterm -e",
|
||||||
"gnome-terminal --window --",
|
"aterm": "aterm -e",
|
||||||
"lxterminal -e",
|
"eterm": "eterm -e",
|
||||||
"konsole -e",
|
"rxvt": "rxvt -e",
|
||||||
"xterm -e",
|
"konsole": "konsole -e",
|
||||||
"aterm -e",
|
"lxterminal": "lxterminal -e",
|
||||||
"eterm -e",
|
"xfce4-terminal": "xfce4-terminal -x",
|
||||||
"rxvt -e",
|
"gnome-terminal": "gnome-terminal --window --",
|
||||||
"xfce4-terminal -x",
|
}
|
||||||
]
|
|
||||||
EDITORS = ["$EDITOR", "vim", "emacs", "gedit", "nano", "vi"]
|
EDITORS = ["$EDITOR", "vim", "emacs", "gedit", "nano", "vi"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +49,14 @@ def copy_files(current_path, new_path):
|
||||||
shutil.copy(current_file, new_file)
|
shutil.copy(current_file, new_file)
|
||||||
|
|
||||||
|
|
||||||
|
def find_terminal():
|
||||||
|
for term in sorted(TERMINALS):
|
||||||
|
cmd = TERMINALS[term]
|
||||||
|
if shutil.which(term):
|
||||||
|
return cmd
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def check_directory():
|
def check_directory():
|
||||||
if HOME_PATH.exists():
|
if HOME_PATH.exists():
|
||||||
return
|
return
|
||||||
|
@ -66,10 +73,7 @@ def check_directory():
|
||||||
copy_files(LOCAL_XMLS_PATH, XMLS_PATH)
|
copy_files(LOCAL_XMLS_PATH, XMLS_PATH)
|
||||||
copy_files(LOCAL_MOBILITY_PATH, MOBILITY_PATH)
|
copy_files(LOCAL_MOBILITY_PATH, MOBILITY_PATH)
|
||||||
|
|
||||||
if "TERM" in os.environ:
|
terminal = find_terminal()
|
||||||
terminal = TERMINALS[0]
|
|
||||||
else:
|
|
||||||
terminal = TERMINALS[1]
|
|
||||||
if "EDITOR" in os.environ:
|
if "EDITOR" in os.environ:
|
||||||
editor = EDITORS[0]
|
editor = EDITORS[0]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,6 +5,7 @@ import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from tkinter import messagebox
|
||||||
from typing import TYPE_CHECKING, Dict, List
|
from typing import TYPE_CHECKING, Dict, List
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
|
@ -38,17 +39,6 @@ OBSERVERS = {
|
||||||
"IPSec policies": "setkey -DP",
|
"IPSec policies": "setkey -DP",
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_TERMS = {
|
|
||||||
"xterm": "xterm -e",
|
|
||||||
"aterm": "aterm -e",
|
|
||||||
"eterm": "eterm -e",
|
|
||||||
"rxvt": "rxvt -e",
|
|
||||||
"konsole": "konsole -e",
|
|
||||||
"lxterminal": "lxterminal -e",
|
|
||||||
"xfce4-terminal": "xfce4-terminal -x",
|
|
||||||
"gnome-terminal": "gnome-terminal --window --",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class CoreServer:
|
class CoreServer:
|
||||||
def __init__(self, name: str, address: str, port: int):
|
def __init__(self, name: str, address: str, port: int):
|
||||||
|
@ -571,11 +561,15 @@ class CoreClient:
|
||||||
def launch_terminal(self, node_id: int):
|
def launch_terminal(self, node_id: int):
|
||||||
try:
|
try:
|
||||||
terminal = self.app.guiconfig["preferences"]["terminal"]
|
terminal = self.app.guiconfig["preferences"]["terminal"]
|
||||||
|
if not terminal:
|
||||||
|
messagebox.showerror(
|
||||||
|
"Terminal Error",
|
||||||
|
"No terminal set, please set within the preferences menu",
|
||||||
|
parent=self.app,
|
||||||
|
)
|
||||||
|
return
|
||||||
response = self.client.get_node_terminal(self.session_id, node_id)
|
response = self.client.get_node_terminal(self.session_id, node_id)
|
||||||
output = os.popen(f"echo {terminal}").read()[:-1]
|
cmd = f"{terminal} {response.terminal} &"
|
||||||
if output in DEFAULT_TERMS:
|
|
||||||
terminal = DEFAULT_TERMS[output]
|
|
||||||
cmd = f'{terminal} "{response.terminal}" &'
|
|
||||||
logging.info("launching terminal %s", cmd)
|
logging.info("launching terminal %s", cmd)
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
except grpc.RpcError as e:
|
except grpc.RpcError as e:
|
||||||
|
|
|
@ -56,11 +56,9 @@ class PreferencesDialog(Dialog):
|
||||||
|
|
||||||
label = ttk.Label(frame, text="Terminal")
|
label = ttk.Label(frame, text="Terminal")
|
||||||
label.grid(row=2, column=0, pady=PADY, padx=PADX, sticky="w")
|
label.grid(row=2, column=0, pady=PADY, padx=PADX, sticky="w")
|
||||||
|
terminals = sorted(appconfig.TERMINALS.values())
|
||||||
combobox = ttk.Combobox(
|
combobox = ttk.Combobox(
|
||||||
frame,
|
frame, textvariable=self.terminal, values=terminals, state="readonly"
|
||||||
textvariable=self.terminal,
|
|
||||||
values=appconfig.TERMINALS,
|
|
||||||
state="readonly",
|
|
||||||
)
|
)
|
||||||
combobox.grid(row=2, column=1, sticky="ew")
|
combobox.grid(row=2, column=1, sticky="ew")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue