From 7fdb250b713480ace09ce31216447b49746ac89a Mon Sep 17 00:00:00 2001
From: Luke Leighton <lkcl@lkcl.net>
Date: Mon, 13 Sep 2010 11:52:09 +0100
Subject: [PATCH 15/34] remove app variable, use builder for mainpanel, whitespace cleanup

---
 gnumed/gnumed/client/ProxiedWeb/gui/GNUmedWeb.py   |    6 ++--
 gnumed/gnumed/client/ProxiedWeb/gui/MainPanel.py   |   32 ++++++++++++-------
 .../client/ProxiedWeb/gui/PatientsearchPanel.py    |   29 +++++++++--------
 .../client/ProxiedWeb/gui/PatientsummaryPanel.py   |    6 ++--
 gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py   |    3 +-
 .../client/ProxiedWeb/gui/public/gnumedweb.xml     |    4 +-
 6 files changed, 44 insertions(+), 36 deletions(-)

diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/GNUmedWeb.py b/gnumed/gnumed/client/ProxiedWeb/gui/GNUmedWeb.py
index 6ffe384..0357a37 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/GNUmedWeb.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/GNUmedWeb.py
@@ -19,7 +19,7 @@ class gmTopLevelLayer:
 
         self.TEXT_ERROR = "Server Error"
         self.loginpanel = cLoginPanel() # fires logged out on UI load
