Skip to content

Commit 077c617

Browse files
author
Francisco Arrieta
committed
New flag form expand and collapses, other bug fixes
1 parent c482afb commit 077c617

7 files changed

Lines changed: 171 additions & 26 deletions

File tree

odmtools/controller/NewFlagValuesController.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ def __init__(self, parent, series_service, qualifier_choice, record_service):
99
self.series_service = series_service
1010
self.qualifer_choice = qualifier_choice
1111
self.record_service = record_service
12-
self.__new_annotation = "[New Annontation]"
12+
self.__new_annotation = "New Annontation"
1313

1414
annotations = self.series_service.get_all_annotations()
1515
self.append_items_to_annotation(annotations)
1616
self.annotation_combo.SetSelection(0)
17+
self.annotation_combo.Append(self.__new_annotation)
1718

1819
self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
1920
self.Bind(wx.EVT_CLOSE, self.on_cancel)
2021
self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
2122
self.MakeModal(True)
2223

2324
def append_items_to_annotation(self, annotations):
24-
self.annotation_combo.Append(self.__new_annotation)
2525
if not isinstance(annotations, list):
2626
print "type(annotations) must be list of annotations"
2727
return
@@ -44,3 +44,10 @@ def on_ok(self, event):
4444
self.record_service.flag(annotation.AnnotationID)
4545

4646
self.on_cancel(event)
47+
48+
if __name__ == '__main__':
49+
app = wx.App(False)
50+
controller = NewFlagValuesController(None, None, None, None)
51+
controller.Show()
52+
app.MainLoop()
53+

