Skip to content

Commit

Permalink
New Group Dialog: Use non-collapsible preview box on Linux
Browse files Browse the repository at this point in the history
Fixes #125
  • Loading branch information
davidfstr committed Sep 3, 2023
1 parent 5f3cec6 commit cc23432
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 41 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ Estimated time remaining is shown when downloading groups.
* Linux: Fix dialog that appears on app launch to be sized correctly.
* Linux: Fix View button to open browser even if Crystal run from read-only volume.
* Linux: Fix most other dialogs to be sized correctly.
* However there's still a problem where the "New Group" dialog sometimes
reserves extra space at the bottom of the dialog when previewing members.
* macOS: Fix issue where dialogs could appear at unusual locations,
including offscreen.

Expand Down
69 changes: 46 additions & 23 deletions src/crystal/browser/addgroup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from crystal.model import ResourceGroup
from crystal.util.wx_bind import bind
from crystal.util.wx_dialog import position_dialog_initially
from crystal.util.wx_static_box_sizer import wrap_static_box_sizer_child
from crystal.util.xos import is_linux
import sys
from typing import Union
import wx


Expand Down Expand Up @@ -38,27 +40,42 @@ def __init__(self, parent, on_finish, project, initial_url=None, initial_source=
bind(dialog, wx.EVT_BUTTON, self._on_button)
bind(dialog, wx.EVT_CLOSE, self._on_close)

preview_box = wx.CollapsiblePane(
dialog, label='Preview Members',
name='cr-add-group-dialog__preview-members')
preview_box.Expand()
preview_box_root = preview_box.GetPane()
preview_box_root_sizer = wx.BoxSizer(wx.VERTICAL)
preview_box_root.SetSizer(preview_box_root_sizer)
preview_box_root_sizer.SetSizeHints(preview_box_root)

self.url_list = wx.ListBox(
preview_box_root, style=wx.LB_ALWAYS_SB, size=(-1,150),
name='cr-add-group-dialog__preview-members__list')
# NOTE: Don't use wx.CollapsiblePane on wxGTK/Linux because
# it doesn't resize its parent window properly on
# expand and unexpand events
preview_box_collapsible = not is_linux()
preview_box: Union[wx.Window, wx.Sizer]
preview_box_root: wx.Window
preview_box_root_sizer: wx.BoxSizer
preview_box_flags: int
preview_box_border: int
if preview_box_collapsible:
preview_box = wx.CollapsiblePane(
dialog, label='Preview Members',
name='cr-add-group-dialog__preview-members')
preview_box.Expand()
preview_box_root = preview_box.GetPane()
preview_box_root_sizer = wx.BoxSizer(wx.VERTICAL)
preview_box_root.SetSizer(preview_box_root_sizer)
preview_box_flags = 0
preview_box_border = 0
else:
preview_box_root_sizer = wx.StaticBoxSizer(
wx.VERTICAL, dialog, label='Preview Members')
preview_box = preview_box_root_sizer
preview_box_root = preview_box_root_sizer.GetStaticBox()
preview_box_flags = wx.TOP
preview_box_border = 10

preview_box_root_sizer.Add(wx.StaticText(preview_box_root, label='Known matching URLs:'), flag=wx.EXPAND)
preview_box_root_sizer.Add(self.url_list, flag=wx.EXPAND)
preview_box_root_sizer.Add(
wrap_static_box_sizer_child(self._create_preview_box_content(preview_box_root)),
flag=wx.EXPAND)

content_sizer = wx.BoxSizer(wx.VERTICAL)
content_sizer.Add(
self._create_fields(dialog, initial_url, initial_source),
flag=wx.EXPAND)
content_sizer.Add(preview_box, 0, flag=wx.EXPAND)
content_sizer.Add(preview_box, proportion=0, flag=wx.EXPAND|preview_box_flags, border=preview_box_border)

dialog_sizer.Add(content_sizer, flag=wx.EXPAND|wx.ALL,
border=_WINDOW_INNER_PADDING)
Expand All @@ -70,15 +87,9 @@ def __init__(self, parent, on_finish, project, initial_url=None, initial_source=

position_dialog_initially(dialog)
dialog.Show(True)
if is_linux():
# Fit manually because wxGTK behaves weirdly when there is a
# wx.CollapsiblePane inside a dialog
dialog.Sizer.Fit(dialog)
dialog.Size = dialog.Sizer.Size
else:
dialog.Fit()
dialog.Fit()

def _create_fields(self, parent, initial_url, initial_source):
def _create_fields(self, parent: wx.Window, initial_url: str, initial_source) -> wx.Sizer:
fields_sizer = wx.FlexGridSizer(cols=2,
vgap=_FORM_ROW_SPACING, hgap=_FORM_LABEL_INPUT_SPACING)
fields_sizer.AddGrowableCol(1)
Expand Down Expand Up @@ -122,6 +133,18 @@ def _create_fields(self, parent, initial_url, initial_source):

return fields_sizer

def _create_preview_box_content(self, parent: wx.Window) -> wx.Sizer:
content_sizer = wx.BoxSizer(wx.VERTICAL)

self.url_list = wx.ListBox(
parent, style=wx.LB_ALWAYS_SB, size=(-1,150),
name='cr-add-group-dialog__preview-members__list')

content_sizer.Add(wx.StaticText(parent, label='Known matching URLs:'), flag=wx.EXPAND)
content_sizer.Add(self.url_list, flag=wx.EXPAND)

return content_sizer

# === Operations ===

def _update_preview_urls(self) -> None:
Expand Down
16 changes: 3 additions & 13 deletions src/crystal/browser/preferences.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from crystal.util.wx_bind import bind
from crystal.util.wx_date_picker import fix_date_picker_size
from crystal.util.wx_dialog import position_dialog_initially
from crystal.util.wx_static_box_sizer import wrap_static_box_sizer_child
from crystal.util.xos import is_linux, is_mac_os, is_windows
import datetime
import wx
Expand Down Expand Up @@ -89,7 +90,7 @@ def _create_project_fields(self, parent: wx.Window) -> wx.Sizer:
self.html_parser_field,
flag=wx.EXPAND, pos=wx.GBPosition(1, 1))

return _wrap_static_box_sizer_child(fields_sizer)
return wrap_static_box_sizer_child(fields_sizer)

def _create_session_fields(self, parent: wx.Window) -> wx.Sizer:
fields_sizer = wx.GridBagSizer(
Expand Down Expand Up @@ -124,7 +125,7 @@ def _create_session_fields(self, parent: wx.Window) -> wx.Sizer:
self.cookie_field,
flag=wx.EXPAND, pos=wx.GBPosition(4, 1))

return _wrap_static_box_sizer_child(fields_sizer)
return wrap_static_box_sizer_child(fields_sizer)

def _create_stale_before_field(self, parent: wx.Window) -> wx.Sizer:
import wx.adv # import late because does print spurious messages on macOS
Expand Down Expand Up @@ -196,14 +197,3 @@ def _on_ok(self, event: wx.CommandEvent) -> None:

def _on_cancel(self, event: wx.Event) -> None:
self.dialog.Destroy()


def _wrap_static_box_sizer_child(child: wx.Sizer) -> wx.Sizer:
if is_linux():
# Add padding around contents of wx.StaticBoxSizer because
# wxGTK does not do this automatically, unlike macOS and Windows
container = wx.BoxSizer(wx.VERTICAL)
container.Add(child, flag=wx.ALL, border=8)
return container
else:
return child
5 changes: 4 additions & 1 deletion src/crystal/tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ async def test_can_download_and_serve_a_static_site() -> None:

agd.name_field.Value = 'Comic'

assert agd.preview_members_pane.IsExpanded() # expanded by default
assert (
agd.preview_members_pane is None or # always expanded
agd.preview_members_pane.IsExpanded() # expanded by default
)
member_urls = [
agd.preview_members_list.GetString(i)
for i in range(agd.preview_members_list.GetCount())
Expand Down
7 changes: 5 additions & 2 deletions src/crystal/tests/util/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class AddGroupDialog:
name_field: wx.TextCtrl
pattern_field: wx.TextCtrl
source_field: wx.Choice
preview_members_pane: wx.CollapsiblePane
preview_members_pane: Optional[wx.CollapsiblePane]
preview_members_list: wx.ListBox
ok_button: wx.Button

Expand All @@ -335,7 +335,10 @@ async def wait_for() -> AddGroupDialog:
self.source_field = add_group_dialog.FindWindowByName('cr-add-group-dialog__source-field')
assert isinstance(self.source_field, wx.Choice)
self.preview_members_pane = add_group_dialog.FindWindowByName('cr-add-group-dialog__preview-members')
assert isinstance(self.preview_members_pane, wx.CollapsiblePane)
assert (
self.preview_members_pane is None or
isinstance(self.preview_members_pane, wx.CollapsiblePane)
)
self.preview_members_list = add_group_dialog.FindWindowByName('cr-add-group-dialog__preview-members__list')
assert isinstance(self.preview_members_list, wx.ListBox)
self.ok_button = add_group_dialog.FindWindowById(wx.ID_OK)
Expand Down
13 changes: 13 additions & 0 deletions src/crystal/util/wx_static_box_sizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from crystal.util.xos import is_linux
import wx


def wrap_static_box_sizer_child(child: wx.Sizer) -> wx.Sizer:
if is_linux():
# Add padding around contents of wx.StaticBoxSizer because
# wxGTK does not do this automatically, unlike macOS and Windows
container = wx.BoxSizer(wx.VERTICAL)
container.Add(child, flag=wx.ALL|wx.EXPAND, border=8)
return container
else:
return child

0 comments on commit cc23432

Please sign in to comment.