Home | Trees | Indices | Help |
|
---|
|
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 #------------------------------------------------------------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 False47 #============================================================49107 108 #============================================================51 query = u""" 52 SELECT DISTINCT ON (data) * FROM ( 53 SELECT * FROM (( 54 55 SELECT 56 pk_org_unit 57 AS data, 58 unit || ' (' || l10n_unit_category || '): ' || organization || ' (' || l10n_organization_category || ')' 59 AS list_label, 60 unit || ' (' || organization || ')' 61 AS field_label 62 FROM 63 dem.v_org_units 64 WHERE 65 unit %(fragment_condition)s 66 67 ) UNION ALL ( 68 69 SELECT 70 pk_org_unit 71 AS data, 72 l10n_unit_category || ' "' || unit || '": ' || organization || ' (' || l10n_organization_category || ')' 73 AS list_label, 74 unit || ' (' || organization || ')' 75 AS field_label 76 FROM 77 dem.v_org_units 78 WHERE 79 l10n_unit_category %(fragment_condition)s 80 OR 81 unit_category %(fragment_condition)s 82 83 ) UNION ALL ( 84 85 SELECT 86 pk_org_unit 87 AS data, 88 organization || ': ' || unit || ' (' || l10n_unit_category || ')' 89 AS list_label, 90 unit || ' (' || organization || ')' 91 AS field_label 92 FROM 93 dem.v_org_units 94 WHERE 95 organization %(fragment_condition)s 96 97 )) AS all_matches 98 ORDER BY list_label 99 ) AS ordered_matches 100 LIMIT 50 101 """ 102 mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) 103 mp.setThresholds(1, 3, 5) 104 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) 105 self.SetToolTipString(_("Select an organizational unit.")) 106 self.matcher = mp110 """A list for managing organizational units.""" 111213 214 #============================================================ 215 # org unit edit area 216 from Gnumed.wxGladeWidgets import wxgOrgUnitEAPnl 217113 114 try: 115 self.__org = kwargs['org'] 116 del kwargs['org'] 117 except KeyError: 118 self.__org = None 119 120 gmListWidgets.cGenericListManagerPnl.__init__(self, *args, **kwargs) 121 122 self.refresh_callback = self.refresh 123 self.new_callback = self._add 124 self.edit_callback = self._edit 125 self.delete_callback = self._del 126 127 self.__show_none_if_no_org = True 128 self.__init_ui() 129 self.__refresh()130 #-------------------------------------------------------- 131 # external API 132 #-------------------------------------------------------- 135 #-------------------------------------------------------- 136 # event handlers 137 #-------------------------------------------------------- 140 #--------------------------------------------------------142 return edit_org_unit(parent = self, org_unit = item, single_entry = True)143 #-------------------------------------------------------- 146 #-------------------------------------------------------- 149 #-------------------------------------------------------- 150 # internal helpers 151 #--------------------------------------------------------153 self._LCTRL_items.SetToolTipString(_('Units (sites, parts, departments, branches, ...) of organizations registered in GNUmed.')) 154 self._LCTRL_items.set_columns(columns = [ _('Organizational Unit'), _('Unit Category'), u'#' ])155 #self._LCTRL_items.set_column_widths(widths = [wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE]) 156 #--------------------------------------------------------158 159 msg_template = _('Units of: %s') 160 161 if self.__org is None: 162 self._BTN_add.Enable(False) 163 self._BTN_edit.Enable(False) 164 self._BTN_remove.Enable(False) 165 pk = None 166 self.message = msg_template % _('<no organization selected>') 167 if self.__show_none_if_no_org: 168 self._LCTRL_items.set_string_items(items = None) 169 return 170 else: 171 self._BTN_add.Enable(True) 172 pk = self.__org['pk_org'] 173 org_str = u'%s (%s)' % ( 174 self.__org['organization'], 175 self.__org['l10n_category'] 176 ) 177 self.message = msg_template % org_str 178 179 units = gmOrganization.get_org_units(order_by = 'unit, l10n_unit_category', org = pk) 180 items = [ [ 181 u['unit'], 182 gmTools.coalesce(u['l10n_unit_category'], u''), 183 u['pk_org_unit'] 184 ] for u in units ] 185 186 self._LCTRL_items.set_string_items(items) 187 self._LCTRL_items.set_data(units)188 #-------------------------------------------------------- 189 # properties 190 #-------------------------------------------------------- 193 197 198 org = property(_get_org, _set_org) 199 #-------------------------------------------------------- 202204 if show_none_if_no_org == self.__show_none_if_no_org: 205 return 206 if show_none_if_no_org: 207 self.__show_none_if_no_org = True 208 else: 209 self.__show_none_if_no_org = False 210 self.__refresh()211 212 show_none_if_no_org = property(_get_show_none_if_no_org, _set_show_none_if_no_org)219318 #============================================================ 319 from Gnumed.wxGladeWidgets import wxgOrgUnitAddressPnl 320221 222 try: 223 data = kwargs['unit'] 224 del kwargs['unit'] 225 except KeyError: 226 data = None 227 228 wxgOrgUnitEAPnl.wxgOrgUnitEAPnl.__init__(self, *args, **kwargs) 229 gmEditArea.cGenericEditAreaMixin.__init__(self) 230 231 self.mode = 'new' 232 self.data = data 233 if data is not None: 234 self.mode = 'edit'235 236 # self.__init_ui() 237 #---------------------------------------------------------------- 238 # def __init_ui(self): 239 # pass 240 #---------------------------------------------------------------- 241 # generic Edit Area mixin API 242 #----------------------------------------------------------------244 validity = True 245 246 if self._PRW_category.GetData() is not None: 247 self._PRW_category.display_as_valid(True) 248 else: 249 if self._PRW_category.GetValue().strip() == u'': 250 self._PRW_category.display_as_valid(True) 251 else: 252 validity = False 253 self._PRW_category.display_as_valid(False) 254 self._PRW_category.SetFocus() 255 256 if self._PRW_unit.GetData() is not None: 257 self._PRW_unit.display_as_valid(True) 258 else: 259 if self._PRW_unit.GetValue().strip() != u'': 260 self._PRW_unit.display_as_valid(True) 261 else: 262 validity = False 263 self._PRW_unit.display_as_valid(False) 264 self._PRW_unit.SetFocus() 265 266 if self._PRW_org.GetData() is None: 267 validity = False 268 self._PRW_org.display_as_valid(False) 269 self._PRW_org.SetFocus() 270 else: 271 self._PRW_org.display_as_valid(True) 272 273 return validity274 #----------------------------------------------------------------276 data = gmOrganization.create_org_unit ( 277 pk_organization = self._PRW_org.GetData(), 278 unit = self._PRW_unit.GetValue().strip() 279 ) 280 data['pk_category_unit'] = self._PRW_category.GetData() 281 data.save() 282 283 self.data = data 284 return True285 #----------------------------------------------------------------287 self.data['pk_org'] = self._PRW_org.GetData() 288 self.data['unit'] = self._PRW_unit.GetValue().strip() 289 self.data['pk_category_unit'] = self._PRW_category.GetData() 290 self.data.save() 291 return True292 #----------------------------------------------------------------294 self._PRW_org.SetText(value = u'', data = None) 295 self._PRW_unit.SetText(value = u'', data = None) 296 self._PRW_category.SetText(value = u'', data = None) 297 298 self._PRW_unit.SetFocus()299 #----------------------------------------------------------------301 self._PRW_org.SetText(value = self.data['organization'], data = self.data['pk_org']) 302 self._PRW_unit.SetText(value = u'', data = None) 303 self._PRW_category.SetText(value = self.data['unit_category'], data = self.data['pk_category_unit']) 304 305 self._PRW_unit.SetFocus()306 #----------------------------------------------------------------308 self._PRW_org.SetText(value = self.data['organization'], data = self.data['pk_org']) 309 self._PRW_unit.SetText(value = self.data['unit'], data = self.data['pk_org_unit']) 310 self._PRW_category.SetText(value = self.data['unit_category'], data = self.data['pk_category_unit']) 311 312 self._PRW_unit.SetFocus()313 #---------------------------------------------------------------- 316 317 organization = property(lambda x:x, _set_org)322434 #============================================================ 435 # organizations API 436 #------------------------------------------------------------324 325 wxgOrgUnitAddressPnl.wxgOrgUnitAddressPnl.__init__(self, *args, **kwargs) 326 327 self.__unit = None328 #-------------------------------------------------------- 329 # internal helpers 330 #--------------------------------------------------------332 if self.__unit is None: 333 self.message = _('<no unit selected>') 334 self._PRW_address_searcher.SetText(u'', None) 335 self._PRW_address_searcher.Enable(False) 336 self._PRW_address_searcher.display_as_disabled(True) 337 self._BTN_save_picked_address.Enable(False) 338 self._BTN_add_new_address.Enable(False) 339 else: 340 if self.__unit['l10n_unit_category'] is None: 341 cat = u'' 342 left_delim = u'' 343 right_delim = u'' 344 else: 345 cat = u'%s ' % self.__unit['l10n_unit_category'] 346 left_delim = gmTools.u_left_double_angle_quote 347 right_delim = gmTools.u_right_double_angle_quote 348 self.message = u'%s%s%s%s' % ( 349 cat, 350 left_delim, 351 self.__unit['unit'], 352 right_delim 353 ) 354 self._PRW_address_searcher.Enable(True) 355 self._PRW_address_searcher.address = self.__unit['pk_address'] 356 self._PRW_address_searcher.Enable(True) 357 self._PRW_address_searcher.display_as_disabled(False) 358 self._BTN_save_picked_address.Enable(True) 359 self._BTN_add_new_address.Enable(True)360 #-------------------------------------------------------- 361 # event handlers 362 #-------------------------------------------------------- 376 #-------------------------------------------------------- 387 #-------------------------------------------------------- 409 #-------------------------------------------------------- 410 # properties 411 #-------------------------------------------------------- 414 418 419 unit = property(_get_unit, _set_unit) 420 #-------------------------------------------------------- 423425 if msg is None: 426 self._LBL_message.Hide() 427 self._LBL_message.SetLabel(u'') 428 else: 429 self._LBL_message.SetLabel(msg) 430 self._LBL_message.Show() 431 self.Layout()432 433 message = property(_get_message, _set_message)438 439 if parent is None: 440 parent = wx.GetApp().GetTopWindow() 441 442 dlg = cOrganizationManagerDlg(parent, -1) 443 dlg.ShowModal()444 #============================================================446 ea = cOrganizationEAPnl(parent = parent, id = -1) 447 ea.data = org 448 ea.mode = gmTools.coalesce(org, 'new', 'edit') 449 dlg = gmEditArea.cGenericEditAreaDlg2(parent = parent, id = -1, edit_area = ea, single_entry = single_entry) 450 dlg.SetTitle(gmTools.coalesce(org, _('Adding new organization'), _('Editing organization'))) 451 if dlg.ShowModal() == wx.ID_OK: 452 dlg.Destroy() 453 return True 454 dlg.Destroy() 455 return False456 #============================================================458503 504 #==================================================================== 505 from Gnumed.wxGladeWidgets import wxgOrganizationEAPnl 506460 query = u""" 461 SELECT DISTINCT ON (data) * FROM ( 462 SELECT * FROM (( 463 464 SELECT 465 pk_org 466 AS data, 467 organization || ' (' || l10n_category || ')' 468 AS list_label, 469 organization || ' (' || l10n_category || ')' 470 AS field_label 471 FROM 472 dem.v_orgs 473 WHERE 474 organization %(fragment_condition)s 475 476 ) UNION ALL ( 477 478 SELECT 479 pk_org 480 AS data, 481 l10n_category || ': ' || organization 482 AS list_label, 483 organization || ' (' || l10n_category || ')' 484 AS field_label 485 FROM 486 dem.v_orgs 487 WHERE 488 l10n_category %(fragment_condition)s 489 OR 490 category %(fragment_condition)s 491 492 )) AS all_matches 493 ORDER BY list_label 494 ) AS ordered_matches 495 LIMIT 50 496 """ 497 mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) 498 mp.setThresholds(1, 3, 5) 499 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) 500 self.SetToolTipString(_("Select an organization.")) 501 self.matcher = mp 502 self.selection_only = True507 -class cOrganizationEAPnl(wxgOrganizationEAPnl.wxgOrganizationEAPnl, gmEditArea.cGenericEditAreaMixin):508594 595 #============================================================510 511 try: 512 data = kwargs['organization'] 513 del kwargs['organization'] 514 except KeyError: 515 data = None 516 517 wxgOrganizationEAPnl.wxgOrganizationEAPnl.__init__(self, *args, **kwargs) 518 gmEditArea.cGenericEditAreaMixin.__init__(self) 519 520 self.mode = 'new' 521 self.data = data 522 if data is not None: 523 self.mode = 'edit'524 525 #self.__init_ui() 526 #---------------------------------------------------------------- 529 #---------------------------------------------------------------- 530 # generic Edit Area mixin API 531 #----------------------------------------------------------------533 validity = True 534 535 if self._PRW_category.GetData() is None: 536 validity = False 537 self._PRW_category.display_as_valid(False) 538 self._PRW_category.SetFocus() 539 else: 540 self._PRW_category.display_as_valid(True) 541 542 if self.mode == 'edit': 543 if self._PRW_org.GetData() is None: 544 validity = False 545 self._PRW_org.display_as_valid(False) 546 self._PRW_org.SetFocus() 547 else: 548 self._PRW_org.display_as_valid(True) 549 else: 550 if self._PRW_org.GetValue().strip() == u'': 551 validity = False 552 self._PRW_org.display_as_valid(False) 553 self._PRW_org.SetFocus() 554 else: 555 if self._PRW_org.GetData() is not None: 556 validity = False 557 self._PRW_org.display_as_valid(False) 558 self._PRW_org.SetFocus() 559 else: 560 self._PRW_org.display_as_valid(True) 561 562 return validity563 #----------------------------------------------------------------565 self.data = gmOrganization.create_org ( 566 organization = self._PRW_org.GetValue().strip(), 567 category = self._PRW_category.GetData() 568 ) 569 return True570 #----------------------------------------------------------------572 self.data['pk_org'] = self._PRW_org.GetData() 573 self.data['pk_category_org'] = self._PRW_category.GetData() 574 self.data.save() 575 return True576 #----------------------------------------------------------------578 self._PRW_org.SetText(value = u'', data = None) 579 self._PRW_category.SetText(value = u'', data = None) 580 581 self._PRW_org.SetFocus()582 #----------------------------------------------------------------584 self._PRW_org.SetText(value = u'', data = None) 585 self._PRW_category.SetText(value = self.data['l10n_category'], data = self.data['pk_category_org']) 586 587 self._PRW_org.SetFocus()588 #----------------------------------------------------------------597626 627 #============================================================599 query = u""" 600 SELECT DISTINCT ON (data) 601 * 602 FROM ( 603 SELECT 604 pk 605 AS data, 606 _(description) || ' (' || description || ')' 607 AS list_label, 608 _(description) 609 AS field_label 610 FROM 611 dem.org_category 612 WHERE 613 _(description) %(fragment_condition)s 614 OR 615 description %(fragment_condition)s 616 ORDER BY list_label 617 ) AS ordered_matches 618 LIMIT 50 619 """ 620 mp = gmMatchProvider.cMatchProvider_SQL2(queries=query) 621 mp.setThresholds(1, 3, 5) 622 gmPhraseWheel.cPhraseWheel.__init__(self, *args, **kwargs) 623 self.SetToolTipString(_("Select an organizational category.")) 624 self.matcher = mp 625 self.selection_only = True629 """A list for managing organizations.""" 630670 #self._LCTRL_items.set_column_widths(widths = [wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE]) 671 #============================================================ 672 from Gnumed.wxGladeWidgets import wxgOrganizationManagerDlg 673632 633 gmListWidgets.cGenericListManagerPnl.__init__(self, *args, **kwargs) 634 635 self.refresh_callback = self.refresh 636 self.new_callback = self._add 637 self.edit_callback = self._edit 638 self.delete_callback = self._del 639 640 self.__init_ui() 641 self.refresh()642 #-------------------------------------------------------- 643 # external API 644 #--------------------------------------------------------646 orgs = gmOrganization.get_orgs(order_by = 'organization, l10n_category') 647 items = [ [o['organization'], o['l10n_category'], o['pk_org']] for o in orgs ] 648 self._LCTRL_items.set_string_items(items) 649 self._LCTRL_items.set_data(orgs)650 #-------------------------------------------------------- 651 # event handlers 652 #-------------------------------------------------------- 655 #-------------------------------------------------------- 658 #-------------------------------------------------------- 661 #-------------------------------------------------------- 664 #-------------------------------------------------------- 665 # internal helpers 666 #--------------------------------------------------------668 self._LCTRL_items.SetToolTipString(_('Organizations registered in GNUmed.')) 669 self._LCTRL_items.set_columns(columns = [_('Organization'), _('Category'), u'#'])675706 #============================================================ 707 # main 708 #------------------------------------------------------------ 709 if __name__ == "__main__": 710 711 if len(sys.argv) < 2: 712 sys.exit() 713 714 if sys.argv[1] != u'test': 715 sys.exit() 716 717 from Gnumed.pycommon import gmPG2 718 from Gnumed.pycommon import gmI18N 719 gmI18N.activate_locale() 720 gmI18N.install_domain() 721 722 #--------------------------------------------------------677 678 wxgOrganizationManagerDlg.wxgOrganizationManagerDlg.__init__(self, *args, **kwargs) 679 680 self.Centre(direction = wx.BOTH) 681 682 self._PNL_address.type_is_editable = False 683 self._PNL_orgs.select_callback = self._on_org_selected 684 self._PNL_units.select_callback = self._on_unit_selected 685 self._PNL_comms.message = _('Communication channels') 686 687 # FIXME: find proper button 688 #self._PNL_units.MoveAfterInTabOrder(self._PNL_orgs._BTN_) 689 690 self._on_org_selected(None) 691 self._PNL_orgs._LCTRL_items.SetFocus()692 #-------------------------------------------------------- 693 # event handlers 694 #-------------------------------------------------------- 698 #--------------------------------------------------------700 self._PNL_address.unit = item 701 self._PNL_comms.channel_owner = item 702 if item is None: 703 self._PNL_comms._BTN_add.Enable(False) 704 else: 705 self._PNL_comms._BTN_add.Enable(True)724 app = wx.PyWidgetTester(size = (200, 50)) 725 pw = cOrganizationPhraseWheel(app.frame, -1) 726 app.frame.Show(True) 727 app.MainLoop()728 #--------------------------------------------------------730 app = wx.PyWidgetTester(size = (200, 50)) 731 pw = cOrgUnitPhraseWheel(app.frame, -1) 732 app.frame.Show(True) 733 app.MainLoop()734 #--------------------------------------------------------736 conn = gmPG2.get_connection() 737 app = wx.PyWidgetTester(size = (600, 600)) 738 dlg = cOrganizationManagerDlg(app.frame, -1, size = (600, 600)) 739 dlg.SetSize((600, 600)) 740 dlg.ShowModal() 741 # app.SetWidget(dlg, -1) 742 app.MainLoop()743 #-------------------------------------------------------- 744 #test_org_unit_prw() 745 #test_org_prw() 746 test() 747 748 #====================================================================== 749
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Sep 7 03:59:06 2011 | http://epydoc.sourceforge.net |