Skip to content

Commit 0fd7217

Browse files
author
Francisco Arrieta
committed
Updated the flag values
Includes a redesign and refactor of the flag values gui. Using MVC style. Creating an annotation works. Bug fixes
1 parent 44713b5 commit 0fd7217

5 files changed

Lines changed: 129 additions & 18 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import wx
2+
from odmtools.view.NewFlagValuesView import NewFlagValuesView
3+
4+
5+
class NewFlagValuesController(NewFlagValuesView):
6+
def __init__(self, parent, series_service, qualifier_choice, record_service):
7+
8+
NewFlagValuesView.__init__(self, parent)
9+
self.series_service = series_service
10+
self.qualifer_choice = qualifier_choice
11+
self.record_service = record_service
12+
13+
annotations = self.series_service.get_all_annotations()
14+
self.append_items_to_annotation(annotations)
15+
self.annotation_combo.SetSelection(0)
16+
17+
self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
18+
self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
19+
self.MakeModal(True)
20+
21+
def append_items_to_annotation(self, annotations):
22+
self.annotation_combo.Append("[New Annontation]")
23+
if not isinstance(annotations, list):
24+
print "type(annotations) must be list of annotations"
25+
return
26+
27+
for item in annotations:
28+
self.annotation_combo.Append(item.AnnotationCode + item.AnnotationText)
29+
30+
def on_cancel(self, event):
31+
self.MakeModal(False)
32+
self.Destroy()
33+
event.Skip()
34+
35+
def on_ok(self, event):
36+
code = self.code_textbox.GetValue()
37+
text = self.text_textbox.GetValue()
38+
39+
self.series_service.create_annotation(code, text)
40+
self.on_cancel(event)

odmtools/controller/logicCellEdit.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
"""
2-
ADD Point Cell Editor Logic
3-
"""
41
from collections import OrderedDict
52
import datetime
6-
73
import wx
84
import wx.combo
95
from wx.lib import masked
10-
from odmtools.gui.frmFlagValues import frmFlagValues
11-
from odmtools.lib.ObjectListView import CellEditor
126

137
__author__ = 'Jacob'
148

odmtools/gui/mnuRibbon.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
from odmtools.controller.frmDataFilters import frmDataFilter
1313
from odmtools.controller.frmChangeValue import frmChangeValue
14-
from frmFlagValues import frmFlagValues
14+
# from frmFlagValues import frmFlagValues
15+
from odmtools.controller.NewFlagValuesController import NewFlagValuesController
1516
from odmtools.controller.frmLinearDrift import frmLinearDrift
1617
from odmtools.controller.frmAbout import frmAbout
1718
from odmtools.controller.frmGapFill import frmGapFill
@@ -446,13 +447,15 @@ def onEditFlag(self, event):
446447
series_service = serviceManager.get_series_service()
447448
qualifierChoices = OrderedDict((x.AnnotationCode + '-' + x.AnnotationText, x.AnnotationID) for x in series_service.get_all_qualifiers()
448449
if x.AnnotationCode and x.AnnotationText)
449-
add_flag = frmFlagValues(self.parent, series_service, qualifierChoices)
450-
val = add_flag.ShowModal()
451-
452-
if val == wx.ID_OK:
453-
logger.debug("FLAG Value: %s, type: %s" % (val, type(val)))
454-
self.parent.getRecordService().flag(add_flag.GetValue())
455-
add_flag.Destroy()
450+
# add_flag = frmFlagValues(self.parent, series_service, qualifierChoices)
451+
add_flag_controller = NewFlagValuesController(self, series_service, qualifierChoices, self.parent.getRecordService())
452+
# val = add_flag.ShowModal()
453+
add_flag_controller.Show()
454+
455+
# if val == wx.ID_OK:
456+
# logger.debug("FLAG Value: %s, type: %s" % (val, type(val)))
457+
# self.parent.getRecordService().flag(add_flag.GetValue())
458+
# add_flag.Destroy()
456459
event.Skip()
457460

458461
# ###################################

odmtools/odmservices/series_service.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from odm2api.ODM2.services import ReadODM2, UpdateODM2, DeleteODM2, CreateODM2
55
from odm2api import serviceBase
66
from odm2api.ODM2.models import *
7+
import datetime
78
from odmtools.common.logger import LoggerTool
89
import pandas as pd
910
logger =logging.getLogger('main')
@@ -992,16 +993,24 @@ def create_processing_level(self, code, definition, explanation):
992993
def create_annotation_by_anno(self, annotation):
993994
return self.create.createAnnotations(annotation)
994995

995-
def create_annotation(self, code, description):
996+
def create_annotation(self, code, text, link=None):
996997
"""
997998
:param code:
998-
:param description:
999+
:param text:
9991000
:return:
10001001
"""
10011002
annotation = Annotations()
10021003
annotation.AnnotationCode = code
1003-
annotation.AnnotationText = description
1004-
annotation.AnnotationTypeCV = "timeSeriesResultValueAnnotation"
1004+
annotation.AnnotationText = text
1005+
annotation.AnnotationTypeCV = "Time series result value annotation"
1006+
current_time = datetime.datetime.now()
1007+
utc_time = datetime.datetime.utcnow()
1008+
annotation.AnnotationDateTime = current_time
1009+
1010+
difference_in_timezone = utc_time - current_time
1011+
offset_in_hours = difference_in_timezone.seconds / 3600
1012+
annotation.AnnotationUTCOffset = offset_in_hours
1013+
annotation.AnnotationLink = link
10051014

10061015
return self.create_annotation_by_anno(annotation)
10071016

odmtools/view/NewFlagValuesView.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import wx
2+
3+
4+
class NewFlagValuesView(wx.Frame):
5+
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)
7+
8+
panel = wx.Panel(self)
9+
content_panel = wx.Panel(panel)
10+
bottom_panel = wx.Panel(panel)
11+
12+
##########################################
13+
# CONTENT PANEL
14+
##########################################
15+
16+
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)
24+
25+
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)
28+
content_panel_sizer.Add(code_title, 0, wx.EXPAND | wx.ALL ^ wx.BOTTOM, 10)
29+
content_panel_sizer.Add(self.code_textbox, 0, wx.LEFT | wx.RIGHT, 10)
30+
content_panel_sizer.Add(text_title, 0, wx.EXPAND | wx.ALL ^ wx.BOTTOM, 10)
31+
content_panel_sizer.Add(self.text_textbox , 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
32+
content_panel_sizer.Add(link_text, 0, wx.EXPAND | wx.ALL ^ wx.BOTTOM, 10)
33+
content_panel_sizer.Add(self.link_textbox, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
34+
35+
content_panel.SetSizer(content_panel_sizer)
36+
37+
##########################################
38+
# BOTTOM PANEL
39+
##########################################
40+
41+
self.ok_button = wx.Button(bottom_panel, label="OK")
42+
self.cancel_button = wx.Button(bottom_panel, label="CANCEL")
43+
static_line = wx.StaticLine(bottom_panel)
44+
45+
bottom_panel_sizer = wx.BoxSizer(wx.VERTICAL)
46+
button_sizer = wx.BoxSizer(wx.HORIZONTAL)
47+
button_sizer.AddSpacer((0, 0), 1, wx.EXPAND, 2)
48+
button_sizer.Add(self.ok_button, 0, wx.EXPAND | wx.ALL ^ wx.RIGHT, 5)
49+
button_sizer.Add(self.cancel_button, 0, wx.EXPAND | wx.ALL, 5)
50+
51+
bottom_panel_sizer.Add(static_line, 0, wx.EXPAND)
52+
bottom_panel_sizer.Add(button_sizer, 0, wx.ALIGN_RIGHT)
53+
54+
bottom_panel.SetSizer(bottom_panel_sizer)
55+
56+
main_sizer = wx.BoxSizer(wx.VERTICAL)
57+
main_sizer.Add(content_panel, 1, wx.EXPAND | wx.ALL, 0)
58+
main_sizer.Add(bottom_panel, 0, wx.EXPAND | wx.ALL, 0)
59+
60+
panel.SetSizer(main_sizer)
61+
main_sizer.Fit(self)
62+
self.SetSize((400, 300))
63+
64+
65+

0 commit comments

Comments
 (0)