Skip to content

Commit

Permalink
Add host and port command line options
Browse files Browse the repository at this point in the history
Auto-connect to host if given.
  • Loading branch information
photron committed Dec 1, 2022
1 parent 0e8bea4 commit 4b5984e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/brickv/main.py
Expand Up @@ -344,6 +344,8 @@ def main(dev_mode):
parser.add_argument('-v', '--version', action='version', version=config.BRICKV_VERSION)
parser.add_argument('--no-dev-mode', action='store_true', help='disable Python dev mode')
parser.add_argument('--no-error-reporter', action='store_true', help='disable error reporter')
parser.add_argument('host', nargs='?', help='connect to the given host')
parser.add_argument('--port', type=int, help='port override if host is given')

args = parser.parse_args(sys.argv[1:])

Expand Down Expand Up @@ -390,7 +392,7 @@ def main(dev_mode):

from brickv.mainwindow import MainWindow

main_window = MainWindow(brickv_version)
main_window = MainWindow(brickv_version, args.host, args.port)
main_window.show()

splash.finish(main_window)
Expand Down
13 changes: 12 additions & 1 deletion src/brickv/mainwindow.py
Expand Up @@ -70,7 +70,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
qtcb_connected = pyqtSignal(int)
qtcb_disconnected = pyqtSignal(int)

def __init__(self, brickv_version_ref, parent=None):
def __init__(self, brickv_version_ref, host, port, parent=None):
QMainWindow.__init__(self, parent)

self.brickv_version_ref = brickv_version_ref
Expand Down Expand Up @@ -234,6 +234,17 @@ def __init__(self, brickv_version_ref, parent=None):
self.ipcon_available = False

self.update_ui_state()
if host != None:
QTimer.singleShot(0, lambda: self.auto_connect(host, port))

def auto_connect(self, host, port):
self.combo_host.setCurrentText(host)

if port != None:
self.checkbox_different_port.setChecked(port != config.DEFAULT_PORT)
self.spinbox_port.setValue(port)

self.connect_clicked()

def get_last_host(self):
return self.last_host
Expand Down

0 comments on commit 4b5984e

Please sign in to comment.