Minimize console window when run in GUI mode

This commit is contained in:
Orsiris de Jong 2023-02-05 17:41:39 +01:00
parent de0f4693dd
commit 9e4283a56c
3 changed files with 35 additions and 2 deletions

View file

@ -10,7 +10,7 @@ __description__ = "NetPerfect Backup Client"
__copyright__ = "Copyright (C) 2022-2023 NetInvent"
__license__ = "GPL-3.0-only"
__build__ = "2023013102"
__version__ = "2.2.0-rc2"
__version__ = "2.2.0-rc3"
import os
@ -41,6 +41,7 @@ from npbackup.core.i18n_helper import _t
from npbackup.path_helper import CURRENT_DIR, CURRENT_EXECUTABLE
from npbackup.upgrade_client.upgrader import need_upgrade
from npbackup.core.upgrade_runner import run_upgrade
from npbackup.gui.minimize_window import minimize_current_window
del sys.path[0]
@ -444,6 +445,9 @@ This is free software, and you are welcome to redistribute it under certain cond
# EXIT_CODE 21 = current backup process already running
sys.exit(21)
# When no argument is given, let's run the GUI
# Also, let's minimize the commandline window so the GUI user isn't distracted
minimize_current_window()
logger.info("Running GUI")
try:
version_string = "{} v{} {}\n{}".format(

View file

@ -0,0 +1,28 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of npbackup
__intname__ = "npbackup.gui.window_reducer"
__author__ = "Orsiris de Jong"
__copyright__ = "Copyright (C) 2022-2023 NetInvent"
__license__ = "GPL-3.0-only"
__build__ = "2023020501"
import sys
import os
import win32gui
import win32con
def minimize_current_window():
"""
Minimizes current commandline window in GUI mode
"""
if os.name == 'nt':
current_executable = os.path.abspath(sys.argv[0])
# console window will have the name of current executable
hwndMain = win32gui.FindWindow(None, current_executable)
if hwndMain:
win32gui.ShowWindow(hwndMain, win32con.SW_MINIMIZE)

View file

@ -16,3 +16,4 @@ pyyaml # Required for python-i18n which does not work with ruamel.yaml
python-i18n
# python-i18n local copy from https://github.com/Krutyi-4el/python-i18n:
packaging
pywin32; platform_system == "Windows"