dialogs/BlockPreviewDialog.py
changeset 2437 105c20fdeb19
parent 1881 091005ec69c4
child 2509 9c5f835b031e
equal deleted inserted replaced
2436:82bfc75bcd9d 2437:105c20fdeb19
    23 # along with this program; if not, write to the Free Software
    23 # along with this program; if not, write to the Free Software
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    25 
    25 
    26 
    26 
    27 from __future__ import absolute_import
    27 from __future__ import absolute_import
       
    28 from __future__ import division
    28 import wx
    29 import wx
    29 
    30 
    30 from plcopen.structures import TestIdentifier, IEC_KEYWORDS
    31 from plcopen.structures import TestIdentifier, IEC_KEYWORDS
    31 from graphics.GraphicCommons import FREEDRAWING_MODE
    32 from graphics.GraphicCommons import FREEDRAWING_MODE
    32 
    33 
   280         # If graphic element is too big to be displayed in preview panel,
   281         # If graphic element is too big to be displayed in preview panel,
   281         # calculate preview panel scale so that graphic element fit inside
   282         # calculate preview panel scale so that graphic element fit inside
   282         k = 1.1 if (bbox.width * 1.1 > client_size.width or
   283         k = 1.1 if (bbox.width * 1.1 > client_size.width or
   283                     bbox.height * 1.1 > client_size.height) \
   284                     bbox.height * 1.1 > client_size.height) \
   284             else 1.0
   285             else 1.0
   285         scale = (max(float(bbox.width) / client_size.width,
   286         scale = (max(bbox.width / client_size.width,
   286                      float(bbox.height) / client_size.height) * k)
   287                      bbox.height / client_size.height) * k)
   287         dc.SetUserScale(1.0 / scale, 1.0 / scale)
   288         dc.SetUserScale(1.0 / scale, 1.0 / scale)
   288 
   289 
   289         # Center graphic element in preview panel
   290         # Center graphic element in preview panel
   290         x = int(client_size.width * scale - bbox.width) / 2 + posx - bbox.x
   291         x = int(client_size.width * scale - bbox.width) // 2 + posx - bbox.x
   291         y = int(client_size.height * scale - bbox.height) / 2 + posy - bbox.y
   292         y = int(client_size.height * scale - bbox.height) // 2 + posy - bbox.y
   292         self.Element.SetPosition(x, y)
   293         self.Element.SetPosition(x, y)
   293 
   294 
   294         # Draw graphic element
   295         # Draw graphic element
   295         self.Element.Draw(dc)
   296         self.Element.Draw(dc)
   296 
   297