/[gnue]/gnue-navigator/src/UIwin32.py
ViewVC logotype

Diff of /gnue-navigator/src/UIwin32.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by btami, Fri Jun 27 07:22:43 2003 UTC revision 1.3 by btami, Sat Jul 5 22:09:30 2003 UTC
# Line 29  Line 29 
29  # reuse GNUe Form's UI* classes if at all possible.  # reuse GNUe Form's UI* classes if at all possible.
30    
31    
32  from time import sleep  import os, sys
 import os, sys, string  
33  from gnue.common.datasources import GDataObjects, GConnections  from gnue.common.datasources import GDataObjects, GConnections
34  from gnue.common.utils.FileUtils import dyn_import, openResource  from gnue.common.utils.FileUtils import dyn_import, openResource
35  from gnue.common.apps import GConfig  from gnue.common.apps import GConfig
# Line 48  except ImportError: Line 47  except ImportError:
47    FORMS_SUPPORT=1    FORMS_SUPPORT=1
48    print 'GNUe Forms is not installed on your system'    print 'GNUe Forms is not installed on your system'
49    
50  import struct, array  import struct, array, tempfile
51  import win32api, win32gui, win32ui, win32con, commctrl  import win32api, win32gui, win32ui, win32con, commctrl
52    from pywin.mfc import window, activex
53    from win32com.client import gencache
54    
55    WebBrowserModule = gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
56    if WebBrowserModule is None:
57      raise ImportError, "IE4 does not appear to be installed."
58    
59  ID_EXIT = getNextId()  ID_EXIT = getNextId()
60  ID_FAV_ORG = getNextId()  ID_FAV_ORG = getNextId()
# Line 58  ID_ABOUT = getNextId() Line 63  ID_ABOUT = getNextId()
63    
64  _menustyle = win32con.MF_STRING  _menustyle = win32con.MF_STRING
65    
66    images_dir = GConfig.getInstalledBase('forms_images','common_images') + '/'
67    
68  class Instance:  class Instance:
69    def __init__(self, processes):    def __init__(self, processes):
70      self.processes = processes      self.processes = processes
71      self._formInstances = {}      self._formInstances = {}
72    
73      self.titlePage = "A part of the GNU Enterprise Project"      self.titlePage = """
74        <html>
75          <body>
76            <center>
77             <B>GNUe Navigator</B>
78             <p><img src="%s"></p>
79             <p>A part of the <a href="http://www.gnuenteprise.org/">GNU Enterprise Project</a></p>
80            </center>
81          </body>
82        </html>
83        """ % (images_dir+"/ship2.png")
84    
85      win32gui.InitCommonControls()      win32gui.InitCommonControls()
86      message_map = {      message_map = {
# Line 81  class Instance: Line 97  class Instance:
97      wc.lpfnWndProc = message_map # could also specify a wndproc.      wc.lpfnWndProc = message_map # could also specify a wndproc.
98      self.classAtom = win32gui.RegisterClass(wc)      self.classAtom = win32gui.RegisterClass(wc)
99      self.hTree = 0      self.hTree = 0
     self.hEdit = 0  
100    
101    def run(self, connections):    def run(self, connections):
102      #      #
# Line 104  class Instance: Line 119  class Instance:
119            
120      self.CreateMenu()      self.CreateMenu()
121      self.BuildTree()      self.BuildTree()
122      self.CreateEdit()      self.tempfile = tempfile.mktemp('.html')
123        self.tempfileHandle = open(self.tempfile, 'w')
124        self.tempfileHandle.write(self.titlePage)
125        self.tempfileHandle.flush()
126    
127        self.CreateBrowser(self.tempfile)
128    
129      self.processes.setClientHandlers({'form':self.runForm})      self.processes.setClientHandlers({'form':self.runForm})
130    
# Line 155  class Instance: Line 175  class Instance:
175  #    win32gui.SendMessage(self.hTree, commctrl.TVM_SETIMAGELIST, commctrl.TVSIL_NORMAL, himl)  #    win32gui.SendMessage(self.hTree, commctrl.TVM_SETIMAGELIST, commctrl.TVSIL_NORMAL, himl)
176    
177    
178    def CreateEdit(self):    def CreateBrowser(self, url):
179        self.browser = BrowserFrame(url)
180      l,t,r,b = win32gui.GetClientRect(self.hMainWindow)      l,t,r,b = win32gui.GetClientRect(self.hMainWindow)
181      style = win32con.WS_VISIBLE | win32con.WS_CHILD |\      self.browser.Create("", rect=((r-l)/3, 0, r-l, b-t),\
182                 win32con.ES_MULTILINE | win32con.ES_READONLY | win32con.ES_LEFT #CENTER                                 parent=win32ui.CreateWindowFromHandle(self.hMainWindow))
     width = (r-l) - (r-l)/3  
     height = b-t  
     self.hEdit = win32gui.CreateWindowEx(win32con.WS_EX_CLIENTEDGE, 'EDIT', '', style, \  
                                                           (r-l)/3,0, width,height, self.hMainWindow, getNextId(), 0, None)  
   
     text = 'GNUe Navigator \r\n \r\n A part of the GNU Enterprise Project'  
     win32gui.SetWindowText(self.hEdit, text)  
     win32gui.ShowWindow(self.hEdit, win32con.SW_SHOWNORMAL)  
183    
184    
185    def OnWMNotify(self, hwnd, msg, wParam, lParam):    def OnWMNotify(self, hwnd, msg, wParam, lParam):
# Line 182  class Instance: Line 195  class Instance:
195    
196      if code == commctrl.TVN_SELCHANGED:      if code == commctrl.TVN_SELCHANGED:
197        object = self._mapping[nhItem]        object = self._mapping[nhItem]
198        win32gui.SetWindowText(self.hEdit, "")        win32gui.SetWindowText(self.browser.GetSafeHwnd(), "")
199        for item in object._children:        for item in object._children:
200          if item._type == 'GNDescription':          if item._type == 'GNDescription':
201            # TODO: use win32help.HtmlHelp or something else...            content = item.getChildrenAsContent()
202            text0 = item.getChildrenAsContent()            self.tempfileHandle.truncate(0)
203            text1 = text0.replace("\n","").replace("<CENTER>","").replace("</CENTER>","").replace("<H1>","").replace("</H1>","\r\n\r\n")            self.tempfileHandle.write("<html\n>")
204            text2 = text1.replace("<p>","\r\n").replace("<B>","").replace("</B>","\r\n").replace("<hr>","\r\n\r\n").replace("<i>","")            self.tempfileHandle.write(content)
205            text3 = text2.replace("</i>","").replace("<a href=","").replace('<font size="-2">',"").replace("</font>","").replace(">","")            self.tempfileHandle.flush()
206            text4 = text3.replace("\t"," ").replace("  ","|").replace("|","")            self.browser.ocx.Refresh()
           win32gui.SetWindowText(self.hEdit, text4)  
207            break            break
208    
209      elif code == commctrl.NM_DBLCLK or code == commctrl.NM_RETURN:      elif code == commctrl.NM_DBLCLK or code == commctrl.NM_RETURN:
# Line 209  class Instance: Line 221  class Instance:
221      win32gui.DestroyWindow(hwnd)      win32gui.DestroyWindow(hwnd)
222      if len(self._app._MainWindowList) == 0:      if len(self._app._MainWindowList) == 0:
223        win32gui.PostQuitMessage(0) # Terminate the app.        win32gui.PostQuitMessage(0) # Terminate the app.
224        self.tempfileHandle.close()
225    
226    
227    def OnWMCommand(self, hwnd, msg, wParam, lParam):    def OnWMCommand(self, hwnd, msg, wParam, lParam):
# Line 223  class Instance: Line 236  class Instance:
236    def OnWMSize(self, hwnd, msg, wParam, lParam):    def OnWMSize(self, hwnd, msg, wParam, lParam):
237      l,t,r,b = win32gui.GetClientRect(self.hMainWindow)      l,t,r,b = win32gui.GetClientRect(self.hMainWindow)
238      win32gui.SetWindowPos(self.hTree, 0, 0, 0, (r-l)/3, b-t, win32con.SWP_NOMOVE | win32con.SWP_NOZORDER)      win32gui.SetWindowPos(self.hTree, 0, 0, 0, (r-l)/3, b-t, win32con.SWP_NOMOVE | win32con.SWP_NOZORDER)
239      win32gui.SetWindowPos(self.hEdit, 0, (r-l)/3, 0, (r-l) - (r-l)/3, b-t, win32con.SWP_NOZORDER)      try:
240          win32gui.SetWindowPos(self.browser.GetSafeHwnd(), 0, (r-l)/3, 0, (r-l) - (r-l)/3, b-t, win32con.SWP_NOZORDER)
241        except:
242          pass
243    
244    
245    def __buildTreeControl(self, object):    def __buildTreeControl(self, object):
# Line 346  class Instance: Line 362  class Instance:
362  #    dlg.Destroy()  #    dlg.Destroy()
363    
364       print mesg       print mesg
365    
366    
367    class MyWebBrowser(activex.Control, WebBrowserModule.WebBrowser):
368      pass
369    #  def OnBeforeNavigate2(self, pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel):
370    #    self.GetParent().OnNavigate(URL)
371    
372    
373    class BrowserFrame(window.Wnd):
374      def __init__(self, url):
375        self.url = url
376    
377      def Create(self, title, rect = None, parent = None):
378        style = win32con.WS_CHILD | win32con.WS_VISIBLE
379        window.Wnd.__init__(self, win32ui.CreateWnd ())
380        self._obj_.AttachObject(self)
381        self._obj_.CreateWindow(None, title, style, rect, parent, getNextId())
382        rect = self.GetClientRect()
383        rect = (0,0,rect[2]-rect[0], rect[3]-rect[1])
384        self.ocx = MyWebBrowser()
385        win32ui.EnableControlContainer()
386        self.ocx.CreateControl("", style, rect, self, getNextId())    
387        self.ocx.Navigate(self.url)
388        self.HookMessage (self.OnSize, win32con.WM_SIZE)
389        
390      def OnSize (self, params):
391        rect = self.GetClientRect()
392        rect = (0,0,rect[2]-rect[0], rect[3]-rect[1])
393        self.ocx.SetWindowPos(0, rect, 0)
394    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26