odmtools/gui/wizSave.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def on_wizard_finished(self, event):
356356
wx.YES_NO | wx.ICON_QUESTION)
357357
if val == 2:
358358
logger.info("User selected yes to save a level 0 dataset")
359-
val_2 = wx.MessageBox("This action cannot be undone.\nAre you sure you are sure?\n",
359+
val_2 = wx.MessageBox("This interactive_item cannot be undone.\nAre you sure you are sure?\n",
360360
'Are you REALLY sure?',
361361
wx.YES_NO | wx.ICON_QUESTION)
362362
if val_2 == 2:
@@ -368,7 +368,7 @@ def on_wizard_finished(self, event):
368368
if self.pgExisting.pnlExisting.rbAppend.GetValue():
369369
keyword = "append to"
370370

371-
message = "You are about to " + keyword + " an existing series_service,\nthis action cannot be undone.\nWould you like to continue?\n"
371+
message = "You are about to " + keyword + " an existing series_service,\nthis interactive_item cannot be undone.\nWould you like to continue?\n"
372372
cont = wx.MessageBox(message, 'Are you sure?', wx.YES_NO | wx.ICON_QUESTION)
373373
if cont == 2:
374374
closeSuccessful = True

odmtools/lib/ObjectListView/ListCtrlPrinter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
particular, it configures the printing DC so that its origin and scale are correct. This
7777
enables the ``ReportEngine`` to simply render the report without knowing the
7878
characteristics of the underlying printer DPI, unprintable region, or the scale of a print
79-
preview. When The ``ListCtrlPrintout`` encounters some action that is cannot perform (like
79+
preview. When The ``ListCtrlPrintout`` encounters some interactive_item that is cannot perform (like
8080
actually rendering a page) it calls back into ``ListCtrlPrinter`` (which simply forwards
8181
to the ``ReportEngine``).
8282
@@ -1879,7 +1879,7 @@ def CalculateSlices(self, maxWidth, columnWidths):
18791879
"""
18801880
firstColumn = 0
18811881

1882-
# If a GroupListView has a column just for the expand/collapse, don't include it
1882+
# If a GroupListView has a column just for the is_expanded/collapse, don't include it
18831883
if hasattr(self.lv, "useExpansionColumn") and self.lv.useExpansionColumn:
18841884
firstColumn = 1
18851885

odmtools/lib/ObjectListView/OLVEvent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ def __init__(self, objectListView, groups):
229229

230230
class ExpandCollapseEvent(VetoableEvent):
231231
"""
232-
The user wants to expand or collapse one or more groups, or has just done so.
232+
The user wants to is_expanded or collapse one or more groups, or has just done so.
233233
234234
If the handler calls Veto() for a Expanding or Collapsing event,
235-
the expand/collapse action will be cancelled.
235+
the is_expanded/collapse interactive_item will be cancelled.
236236
237237
Calling Veto() has no effect on a Expanded or Collapsed event
238238
"""

odmtools/lib/ObjectListView/ObjectListView.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class ObjectListView(wx.ListCtrl):
161161
this is will also put a HTML version into the clipboard)
162162
163163
Left-Arrow, Right-Arrow
164-
[GroupListView only] This will collapse/expand all selected groups.
164+
[GroupListView only] This will collapse/is_expanded all selected groups.
165165
166166
* oddRowsBackColor
167167
When `useAlternateBackColors` is true, odd numbered rows will have this
@@ -2620,7 +2620,7 @@ def __init__(self, *args, **kwargs):
26202620
* useExpansionColumn
26212621
26222622
If this is True (the default), the expansion/contraction icon will have its
2623-
own column at position 0. If this is false, the expand/contract icon will be
2623+
own column at position 0. If this is false, the is_expanded/contract icon will be
26242624
in the first user specified column. This must be set before SetColumns() is called.
26252625
If it is changed, SetColumns() must be called again.
26262626
"""
@@ -3088,7 +3088,7 @@ def Reveal(self, modelObject):
30883088
return True
30893089

30903090
# Find which group (if any) the object belongs to, and
3091-
# expand it and then try to reveal it again
3091+
# is_expanded it and then try to reveal it again
30923092
for group in self.groups:
30933093
if not group.isExpanded and modelObject in group.modelObjects:
30943094
self.Expand(group)
@@ -3197,7 +3197,7 @@ def _GetValuesAsMultiList(self, objects):
31973197
"""
31983198
Return a list of lists of the string of the aspects of the given objects
31993199
"""
3200-
cols = self.columns[self.GetPrimaryColumnIndex():] # We don't want to copy the expand icon columns
3200+
cols = self.columns[self.GetPrimaryColumnIndex():] # We don't want to copy the is_expanded icon columns
32013201
objects = [x for x in objects if x is not None and not isinstance(x, ListGroup)]
32023202
return [[column.GetStringValue(x) for column in cols] for x in objects]
32033203

@@ -3413,7 +3413,7 @@ class ColumnDefn(object):
34133413
* isSpaceFilling
34143414
Is this column a space filler? Space filling columns resize to occupy free
34153415
space within the listview. As the listview is expanded, space filling columns
3416-
expand as well. Conversely, as the control shrinks these columns shrink too.
3416+
is_expanded as well. Conversely, as the control shrinks these columns shrink too.
34173417
34183418
Space filling columns can disappear (i.e. have a width of 0) if the control
34193419
becomes too small. You can set `minimumWidth` to prevent them from
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import wx
2+
3+
4+
class CustomCollapsiblePanel(wx.Panel):
5+
def __init__(self, parent, title="Sample Title", expand=0, use_combo=False, combo_trigger_item=-1):
6+
wx.Panel.__init__(self, parent)
7+
self.__master_sizer = wx.BoxSizer(wx.VERTICAL)
8+
9+
self.parent = parent # parent of this panel
10+
self.title = title
11+
self.is_expanded = expand # is_expanded status
12+
self.__using_combo = use_combo
13+
self.trigger_item = combo_trigger_item
14+
15+
# this will be the main sizer for this panel
16+
self.vbox = wx.BoxSizer(wx.VERTICAL)
17+
18+
# this sizer contains is_expanded button and title of frame
19+
self.hbox = wx.BoxSizer(wx.VERTICAL)
20+
21+
# self.interactive_item is the item that is interacted with to is_expanded or collapse the panel
22+
if self.__using_combo:
23+
self.interactive_item = wx.ComboBox(self, style=wx.CB_READONLY, name="interactive_item")
24+
self.interactive_item.Bind(wx.EVT_COMBOBOX, self.on_interactive_item)
25+
else:
26+
self.interactive_item = wx.Button(self, label=title, size=(-1, 18), style=wx.BU_LEFT | wx.STATIC_BORDER, name='interactive_item')
27+
self.interactive_item.Bind(wx.EVT_BUTTON, self.on_interactive_item)
28+
29+
# self.lbl = wx.StaticText(self, -1, size=(-1, 5), name='cplbl')
30+
31+
self.hbox.Add(self.interactive_item, 1, wx.EXPAND)
32+
# self.hbox.Add(self.lbl, 0)
33+
34+
# add to main sizer(vbox)
35+
self.vbox.Add(self.hbox, 0, wx.EXPAND)
36+
37+
def on_interactive_item(self, event=None):
38+
"""
39+
Case for combo box: If the selected item matches the trigger item then expand, otherwise collapse
40+
Case for button: collapse if expanded and expand if collapsed
41+
:param event:
42+
:return:
43+
"""
44+
if isinstance(self.interactive_item, wx.ComboBox):
45+
if self.interactive_item.GetStringSelection() == self.trigger_item:
46+
self.expand_panel()
47+
else:
48+
self.collapse_panel()
49+
else:
50+
if self.is_expanded:
51+
self.collapse_panel()
52+
else:
53+
self.expand_panel()
54+
55+
if event:
56+
event.Skip()
57+
58+
def expand_panel(self):
59+
self.is_expanded = True
60+
self.__redraw_panel()
61+
self.GetTopLevelParent().SetSize((400, 300))
62+
63+
def __redraw_panel(self):
64+
for child in self.GetChildren():
65+
if child.GetName() == "interactive_item":
66+
continue
67+
child.Show(self.is_expanded)
68+
self.parent.Layout()
69+
self.parent.SendSizeEvent() # make scrollbars visible if parent is scrolledWindow and if they are required automatically
70+
# self.lbl.SetFocus() # Remove focus from button when pressed
71+
self.parent.Refresh()
72+
73+
def collapse_panel(self):
74+
self.is_expanded = False
75+
self.__redraw_panel()
76+
self.GetTopLevelParent().SetSize((400, 150))
77+
78+
def finish_layout(self):
79+
80+
allSizers = []
81+
childSizer = None
82+
# Get all the sizers containing all the children of this panel
83+
for child in self.GetChildren():
84+
if child.GetName() == 'interactive_item' or child.GetName() == 'cplbl':
85+
continue
86+
87+
childSizer = child.GetContainingSizer()
88+
if childSizer != None:
89+
# add the sizer in the list if it's no there.
90+
# can't use set as it changes the order of elements
91+
# this way we can have unique sizer or not repeating ones
92+
if not childSizer in allSizers:
93+
allSizers.append(childSizer)
94+
95+
# Get root level sizers and add to main sizer name 'vbox'
96+
if len(allSizers):
97+
for sizer in self.getRootSizers(allSizers):
98+
self.vbox.Add(sizer, 0, wx.EXPAND)
99+
else:
100+
print 'children of this panel are not in any sizers. They should be in a sizer/s'
101+
102+
# When deleting this panel in any case, masterSizer is also getting deleted. we have to create it again
103+
if not isinstance(self.__master_sizer, wx._core.BoxSizer):
104+
self.__master_sizer = wx.BoxSizer(wx.VERTICAL)
105+
106+
self.__master_sizer.Add(self, 0, wx.EXPAND)
107+
108+
# Rearrange everything
109+
self.SetSizer(self.vbox)
110+
self.Fit()
111+
self.on_interactive_item()
112+
113+
def getRootSizers(self, sizerList):
114+
'''
115+
'sizerList' contains many sizers and may possible nested sizers or sizers added inside another sizers.
116+
This function process the list and returns only root level sizers.
117+
We'll add only root level sizers to main sizer of this class name 'vbox'.
118+
'''
119+
finalList = sizerList[:]
120+
copyList = sizerList[:]
121+
122+
for sizer in copyList:
123+
if len(sizer.GetChildren()):
124+
for child in sizer.GetChildren():
125+
if child.GetClassName() == 'wxSizerItem':
126+
try:
127+
finalList.remove(child.GetSizer())
128+
except:
129+
pass
130+
return finalList

odmtools/view/NewFlagValuesView.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
import wx
2+
from odmtools.view.CustomCollapsiblePanel import CustomCollapsiblePanel
3+
from wx.lib.scrolledpanel import ScrolledPanel
24

35

46
class NewFlagValuesView(wx.Frame):
57
def __init__(self, parent):
6-
wx.Frame.__init__(self, parent, title="Flag Values", style=wx.FRAME_FLOAT_ON_PARENT | wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)
8+
wx.Frame.__init__(self, parent, title="Flag Values", style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)
79

810
panel = wx.Panel(self)
9-
content_panel = wx.Panel(panel)
11+
content_panel = ScrolledPanel(panel)
1012
bottom_panel = wx.Panel(panel)
1113

1214
##########################################
1315
# CONTENT PANEL
1416
##########################################
17+
content_panel.SetupScrolling()
1518

1619
annotation_title = wx.StaticText(content_panel, label="Annotation")
17-
self.annotation_combo = wx.ComboBox(content_panel, style=wx.CB_READONLY | wx.CB_SORT)
18-
code_title = wx.StaticText(content_panel, label="Code")
19-
self.code_textbox = wx.TextCtrl(content_panel, size=(100, -1))
20-
text_title = wx.StaticText(content_panel, label="Text")
21-
self.text_textbox = wx.TextCtrl(content_panel)
22-
link_text = wx.StaticText(content_panel, label="Link")
23-
self.link_textbox = wx.TextCtrl(content_panel)
20+
collapsible_panel = CustomCollapsiblePanel(content_panel, title="Panel 1", expand=0, use_combo=True, combo_trigger_item="New Annontation")
21+
self.annotation_combo = collapsible_panel.interactive_item
2422

23+
code_title = wx.StaticText(collapsible_panel, label="Code")
24+
self.code_textbox = wx.TextCtrl(collapsible_panel, size=(100, -1))
25+
text_title = wx.StaticText(collapsible_panel, label="Text")
26+
self.text_textbox = wx.TextCtrl(collapsible_panel)
27+
link_text = wx.StaticText(collapsible_panel, label="Link")
28+
self.link_textbox = wx.TextCtrl(collapsible_panel)
29+
30+
sizer = wx.BoxSizer(wx.VERTICAL)
2531
content_panel_sizer = wx.BoxSizer(wx.VERTICAL)
26-
content_panel_sizer.Add(annotation_title, 0, wx.EXPAND | wx.ALL ^ wx.BOTTOM, 10)
27-
content_panel_sizer.Add(self.annotation_combo, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
2832
content_panel_sizer.Add(code_title, 0, wx.EXPAND | wx.ALL ^ wx.BOTTOM, 10)
2933
content_panel_sizer.Add(self.code_textbox, 0, wx.LEFT | wx.RIGHT, 10)
3034
content_panel_sizer.Add(text_title, 0, wx.EXPAND | wx.ALL ^ wx.BOTTOM, 10)
3135
content_panel_sizer.Add(self.text_textbox , 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
3236
content_panel_sizer.Add(link_text, 0, wx.EXPAND | wx.ALL ^ wx.BOTTOM, 10)
3337
content_panel_sizer.Add(self.link_textbox, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
3438

35-
content_panel.SetSizer(content_panel_sizer)
39+
collapsible_panel.finish_layout()
40+
41+
sizer.Add(annotation_title, 0, wx.EXPAND | wx.ALL ^ wx.BOTTOM, 10)
42+
sizer.Add(collapsible_panel, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
43+
content_panel.SetSizer(sizer)
3644

3745
##########################################
3846
# BOTTOM PANEL
@@ -60,7 +68,7 @@ def __init__(self, parent):
6068

6169
panel.SetSizer(main_sizer)
6270
main_sizer.Fit(self)
63-
self.SetSize((400, 300))
71+
self.SetSize((400, 150))
6472

6573

6674

0 commit comments

Comments
 (0)