Skip to content

Commit c3ccbfe

Browse files
committed
Merge branch '2.2' into 3.0
# Conflicts: # setup.py
2 parents de38c4a + 714dae4 commit c3ccbfe

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

gns3/graphics_view.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def mouseDoubleClickEvent(self, event):
664664
self.configureSlot()
665665
return
666666
else:
667-
if sys.platform.startswith("win") and item.node().bringToFront():
667+
if item.node().bringToFront():
668668
return
669669
self.consoleFromItems(self.scene().selectedItems())
670670
return
@@ -870,8 +870,8 @@ def populateDeviceContextualMenu(self, menu):
870870
show_in_file_manager_action.triggered.connect(self.showInFileManagerSlot)
871871
menu.addAction(show_in_file_manager_action)
872872

873-
if sys.platform.startswith("win") and True in list(map(lambda item: isinstance(item, NodeItem) and hasattr(item.node(), "bringToFront"), items)):
874-
# Action: bring console or window to front (Windows only)
873+
if not sys.platform.startswith("darwin") and True in list(map(lambda item: isinstance(item, NodeItem) and hasattr(item.node(), "bringToFront"), items)):
874+
# Action: bring console or window to front (Windows and Linux only)
875875
bring_to_front_action = QtWidgets.QAction("Bring to front", menu)
876876
bring_to_front_action.setIcon(get_icon("front.svg"))
877877
bring_to_front_action.triggered.connect(self.bringToFrontSlot)

gns3/modules/virtualbox/virtualbox_vm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""
1919
VirtualBox VM implementation.
2020
"""
21+
import sys
2122

2223
from gns3.node import Node
2324
from gns3.utils.bring_to_front import bring_window_to_front_from_process_name
@@ -100,7 +101,7 @@ def bringToFront(self):
100101
Bring the VM window to front.
101102
"""
102103

103-
if self.status() == Node.started:
104+
if self.status() == Node.started and sys.platform.startswith("win"):
104105
# try 2 different window title formats
105106
bring_window_to_front_from_process_name("VirtualBox.exe", title="{} [".format(self._settings["vmname"]))
106107
bring_window_to_front_from_process_name("VirtualBox.exe", title="{} (".format(self._settings["vmname"]))

gns3/modules/vmware/vmware_vm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
VMware VM implementation.
2020
"""
2121

22+
import sys
23+
2224
from gns3.qt import QtCore
2325
from gns3.node import Node
2426
from gns3.utils.bring_to_front import bring_window_to_front_from_process_name
@@ -124,7 +126,7 @@ def bringToFront(self):
124126
Bring the VM window to front.
125127
"""
126128

127-
if self.status() == Node.started:
129+
if self.status() == Node.started and sys.platform.startswith("win"):
128130
try:
129131
vmx_pairs = self.module().parseVMwareFile(self.settings()["vmx_path"])
130132
except OSError as e:

gns3/node.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

1818
import os
19+
import sys
1920
import pathlib
2021
import re
22+
import shutil
23+
import subprocess
2124

2225
from gns3.controller import Controller
2326
from gns3.ports.ethernet_port import EthernetPort
@@ -803,18 +806,30 @@ def bringToFront(self):
803806
"""
804807

805808
if self.status() == Node.started:
806-
console_command = self.consoleCommand()
807-
if console_command:
808-
process_name = console_command.split()[0]
809-
if bring_window_to_front_from_process_name(process_name, self.name()):
809+
if sys.platform.startswith("linux"):
810+
wmctrl_path = shutil.which("wmctrl")
811+
if wmctrl_path:
812+
try:
813+
# use wmctrl to raise the window based on the node name (this doesn't work well with window having multiple tabs)
814+
subprocess.run([wmctrl_path, "-a", self.name()], check=True, env=os.environ)
815+
return True
816+
except subprocess.CalledProcessError:
817+
log.debug("Could not find window title '{}' to bring it to front".format(self.name()))
818+
except OSError as e:
819+
log.warning("Count not focus on terminal window: '{}'".format(e))
820+
elif sys.platform.startswith("win"):
821+
console_command = self.consoleCommand()
822+
if console_command:
823+
process_name = console_command.split()[0]
824+
if bring_window_to_front_from_process_name(process_name, self.name()):
825+
return True
826+
else:
827+
log.debug("Could not find process name '' and window title '{}' to bring it to front".format(process_name, self.name()))
828+
829+
if bring_window_to_front_from_title(self.name()):
810830
return True
811831
else:
812-
log.debug("Could not find process name '' and window title '{}' to bring it to front".format(process_name, self.name()))
813-
814-
if bring_window_to_front_from_title(self.name()):
815-
return True
816-
else:
817-
log.debug("Could not find window title '{}' to bring it to front".format(self.name()))
832+
log.debug("Could not find window title '{}' to bring it to front".format(self.name()))
818833
return False
819834

820835
def importFile(self, path, source_path):

gns3/telnet_console.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import shlex
2727
import subprocess
2828
import psutil
29+
import shutil
2930

3031
from .main_window import MainWindow
3132
from .controller import Controller
@@ -102,7 +103,16 @@ def exec_command(self, command):
102103
# inject gnome-terminal environment variables
103104
if "GNOME_TERMINAL_SERVICE" not in env or "GNOME_TERMINAL_SCREEN" not in env:
104105
env.update(gnome_terminal_env())
105-
subprocess.Popen(args, env=env)
106+
proc = subprocess.Popen(args, env=env)
107+
if sys.platform.startswith("linux"):
108+
wmctrl_path = shutil.which("wmctrl")
109+
if wmctrl_path:
110+
proc.wait() # wait for the terminal to open
111+
try:
112+
# use wmctrl to raise the window based on the node name
113+
subprocess.run([wmctrl_path, "-a", self._name], env=os.environ)
114+
except OSError as e:
115+
self.consoleError.emit("Count not focus on terminal window: '{}'".format(e))
106116

107117
def run(self):
108118

0 commit comments

Comments
 (0)