PLCOpenEditor.py
changeset 221 25f2b4924347
parent 220 127d1323e5e0
child 223 ea857c3a0427
equal deleted inserted replaced
220:127d1323e5e0 221:25f2b4924347
   232         AppendMenu(parent, help='', id=wx.ID_PRINT,
   232         AppendMenu(parent, help='', id=wx.ID_PRINT,
   233               kind=wx.ITEM_NORMAL, text=u'Print')
   233               kind=wx.ITEM_NORMAL, text=u'Print')
   234         parent.AppendSeparator()
   234         parent.AppendSeparator()
   235         AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
   235         AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
   236               kind=wx.ITEM_NORMAL, text=u'Properties')
   236               kind=wx.ITEM_NORMAL, text=u'Properties')
       
   237         parent.AppendSeparator()
   237         if self.ModeSolo:
   238         if self.ModeSolo:
   238             parent.AppendSeparator()
       
   239             AppendMenu(parent, help='', id=wx.ID_EXIT,
   239             AppendMenu(parent, help='', id=wx.ID_EXIT,
   240                   kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q')
   240                   kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q')
   241             
   241         else:
   242         self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
   242             AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
   243         self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
   243                   kind=wx.ITEM_NORMAL, text=u'Close\tCTRL+Q')
       
   244         
       
   245         if self.ModeSolo:
       
   246             self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
       
   247             self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
   244         self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
   248         self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
   245         self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
   249         if self.ModeSolo:
       
   250             self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
   246         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
   251         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
   247         self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
   252         if self.ModeSolo:
   248         self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu,
   253             self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
   249               id=ID_PLCOPENEDITORFILEMENUGENERATE)
   254             self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu,
       
   255                   id=ID_PLCOPENEDITORFILEMENUGENERATE)
   250         self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
   256         self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
   251         self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
   257         self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
   252         self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
   258         self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
   253         self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
   259         self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
   254         self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
   260         if self.ModeSolo:
       
   261             self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
       
   262         else:
       
   263             self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_CLOSE_ALL)
   255     
   264     
   256     def _init_coll_EditMenu_Items(self, parent):
   265     def _init_coll_EditMenu_Items(self, parent):
   257         AppendMenu(parent, help='', id=wx.ID_REFRESH,
   266         AppendMenu(parent, help='', id=wx.ID_REFRESH,
   258               kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R')
   267               kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R')
   259         AppendMenu(parent, help='', id=wx.ID_UNDO,
   268         AppendMenu(parent, help='', id=wx.ID_UNDO,
   337                   style=wx.DEFAULT_FRAME_STYLE, title=u'PLCOpenEditor')
   346                   style=wx.DEFAULT_FRAME_STYLE, title=u'PLCOpenEditor')
   338         self._init_utils()
   347         self._init_utils()
   339         self.SetClientSize(wx.Size(1000, 600))
   348         self.SetClientSize(wx.Size(1000, 600))
   340         self.SetMenuBar(self.MenuBar)
   349         self.SetMenuBar(self.MenuBar)
   341         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   350         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
   342         if not self.ModeSolo:
       
   343             self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
       
   344             self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
       
   345             accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 119, wx.ID_CLOSE),
       
   346                                          wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)])
       
   347             self.SetAcceleratorTable(accel)
       
   348         
   351         
   349         if wx.VERSION >= (2, 8, 0):
   352         if wx.VERSION >= (2, 8, 0):
   350             self.AUIManager = wx.aui.AuiManager(self)
   353             self.AUIManager = wx.aui.AuiManager(self)
   351             self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
   354             self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
   352             self.Panes = {}
   355             self.Panes = {}
   667 #-------------------------------------------------------------------------------
   670 #-------------------------------------------------------------------------------
   668 #                            File Menu Functions
   671 #                            File Menu Functions
   669 #-------------------------------------------------------------------------------
   672 #-------------------------------------------------------------------------------
   670 
   673 
   671     def RefreshFileMenu(self):
   674     def RefreshFileMenu(self):
   672         if self.ModeSolo:
   675         if self.Controler.HasOpenedProject():
   673             if self.Controler.HasOpenedProject():
   676             selected = self.GetPageSelection()
   674                 selected = self.GetPageSelection()
   677             if selected >= 0:
   675                 if selected >= 0:
   678                 graphic_viewer = isinstance(self.GetPage(selected), Viewer)
   676                     graphic_viewer = isinstance(self.GetPage(selected), Viewer)
   679             else:
       
   680                 graphic_viewer = False
       
   681             if self.GetPageCount() > 0:
       
   682                 self.FileMenu.Enable(wx.ID_CLOSE, True)
       
   683                 if graphic_viewer:
       
   684                     self.FileMenu.Enable(wx.ID_PREVIEW, True)
       
   685                     self.FileMenu.Enable(wx.ID_PRINT, True)
   677                 else:
   686                 else:
   678                     graphic_viewer = False
       
   679                 if self.GetPageCount() > 0:
       
   680                     self.FileMenu.Enable(wx.ID_CLOSE, True)
       
   681                     if graphic_viewer:
       
   682                         self.FileMenu.Enable(wx.ID_PREVIEW, True)
       
   683                         self.FileMenu.Enable(wx.ID_PRINT, True)
       
   684                     else:
       
   685                         self.FileMenu.Enable(wx.ID_PREVIEW, False)
       
   686                         self.FileMenu.Enable(wx.ID_PRINT, False)
       
   687                 else:
       
   688                     self.FileMenu.Enable(wx.ID_CLOSE, False)
       
   689                     self.FileMenu.Enable(wx.ID_PREVIEW, False)
   687                     self.FileMenu.Enable(wx.ID_PREVIEW, False)
   690                     self.FileMenu.Enable(wx.ID_PRINT, False)
   688                     self.FileMenu.Enable(wx.ID_PRINT, False)
       
   689             else:
       
   690                 self.FileMenu.Enable(wx.ID_CLOSE, False)
       
   691                 self.FileMenu.Enable(wx.ID_PREVIEW, False)
       
   692                 self.FileMenu.Enable(wx.ID_PRINT, False)
       
   693             self.FileMenu.Enable(wx.ID_SAVE, True)
       
   694             self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
       
   695             self.FileMenu.Enable(wx.ID_PROPERTIES, True)
       
   696             if self.ModeSolo:
   691                 self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
   697                 self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
   692                 self.FileMenu.Enable(wx.ID_SAVE, True)
       
   693                 self.FileMenu.Enable(wx.ID_SAVEAS, True)
   698                 self.FileMenu.Enable(wx.ID_SAVEAS, True)
   694                 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True)
   699                 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True)
   695                 self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
   700         else:
   696                 self.FileMenu.Enable(wx.ID_PROPERTIES, True)
   701             self.FileMenu.Enable(wx.ID_CLOSE, False)
   697             else:
   702             self.FileMenu.Enable(wx.ID_SAVE, False)
   698                 self.FileMenu.Enable(wx.ID_CLOSE, False)
   703             self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
       
   704             self.FileMenu.Enable(wx.ID_PREVIEW, False)
       
   705             self.FileMenu.Enable(wx.ID_PRINT, False)
       
   706             self.FileMenu.Enable(wx.ID_PROPERTIES, False)
       
   707             if self.ModeSolo:
   699                 self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
   708                 self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
   700                 self.FileMenu.Enable(wx.ID_SAVE, False)
       
   701                 self.FileMenu.Enable(wx.ID_SAVEAS, False)
   709                 self.FileMenu.Enable(wx.ID_SAVEAS, False)
   702                 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False)
   710                 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False)
   703                 self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
       
   704                 self.FileMenu.Enable(wx.ID_PREVIEW, False)
       
   705                 self.FileMenu.Enable(wx.ID_PRINT, False)
       
   706                 self.FileMenu.Enable(wx.ID_PROPERTIES, False)
       
   707 
   711 
   708     def OnNewProjectMenu(self, event):
   712     def OnNewProjectMenu(self, event):
   709         dialog = ProjectDialog(self)
   713         dialog = ProjectDialog(self)
   710         if dialog.ShowModal() == wx.ID_OK:
   714         if dialog.ShowModal() == wx.ID_OK:
   711             properties = dialog.GetValues()
   715             properties = dialog.GetValues()
  3895 class GraphicPrintout(wx.Printout):
  3899 class GraphicPrintout(wx.Printout):
  3896     def __init__(self, viewer, page_size, margins, preview = False):
  3900     def __init__(self, viewer, page_size, margins, preview = False):
  3897         wx.Printout.__init__(self)
  3901         wx.Printout.__init__(self)
  3898         self.Viewer = viewer
  3902         self.Viewer = viewer
  3899         self.PageSize = page_size
  3903         self.PageSize = page_size
       
  3904         if self.PageSize[0] == 0 or self.PageSize[1] == 0:
       
  3905             self.PageSize = (1050, 1485)
  3900         self.Preview = preview
  3906         self.Preview = preview
  3901         self.Margins = margins
  3907         self.Margins = margins
  3902         self.FontSize = 14
  3908         self.FontSize = 5
  3903         self.TextMargin = 5
  3909         self.TextMargin = 3
  3904         
  3910         
  3905         maxx, maxy = viewer.GetMaxSize()
  3911         maxx, maxy = viewer.GetMaxSize()
  3906         self.PageGrid = (UPPER_DIV(maxx, page_size[0]), UPPER_DIV(maxy, page_size[1]))
  3912         self.PageGrid = (UPPER_DIV(maxx, self.PageSize[0]), 
       
  3913                          UPPER_DIV(maxy, self.PageSize[1]))
  3907         
  3914         
  3908     def GetPageNumber(self):
  3915     def GetPageNumber(self):
  3909         return self.PageGrid[0] * self.PageGrid[1]
  3916         return self.PageGrid[0] * self.PageGrid[1]
  3910     
  3917     
  3911     def HasPage(self, page):
  3918     def HasPage(self, page):
  3917 
  3924 
  3918     def OnBeginDocument(self, startPage, endPage):
  3925     def OnBeginDocument(self, startPage, endPage):
  3919         dc = self.GetDC()
  3926         dc = self.GetDC()
  3920         if not self.Preview and isinstance(dc, wx.PostScriptDC):
  3927         if not self.Preview and isinstance(dc, wx.PostScriptDC):
  3921             dc.SetResolution(720)
  3928             dc.SetResolution(720)
  3922             self.FontSize = 140
       
  3923             self.TextMargin = 50
       
  3924         super(GraphicPrintout, self).OnBeginDocument(startPage, endPage)
  3929         super(GraphicPrintout, self).OnBeginDocument(startPage, endPage)
  3925 
  3930 
  3926     def OnPrintPage(self, page):
  3931     def OnPrintPage(self, page):
  3927         dc = self.GetDC()
  3932         dc = self.GetDC()
       
  3933         dc.SetUserScale(1.0, 1.0)
       
  3934         dc.SetDeviceOrigin(0, 0)
  3928         dc.printing = not self.Preview
  3935         dc.printing = not self.Preview
  3929         
  3936         
  3930         # Get the size of the DC in pixels
  3937         # Get the size of the DC in pixels
  3931         ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
  3938         ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
  3932         ppiScreenX, ppiScreenY = self.GetPPIScreen()
  3939         ppiScreenX, ppiScreenY = self.GetPPIScreen()
  3933         pw, ph = self.GetPageSizePixels()
  3940         pw, ph = self.GetPageSizePixels()
  3934         dw, dh = dc.GetSizeTuple()
  3941         dw, dh = dc.GetSizeTuple()
  3935         Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4)
  3942         Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4)
  3936         Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4)
  3943         Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4)
  3937         
  3944         
       
  3945         fontsize = self.FontSize * Yscale
       
  3946         text_margin = self.TextMargin * Yscale
       
  3947         
  3938         margin_left = self.Margins[0].x * Xscale
  3948         margin_left = self.Margins[0].x * Xscale
  3939         margin_top = self.Margins[0].y * Yscale
  3949         margin_top = self.Margins[0].y * Yscale
  3940         area_width = dw - self.Margins[1].x * Xscale - margin_left
  3950         area_width = dw - self.Margins[1].x * Xscale - margin_left
  3941         area_height = dh - self.Margins[1].y * Yscale - margin_top
  3951         area_height = dh - self.Margins[1].y * Yscale - margin_top
  3942         
  3952         
  3943         dc.SetPen(wx.BLACK_PEN)
  3953         dc.SetPen(wx.BLACK_PEN)
  3944         dc.SetBrush(wx.TRANSPARENT_BRUSH)    
  3954         dc.SetBrush(wx.TRANSPARENT_BRUSH)    
  3945         dc.DrawRectangle(margin_left, margin_top, area_width, area_height)
  3955         dc.DrawRectangle(margin_left, margin_top, area_width, area_height)
  3946         
  3956         
  3947         dc.SetFont(wx.Font(self.FontSize, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
  3957         dc.SetFont(wx.Font(fontsize, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
  3948         dc.SetTextForeground(wx.BLACK)
  3958         dc.SetTextForeground(wx.BLACK)
  3949         block_name = " - ".join(self.Viewer.GetTagName().split("::")[1:])
  3959         block_name = " - ".join(self.Viewer.GetTagName().split("::")[1:])
  3950         text_width, text_height = dc.GetTextExtent(block_name)
  3960         text_width, text_height = dc.GetTextExtent(block_name)
  3951         dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin)
  3961         dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin)
  3952         dc.DrawText("Page: %d" % page, margin_left, margin_top + area_height + self.TextMargin)
  3962         dc.DrawText("Page: %d" % page, margin_left, margin_top + area_height + self.TextMargin)
  3959         scaleY = float(area_height) / float(self.PageSize[1])
  3969         scaleY = float(area_height) / float(self.PageSize[1])
  3960         scale = min(scaleX, scaleY)
  3970         scale = min(scaleX, scaleY)
  3961 
  3971 
  3962         # Set the scale and origin
  3972         # Set the scale and origin
  3963         dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top)
  3973         dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top)
       
  3974         dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale)
  3964         dc.SetUserScale(scale, scale)
  3975         dc.SetUserScale(scale, scale)
  3965         dc.SetClippingRegion(posX, posY, self.PageSize[0], self.PageSize[1])
       
  3966         
  3976         
  3967         #-------------------------------------------
  3977         #-------------------------------------------
  3968         
  3978         
  3969         self.Viewer.DoDrawing(dc, True)
  3979         self.Viewer.DoDrawing(dc, True)
  3970         
  3980