objdictgen/objdictedit.py
changeset 72 68524f7c58b5
parent 68 234dad27b398
child 147 de96ec63a793
equal deleted inserted replaced
71:95cd3376cc9f 72:68524f7c58b5
    21 #You should have received a copy of the GNU Lesser General Public
    21 #You should have received a copy of the GNU Lesser General Public
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 from wxPython.wx import *
    25 from wxPython.wx import *
    26 from wxPython.html import *
       
    27 from wxPython.grid import *
    26 from wxPython.grid import *
    28 import wx
    27 import wx
    29 from wx.lib.anchors import LayoutAnchors
    28 from wx.lib.anchors import LayoutAnchors
    30 import wx.grid
    29 import wx.grid
    31 
    30 
    36 
    35 
    37 from nodemanager import *
    36 from nodemanager import *
    38 from node import OD_Subindex,OD_MultipleSubindexes,OD_IdenticalSubindexes,OD_IdenticalIndexes
    37 from node import OD_Subindex,OD_MultipleSubindexes,OD_IdenticalSubindexes,OD_IdenticalIndexes
    39 from doc_index.DS301_index import *
    38 from doc_index.DS301_index import *
    40 
    39 
    41 wxEVT_HTML_URL_CLICK = wxNewId()
    40 try:
    42 
    41     from wxPython.html import *
    43 def EVT_HTML_URL_CLICK(win, func):
    42 
    44     win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func)
    43     wxEVT_HTML_URL_CLICK = wxNewId()
    45 
    44 
    46 class wxHtmlWindowUrlClick(wxPyEvent):
    45     def EVT_HTML_URL_CLICK(win, func):
    47     def __init__(self, linkinfo):
    46         win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func)
    48         wxPyEvent.__init__(self)
    47 
    49         self.SetEventType(wxEVT_HTML_URL_CLICK)
    48     class wxHtmlWindowUrlClick(wxPyEvent):
    50         self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
    49         def __init__(self, linkinfo):
    51 
    50             wxPyEvent.__init__(self)
    52 class wxUrlClickHtmlWindow(wxHtmlWindow):
    51             self.SetEventType(wxEVT_HTML_URL_CLICK)
    53     """ HTML window that generates and OnLinkClicked event.
    52             self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
    54 
    53 
    55     Use this to avoid having to override HTMLWindow
    54     class wxUrlClickHtmlWindow(wxHtmlWindow):
    56     """
    55         """ HTML window that generates and OnLinkClicked event.
    57     def OnLinkClicked(self, linkinfo):
    56 
    58         wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo))
    57         Use this to avoid having to override HTMLWindow
       
    58         """
       
    59         def OnLinkClicked(self, linkinfo):
       
    60             wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo))
       
    61     
       
    62 #-------------------------------------------------------------------------------
       
    63 #                                Html Frame
       
    64 #-------------------------------------------------------------------------------
       
    65 
       
    66     [wxID_HTMLFRAME, wxID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)]
       
    67 
       
    68     class HtmlFrame(wx.Frame):
       
    69         def _init_ctrls(self, prnt):
       
    70             # generated method, don't edit
       
    71             wx.Frame.__init__(self, id=wxID_HTMLFRAME, name='HtmlFrame',
       
    72                   parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
       
    73                   style=wx.DEFAULT_FRAME_STYLE, title='')
       
    74             self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_HTMLFRAME)
       
    75             
       
    76             self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT,
       
    77                   name='HtmlContent', parent=self, pos=wx.Point(0, 0),
       
    78                   size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION)
       
    79             EVT_HTML_URL_CLICK(self.HtmlContent, self.OnLinkClick)
       
    80 
       
    81         def __init__(self, parent, opened):
       
    82             self._init_ctrls(parent)
       
    83             self.HtmlFrameOpened = opened
       
    84         
       
    85         def SetHtmlCode(self, htmlcode):
       
    86             self.HtmlContent.SetPage(htmlcode)
       
    87             
       
    88         def SetHtmlPage(self, htmlpage):
       
    89             self.HtmlContent.LoadPage(htmlpage)
       
    90             
       
    91         def OnCloseFrame(self, event):
       
    92             self.HtmlFrameOpened.remove(self.GetTitle())
       
    93             event.Skip()
       
    94         
       
    95         def OnLinkClick(self, event):
       
    96             url = event.linkinfo[0]
       
    97             try:
       
    98                 import webbrowser
       
    99             except ImportError:
       
   100                 wxMessageBox('Please point your browser at: %s' % url)
       
   101             else:
       
   102                 webbrowser.open(url)
       
   103     
       
   104     Html_Window = True
       
   105 except:
       
   106     Html_Window = False
    59 
   107 
    60 def create(parent):
   108 def create(parent):
    61     return objdictedit(parent)
   109     return objdictedit(parent)
    62 
   110 
    63 def usage():
   111 def usage():
   804     def _init_coll_HelpMenu_Items(self, parent):
   852     def _init_coll_HelpMenu_Items(self, parent):
   805         # generated method, don't edit
   853         # generated method, don't edit
   806 
   854 
   807         parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS0,
   855         parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS0,
   808               kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
   856               kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
   809         parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS1,
       
   810               kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
       
   811         parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS2,
       
   812               kind=wx.ITEM_NORMAL, text='About')
       
   813         self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu,
   857         self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu,
   814               id=wxID_OBJDICTEDITHELPMENUITEMS0)
   858               id=wxID_OBJDICTEDITHELPMENUITEMS0)
   815         self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu,
   859         if Html_Window:
   816               id=wxID_OBJDICTEDITHELPMENUITEMS1)
   860             parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS1,
   817         self.Bind(wx.EVT_MENU, self.OnAboutMenu,
   861                   kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
   818               id=wxID_OBJDICTEDITHELPMENUITEMS2)
   862             parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS2,
       
   863                   kind=wx.ITEM_NORMAL, text='About')
       
   864             self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu,
       
   865                   id=wxID_OBJDICTEDITHELPMENUITEMS1)
       
   866             self.Bind(wx.EVT_MENU, self.OnAboutMenu,
       
   867                   id=wxID_OBJDICTEDITHELPMENUITEMS2)
   819 
   868 
   820     def _init_coll_FileMenu_Items(self, parent):
   869     def _init_coll_FileMenu_Items(self, parent):
   821         # generated method, don't edit
   870         # generated method, don't edit
   822 
   871 
   823         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS5,
   872         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS5,
   999         	self.RefreshBufferState()
  1048         	self.RefreshBufferState()
  1000         	self.RefreshProfileMenu()
  1049         	self.RefreshProfileMenu()
  1001         event.Skip()
  1050         event.Skip()
  1002 
  1051 
  1003     def OnHelpDS301Menu(self, event):
  1052     def OnHelpDS301Menu(self, event):
       
  1053         find_index = False
  1004         selected = self.FileOpened.GetSelection()
  1054         selected = self.FileOpened.GetSelection()
  1005         if selected >= 0:
  1055         if selected >= 0:
  1006             window = self.FileOpened.GetPage(selected)
  1056             window = self.FileOpened.GetPage(selected)
  1007             result = window.GetSelection()
  1057             result = window.GetSelection()
  1008             if result:
  1058             if result:
       
  1059                 find_index = True
  1009                 index, subIndex = result
  1060                 index, subIndex = result
  1010                 result = OpenPDFDocIndex(index)
  1061                 result = OpenPDFDocIndex(index)
  1011                 if type(result) == StringType:
  1062                 if type(result) == StringType:
  1012                     message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
  1063                     message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
  1013                     message.ShowModal()
  1064                     message.ShowModal()
  1014                     message.Destroy()
  1065                     message.Destroy()
       
  1066         if not find_index:
       
  1067             result = OpenPDFDocIndex(None)
       
  1068             if type(result) == StringType:
       
  1069                 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
       
  1070                 message.ShowModal()
       
  1071                 message.Destroy()
  1015         event.Skip()
  1072         event.Skip()
  1016         
  1073         
  1017     def OnHelpCANFestivalMenu(self, event):
  1074     def OnHelpCANFestivalMenu(self, event):
  1018         self.OpenHtmlFrame("CAN Festival Reference", "../doc/canfestival.html", wx.Size(1000, 600))
  1075         self.OpenHtmlFrame("CAN Festival Reference", "../doc/canfestival.html", wx.Size(1000, 600))
  1019         event.Skip()
  1076         event.Skip()
  2215                 self.Profile.Insert(name, length - 2)
  2272                 self.Profile.Insert(name, length - 2)
  2216                 self.Profile.SetStringSelection(name)
  2273                 self.Profile.SetStringSelection(name)
  2217             else:
  2274             else:
  2218                 self.Profile.SetStringSelection("None")
  2275                 self.Profile.SetStringSelection("None")
  2219         event.Skip()
  2276         event.Skip()
  2220 
       
  2221 
       
  2222 
       
  2223 #-------------------------------------------------------------------------------
       
  2224 #                                Html Frame
       
  2225 #-------------------------------------------------------------------------------
       
  2226 
       
  2227 
       
  2228 [wxID_HTMLFRAME, wxID_HTMLFRAMEHTMLCONTENT, 
       
  2229 ] = [wx.NewId() for _init_ctrls in range(2)]
       
  2230 
       
  2231 class HtmlFrame(wx.Frame):
       
  2232     def _init_ctrls(self, prnt):
       
  2233         # generated method, don't edit
       
  2234         wx.Frame.__init__(self, id=wxID_HTMLFRAME, name='HtmlFrame',
       
  2235               parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
       
  2236               style=wx.DEFAULT_FRAME_STYLE, title='')
       
  2237         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_HTMLFRAME)
       
  2238         
       
  2239         self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT,
       
  2240               name='HtmlContent', parent=self, pos=wx.Point(0, 0),
       
  2241               size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION)
       
  2242         EVT_HTML_URL_CLICK(self.HtmlContent, self.OnLinkClick)
       
  2243 
       
  2244     def __init__(self, parent, opened):
       
  2245         self._init_ctrls(parent)
       
  2246         self.HtmlFrameOpened = opened
       
  2247     
       
  2248     def SetHtmlCode(self, htmlcode):
       
  2249         self.HtmlContent.SetPage(htmlcode)
       
  2250         
       
  2251     def SetHtmlPage(self, htmlpage):
       
  2252         self.HtmlContent.LoadPage(htmlpage)
       
  2253         
       
  2254     def OnCloseFrame(self, event):
       
  2255         self.HtmlFrameOpened.remove(self.GetTitle())
       
  2256         event.Skip()
       
  2257     
       
  2258     def OnLinkClick(self, event):
       
  2259         url = event.linkinfo[0]
       
  2260         try:
       
  2261             import webbrowser
       
  2262         except ImportError:
       
  2263             wxMessageBox('Please point your browser at: %s' % url)
       
  2264         else:
       
  2265             webbrowser.open(url)
       
  2266     
  2277     
  2267 
  2278 
  2268 #-------------------------------------------------------------------------------
  2279 #-------------------------------------------------------------------------------
  2269 #                               Exception Handler
  2280 #                               Exception Handler
  2270 #-------------------------------------------------------------------------------
  2281 #-------------------------------------------------------------------------------