-        self.afterloginpanel = cMainPanel(self, Spacing=8, Width="100%")
+        self.afterloginpanel = cMainPanel()
 
         self.maindisplay = DockPanel(
                           HorizontalAlignment=HasAlignment.ALIGN_CENTER,
@@ -40,14 +40,14 @@ class gmTopLevelLayer:
         self.login_username = None
         self.loginpanel.setStatus("") # reset status display
         if self.maindisplay.center is not None:
-            self.maindisplay.remove(self.afterloginpanel)
+            self.maindisplay.remove(self.afterloginpanel.getPanel())
         self.maindisplay.add(self.loginpanel.getPanel(), DockPanel.CENTER)
 
     def logged_in(self, username):
         self.login_username = username
         if self.maindisplay.center is not None:
             self.maindisplay.remove(self.loginpanel.getPanel())
-        self.maindisplay.add(self.afterloginpanel, DockPanel.CENTER)
+        self.maindisplay.add(self.afterloginpanel.getPanel(), DockPanel.CENTER)
 
 #======================================================
 if __name__ == '__main__':
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/MainPanel.py b/gnumed/gnumed/client/ProxiedWeb/gui/MainPanel.py
index ece5271..fbb0b70 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/MainPanel.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/MainPanel.py
@@ -19,22 +19,30 @@ from LogoutCommand import cLogoutCommand
 
 #======================================================
 class cMainPanel(cOpenCommand, cSaveCommand, cLogoutCommand):
+
     def __init__(self):
 
+        HTTPUILoader(self).load("gnumedweb.xml") # calls onUILoaded when done
+
+    def onUILoaded(self, text):
+        self.b = Builder(text)
+        self.mp = self.b.createInstance("MainPanel", self)
+
         # tab panel
-        self.fTabs = DecoratedTabPanel(Size=("1024px", "100%"))
-        self.fTabs.add(cPatientsummaryPanel(app), "Patient summary")
-        self.fTabs.add(HTML("Panel 2"), "Tab2")
-        self.fTabs.add(HTML(""), None) # spacer
-        self.fTabs.add(cTestPanel(app), "RPC Test")
-        self.fTabs.add(HTML("This is a Test.<br />Tab should be on right"),
+        self.mp.fTabs.add(cPatientsummaryPanel(), "Patient summary")
+        self.mp.fTabs.add(HTML("Panel 2"), "Tab2")
+        self.mp.fTabs.add(HTML(""), None) # spacer
+        self.mp.fTabs.add(cTestPanel(), "RPC Test")
+        self.mp.fTabs.add(HTML("This is a Test.<br />Tab should be on right"),
                        "Test")
-        self.fTabs.selectTab(0)
+        self.mp.fTabs.selectTab(0)
+
+        self.searchpanel = cPatientsearchPanel()
+        self.mp.insert(self.searchpanel, 1)
 
-        # commands
-        self.savecmd = cSaveCommand(app)
-        self.opencmd = cOpenCommand(app)
-        self.logoutcmd = cLogoutCommand(app)
+    def getPanel(self):
+        return self.mp
 
-        self.searchpanel = cPatientsearchPanel(app)
+    def onMenuItemRegisterPerson(self):
+        print "TODO: register person"
 
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/PatientsearchPanel.py b/gnumed/gnumed/client/ProxiedWeb/gui/PatientsearchPanel.py
index e41ce19..6cf8c06 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/PatientsearchPanel.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/PatientsearchPanel.py
@@ -16,31 +16,31 @@ class cPatientsearchPanel(HorizontalPanel):
     def __init__(self, **kwargs):
         HorizontalPanel.__init__(self, **kwargs)
 
-	self.patientphoto = Image("images/empty-face-in-bust.png")
-	self.searchbox = TextBox(Text="<search patient here>")
-	self.search_button = Button("Search", self)
-	self.lblcave= Label()
+        self.patientphoto = Image("images/empty-face-in-bust.png")
+        self.searchbox = TextBox(Text="<search patient here>")
+        self.search_button = Button("Search", self)
+        self.lblcave= Label()
         self.lblcave.setText("cave")
         self.allergybox = TextBox(Text = "allergies")
-	self.add(self.patientphoto)
-	self.add(self.searchbox)
-	self.add(self.search_button)
-	self.add(self.lblcave)
-	self.add(self.allergybox)
+        self.add(self.patientphoto)
+        self.add(self.searchbox)
+        self.add(self.search_button)
+        self.add(self.lblcave)
+        self.add(self.allergybox)
         
     #--------------------------------------------------
     def onClick(self, sender):
 
         # demonstrate proxy & callMethod()
         if sender == self.search_button:
-		search_term = self.searchbox.getText()
-                id = Remote.svc.search_patient(self, search_term)
+            search_term = self.searchbox.getText()
+            id = Remote.svc.search_patient(self, search_term)
 
     #--------------------------------------------------
     def onRemoteResponse(self, response, request_info):
         method = request_info.method
         if method == 'search_patient':
-		self.searchbox.setText(str(response))
+            self.searchbox.setText(str(response))
 
     #--------------------------------------------------
     def onRemoteError(self, code, errobj, request_info):
@@ -56,7 +56,7 @@ class cPatientsearchPanel(HorizontalPanel):
             #self.status.setText("HTTP error %d: %s" % 
             #                    (code, message))
             msg = "HTTP error %d: %s" % (code, message)
-            self.popup = cSimplePopup(contents = msg)
+            self.popup = cSimplePopup(msg)
         else:
             code = errobj['code']
             #if message['message'] == 'Cannot request login parameters.':
@@ -65,4 +65,5 @@ class cPatientsearchPanel(HorizontalPanel):
             #    self.status.setText("JSONRPC Error %s: %s" %
             #                    (code, message))
             msg = ("JSONRPC Error %s: %s" % (code, message))
-            self.popup = cSimplePopup(contents = msg)
+            self.popup = cSimplePopup(msg)
+
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/PatientsummaryPanel.py b/gnumed/gnumed/client/ProxiedWeb/gui/PatientsummaryPanel.py
index f87c5b0..a1c6557 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/PatientsummaryPanel.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/PatientsummaryPanel.py
@@ -3,8 +3,7 @@ from pyjamas.ui.StackPanel import StackPanel
 from pyjamas.ui.HTML import HTML
 
 class cPatientsummaryPanel(SimplePanel):
-    def __init__(self, app):
-        self.app = app
+    def __init__(self):
         SimplePanel.__init__(self)
 
         stack = StackPanel(Width="100%", Height="300px")
@@ -28,4 +27,5 @@ class cPatientsummaryPanel(SimplePanel):
         stack.add(HTML('The smart money<br>is on the<br>black horse.'),
                   "Problem list")
  
-        self.add(stack)
\ No newline at end of file
+        self.add(stack)
+
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py b/gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py
index e753f04..9b22094 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/TestPanel.py
@@ -15,8 +15,7 @@ import Remote
 
 #======================================================
 class cTestPanel(VerticalPanel):
-    def __init__(self, app, **kwargs):
-        self.app = app
+    def __init__(self, **kwargs):
         VerticalPanel.__init__(self, **kwargs)
 
         info = """<h2>JSON-RPC Example</h2>
diff --git a/gnumed/gnumed/client/ProxiedWeb/gui/public/gnumedweb.xml b/gnumed/gnumed/client/ProxiedWeb/gui/public/gnumedweb.xml
index 0ffaada..01b24e8 100644
--- a/gnumed/gnumed/client/ProxiedWeb/gui/public/gnumedweb.xml
+++ b/gnumed/gnumed/client/ProxiedWeb/gui/public/gnumedweb.xml
@@ -132,13 +132,13 @@
 					<property name="name" value="MenuBar1" />
 				</properties>
 			</component>
-			<component id="TabPanel1" name="TabPanel" type="Panel" index="1">
+			<component id="fTabs" name="TabPanel" type="Panel" index="1">
 				<properties name="layout">
 					<property name="width" value="100%" />
 					<property name="height" value="100%" />
 				</properties>
 				<properties name="common">
-					<property name="name" value="TabPanel1" />
+					<property name="name" value="fTabs" />
 				</properties>
 			</component>
 		</components>
-- 
1.7.1

