Skip to content

Commit

Permalink
make confirm exit option actually work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtJacobson committed Dec 28, 2018
1 parent d87abdd commit 8b31786
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qtpyvcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
--hide-menu-bar Hides the menu bar, if present.
--hide-status-bar Hides the status bar, if present.
--confirm-exit BOOL
Whether to show dialog to confirm exit. [default: True]
Whether to show dialog to confirm exit.
Application Options:
--log-level=(DEBUG | INFO | WARN | ERROR | CRITICAL)
Expand Down
28 changes: 24 additions & 4 deletions qtpyvcp/utilities/opt_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
--hide-menu-bar Hides the menu bar, if present.
--hide-status-bar Hides the status bar, if present.
--confirm-exit BOOL
Whether to show dialog to confirm exit. [default: True]
Whether to show dialog to confirm exit.
Application Options:
--log-level=(DEBUG | INFO | WARN | ERROR | CRITICAL)
Expand Down Expand Up @@ -74,8 +74,25 @@ def parse_opts(doc=__doc__, vcp_name='NotSpecified', vcp_cmd='notspecified', vcp

raw_args = docopt(doc, version=version_str)

def convType(val):
if isinstance(val, basestring):
if val.lower() in ['true', 'on', 'yes', 'false', 'off', 'no']:
return val.lower() in ['true', 'on', 'yes']

try:
return int(val)
except ValueError:
pass

try:
return float(val)
except ValueError:
pass

return val

# convert raw argument dict keys to valid python attribute names
opts = DotDict({arg.strip('-<>').replace('-', '_') : value for arg, value in raw_args.items()})
opts = DotDict({arg.strip('-<>').replace('-', '_') : convType(value) for arg, value in raw_args.items()})

# read options from INI file and merge with cmd line options
ini_file = ini(normalizePath(opts.ini, os.path.expanduser('~/linuxcnc/configs')))
Expand All @@ -87,14 +104,17 @@ def parse_opts(doc=__doc__, vcp_name='NotSpecified', vcp_cmd='notspecified', vcp
# convert str values to bool
if type(v) == bool:
# TODO: Find a way to prefer cmd line values over INI values
ini_val = ini_val.lower() in ['true', '1', 'on']
ini_val = ini_val.lower() in ['true', 'on', 'yes', '1']

# if its a non bool value and it was specified on the cmd line
# then prefer the cmd line value
elif v is not None:
continue

opts[k] = ini_val
opts[k] = convType(ini_val)

# import json
# print json.dumps(opts, sort_keys=True, indent=4)

# Check if LinuxCNC is running
if not os.path.isfile('/tmp/linuxcnc.lock'):
Expand Down
3 changes: 1 addition & 2 deletions qtpyvcp/widgets/form_widgets/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def __init__(self, parent=None, opts=None, ui_file=None, stylesheet=None,
self.app = QApplication.instance()
self.status = getPlugin('status')

self.confirm_exit = opts.confirm_exit.lower() in \
['true', 'yes', '1'] or confirm_exit
self.confirm_exit = confirm_exit if opts.confirm_exit is None else opts.confirm_exit

# Load the UI file AFTER defining variables, otherwise the values
# set in QtDesigner get overridden by the default values
Expand Down

0 comments on commit 8b31786

Please sign in to comment.