1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
|
"""GNUmed provider inbox handling widgets.
"""
#================================================================
# $Source: /sources/gnumed/gnumed/gnumed/client/wxpython/gmProviderInboxWidgets.py,v $
# $Id: gmProviderInboxWidgets.py,v 1.19.2.2 2008/02/25 16:43:41 ncq Exp $
__version__ = "$Revision: 1.19.2.2 $"
__author__ = "Karsten Hilbert <Karsten.Hilbert@gmx.net>"
import sys
import wx
if __name__ == '__main__':
sys.path.insert(0, '../../')
from Gnumed.pycommon import gmLog, gmI18N, gmDispatcher, gmSignals, gmTools, gmCfg
from Gnumed.business import gmPerson, gmSurgery
from Gnumed.wxpython import gmGuiHelpers, gmListWidgets, gmPlugin, gmRegetMixin
from Gnumed.wxGladeWidgets import wxgProviderInboxPnl
_log = gmLog.gmDefLog
_log.Log(gmLog.lInfo, __version__)
_indicator = {
-1: '',
0: '',
1: '!'
}
#============================================================
# practice related widgets
#============================================================
# FIXME: this should be moved elsewhere !
#============================================================
def configure_workplace_plugins(parent=None):
#-----------------------------------
def edit(workplace=None):
available_plugins = gmPlugin.get_installed_plugins(plugin_dir='gui')
dbcfg = gmCfg.cCfgSQL()
if workplace is None:
dlg = wx.TextEntryDialog (
parent = parent,
message = _('Enter a descriptive name for the new workplace:'),
caption = _('Configuring GNUmed workplaces ...'),
defaultValue = u'',
style = wx.OK | wx.CENTRE
)
dlg.ShowModal()
workplace = dlg.GetValue().strip()
if workplace == u'':
gmGuiHelpers.gm_show_error(_('Cannot save a new workplace without a name.'), _('Configuring GNUmed workplaces ...'), gmLog.lErr)
return False
curr_plugins = []
choices = available_plugins
else:
curr_plugins = gmTools.coalesce(dbcfg.get2 (
option = u'horstspace.notebook.plugin_load_order',
workplace = workplace,
bias = 'workplace'
), [])
choices = curr_plugins[:]
for p in available_plugins:
if p not in choices:
choices.append(p)
sels = range(len(curr_plugins))
new_plugins = gmListWidgets.get_choices_from_list (
parent = parent,
msg = _(
'\nSelect the plugins to load for the workplace "%s".\n'
'\n'
'Note that he plugins currently associated with\n'
'this workplace are preselected.\n'
) % workplace,
caption = _('Configuring GNUmed workplaces ...'),
choices = choices,
selections = sels,
columns = [_('Plugins')],
single_selection = False
)
if new_plugins == curr_plugins:
return True
if new_plugins is None:
return True
dbcfg.set (
option = u'horstspace.notebook.plugin_load_order',
value = new_plugins,
workplace = workplace
)
return True
#-----------------------------------
if parent is None:
parent = wx.GetApp().GetTopWindow()
curr_workplace = gmSurgery.gmCurrentPractice().active_workplace
workplaces = gmSurgery.gmCurrentPractice().workplaces
try:
sels = [workplaces.index(curr_workplace)]
except ValueError:
sels = []
gmListWidgets.get_choices_from_list (
parent = parent,
msg = _(
'\nSelect the workplace to configure below.\n'
'\n'
'The currently active workplace is preselected.\n'
),
caption = _('Configuring GNUmed workplaces ...'),
choices = workplaces,
selections = sels,
columns = [_('Workplace')],
single_selection = True,
edit_callback = edit,
new_callback = edit
)
#============================================================
class cProviderInboxPnl(wxgProviderInboxPnl.wxgProviderInboxPnl, gmRegetMixin.cRegetOnPaintMixin):
_item_handlers = {}
#--------------------------------------------------------
def __init__(self, *args, **kwds):
wxgProviderInboxPnl.wxgProviderInboxPnl.__init__(self, *args, **kwds)
gmRegetMixin.cRegetOnPaintMixin.__init__(self)
self.provider = gmPerson.gmCurrentProvider()
self.__init_ui()
cProviderInboxPnl._item_handlers['clinical.review docs'] = self._goto_doc_review
#--------------------------------------------------------
# reget-on-paint API
#--------------------------------------------------------
def _populate_with_data(self):
self.__populate_inbox()
#--------------------------------------------------------
# internal helpers
#--------------------------------------------------------
def __register_interests(self):
gmDispatcher.connect(signal = u'provider_inbox_mod_db', receiver = self._on_provider_inbox_mod_db)
#--------------------------------------------------------
def __init_ui(self):
self._LCTRL_provider_inbox.set_columns([u'', _('category'), _('type'), _('message')])
msg = _("""
Welcome %(title)s %(lname)s !
Below find the new messages in your Inbox.
""") % {
'title': gmTools.coalesce (
self.provider['title'],
gmPerson.map_gender2salutation(self.provider['gender'])
),
'lname': self.provider['lastnames']
}
self._msg_welcome.SetLabel(msg)
#--------------------------------------------------------
def __populate_inbox(self):
"""Fill UI with data."""
self.__msgs = self.provider.inbox.messages
self._LCTRL_provider_inbox.set_string_items(items = [ [_indicator[m[0]], m[1], m[2], m[3]] for m in self.__msgs ])
self._LCTRL_provider_inbox.set_data(data = self.__msgs)
self._LCTRL_provider_inbox.set_column_widths()
#--------------------------------------------------------
# event handlers
#--------------------------------------------------------
def _on_provider_inbox_mod_db(self, *args, **kwargs):
wx.CallAfter(self._schedule_data_reget)
gmDispatcher.send(signal = u'request_user_attention', msg = _('Please check your GNUmed Inbox !'))
#--------------------------------------------------------
def _lst_item_activated(self, evt):
msg = self._LCTRL_provider_inbox.get_selected_item_data(only_one = True)
if msg is None:
return
handler_key = '%s.%s' % (msg[4], msg[5])
try:
handle_item = cProviderInboxPnl._item_handlers[handler_key]
except KeyError:
gmGuiHelpers.gm_show_warning (
_(
"""Unknown message type:
[%s]
Don't know what to do with it.
Leaving message in inbox.""") % handler_key,
_('handling provider inbox item'),
gmLog.lWarn
)
return False
if not handle_item(pk_context = msg[6]):
_log.Log(gmLog.lErr, 'item handler returned "false"')
_log.Log(gmLog.lErr, 'handler key: [%s]' % handler_key)
_log.Log(gmLog.lErr, 'message: %s' % str(msg))
return False
return True
#--------------------------------------------------------
def _lst_item_focused(self, evt):
msg = self._LCTRL_provider_inbox.get_selected_item_data(only_one = True)
if msg is None:
return
if msg[7] is None:
tmp = _('Message: %s') % msg[3]
else:
tmp = _('Message: %s\nData: %s') % (msg[3], msg[7])
self._TXT_inbox_item_comment.SetValue(tmp)
#--------------------------------------------------------
def _lst_item_right_clicked(self, evt):
tmp = self._LCTRL_provider_inbox.get_selected_item_data(only_one = True)
if tmp is None:
return
self.__focussed_msg = tmp
# build menu
menu = wx.Menu(title = _('Inbox Message menu'))
# - delete message
ID = wx.NewId()
menu.AppendItem(wx.MenuItem(menu, ID, _('delete message')))
wx.EVT_MENU(menu, ID, self._on_delete_focussed_msg)
# show menu
self.PopupMenu(menu, wx.DefaultPosition)
menu.Destroy()
#--------------------------------------------------------
# item handlers
#--------------------------------------------------------
def _on_delete_focussed_msg(self, evt):
if not self.provider.inbox.delete_message(self.__focussed_msg[8]):
gmDispatcher.send(signal='statustext', msg=_('Cannot remove message from Inbox.'))
return False
return True
#--------------------------------------------------------
def _goto_doc_review(self, pk_context=None):
if not gmPerson.set_active_patient(patient=gmPerson.cIdentity(aPK_obj=pk_context)):
gmGuiHelpers.gm_show_error (
_('Supposedly there are unreviewed documents'
'for patient [%s]. However, I cannot find'
'that patient in the GNUmed database.'
) % pk_context,
_('handling provider inbox item'),
gmLog.lErr
)
return False
gmDispatcher.send(signal = 'display_widget', name = 'gmShowMedDocs', sort_mode = 'review')
return True
#============================================================
if __name__ == '__main__':
_log.SetAllLogLevels(gmLog.lData)
gmI18N.activate_locale()
gmI18N.install_domain(domain = 'gnumed')
def test_configure_wp_plugins():
app = wx.PyWidgetTester(size = (400, 300))
configure_workplace_plugins()
if len(sys.argv) > 1 and sys.argv[1] == 'test':
test_configure_wp_plugins()
#============================================================
# $Log: gmProviderInboxWidgets.py,v $
# Revision 1.19.2.2 2008/02/25 16:43:41 ncq
# - dbcfg = ... was in the wrong place
#
# Revision 1.19.2.1 2008/01/22 17:22:07 ncq
# - don't crash on empty workplace
#
# Revision 1.19 2007/11/28 11:56:30 ncq
# - better logging
#
# Revision 1.18 2007/11/23 23:36:38 ncq
# - finish configure_workplace_plugins()
#
# Revision 1.17 2007/11/02 13:59:33 ncq
# - request user attention when new item arrives
#
# Revision 1.16 2007/10/30 12:51:45 ncq
# - make it a reget mixin child
# - cleanup
# - listen on backend changes
#
# Revision 1.15 2007/10/08 13:05:10 ncq
# - use gmListWidgets.cReportListCtrl
# - fix right-click on empty message list crashes
# - start test suite
# - start configure_workplace_plugins()
#
# Revision 1.14 2007/08/12 00:12:41 ncq
# - no more gmSignals.py
#
# Revision 1.13 2007/05/14 13:11:25 ncq
# - use statustext() signal
#
# Revision 1.12 2007/01/04 22:52:34 ncq
# - show proper salutation for people without title
#
# Revision 1.11 2006/12/17 20:46:24 ncq
# - cleanup
#
# Revision 1.10 2006/11/24 10:01:31 ncq
# - gm_beep_statustext() -> gm_statustext()
#
# Revision 1.9 2006/05/28 16:19:54 ncq
# - repopulate_ui() needed for receive_focus() from plugin base class
#
# Revision 1.8 2006/05/20 18:55:21 ncq
# - calculate handler via original category/type not i18ned one
#
# Revision 1.7 2006/05/16 15:56:03 ncq
# - properly resize columns
#
# Revision 1.6 2006/05/15 14:46:38 ncq
# - implement message deletion via context menu popup
#
# Revision 1.5 2006/05/15 13:39:31 ncq
# - cleanup
#
# Revision 1.4 2006/05/12 22:04:22 ncq
# - add _populate_with_data()
# - fully implement _goto_doc_review()
#
# Revision 1.3 2006/05/12 12:21:58 ncq
# - implement double-click item handling
# - use gmCurrentProvider
# - show message on item focused
#
# Revision 1.2 2006/01/22 18:10:52 ncq
# - now really display messages from backend
#
# Revision 1.1 2006/01/15 14:30:56 ncq
# - first crude cut at this
#
#
|