Skip to content

Commit

Permalink
Build Windows client console exe (#450) (#631)
Browse files Browse the repository at this point in the history
* Add Utils support for Windows console

* Avoid GraphicalUI if Windows Console

* Don't show GuiConfig for EXE console

* Add enter-to-exit prompt when EXE console is missing args

* Build syncplayConsole EXE

* Fix isWindowsConsole() check

* Limit stderr->blackhole code to Windows client console EXEs
  • Loading branch information
Et0h authored Oct 11, 2023
1 parent 7456a94 commit 20846ca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
4 changes: 1 addition & 3 deletions buildPy2exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,7 @@ def run(self):
"icon_resources": [(1, "syncplay\\resources\\icon.ico")],
'dest_base': "Syncplay"},
],
console=['syncplayServer.py'],
# *** If you wish to make the Syncplay client use console mode (for --no-gui to work) then comment out the above two lines and uncomment the following line:
# console=['syncplayServer.py', {"script":"syncplayClient.py", "icon_resources":[(1, "resources\\icon.ico")], 'dest_base': "Syncplay"}],
console=['syncplayServer.py', {"script":"syncplayClient.py", "icon_resources":[(1, "syncplay\\resources\\icon.ico")], 'dest_base': "SyncplayConsole"}],

options={
'py2exe': {
Expand Down
6 changes: 4 additions & 2 deletions syncplay/ui/ConfigurationGetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,12 @@ def _checkConfig(self):
sys.exit()

def _promptForMissingArguments(self, error=None):
if self._config['noGui']:
if self._config['noGui'] or utils.isWindowsConsole():
if error:
print("{}!".format(error))
print(getMessage("missing-arguments-error"))
if utils.isWindowsConsole():
input(getMessage("enter-to-exit-prompt"))
sys.exit()
else:
from syncplay.ui.GuiConfiguration import GuiConfiguration
Expand Down Expand Up @@ -550,7 +552,7 @@ def getConfiguration(self):
# Arguments not validated yet - booleans are still text values
if self._config['language']:
setLanguage(self._config['language'])
if (self._config['forceGuiPrompt'] == "True" or not self._config['file']) and not self._config['noGui']:
if (self._config['forceGuiPrompt'] == "True" or not self._config['file']) and not self._config['noGui'] and not utils.isWindowsConsole():
self._forceGuiPrompt()
self._checkConfig()
self._saveConfig(iniPath)
Expand Down
12 changes: 7 additions & 5 deletions syncplay/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import os
from syncplay.utils import isWindowsConsole

if "QT_PREFERRED_BINDING" not in os.environ:
os.environ["QT_PREFERRED_BINDING"] = os.pathsep.join(
["PySide6", "PySide2", "PySide", "PyQt5", "PyQt4"]
)

try:
from syncplay.ui.gui import MainWindow as GraphicalUI
except ImportError:
pass
if not isWindowsConsole():
try:
from syncplay.ui.gui import MainWindow as GraphicalUI
except ImportError:
pass
from syncplay.ui.consoleUI import ConsoleUI


def getUi(graphical=True, passedBar=None):
if graphical:
if graphical and not isWindowsConsole():
ui = GraphicalUI(passedBar=passedBar)
else:
ui = ConsoleUI()
Expand Down
24 changes: 24 additions & 0 deletions syncplay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def isMacOS():
def isBSD():
return constants.OS_BSD in sys.platform or sys.platform.startswith(constants.OS_DRAGONFLY)

def isWindowsConsole():
return os.path.basename(sys.executable) == "SyncplayConsole.exe"

def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
"""Retry calling the decorated function using an exponential backoff.
Expand Down Expand Up @@ -225,6 +227,28 @@ def flush(self):
sys.stdout = Blackhole()
del Blackhole

elif isWindowsConsole():
class Blackhole(object):
softspace = 0

def write(self, text):
pass

def flush(self):
pass

class Stderr(object):
softspace = 0
_file = None
_error = None

def flush(self):
if self._file is not None:
self._file.flush()

sys.stderr = Blackhole()
del Blackhole


def truncateText(unicodeText, maxLength):
try:
Expand Down

0 comments on commit 20846ca

Please sign in to comment.