Skip to content

ui.py: Reuse existing windows on resize - #217

Merged
richrd merged 1 commit into
richrd:devfrom
Consolatis:fix/newwin
Jan 23, 2018
Merged

richrd merged 1 commit into
richrd:devfrom
Consolatis:fix/newwin

Conversation

@Consolatis

@Consolatis Consolatis commented Jan 4, 2018 •

Copy link
Copy Markdown
Contributor

Reuse existing curses windows on resize instead of recreating them

Edit:
To clarify the reasoning for this change: I added this because my local WIP branch for statusbar components creates an instance of StatusBar() for each bar (currently only top and bottom) which gets a curses window via constructor so the window should always be available.

Things to do:

  • investigate editor move error
  • squash
  • rebase

@Consolatis
Consolatis force-pushed the fix/newwin branch 2 times, most recently from 0dba526 to ddff466 Compare January 4, 2018 22:13
Comment thread suplemon/ui.py
# Test for new curses
if "get_wch" not in dir(self.header_win):
# Notify only once
if not self.warned_old_curses:

@Consolatis Consolatis Jan 4, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not check if self.warned_old_curses has other implications outside of ui.py or can be removed completely after this change. A quick grep -R inside the repo seems to suggest it can be removed completely. If that is indeed the case I'll remove it from __init__ as well.

Edit:
Force pushed a new version which removed it.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok. It's not used anywhere else like you said.

@Consolatis

Copy link
Copy Markdown
Contributor Author

With this applied I sometimes get log outputs from the editor win like this:

2018-01-23 13:07:19,678 - suplemon.viewer - WARNING - Moving window failed!
Traceback (most recent call last):
  File "/path/to/suplemon/suplemon/viewer.py", line 284, in move_win
    self.window.mvwin(yx[0], yx[1])
_curses.error: mvwin() returned ERR

It doesn't seem to affect anything but still strange. Will need to investigate.

Comment thread suplemon/ui.py
# Not sure why editor implements this on its own
# and if it's a good thing or not.
self.app.get_editor().move_win((offset_top, 0))
self.app.get_editor().resize((y - offset_top - offset_bottom, x))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to be getting some errors when resizing the terminal. It works fine and everything looks like it should, but curses complains a little bit:

2018-01-21 17:33:15,393 - suplemon.viewer - WARNING - Moving window failed!
Traceback (most recent call last):
  File "/home/wavi/code/python/suplemon-contrib/consolatis-suplemon/suplemon/viewer.py", line 284, in move_win
    self.window.mvwin(yx[0], yx[1])
_curses.error: mvwin() returned ERR

This seems to go away if the two lines above are swapped, so that resize is run first and move_win after that. I'm guessing it might be complaining because the window is too big and would be placed on top of the legend or status bar after the move. I'm not sure though.

I think it'd be fine to just swap the lines and go forward with this 👍

@richrd

richrd commented Jan 23, 2018

Copy link
Copy Markdown
Owner

Oops, forgot to submit my comment earlier. See above. The mvwin was wrapped with that try/except a long time ago because I noticed that it might fail randomly sometimes. It's no big deal but the above seems to help.

@Consolatis

Copy link
Copy Markdown
Contributor Author

Switched those two around and indeed: no more errors showing up.
If there is nothing else to do I'll squash those two commits into one.

@richrd

richrd commented Jan 23, 2018

Copy link
Copy Markdown
Owner

Yeah, that's all :) Thanks!

@Consolatis

Copy link
Copy Markdown
Contributor Author

squashed the commits :)

@richrd
richrd merged commit d15d1ab into richrd:dev Jan 23, 2018
@richrd

richrd commented Jan 23, 2018

Copy link
Copy Markdown
Owner

Merged :)

@Consolatis
Consolatis deleted the fix/newwin branch January 23, 2018 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants