Package Gnumed :: Package wxpython :: Module gmOrganizationWidgets
[frames] | no frames]

Source Code for Module Gnumed.wxpython.gmOrganizationWidgets

  1  """GNUmed organization handling widgets. 
  2   
  3  copyright: authors 
  4  """ 
  5  #============================================================ 
  6  __author__ = "K.Hilbert" 
  7  __license__ = "GPL v2 or later (details at http://www.gnu.org)" 
  8   
  9  import logging, sys 
 10   
 11   
 12  import wx 
 13   
 14   
 15  if __name__ == '__main__': 
 16          sys.path.insert(0, '../../') 
 17  from Gnumed.pycommon import gmTools 
 18  from Gnumed.pycommon import gmMatchProvider 
 19  from Gnumed.pycommon import gmDispatcher 
 20  from Gnumed.business import gmOrganization 
 21  from Gnumed.wxpython import gmListWidgets 
 22  from Gnumed.wxpython import gmEditArea 
 23  from Gnumed.wxpython import gmPhraseWheel 
 24  from Gnumed.wxpython import gmPersonContactWidgets 
 25  from Gnumed.wxpython import gmAddressWidgets 
 26  from Gnumed.wxpython import gmGuiHelpers 
 27   
 28   
 29  _log = logging.getLogger('gm.organization') 
 30   
 31  #============================================================ 
 32  # organizational units API 
 33  #------------------------------------------------------------ 
34 -def edit_org_unit(parent=None, org_unit=None, single_entry=False, org=None):
35 ea = cOrgUnitEAPnl(parent = parent, id = -1) 36 ea.data = org_unit 37 ea.mode = gmTools.coalesce(org_unit, 'new', 'edit') 38 dlg = gmEditArea.cGenericEditAreaDlg2(parent = parent, id = -1, edit_area = ea, single_entry = single_entry) 39 if org is not None: 40 ea.organization = org 41 dlg.SetTitle(gmTools.coalesce(org_unit, _('Adding new organizational unit'), _('Editing organizational unit'))) 42 if dlg.ShowModal() == wx.ID_OK: 43 dlg.Destroy() 44 return True 45 dlg.Destroy() 46 return False
47 48 #============================================================
49 -def select_org_unit(parent=None, msg=None, no_parent=False):
50 51 if no_parent: 52 parent = None 53 else: 54 if parent is None: 55 parent = wx.GetApp().GetTopWindow() 56 57 #-------------------- 58 def new(): 59 manage_orgs(parent = parent, no_parent = no_parent) 60 return True
61 #-------------------- 62 def refresh(lctrl): 63 units = gmOrganization.get_org_units(order_by = 'organization, unit, l10n_unit_category') 64 items = [ [ 65 u['organization'], 66 u['unit'], 67 gmTools.coalesce(u['l10n_unit_category'], u''), 68 u['pk_org_unit'] 69 ] for u in units ] 70 71 lctrl.set_string_items(items = items) 72 lctrl.set_data(data = units) 73 #-------------------- 74 if msg is None: 75 msg = _("Organizations and units thereof.\n") 76 77 return gmListWidgets.get_choices_from_list ( 78 parent = parent, 79 msg = msg, 80 caption = _('Unit selection ...'), 81 columns = [_('Organization'), _('Unit'), _('Unit type'), '#'], 82 can_return_empty = False, 83 single_selection = True, 84 refresh_callback = refresh, 85 new_callback = new 86 ) 87 88 #============================================================
89 -class cOrgUnitPhraseWheel(gmPhraseWheel.cPhraseWheel):
90
91 - def __init__(self, *args, **kwargs):
92 query = u""" 93 SELECT DISTINCT ON (data) * FROM ( 94 SELECT * FROM (( 95 96 SELECT 97 pk_org_unit 98 AS data, 99 unit || coalesce(' (' || l10n_unit_category || ')', '') || ': ' || organization || ' (' || l10n_organization_category || ')' 100 AS list_label, 101 unit || ' (' || organization || ')' 102 AS field_label 103 FROM 104 dem.v_org_units 105 WHERE 106 unit %(fragment_condition)s 107 108 ) UNION ALL ( 109 110 SELECT 111 pk_org_unit 112 AS data, 113 coalesce(l10n_unit_category || ' ', '') || '"' || unit || '": ' || organization || ' (' || l10n_organization_category || ')' 114 AS list_label, 115 unit || ' (' || organization || ')' 116 AS field_label 117 FROM 118 dem.v_org_units 119 WHERE 120 l10n_unit_category %(fragment_condition)s 121 OR 122 unit_category %(fragment_condition)s 123 124 ) UNION ALL ( 125 126 SELECT 127 pk_org_unit 128 AS data, 129 organization || ': ' || unit || coalesce(' (' || l10n_unit_category || ')', '') 130 AS list_label, 131 unit || ' (' || organization || ')' 132 AS field_label 133 FROM 134 dem.v_org_units 135 WHERE 136 organization %(fragment_condition)s 137 138 )) AS all_matches 139 ORDER BY list_label 140 ) AS ordered_matches 141 LIMIT 50 142 """ 143 mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) 144 mp.setThresholds(1, 3, 5) 145 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) 146 self.SetToolTipString(_("Select an organizational unit.")) 147 self.matcher = mp
148 #--------------------------------------------------------
149 - def _get_data_tooltip(self):
150 if self.GetData() is None: 151 return None 152 unit = self._data2instance() 153 if unit is None: 154 return None 155 return u'\n'.join(unit.format(with_address = True))
156 #--------------------------------------------------------
157 - def _data2instance(self):
158 if self.GetData() is None: 159 return None 160 return gmOrganization.cOrgUnit(aPK_obj = self.GetData())
161 #============================================================
162 -class cOrgUnitsManagerPnl(gmListWidgets.cGenericListManagerPnl):
163 """A list for managing organizational units.""" 164
165 - def __init__(self, *args, **kwargs):
166 167 try: 168 self.__org = kwargs['org'] 169 del kwargs['org'] 170 except KeyError: 171 self.__org = None 172 173 gmListWidgets.cGenericListManagerPnl.__init__(self, *args, **kwargs) 174 175 self.refresh_callback = self.refresh 176 self.new_callback = self._add 177 self.edit_callback = self._edit 178 self.delete_callback = self._del 179 180 self.__show_none_if_no_org = True 181 self.__init_ui() 182 self.__refresh()
183 #-------------------------------------------------------- 184 # external API 185 #--------------------------------------------------------
186 - def refresh(self, lctrl=None):
187 self.__refresh()
188 #-------------------------------------------------------- 189 # event handlers 190 #--------------------------------------------------------
191 - def _add(self):
192 return edit_org_unit(parent = self, org_unit = None, single_entry = False, org = self.__org)
193 #--------------------------------------------------------
194 - def _edit(self, item):
195 return edit_org_unit(parent = self, org_unit = item, single_entry = True)
196 #--------------------------------------------------------
197 - def _del(self, item):
198 return gmOrganization.delete_org_unit(unit = item['pk_org'])
199 #--------------------------------------------------------
200 - def _on_list_item_focused(self, event):
201 pass
202 #-------------------------------------------------------- 203 # internal helpers 204 #--------------------------------------------------------
205 - def __init_ui(self):
206 self._LCTRL_items.SetToolTipString(_('Units (sites, parts, departments, branches, ...) of organizations registered in GNUmed.')) 207 self._LCTRL_items.set_columns(columns = [ _('Organizational Unit'), _('Unit Category'), u'#' ])
208 #self._LCTRL_items.set_column_widths(widths = [wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE]) 209 #--------------------------------------------------------
210 - def __refresh(self):
211 212 msg_template = _('Units of: %s') 213 214 if self.__org is None: 215 self._BTN_add.Enable(False) 216 self._BTN_edit.Enable(False) 217 self._BTN_remove.Enable(False) 218 pk = None 219 self.message = msg_template % _('<no organization selected>') 220 if self.__show_none_if_no_org: 221 self._LCTRL_items.set_string_items(items = None) 222 return 223 else: 224 self._BTN_add.Enable(True) 225 pk = self.__org['pk_org'] 226 org_str = u'%s (%s)' % ( 227 self.__org['organization'], 228 self.__org['l10n_category'] 229 ) 230 self.message = msg_template % org_str 231 232 units = gmOrganization.get_org_units(order_by = 'unit, l10n_unit_category', org = pk) 233 items = [ [ 234 u['unit'], 235 gmTools.coalesce(u['l10n_unit_category'], u''), 236 u['pk_org_unit'] 237 ] for u in units ] 238 239 self._LCTRL_items.set_string_items(items) 240 self._LCTRL_items.set_data(units)
241 #-------------------------------------------------------- 242 # properties 243 #--------------------------------------------------------
244 - def _get_org(self):
245 return self.__org
246
247 - def _set_org(self, org):
248 self.__org = org 249 self.__refresh()
250 251 org = property(_get_org, _set_org) 252 #--------------------------------------------------------
253 - def _get_show_none_if_no_org(self):
254 return self.__show_none_if_no_org
255
256 - def _set_show_none_if_no_org(self, show_none_if_no_org):
257 if show_none_if_no_org == self.__show_none_if_no_org: 258 return 259 if show_none_if_no_org: 260 self.__show_none_if_no_org = True 261 else: 262 self.__show_none_if_no_org = False 263 self.__refresh()
264 265 show_none_if_no_org = property(_get_show_none_if_no_org, _set_show_none_if_no_org)
266 267 #============================================================ 268 # org unit edit area 269 from Gnumed.wxGladeWidgets import wxgOrgUnitEAPnl 270
271 -class cOrgUnitEAPnl(wxgOrgUnitEAPnl.wxgOrgUnitEAPnl, gmEditArea.cGenericEditAreaMixin):
272
273 - def __init__(self, *args, **kwargs):
274 275 try: 276 data = kwargs['unit'] 277 del kwargs['unit'] 278 except KeyError: 279 data = None 280 281 wxgOrgUnitEAPnl.wxgOrgUnitEAPnl.__init__(self, *args, **kwargs) 282 gmEditArea.cGenericEditAreaMixin.__init__(self) 283 284 self.mode = 'new' 285 self.data = data 286 if data is not None: 287 self.mode = 'edit'
288 289 # self.__init_ui() 290 #---------------------------------------------------------------- 291 # def __init_ui(self): 292 # pass 293 #---------------------------------------------------------------- 294 # generic Edit Area mixin API 295 #----------------------------------------------------------------
296 - def _valid_for_save(self):
297 validity = True 298 299 if self._PRW_category.GetData() is not None: 300 self._PRW_category.display_as_valid(True) 301 else: 302 if self._PRW_category.GetValue().strip() == u'': 303 self._PRW_category.display_as_valid(True) 304 else: 305 validity = False 306 self._PRW_category.display_as_valid(False) 307 self._PRW_category.SetFocus() 308 309 if self._PRW_unit.GetData() is not None: 310 self._PRW_unit.display_as_valid(True) 311 else: 312 if self._PRW_unit.GetValue().strip() != u'': 313 self._PRW_unit.display_as_valid(True) 314 else: 315 validity = False 316 self._PRW_unit.display_as_valid(False) 317 self._PRW_unit.SetFocus() 318 319 if self._PRW_org.GetData() is None: 320 validity = False 321 self._PRW_org.display_as_valid(False) 322 self._PRW_org.SetFocus() 323 else: 324 self._PRW_org.display_as_valid(True) 325 326 return validity
327 #----------------------------------------------------------------
328 - def _save_as_new(self):
329 data = gmOrganization.create_org_unit ( 330 pk_organization = self._PRW_org.GetData(), 331 unit = self._PRW_unit.GetValue().strip() 332 ) 333 data['pk_category_unit'] = self._PRW_category.GetData() 334 data.save() 335 336 self.data = data 337 return True
338 #----------------------------------------------------------------
339 - def _save_as_update(self):
340 self.data['pk_org'] = self._PRW_org.GetData() 341 self.data['unit'] = self._PRW_unit.GetValue().strip() 342 self.data['pk_category_unit'] = self._PRW_category.GetData() 343 self.data.save() 344 return True
345 #----------------------------------------------------------------
346 - def _refresh_as_new(self):
347 self._PRW_org.SetText(value = u'', data = None) 348 self._PRW_unit.SetText(value = u'', data = None) 349 self._PRW_category.SetText(value = u'', data = None) 350 351 self._PRW_unit.SetFocus()
352 #----------------------------------------------------------------
354 self._PRW_org.SetText(value = self.data['organization'], data = self.data['pk_org']) 355 self._PRW_unit.SetText(value = u'', data = None) 356 self._PRW_category.SetText(value = self.data['unit_category'], data = self.data['pk_category_unit']) 357 358 self._PRW_unit.SetFocus()
359 #----------------------------------------------------------------
360 - def _refresh_from_existing(self):
361 self._PRW_org.SetText(value = self.data['organization'], data = self.data['pk_org']) 362 self._PRW_unit.SetText(value = self.data['unit'], data = self.data['pk_org_unit']) 363 self._PRW_category.SetText(value = self.data['unit_category'], data = self.data['pk_category_unit']) 364 365 self._PRW_unit.SetFocus()
366 #----------------------------------------------------------------
367 - def _set_org(self, org):
368 self._PRW_org.SetText(value = org['organization'], data = org['pk_org'])
369 370 organization = property(lambda x:x, _set_org)
371 #============================================================ 372 from Gnumed.wxGladeWidgets import wxgOrgUnitAddressPnl 373
374 -class cOrgUnitAddressPnl(wxgOrgUnitAddressPnl.wxgOrgUnitAddressPnl):
375
376 - def __init__(self, *args, **kwargs):
377 378 wxgOrgUnitAddressPnl.wxgOrgUnitAddressPnl.__init__(self, *args, **kwargs) 379 380 self.__unit = None
381 #-------------------------------------------------------- 382 # internal helpers 383 #--------------------------------------------------------
384 - def __refresh(self):
385 if self.__unit is None: 386 self.message = _('<no unit selected>') 387 self._PRW_address_searcher.SetText(u'', None) 388 self._PRW_address_searcher.Enable(False) 389 self._PRW_address_searcher.display_as_disabled(True) 390 self._BTN_save_picked_address.Enable(False) 391 self._BTN_add_new_address.Enable(False) 392 else: 393 if self.__unit['l10n_unit_category'] is None: 394 cat = u'' 395 left_delim = u'' 396 right_delim = u'' 397 else: 398 cat = u'%s ' % self.__unit['l10n_unit_category'] 399 left_delim = gmTools.u_left_double_angle_quote 400 right_delim = gmTools.u_right_double_angle_quote 401 self.message = u'%s%s%s%s' % ( 402 cat, 403 left_delim, 404 self.__unit['unit'], 405 right_delim 406 ) 407 self._PRW_address_searcher.Enable(True) 408 self._PRW_address_searcher.address = self.__unit['pk_address'] 409 self._PRW_address_searcher.Enable(True) 410 self._PRW_address_searcher.display_as_disabled(False) 411 self._BTN_save_picked_address.Enable(True) 412 self._BTN_add_new_address.Enable(True)
413 #-------------------------------------------------------- 414 # event handlers 415 #--------------------------------------------------------
417 if self._PRW_address_searcher.GetData() is None: 418 if self._PRW_address_searcher.GetValue().strip() != u'': 419 gmDispatcher.send(signal = 'statustext', msg = _('Invalid address selection.')) 420 self._PRW_address_searcher.display_as_valid(False) 421 self._PRW_address_searcher.SetFocus() 422 return 423 424 self._PRW_address_searcher.display_as_valid(True) 425 426 self.__unit['pk_address'] = self._PRW_address_searcher.GetData() 427 self.__unit.save() 428 self.__refresh()
429 #--------------------------------------------------------
430 - def _on_add_new_address_button_pressed(self, event):
431 ea = gmAddressWidgets.cAddressEAPnl(self, -1) 432 ea.address_holder = self.__unit 433 ea.type_is_editable = False 434 dlg = gmEditArea.cGenericEditAreaDlg2(self, -1, edit_area = ea) 435 dlg.SetTitle(_('Adding new address')) 436 if dlg.ShowModal() != wx.ID_OK: 437 return False 438 self.__refresh() 439 return True
440 #--------------------------------------------------------
441 - def _on_manage_addresses_button_pressed(self, event):
442 picked_address = gmAddressWidgets.manage_addresses(parent = self) 443 if picked_address is None: 444 return 445 446 question = u'%s\n\n %s\n' % ( 447 _('Link the following address to the organizational unit ?'), 448 u'\n '.join(picked_address.format()) 449 ) 450 451 link_it = gmGuiHelpers.gm_show_question ( 452 title = _('Linking selected address'), 453 question = question 454 ) 455 if not link_it: 456 return 457 458 self._PRW_address_searcher.address = picked_address['pk_address'] 459 self._PRW_address_searcher.display_as_valid(True) 460 self.__unit['pk_address'] = self._PRW_address_searcher.GetData() 461 self.__unit.save()
462 #-------------------------------------------------------- 463 # properties 464 #--------------------------------------------------------
465 - def _get_unit(self):
466 return self.__unit
467
468 - def _set_unit(self, unit):
469 self.__unit = unit 470 self.__refresh()
471 472 unit = property(_get_unit, _set_unit) 473 #--------------------------------------------------------
474 - def _get_message(self):
475 return self._LBL_message.GetLabel()
476
477 - def _set_message(self, msg):
478 if msg is None: 479 self._LBL_message.Hide() 480 self._LBL_message.SetLabel(u'') 481 else: 482 self._LBL_message.SetLabel(msg) 483 self._LBL_message.Show() 484 self.Layout()
485 486 message = property(_get_message, _set_message)
487 #============================================================ 488 # organizations API 489 #------------------------------------------------------------
490 -def manage_orgs(parent=None, no_parent=False):
491 492 if no_parent: 493 parent = None 494 else: 495 if parent is None: 496 parent = wx.GetApp().GetTopWindow() 497 498 dlg = cOrganizationManagerDlg(parent, -1) 499 dlg.ShowModal() 500 dlg.Destroy()
501 #============================================================
502 -def edit_org(parent=None, org=None, single_entry=False):
503 ea = cOrganizationEAPnl(parent = parent, id = -1) 504 ea.data = org 505 ea.mode = gmTools.coalesce(org, 'new', 'edit') 506 dlg = gmEditArea.cGenericEditAreaDlg2(parent = parent, id = -1, edit_area = ea, single_entry = single_entry) 507 dlg.SetTitle(gmTools.coalesce(org, _('Adding new organization'), _('Editing organization'))) 508 if dlg.ShowModal() == wx.ID_OK: 509 dlg.Destroy() 510 return True 511 dlg.Destroy() 512 return False
513 #============================================================
514 -class cOrganizationPhraseWheel(gmPhraseWheel.cPhraseWheel):
515
516 - def __init__(self, *args, **kwargs):
517 query = u""" 518 SELECT DISTINCT ON (data) * FROM ( 519 SELECT * FROM (( 520 521 SELECT 522 pk_org 523 AS data, 524 organization || ' (' || l10n_category || ')' 525 AS list_label, 526 organization || ' (' || l10n_category || ')' 527 AS field_label 528 FROM 529 dem.v_orgs 530 WHERE 531 organization %(fragment_condition)s 532 533 ) UNION ALL ( 534 535 SELECT 536 pk_org 537 AS data, 538 l10n_category || ': ' || organization 539 AS list_label, 540 organization || ' (' || l10n_category || ')' 541 AS field_label 542 FROM 543 dem.v_orgs 544 WHERE 545 l10n_category %(fragment_condition)s 546 OR 547 category %(fragment_condition)s 548 549 )) AS all_matches 550 ORDER BY list_label 551 ) AS ordered_matches 552 LIMIT 50 553 """ 554 mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) 555 mp.setThresholds(1, 3, 5) 556 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) 557 self.SetToolTipString(_("Select an organization.")) 558 self.matcher = mp 559 self.selection_only = True
560 561 #==================================================================== 562 from Gnumed.wxGladeWidgets import wxgOrganizationEAPnl 563
564 -class cOrganizationEAPnl(wxgOrganizationEAPnl.wxgOrganizationEAPnl, gmEditArea.cGenericEditAreaMixin):
565
566 - def __init__(self, *args, **kwargs):
567 568 try: 569 data = kwargs['organization'] 570 del kwargs['organization'] 571 except KeyError: 572 data = None 573 574 wxgOrganizationEAPnl.wxgOrganizationEAPnl.__init__(self, *args, **kwargs) 575 gmEditArea.cGenericEditAreaMixin.__init__(self) 576 577 self.mode = 'new' 578 self.data = data 579 if data is not None: 580 self.mode = 'edit'
581 582 #self.__init_ui() 583 #----------------------------------------------------------------
584 - def __init_ui(self):
585 self._PRW_org.selection_only = False
586 #---------------------------------------------------------------- 587 # generic Edit Area mixin API 588 #----------------------------------------------------------------
589 - def _valid_for_save(self):
590 validity = True 591 592 if self._PRW_category.GetData() is None: 593 validity = False 594 self._PRW_category.display_as_valid(False) 595 self._PRW_category.SetFocus() 596 else: 597 self._PRW_category.display_as_valid(True) 598 599 if self.mode == 'edit': 600 if self._PRW_org.GetData() is None: 601 validity = False 602 self._PRW_org.display_as_valid(False) 603 self._PRW_org.SetFocus() 604 else: 605 self._PRW_org.display_as_valid(True) 606 else: 607 if self._PRW_org.GetValue().strip() == u'': 608 validity = False 609 self._PRW_org.display_as_valid(False) 610 self._PRW_org.SetFocus() 611 else: 612 if self._PRW_org.GetData() is not None: 613 validity = False 614 self._PRW_org.display_as_valid(False) 615 self._PRW_org.SetFocus() 616 else: 617 self._PRW_org.display_as_valid(True) 618 619 return validity
620 #----------------------------------------------------------------
621 - def _save_as_new(self):
622 self.data = gmOrganization.create_org ( 623 organization = self._PRW_org.GetValue().strip(), 624 category = self._PRW_category.GetData() 625 ) 626 return True
627 #----------------------------------------------------------------
628 - def _save_as_update(self):
629 self.data['pk_org'] = self._PRW_org.GetData() 630 self.data['pk_category_org'] = self._PRW_category.GetData() 631 self.data.save() 632 return True
633 #----------------------------------------------------------------
634 - def _refresh_as_new(self):
635 self._PRW_org.SetText(value = u'', data = None) 636 self._PRW_category.SetText(value = u'', data = None) 637 638 self._PRW_org.SetFocus()
639 #----------------------------------------------------------------
641 self._PRW_org.SetText(value = u'', data = None) 642 self._PRW_category.SetText(value = self.data['l10n_category'], data = self.data['pk_category_org']) 643 644 self._PRW_org.SetFocus()
645 #----------------------------------------------------------------
646 - def _refresh_from_existing(self):
647 self._PRW_org.SetText(value = self.data['organization'], data = self.data['pk_org']) 648 self._PRW_category.SetText(value = self.data['l10n_category'], data = self.data['pk_category_org']) 649 650 self._PRW_category.SetFocus()
651 652 #============================================================
653 -class cOrgCategoryPhraseWheel(gmPhraseWheel.cPhraseWheel):
654
655 - def __init__(self, *args, **kwargs):
656 query = u""" 657 SELECT DISTINCT ON (data) 658 * 659 FROM ( 660 SELECT 661 pk 662 AS data, 663 _(description) || ' (' || description || ')' 664 AS list_label, 665 _(description) 666 AS field_label 667 FROM 668 dem.org_category 669 WHERE 670 _(description) %(fragment_condition)s 671 OR 672 description %(fragment_condition)s 673 ORDER BY list_label 674 ) AS ordered_matches 675 LIMIT 50 676 """ 677 mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) 678 mp.setThresholds(1, 3, 5) 679 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) 680 self.SetToolTipString(_("Select an organizational category.")) 681 self.matcher = mp 682 self.selection_only = True
683 684 #============================================================
685 -class cOrganizationsManagerPnl(gmListWidgets.cGenericListManagerPnl):
686 """A list for managing organizations.""" 687
688 - def __init__(self, *args, **kwargs):
689 690 gmListWidgets.cGenericListManagerPnl.__init__(self, *args, **kwargs) 691 692 self.refresh_callback = self.refresh 693 self.new_callback = self._add 694 self.edit_callback = self._edit 695 self.delete_callback = self._del 696 697 self.__init_ui() 698 self.refresh()
699 #-------------------------------------------------------- 700 # external API 701 #--------------------------------------------------------
702 - def refresh(self, lctrl=None):
703 orgs = gmOrganization.get_orgs(order_by = 'organization, l10n_category') 704 items = [ [o['organization'], o['l10n_category'], o['pk_org']] for o in orgs ] 705 self._LCTRL_items.set_string_items(items) 706 self._LCTRL_items.set_data(orgs)
707 #-------------------------------------------------------- 708 # event handlers 709 #--------------------------------------------------------
710 - def _add(self):
711 return edit_org(parent = self, org = None, single_entry = False)
712 #--------------------------------------------------------
713 - def _edit(self, item):
714 return edit_org(parent = self, org = item, single_entry = True)
715 #--------------------------------------------------------
716 - def _del(self, item):
717 return gmOrganization.delete_org(organization = item['pk_org'])
718 #--------------------------------------------------------
719 - def _on_list_item_focused(self, event):
720 pass
721 #-------------------------------------------------------- 722 # internal helpers 723 #--------------------------------------------------------
724 - def __init_ui(self):
725 self._LCTRL_items.SetToolTipString(_('Organizations registered in GNUmed.')) 726 self._LCTRL_items.set_columns(columns = [_('Organization'), _('Category'), u'#'])
727 #self._LCTRL_items.set_column_widths(widths = [wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE]) 728 #============================================================ 729 from Gnumed.wxGladeWidgets import wxgOrganizationManagerDlg 730
731 -class cOrganizationManagerDlg(wxgOrganizationManagerDlg.wxgOrganizationManagerDlg):
732
733 - def __init__(self, *args, **kwargs):
734 735 wxgOrganizationManagerDlg.wxgOrganizationManagerDlg.__init__(self, *args, **kwargs) 736 737 self.Centre(direction = wx.BOTH) 738 739 self._PNL_address.type_is_editable = False 740 self._PNL_orgs.select_callback = self._on_org_selected 741 self._PNL_units.select_callback = self._on_unit_selected 742 self._PNL_comms.message = _('Communication channels') 743 744 # FIXME: find proper button 745 #self._PNL_units.MoveAfterInTabOrder(self._PNL_orgs._BTN_) 746 747 self._on_org_selected(None) 748 self._PNL_orgs._LCTRL_items.SetFocus()
749 #-------------------------------------------------------- 750 # event handlers 751 #--------------------------------------------------------
752 - def _on_org_selected(self, item):
753 self._PNL_units.org = item 754 self._on_unit_selected(None)
755 #--------------------------------------------------------
756 - def _on_unit_selected(self, item):
757 self._PNL_address.unit = item 758 self._PNL_comms.channel_owner = item 759 if item is None: 760 self._PNL_comms._BTN_add.Enable(False) 761 else: 762 self._PNL_comms._BTN_add.Enable(True)
763 #============================================================ 764 # main 765 #------------------------------------------------------------ 766 if __name__ == "__main__": 767 768 if len(sys.argv) < 2: 769 sys.exit() 770 771 if sys.argv[1] != u'test': 772 sys.exit() 773 774 from Gnumed.pycommon import gmPG2 775 from Gnumed.pycommon import gmI18N 776 gmI18N.activate_locale() 777 gmI18N.install_domain() 778 779 #--------------------------------------------------------
780 - def test_org_prw():
781 app = wx.PyWidgetTester(size = (200, 50)) 782 pw = cOrganizationPhraseWheel(app.frame, -1) 783 app.frame.Show(True) 784 app.MainLoop()
785 #--------------------------------------------------------
786 - def test_org_unit_prw():
787 app = wx.PyWidgetTester(size = (200, 50)) 788 pw = cOrgUnitPhraseWheel(app.frame, -1) 789 app.frame.Show(True) 790 app.MainLoop()
791 #--------------------------------------------------------
792 - def test():
793 conn = gmPG2.get_connection() 794 app = wx.PyWidgetTester(size = (600, 600)) 795 dlg = cOrganizationManagerDlg(app.frame, -1, size = (600, 600)) 796 dlg.SetSize((600, 600)) 797 dlg.ShowModal() 798 # app.SetWidget(dlg, -1) 799 app.MainLoop()
800 #-------------------------------------------------------- 801 #test_org_unit_prw() 802 #test_org_prw() 803 test() 804 805 #====================================================================== 806