|
16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
|
18 | 18 | import os |
| 19 | +import sys |
19 | 20 | import pathlib |
20 | 21 | import re |
| 22 | +import shutil |
| 23 | +import subprocess |
21 | 24 |
|
22 | 25 | from gns3.controller import Controller |
23 | 26 | from gns3.ports.ethernet_port import EthernetPort |
@@ -740,18 +743,30 @@ def bringToFront(self): |
740 | 743 | """ |
741 | 744 |
|
742 | 745 | if self.status() == Node.started: |
743 | | - console_command = self.consoleCommand() |
744 | | - if console_command: |
745 | | - process_name = console_command.split()[0] |
746 | | - if bring_window_to_front_from_process_name(process_name, self.name()): |
| 746 | + if sys.platform.startswith("linux"): |
| 747 | + wmctrl_path = shutil.which("wmctrl") |
| 748 | + if wmctrl_path: |
| 749 | + try: |
| 750 | + # use wmctrl to raise the window based on the node name (this doesn't work well with window having multiple tabs) |
| 751 | + subprocess.run([wmctrl_path, "-a", self.name()], check=True, env=os.environ) |
| 752 | + return True |
| 753 | + except subprocess.CalledProcessError: |
| 754 | + log.debug("Could not find window title '{}' to bring it to front".format(self.name())) |
| 755 | + except OSError as e: |
| 756 | + log.warning("Count not focus on terminal window: '{}'".format(e)) |
| 757 | + elif sys.platform.startswith("win"): |
| 758 | + console_command = self.consoleCommand() |
| 759 | + if console_command: |
| 760 | + process_name = console_command.split()[0] |
| 761 | + if bring_window_to_front_from_process_name(process_name, self.name()): |
| 762 | + return True |
| 763 | + else: |
| 764 | + log.debug("Could not find process name '' and window title '{}' to bring it to front".format(process_name, self.name())) |
| 765 | + |
| 766 | + if bring_window_to_front_from_title(self.name()): |
747 | 767 | return True |
748 | 768 | else: |
749 | | - log.debug("Could not find process name '' and window title '{}' to bring it to front".format(process_name, self.name())) |
750 | | - |
751 | | - if bring_window_to_front_from_title(self.name()): |
752 | | - return True |
753 | | - else: |
754 | | - log.debug("Could not find window title '{}' to bring it to front".format(self.name())) |
| 769 | + log.debug("Could not find window title '{}' to bring it to front".format(self.name())) |
755 | 770 | return False |
756 | 771 |
|
757 | 772 | def importFile(self, path, source_path): |
|
0 commit comments