Skip to content

Commit

Permalink
minor thangs
Browse files Browse the repository at this point in the history
- cleaned up docstring a little bit
- switched location of terminal settings to 'TERMINAL_SETETINGS_FN'
- added 'custom' size mode
- made 'TERMINAL_WINSIZE_BEHAVIOR', a 'choice' box, and 'remember' is the default
- fixed resizing of Control Panel widgets so they fill the available space
  • Loading branch information
sneakers-the-rat committed Feb 10, 2021
1 parent 164bc91 commit 904976d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
5 changes: 4 additions & 1 deletion autopilot/core/gui.py
Expand Up @@ -144,7 +144,9 @@ def __init__(self, subjects, start_fn, pilots=None):

self.init_ui()

self.setSizePolicy(QtWidgets.QSizePolicy.Maximum,QtWidgets.QSizePolicy.Maximum)
# self.setSizePolicy(QtWidgets.QSizePolicy.Maximum,QtWidgets.QSizePolicy.Maximum)
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Expanding)

self.setStyleSheet(styles.CONTROL_PANEL)

def init_ui(self):
Expand Down Expand Up @@ -398,6 +400,7 @@ def init_ui(self):
Initializes UI elements - creates widgets and adds to :py:attr:`Pilot_Panel.layout` .
Called on init.
"""

label = QtWidgets.QLabel(self.pilot)
label.setStyleSheet("font: bold 14pt; text-align:right")
label.setAlignment(QtCore.Qt.AlignVCenter)
Expand Down
30 changes: 16 additions & 14 deletions autopilot/core/terminal.py
Expand Up @@ -65,7 +65,7 @@

class Terminal(QtWidgets.QMainWindow):
"""
Central host to a fleet of :class:`.Pilot` s and user-facing
Central host to a swarm of :class:`.Pilot` s and user-facing
:mod:`~.core.gui` objects.
Called as a module with the -f flag to give the location of a prefs file, eg::
Expand All @@ -89,17 +89,10 @@ class Terminal(QtWidgets.QMainWindow):
| `'HANDSHAKE'` | :meth:`~.Terminal.l_handshake` | Pilot first contact, telling us it's alive and its IP |
+---------------+--------------------------------+--------------------------------------------------------+
** Prefs needed by Terminal **
Typically set by :mod:`.setup.setup_terminal`
* **BASEDIR** - Base directory for all local autopilot data, typically `/usr/autopilot`
* **MSGPORT** - Port to use for our ROUTER listener, default `5560`
* **DATADIR** - `os.path.join(params['BASEDIR'], 'data')`
* **SOUNDDIR** - `os.path.join(params['BASEDIR'], 'sounds')`
* **PROTOCOLDIR** - `os.path.join(params['BASEDIR'], 'protocols')`
* **LOGDIR** - `os.path.join(params['BASEDIR'], 'logs')`
* **REPODIR** - Path to autopilot git repo
* **PILOT_DB** - Location of `pilot_db.json` used to populate :attr:`~.Terminal.pilots`
.. note::
See :mod:`autopilot.prefs` for full list of prefs needed by terminal!
Attributes:
node (:class:`~.networking.Net_Node`): Our Net_Node we use to communicate with our main networking object
Expand All @@ -111,6 +104,8 @@ class Terminal(QtWidgets.QMainWindow):
data_panel (:class:`~.plots.Plot_Widget`): Plots for each pilot and subject.
logo (:class:`QtWidgets.QLabel`): Label holding our beautiful logo ;X
logger (:class:`logging.Logger`): Used to log messages and network events.
settings (:class:`PySide2.QtCore.QSettings`): QSettings used to store pyside configuration like window size,
stored in ``prefs.get("TERMINAL_SETTINGS_FN")``
"""

def __init__(self):
Expand All @@ -121,10 +116,10 @@ def __init__(self):
globals()['_TERMINAL'] = self

# Load settings
# These are stored in ~/.config/Autopilot/Terminal.conf
# Currently, the only setting is "geometry", but loading here
# in case we start to use other ones in the future
self.settings = QtCore.QSettings("Autopilot", "Terminal")
self.settings = QtCore.QSettings(prefs.get("TERMINAL_SETTINGS_FN"),
QtCore.QSettings.NativeFormat)

# networking
self.node = None
Expand Down Expand Up @@ -330,8 +325,15 @@ def initUI(self):
else:
# It was saved, so restore the last geometry
self.restoreGeometry(self.settings.value("geometry"))


elif terminal_winsize_behavior == "custom":
custom_size = prefs.get('TERMINAL_CUSTOM_SIZE')
self.move(custom_size[0], custom_size[1])
self.resize(custom_size[2], custom_size[3])
else:
if terminal_winsize_behavior != 'moderate':
self.logger.warning(f'TERMINAL_WINSIZE_BEHAVIOR {terminal_winsize_behavior} is not implemented, defaulting to "moderate"')

# The moderate size
self.move(primary_display.left(), primary_display.top())
self.resize(1000, 400)
Expand Down
25 changes: 18 additions & 7 deletions autopilot/prefs.py
Expand Up @@ -282,15 +282,26 @@ class Scopes(Enum):
"default": str(_basedir / "pilot_db.json"),
"scope": Scopes.TERMINAL
},
'TERMINAL_WINSIZE_BEHAVIOR': {
'TERMINAL_SETTINGS_FN':{
'type': 'str',
'text': (
'How the Terminal window is sized: '
'"maximum", "moderate", or "remember"'
),
'default': 'moderate',
'text': 'filename to store QSettings file for Terminal',
'default': str(_basedir / "terminal.conf"),
"scope": Scopes.TERMINAL
},
'TERMINAL_WINSIZE_BEHAVIOR': {
'type': 'choice',
'text': 'Strategy for resizing terminal window on opening',
"choices": ('remember', 'moderate', 'maximum', 'custom'),
"default": "remember",
"scope": Scopes.TERMINAL
},
},
'TERMINAL_CUSTOM_SIZE': {
'type': 'list',
'text': 'Custom size for window, specified as [px from left, px from top, width, height]',
'default': [0, 0, 1000, 400],
'depends': ('TERMINAL_WINSIZE_BEHAVIOR', 'custom'),
'scope': Scopes.TERMINAL
},
'LINEAGE': {
'type': 'choice',
"text": "Are we a parent or a child?",
Expand Down

0 comments on commit 904976d

Please sign in to comment.