--- a/IDEFrame.py Fri Oct 05 13:48:54 2018 +0300
+++ b/IDEFrame.py Fri Oct 05 14:22:01 2018 +0300
@@ -23,6 +23,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from __future__ import absolute_import
+from __future__ import division from types import TupleType
@@ -201,22 +202,22 @@
raise ValueError("Not possible")
if tab["size"][0] == rect.width:
if tab["pos"][1] == rect.y:
- split = (wx.TOP, float(tab["size"][1]) / float(rect.height))
+ split = (wx.TOP, tab["size"][1] / rect.height) split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER,
rect.width, rect.height - tab["size"][1] - TAB_BORDER)
elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
- split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height))
+ split = (wx.BOTTOM, 1.0 - tab["size"][1] / rect.height) split_rect = wx.Rect(rect.x, rect.y,
rect.width, rect.height - tab["size"][1] - TAB_BORDER)
elif tab["size"][1] == rect.height:
if tab["pos"][0] == rect.x:
- split = (wx.LEFT, float(tab["size"][0]) / float(rect.width))
+ split = (wx.LEFT, tab["size"][0] / rect.width) split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y,
rect.width - tab["size"][0] - TAB_BORDER, rect.height)
elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
- split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width))
+ split = (wx.RIGHT, 1.0 - tab["size"][0] / rect.width) split_rect = wx.Rect(rect.x, rect.y,
rect.width - tab["size"][0] - TAB_BORDER, rect.height)
@@ -2592,7 +2593,7 @@
- return (x / y) + {True: 0, False: 1}[(x % y) == 0]
+ return (x // y) + {True: 0, False: 1}[(x % y) == 0] class GraphicPrintout(wx.Printout):
@@ -2639,8 +2640,8 @@
ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
pw, ph = self.GetPageSizePixels()
dw, dh = dc.GetSizeTuple()
- Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4)
- Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4)
+ Xscale = (dw * ppiPrinterX) / (pw * 25.4) + Yscale = (dh * ppiPrinterY) / (ph * 25.4) fontsize = self.FontSize * Yscale
@@ -2662,10 +2663,10 @@
# Calculate the position on the DC for centering the graphic
posX = area_width * ((page - 1) % self.PageGrid[0])
- posY = area_height * ((page - 1) / self.PageGrid[0])
+ posY = area_height * ((page - 1) // self.PageGrid[0]) - scaleX = float(area_width) / float(self.PageSize[0])
- scaleY = float(area_height) / float(self.PageSize[1])
+ scaleX = area_width / self.PageSize[0] + scaleY = area_height / self.PageSize[1] scale = min(scaleX, scaleY)
# Set the scale and origin
--- a/controls/DebugVariablePanel/DebugVariableGraphicViewer.py Fri Oct 05 13:48:54 2018 +0300
+++ b/controls/DebugVariablePanel/DebugVariableGraphicViewer.py Fri Oct 05 14:22:01 2018 +0300
@@ -24,6 +24,7 @@
from __future__ import absolute_import
+from __future__ import division from types import TupleType
from time import time as gettime
from cycler import cycler
@@ -195,7 +196,7 @@
# Get Before which Viewer the variable has to be moved or added
# according to the position of mouse in Viewer.
# Drag'n Drop is an internal is an internal move inside Debug
@@ -443,10 +444,10 @@
x = rect.x + (- w - offset
else rect.width + offset)
- y = rect.y + (rect.height - h) / 2
+ y = rect.y + (rect.height - h) // 2 - x = rect.x + (rect.width - w) / 2
+ x = rect.x + (rect.width - w) // 2 y = rect.y + (- h - offset
else rect.height + offset)
@@ -801,7 +802,7 @@
self.ParentWindow.SetCanvasPosition(
(self.MouseStartPos.x - event.x) *
- (end_tick - start_tick) / rect.width)
+ (end_tick - start_tick) // rect.width) def OnCanvasScroll(self, event):
@@ -819,7 +820,7 @@
tick = (start_tick + end_tick) / 2.
- self.ParentWindow.ChangeRange(int(-event.step) / 3, tick)
+ self.ParentWindow.ChangeRange(int(-event.step) // 3, tick) # Vetoing event to prevent parent panel to be scrolled
self.ParentWindow.VetoScrollEvent = True
@@ -927,7 +928,7 @@
# Mouse is over Viewer figure and graph is not 3D
bbox = self.GetAxesBoundingBox()
if bbox.InsideXY(x, y) and not self.Is3DCanvas():
- rect = wx.Rect(bbox.x, bbox.y, bbox.width / 2, bbox.height)
+ rect = wx.Rect(bbox.x, bbox.y, bbox.width // 2, bbox.height) # Mouse is over Viewer left part of figure
self.SetHighlight(HIGHLIGHT_LEFT)
@@ -937,7 +938,7 @@
self.SetHighlight(HIGHLIGHT_RIGHT)
# Mouse is over upper part of Viewer
# Viewer is upper one in Debug Variable Panel, show highlight
if self.ParentWindow.IsViewerFirst(self):
self.SetHighlight(HIGHLIGHT_BEFORE)
@@ -1400,11 +1401,11 @@
destGC.SetPen(HIGHLIGHT['DROP_PEN'])
destGC.SetBrush(HIGHLIGHT['DROP_BRUSH'])
- x_offset = (bbox.width / 2
+ x_offset = (bbox.width // 2 if self.Highlight == HIGHLIGHT_RIGHT
destGC.DrawRectangle(bbox.x + x_offset, bbox.y,
- bbox.width / 2, bbox.height)
+ bbox.width // 2, bbox.height) # Draw other Viewer common elements
self.DrawCommonElements(destGC, self.GetButtons())
--- a/controls/DebugVariablePanel/DebugVariablePanel.py Fri Oct 05 13:48:54 2018 +0300
+++ b/controls/DebugVariablePanel/DebugVariablePanel.py Fri Oct 05 14:22:01 2018 +0300
@@ -24,6 +24,7 @@
from __future__ import absolute_import
+from __future__ import division from types import TupleType
@@ -307,7 +308,7 @@
# Calculate range to apply to data
self.CurrentRange = self.RANGE_VALUES[
- self.CanvasRange.GetSelection()][1] / self.Ticktime
+ self.CanvasRange.GetSelection()][1] // self.Ticktime def SetDataProducer(self, producer):
@@ -390,7 +391,7 @@
cursor_tick_idx = numpy.argmin(numpy.abs(self.Ticks - cursor_tick))
if self.Ticks[cursor_tick_idx] == self.CursorTick:
- min(cursor_tick_idx + abs(move) / move,
+ min(cursor_tick_idx + abs(move) // move, self.CursorTick = self.Ticks[cursor_tick_idx]
@@ -488,18 +489,18 @@
merge_type = GRAPH_PARALLEL
if isinstance(panel, DebugVariableTextViewer) or panel.Is3DCanvas():
- if y_mouse > yw + height / 2:
+ if y_mouse > yw + height // 2: wx.CallAfter(self.MoveValue, variable, idx, True)
rect = panel.GetAxesBoundingBox(True)
if rect.InsideXY(x_mouse, y_mouse):
- merge_rect = wx.Rect(rect.x, rect.y, rect.width / 2., rect.height)
+ merge_rect = wx.Rect(rect.x, rect.y, rect.width // 2, rect.height) if merge_rect.InsideXY(x_mouse, y_mouse):
merge_type = GRAPH_ORTHOGONAL
wx.CallAfter(self.MergeGraphs, variable, idx, merge_type, force=True)
- if y_mouse > yw + height / 2:
+ if y_mouse > yw + height // 2: wx.CallAfter(self.MoveValue, variable, idx, True)
@@ -547,16 +548,16 @@
tick_duration = int(tick * self.Ticktime)
- for value, format in [(tick_duration / DAY, _("%dd")),
- ((tick_duration % DAY) / HOUR, _("%dh")),
- ((tick_duration % HOUR) / MINUTE, _("%dm")),
- ((tick_duration % MINUTE) / SECOND, _("%ds"))]:
+ for value, format in [(tick_duration // DAY, _("%dd")), + ((tick_duration % DAY) // HOUR, _("%dh")), + ((tick_duration % HOUR) // MINUTE, _("%dm")), + ((tick_duration % MINUTE) // SECOND, _("%ds"))]: if value > 0 or not_null:
duration += format % value
- duration += _("%03gms") % (float(tick_duration % SECOND) / MILLISECOND)
+ duration += _("%03gms") % ((tick_duration % SECOND) / MILLISECOND) self.TickTimeLabel.SetLabel("t: %s" % duration)
self.TickLabel.SetLabel("")
@@ -638,7 +639,7 @@
def OnRangeChanged(self, event):
- self.CurrentRange = self.RANGE_VALUES[self.CanvasRange.GetSelection()][1] / self.Ticktime
+ self.CurrentRange = self.RANGE_VALUES[self.CanvasRange.GetSelection()][1] // self.Ticktime self.CanvasRange.SetValue(str(self.CurrentRange))
wx.CallAfter(self.RefreshRange)
@@ -909,11 +910,12 @@
xstart, ystart = self.GraphicsWindow.GetViewStart()
window_size = self.GraphicsWindow.GetClientSize()
vwidth, vheight = self.GraphicsSizer.GetMinSize()
- posx = max(0, min(xstart, (vwidth - window_size[0]) / SCROLLBAR_UNIT))
- posy = max(0, min(ystart, (vheight - window_size[1]) / SCROLLBAR_UNIT))
+ posx = max(0, min(xstart, (vwidth - window_size[0]) // SCROLLBAR_UNIT)) + posy = max(0, min(ystart, (vheight - window_size[1]) // SCROLLBAR_UNIT)) self.GraphicsWindow.Scroll(posx, posy)
self.GraphicsWindow.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
- vwidth / SCROLLBAR_UNIT, vheight / SCROLLBAR_UNIT,
+ vwidth // SCROLLBAR_UNIT, + vheight // SCROLLBAR_UNIT, def OnGraphicsWindowEraseBackground(self, event):
--- a/controls/LogViewer.py Fri Oct 05 13:48:54 2018 +0300
+++ b/controls/LogViewer.py Fri Oct 05 14:22:01 2018 +0300
@@ -24,6 +24,7 @@
from __future__ import absolute_import
+from __future__ import division from datetime import datetime
from time import time as gettime
from weakref import proxy
@@ -44,11 +45,11 @@
def ArrowPoints(direction, width, height, xoffset, yoffset):
return [wx.Point(xoffset + 1, yoffset + height - 2),
- wx.Point(xoffset + width / 2, yoffset + 1),
+ wx.Point(xoffset + width // 2, yoffset + 1), wx.Point(xoffset + width - 1, yoffset + height - 2)]
return [wx.Point(xoffset + 1, yoffset - height + 1),
- wx.Point(xoffset + width / 2, yoffset - 2),
+ wx.Point(xoffset + width // 2, yoffset - 2), wx.Point(xoffset + width - 1, yoffset - height + 1)]
@@ -125,7 +126,7 @@
thumb_size = range_rect.height * THUMB_SIZE_RATIO
thumb_range = range_rect.height - thumb_size
self.RefreshThumbPosition(
- max(-1., min((posy - self.ThumbScrollingStartPos.y) * 2. / thumb_range, 1.)))
+ max(-1., min((posy - self.ThumbScrollingStartPos.y) * 2. // thumb_range, 1.))) def OnResize(self, event):
@@ -147,11 +148,11 @@
gc.SetPen(wx.Pen(wx.NamedColour("GREY"), 3))
gc.SetBrush(wx.GREY_BRUSH)
- gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 - 3))
- gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 + 3))
+ gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) // 4 - 3)) + gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) // 4 + 3)) - gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 + 3))
- gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 - 3))
+ gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) // 4 + 3)) + gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) // 4 - 3)) thumb_rect = self.GetThumbRect()
exclusion_rect = wx.Rect(thumb_rect.x, thumb_rect.y,
@@ -223,8 +224,8 @@
w, h = dc.GetTextExtent(self.Label)
- self.Position.x + (self.Size.width - w) / 2,
- self.Position.y + (self.Size.height - h) / 2)
+ self.Position.x + (self.Size.width - w) // 2, + self.Position.y + (self.Size.height - h) // 2) @@ -260,19 +261,19 @@
datetime_text = self.Date.strftime("%d/%m/%y %H:%M")
dw, dh = dc.GetTextExtent(datetime_text)
- dc.DrawText(datetime_text, (width - dw) / 2, offset + (DATE_INFO_SIZE - dh) / 2)
+ dc.DrawText(datetime_text, (width - dw) // 2, offset + (DATE_INFO_SIZE - dh) // 2) seconds_text = "%12.9f" % self.Seconds
sw, sh = dc.GetTextExtent(seconds_text)
- dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) / 2)
+ dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) // 2) bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight()
- dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) / 2)
+ dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) // 2) text = self.Message.replace("\n", " ")
_mw, mh = dc.GetTextExtent(text)
- dc.DrawText(text, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) / 2)
+ dc.DrawText(text, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) // 2) def GetHeight(self, draw_date):
@@ -612,7 +613,7 @@
def ScrollMessagePanelByPage(self, page):
if self.CurrentMessage is not None:
_width, height = self.MessagePanel.GetClientSize()
- message_per_page = max(1, (height - DATE_INFO_SIZE) / MESSAGE_INFO_SIZE - 1)
+ message_per_page = max(1, (height - DATE_INFO_SIZE) // MESSAGE_INFO_SIZE - 1) self.ScrollMessagePanel(page * message_per_page)
def ScrollMessagePanelByTimestamp(self, seconds):
@@ -757,7 +758,7 @@
def OnMessagePanelMouseWheel(self, event):
- self.ScrollMessagePanel(event.GetWheelRotation() / event.GetWheelDelta())
+ self.ScrollMessagePanel(event.GetWheelRotation() // event.GetWheelDelta()) def OnMessagePanelEraseBackground(self, event):
--- a/editors/Viewer.py Fri Oct 05 13:48:54 2018 +0300
+++ b/editors/Viewer.py Fri Oct 05 14:22:01 2018 +0300
@@ -24,6 +24,7 @@
from __future__ import absolute_import
+from __future__ import division from time import time as gettime
from types import TupleType
@@ -308,10 +309,10 @@
block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs=blockinputs)
width, height = block.GetMinSize()
- x = round(float(x) / float(scaling[0])) * scaling[0]
- y = round(float(y) / float(scaling[1])) * scaling[1]
- width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
- height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
+ x = round(x / scaling[0]) * scaling[0] + y = round(y / scaling[1]) * scaling[1] + width = round(width / scaling[0] + 0.5) * scaling[0] + height = round(height / scaling[1] + 0.5) * scaling[1] block.SetSize(width, height)
self.ParentWindow.AddBlock(block)
@@ -860,7 +861,7 @@
client_size = self.Editor.GetClientSize()
- mouse_pos = wx.Point(client_size[0] / 2, client_size[1] / 2)
+ mouse_pos = wx.Point(client_size[0] // 2, client_size[1] // 2) mouse_event = wx.MouseEvent(wx.EVT_MOUSEWHEEL.typeId)
mouse_event.x = mouse_pos.x
mouse_event.y = mouse_pos.y
@@ -1339,7 +1340,8 @@
maxy = int(maxy * self.ViewScale[1])
self.Editor.SetScrollbars(
SCROLLBAR_UNIT, SCROLLBAR_UNIT,
- round(maxx / SCROLLBAR_UNIT) + width_incr, round(maxy / SCROLLBAR_UNIT) + height_incr,
+ round(maxx / SCROLLBAR_UNIT) + width_incr, + round(maxy / SCROLLBAR_UNIT) + height_incr, def EnsureVisible(self, block):
@@ -1356,13 +1358,13 @@
xpos, ypos = xstart, ystart
if block_minx < screen_minx and block_maxx < screen_maxx:
- xpos -= (screen_minx - block_minx) / SCROLLBAR_UNIT + 1
+ xpos -= (screen_minx - block_minx) // SCROLLBAR_UNIT + 1 elif block_maxx > screen_maxx and block_minx > screen_minx:
- xpos += (block_maxx - screen_maxx) / SCROLLBAR_UNIT + 1
+ xpos += (block_maxx - screen_maxx) // SCROLLBAR_UNIT + 1 if block_miny < screen_miny and block_maxy < screen_maxy:
- ypos -= (screen_miny - block_miny) / SCROLLBAR_UNIT + 1
+ ypos -= (screen_miny - block_miny) // SCROLLBAR_UNIT + 1 elif block_maxy > screen_maxy and block_miny > screen_miny:
- ypos += (block_maxy - screen_maxy) / SCROLLBAR_UNIT + 1
+ ypos += (block_maxy - screen_maxy) // SCROLLBAR_UNIT + 1 def SelectInGroup(self, element):
@@ -2317,8 +2319,8 @@
new_pos = event.GetPosition()
xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
- scrollx = max(0, self.StartScreenPos[0] - (new_pos[0] - self.StartMousePos[0]) / SCROLLBAR_UNIT)
- scrolly = max(0, self.StartScreenPos[1] - (new_pos[1] - self.StartMousePos[1]) / SCROLLBAR_UNIT)
+ scrollx = max(0, self.StartScreenPos[0] - (new_pos[0] - self.StartMousePos[0]) // SCROLLBAR_UNIT) + scrolly = max(0, self.StartScreenPos[1] - (new_pos[1] - self.StartMousePos[1]) // SCROLLBAR_UNIT) if scrollx > xmax or scrolly > ymax:
self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax))
self.Scroll(scrollx, scrolly)
@@ -2546,10 +2548,10 @@
variable = FBD_Variable(self, var_class, var_name, var_type, id)
width, height = variable.GetMinSize()
- x = round(float(x) / float(scaling[0])) * scaling[0]
- y = round(float(y) / float(scaling[1])) * scaling[1]
- width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
- height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
+ x = round(x / scaling[0]) * scaling[0] + y = round(y / scaling[1]) * scaling[1] + width = round(width / scaling[0] + 0.5) * scaling[0] + height = round(height / scaling[1] + 0.5) * scaling[1] variable.SetPosition(x, y)
variable.SetSize(width, height)
@@ -2566,8 +2568,8 @@
def GetScaledSize(self, width, height):
if self.Scaling is not None:
- width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0]
- height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1]
+ width = round(width / self.Scaling[0] + 0.4) * self.Scaling[0] + height = round(height / self.Scaling[1] + 0.4) * self.Scaling[1] def AddNewElement(self, element, bbox, wire=None, connector=None):
--- a/etherlab/ConfigEditor.py Fri Oct 05 13:48:54 2018 +0300
+++ b/etherlab/ConfigEditor.py Fri Oct 05 14:22:01 2018 +0300
@@ -10,6 +10,7 @@
# See COPYING file for copyrights details.
from __future__ import absolute_import
+from __future__ import division from types import TupleType
@@ -324,12 +325,12 @@
xstart, ystart = self.EtherCATManagementEditor.GetViewStart()
window_size = self.EtherCATManagementEditor.GetClientSize()
maxx, maxy = self.EtherCATManagementEditor.GetMinSize()
- posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
- posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
+ posx = max(0, min(xstart, (maxx - window_size[0]) // SCROLLBAR_UNIT)) + posy = max(0, min(ystart, (maxy - window_size[1]) // SCROLLBAR_UNIT)) self.EtherCATManagementEditor.Scroll(posx, posy)
self.EtherCATManagementEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
+ maxx // SCROLLBAR_UNIT, + maxy // SCROLLBAR_UNIT, # -------------------------------------------------------------------------------------------------------
@@ -1056,12 +1057,12 @@
xstart, ystart = self.EthercatMasterEditor.GetViewStart()
window_size = self.EthercatMasterEditor.GetClientSize()
maxx, maxy = self.EthercatMasterEditorSizer.GetMinSize()
- posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
- posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
+ posx = max(0, min(xstart, (maxx - window_size[0]) // SCROLLBAR_UNIT)) + posy = max(0, min(ystart, (maxy - window_size[1]) // SCROLLBAR_UNIT)) self.EthercatMasterEditor.Scroll(posx, posy)
self.EthercatMasterEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
+ maxx // SCROLLBAR_UNIT, + maxy // SCROLLBAR_UNIT, @@ -1421,11 +1422,11 @@
xstart, ystart = self.ModuleLibraryEditor.GetViewStart()
window_size = self.ModuleLibraryEditor.GetClientSize()
maxx, maxy = self.ModuleLibraryEditor.GetMinSize()
- posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
- posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
+ posx = max(0, min(xstart, (maxx - window_size[0]) // SCROLLBAR_UNIT)) + posy = max(0, min(ystart, (maxy - window_size[1]) // SCROLLBAR_UNIT)) self.ModuleLibraryEditor.Scroll(posx, posy)
self.ModuleLibraryEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
+ maxx // SCROLLBAR_UNIT, + maxy // SCROLLBAR_UNIT, --- a/graphics/FBD_Objects.py Fri Oct 05 13:48:54 2018 +0300
+++ b/graphics/FBD_Objects.py Fri Oct 05 14:22:01 2018 +0300
@@ -24,6 +24,7 @@
from __future__ import absolute_import
+from __future__ import division from six.moves import xrange
@@ -131,7 +132,7 @@
def GetTextBoundingBox(self):
# Calculate the size of the name outside the block
text_width, text_height = self.NameSize
- return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2,
+ return wx.Rect(self.Pos.x + (self.Size[0] - text_width) // 2, self.Pos.y - (text_height + 2),
@@ -161,9 +162,9 @@
# Calculate the size for the connector lines
lines = max(len(self.Inputs), len(self.Outputs))
- linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE)
+ linesize = max((self.Size[1] - BLOCK_LINE_SIZE) // lines, BLOCK_LINE_SIZE) # Update inputs and outputs positions
- position = BLOCK_LINE_SIZE + linesize / 2
+ position = BLOCK_LINE_SIZE + linesize // 2 ypos = round_scaling(self.Pos.y + position, scaling[1]) - self.Pos.y
@@ -479,9 +480,9 @@
# Draw a rectangle with the block size
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
# Draw block name and block type
- name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
+ name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, self.Pos.y - (name_size[1] + 2))
- type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2,
+ type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) // 2, dc.DrawText(self.Name, name_pos[0], name_pos[1])
dc.DrawText(self.Type, type_pos[0], type_pos[1])
@@ -592,7 +593,7 @@
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE
bbx_width = self.Size[0] + CONNECTOR_SIZE
- bbx_x = min(bbx_x, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2)
+ bbx_x = min(bbx_x, self.Pos.x + (self.Size[0] - self.NameSize[0]) // 2) bbx_width = max(bbx_width, self.NameSize[0])
bbx_height = self.Size[1]
if self.ExecutionOrder != 0:
@@ -605,9 +606,9 @@
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
- position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
+ position = round_scaling(self.Pos.y + self.Size[1] // 2, scaling[1]) - self.Pos.y - position = self.Size[1] / 2
+ position = self.Size[1] // 2 self.Input.SetPosition(wx.Point(0, position))
@@ -778,8 +779,8 @@
name_size = self.NameSize
executionorder_size = self.ExecutionOrderSize
- text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
- self.Pos.y + (self.Size[1] - name_size[1]) / 2)
+ text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, + self.Pos.y + (self.Size[1] - name_size[1]) // 2) # Draw a rectangle with the variable size
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
@@ -877,9 +878,9 @@
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
- position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
+ position = round_scaling(self.Pos.y + self.Size[1] // 2, scaling[1]) - self.Pos.y - position = self.Size[1] / 2
+ position = self.Size[1] // 2 if self.Type == CONNECTOR:
self.Connector.SetPosition(wx.Point(0, position))
@@ -1018,18 +1019,18 @@
# Draw a rectangle with the connection size with arrows inside
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
- arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2)
+ arrowsize = min(self.Size[1] // 2, (self.Size[0] - name_size[0] - 10) // 2) dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize,
- self.Pos.y + self.Size[1] / 2)
- dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2,
+ self.Pos.y + self.Size[1] // 2) + dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] // 2, self.Pos.x, self.Pos.y + self.Size[1])
dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y,
- self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2)
- dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2,
+ self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] // 2) + dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] // 2, self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1])
- text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
- self.Pos.y + (self.Size[1] - name_size[1]) / 2)
+ text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, + self.Pos.y + (self.Size[1] - name_size[1]) // 2) dc.DrawText(self.Name, text_pos[0], text_pos[1])
--- a/graphics/GraphicCommons.py Fri Oct 05 13:48:54 2018 +0300
+++ b/graphics/GraphicCommons.py Fri Oct 05 14:22:01 2018 +0300
@@ -24,6 +24,7 @@
from __future__ import absolute_import
+from __future__ import division from six.moves import xrange
@@ -116,7 +117,7 @@
def round_scaling(x, n, constraint=0):
- fraction = float(x) / float(n)
@@ -186,8 +187,8 @@
pos = event.GetLogicalPosition(dc)
- pos.x = round(float(pos.x) / float(scaling[0])) * scaling[0]
- pos.y = round(float(pos.y) / float(scaling[1])) * scaling[1]
+ pos.x = round(pos.x / scaling[0]) * scaling[0] + pos.y = round(pos.y / scaling[1]) * scaling[1] @@ -435,11 +436,11 @@
pt = wx.Point(*self.Parent.CalcUnscrolledPosition(pos.x, pos.y))
left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE
- center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2
+ center = (self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2 right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex
top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE
- middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2
+ middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE // 2 bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley
extern_rect = wx.Rect(left, top, right + HANDLE_SIZE - left, bottom + HANDLE_SIZE - top)
@@ -683,11 +684,11 @@
dc.SetBrush(wx.BLACK_BRUSH)
left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE
- center = (self.BoundingBox.x + self.BoundingBox.width / 2) * scalex - HANDLE_SIZE / 2
+ center = (self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2 right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex
top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE
- middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE / 2
+ middle = (self.BoundingBox.y + self.BoundingBox.height // 2) * scaley - HANDLE_SIZE // 2 bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley
for x, y in [(left, top), (center, top), (right, top),
@@ -859,13 +860,13 @@
if horizontally == ALIGN_LEFT:
elif horizontally == ALIGN_CENTER:
- movex = (maxx + minx - width) / 2 - posx
+ movex = (maxx + minx - width) // 2 - posx elif horizontally == ALIGN_RIGHT:
movex = maxx - width - posx
if vertically == ALIGN_TOP:
elif vertically == ALIGN_MIDDLE:
- movey = (maxy + miny - height) / 2 - posy
+ movey = (maxy + miny - height) // 2 - posy elif vertically == ALIGN_BOTTOM:
movey = maxy - height - posy
if movex != 0 or movey != 0:
@@ -1087,7 +1088,7 @@
parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] +
- width * (self.Direction[0] - 1) / 2,
+ width * (self.Direction[0] - 1) // 2, parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] +
height * (self.Direction[1] - 1),
@@ -1492,9 +1493,9 @@
# If connector is negated, draw a circle
- xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) / 2
- ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) / 2
- dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE / 2)
+ xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) // 2 + ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) // 2 + dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE // 2) xstart = parent_pos[0] + self.Pos.x
ystart = parent_pos[1] + self.Pos.y
@@ -1519,13 +1520,13 @@
yend = ystart + CONNECTOR_SIZE * self.Direction[1]
dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend)
if self.Direction[0] != 0:
- ytext = parent_pos[1] + self.Pos.y - name_size[1] / 2
+ ytext = parent_pos[1] + self.Pos.y - name_size[1] // 2 if self.Direction[0] < 0:
xtext = parent_pos[0] + self.Pos.x + 5
xtext = parent_pos[0] + self.Pos.x - (name_size[0] + 5)
if self.Direction[1] != 0:
- xtext = parent_pos[0] + self.Pos.x - name_size[0] / 2
+ xtext = parent_pos[0] + self.Pos.x - name_size[0] // 2 if self.Direction[1] < 0:
ytext = parent_pos[1] + self.Pos.y + 5
@@ -1544,7 +1545,7 @@
width, height = self.ValueSize
dc.DrawText(self.ComputedValue,
parent_pos[0] + self.Pos.x + CONNECTOR_SIZE * self.Direction[0] +
- width * (self.Direction[0] - 1) / 2,
+ width * (self.Direction[0] - 1) // 2, parent_pos[1] + self.Pos.y + CONNECTOR_SIZE * self.Direction[1] +
height * (self.Direction[1] - 1))
dc.SetFont(self.ParentBlock.Parent.GetFont())
@@ -1611,17 +1612,17 @@
if self.ValueSize is not None:
width, height = self.ValueSize
if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4:
- x = self.Points[0].x + width * self.StartPoint[1][0] / 2
+ x = self.Points[0].x + width * self.StartPoint[1][0] // 2 y = self.Points[0].y + height * (self.StartPoint[1][1] - 1)
rect = rect.Union(wx.Rect(x, y, width, height))
- x = self.Points[-1].x + width * self.EndPoint[1][0] / 2
+ x = self.Points[-1].x + width * self.EndPoint[1][0] // 2 y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1)
rect = rect.Union(wx.Rect(x, y, width, height))
- middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1
- x = (self.Points[middle].x + self.Points[middle + 1].x - width) / 2
+ middle = len(self.Segments) // 2 + len(self.Segments) % 2 - 1 + x = (self.Points[middle].x + self.Points[middle + 1].x - width) // 2 if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]:
- y = (self.Points[middle].y + self.Points[middle + 1].y - height) / 2
+ y = (self.Points[middle].y + self.Points[middle + 1].y - height) // 2 y = self.Points[middle].y - height
rect = rect.Union(wx.Rect(x, y, width, height))
@@ -2092,9 +2093,9 @@
# Current point is positioned in the middle of start point
# and end point on the current direction and a point is added
if self.Segments[0][0] != 0:
- self.Points[1].x = (end.x + start.x) / 2
+ self.Points[1].x = (end.x + start.x) // 2 if self.Segments[0][1] != 0:
- self.Points[1].y = (end.y + start.y) / 2
+ self.Points[1].y = (end.y + start.y) // 2 self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y))
self.Segments.insert(2, DirectionChoice(
@@ -2136,9 +2137,9 @@
# Current point is positioned in the middle of previous point
# and end point on the current direction and a point is added
if self.Segments[1][0] != 0:
- self.Points[2].x = (self.Points[1].x + end.x) / 2
+ self.Points[2].x = (self.Points[1].x + end.x) // 2 if self.Segments[1][1] != 0:
- self.Points[2].y = (self.Points[1].y + end.y) / 2
+ self.Points[2].y = (self.Points[1].y + end.y) // 2 self.Points.insert(3, wx.Point(self.Points[2].x, self.Points[2].y))
@@ -2160,9 +2161,9 @@
# Current point is positioned in the middle of previous point
# and end point on the current direction
if self.Segments[i - 1][0] != 0:
- self.Points[i].x = (end.x + self.Points[i - 1].x) / 2
+ self.Points[i].x = (end.x + self.Points[i - 1].x) // 2 if self.Segments[i - 1][1] != 0:
- self.Points[i].y = (end.y + self.Points[i - 1].y) / 2
+ self.Points[i].y = (end.y + self.Points[i - 1].y) // 2 self.Points.insert(i + 1, wx.Point(self.Points[i].x, self.Points[i].y))
@@ -2242,9 +2243,9 @@
- pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * width / float(max(lastwidth, 1)))),
+ pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * width / max(lastwidth, 1))), width - dir[0] * MIN_SEGMENT_SIZE))
- pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * height / float(max(lastheight, 1)))),
+ pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * height / max(lastheight, 1))), height - dir[1] * MIN_SEGMENT_SIZE))
self.Points[i] = wx.Point(minx + x + pointx, miny + y + pointy)
self.StartPoint[0] = self.Points[0]
@@ -2266,8 +2267,8 @@
# during a resize dragging
for i, point in enumerate(self.RealPoints):
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected):
- point[0] = point[0] * width / float(max(lastwidth, 1))
- point[1] = point[1] * height / float(max(lastheight, 1))
+ point[0] = point[0] * width / max(lastwidth, 1) + point[1] = point[1] * height / max(lastheight, 1) # Calculate the correct position of the points from real points
for i, point in enumerate(self.RealPoints):
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected):
@@ -2399,9 +2400,9 @@
pointx = self.Points[segment].x
pointy = self.Points[segment].y
- pointx = (self.Points[segment].x + self.Points[segment + 1].x) / 2
+ pointx = (self.Points[segment].x + self.Points[segment + 1].x) // 2 - pointy = (self.Points[segment].y + self.Points[segment + 1].y) / 2
+ pointy = (self.Points[segment].y + self.Points[segment + 1].y) // 2 self.Points.insert(segment + 1, wx.Point(pointx, pointy))
self.Segments.insert(segment + 1, (dir[1], dir[0]))
self.Points.insert(segment + 2, wx.Point(pointx, pointy))
@@ -2410,11 +2411,11 @@
p1x = p2x = self.Points[segment].x
p1y = p2y = self.Points[segment].y
- p1x = (2 * self.Points[segment].x + self.Points[segment + 1].x) / 3
- p2x = (self.Points[segment].x + 2 * self.Points[segment + 1].x) / 3
+ p1x = (2 * self.Points[segment].x + self.Points[segment + 1].x) // 3 + p2x = (self.Points[segment].x + 2 * self.Points[segment + 1].x) // 3 - p1y = (2 * self.Points[segment].y + self.Points[segment + 1].y) / 3
- p2y = (self.Points[segment].y + 2 * self.Points[segment + 1].y) / 3
+ p1y = (2 * self.Points[segment].y + self.Points[segment + 1].y) // 3 + p2y = (self.Points[segment].y + 2 * self.Points[segment + 1].y) // 3 self.Points.insert(segment + 1, wx.Point(p1x, p1y))
self.Segments.insert(segment + 1, (dir[1], dir[0]))
self.Points.insert(segment + 2, wx.Point(p1x, p1y))
@@ -2477,9 +2478,9 @@
direction = (self.StartPoint[1], self.EndPoint[1])
if direction in [(EAST, WEST), (WEST, EAST)]:
- avgy = (self.StartPoint[0].y + self.EndPoint[0].y) / 2
+ avgy = (self.StartPoint[0].y + self.EndPoint[0].y) // 2 - avgy = round(float(avgy) / scaling[1]) * scaling[1]
+ avgy = round(avgy / scaling[1]) * scaling[1] if self.StartConnected is not None:
movey = avgy - self.StartPoint[0].y
startblock = self.StartConnected.GetParentBlock()
@@ -2498,9 +2499,9 @@
self.MoveEndPoint(wx.Point(self.EndPoint[0].x, avgy))
self.Parent.RefreshBuffer()
elif direction in [(NORTH, SOUTH), (SOUTH, NORTH)]:
- avgx = (self.StartPoint[0].x + self.EndPoint[0].x) / 2
+ avgx = (self.StartPoint[0].x + self.EndPoint[0].x) // 2 - avgx = round(float(avgx) / scaling[0]) * scaling[0]
+ avgx = round(avgx / scaling[0]) * scaling[0] if self.StartConnected is not None:
movex = avgx - self.StartPoint[0].x
startblock = self.StartConnected.GetParentBlock()
@@ -2726,17 +2727,17 @@
if self.ValueSize is not None:
width, height = self.ValueSize
if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4:
- x = self.Points[0].x + width * (self.StartPoint[1][0] - 1) / 2
+ x = self.Points[0].x + width * (self.StartPoint[1][0] - 1) // 2 y = self.Points[0].y + height * (self.StartPoint[1][1] - 1)
dc.DrawText(self.ComputedValue, x, y)
- x = self.Points[-1].x + width * (self.EndPoint[1][0] - 1) / 2
+ x = self.Points[-1].x + width * (self.EndPoint[1][0] - 1) // 2 y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1)
dc.DrawText(self.ComputedValue, x, y)
- middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1
- x = (self.Points[middle].x + self.Points[middle + 1].x - width) / 2
+ middle = len(self.Segments) // 2 + len(self.Segments) % 2 - 1 + x = (self.Points[middle].x + self.Points[middle + 1].x - width) // 2 if self.BoundingBox[3] > height and self.Segments[middle] in [NORTH, SOUTH]:
- y = (self.Points[middle].y + self.Points[middle + 1].y - height) / 2
+ y = (self.Points[middle].y + self.Points[middle + 1].y - height) // 2 y = self.Points[middle].y - height
dc.DrawText(self.ComputedValue, x, y)
--- a/graphics/LD_Objects.py Fri Oct 05 13:48:54 2018 +0300
+++ b/graphics/LD_Objects.py Fri Oct 05 14:22:01 2018 +0300
@@ -24,6 +24,7 @@
from __future__ import absolute_import
+from __future__ import division from six.moves import xrange
@@ -49,7 +50,7 @@
self.RealConnectors = None
- self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2]
+ self.Extensions = [LD_LINE_SIZE // 2, LD_LINE_SIZE // 2] self.SetType(type, connectors)
@@ -184,14 +185,14 @@
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
height = self.Size[1] - self.Extensions[0] - self.Extensions[1]
- interval = float(height) / float(max(len(self.Connectors) - 1, 1))
+ interval = height / max(len(self.Connectors) - 1, 1) for i, connector in enumerate(self.Connectors):
position = self.Extensions[0] + int(round(self.RealConnectors[i] * height))
position = self.Extensions[0] + int(round(i * interval))
- position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y
+ position = round((self.Pos.y + position) / scaling[1]) * scaling[1] - self.Pos.y if self.Type == LEFTRAIL:
connector.SetPosition(wx.Point(self.Size[0], position))
elif self.Type == RIGHTRAIL:
@@ -251,7 +252,7 @@
for connector in self.Connectors:
position = connector.GetRelPosition()
- self.RealConnectors.append(max(0., min(float(position.y - self.Extensions[0]) / float(height), 1.)))
+ self.RealConnectors.append(max(0., min((position.y - self.Extensions[0]) / height, 1.))) elif len(self.Connectors) > 1:
self.RealConnectors = map(lambda x: x * 1 / (len(self.Connectors) - 1), xrange(len(self.Connectors)))
@@ -312,7 +313,7 @@
movey = max(-self.BoundingBox.y, movey)
position = handle.GetRelPosition()
- movey = round(float(self.Pos.y + position.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - position.y
+ movey = round((self.Pos.y + position.y + movey) / scaling[1]) * scaling[1] - self.Pos.y - position.y self.MoveConnector(handle, movey)
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -363,8 +364,8 @@
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
# Create an input and output connector
- self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
- self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
+ self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] // 2 + 1), WEST) + self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] // 2 + 1), EAST) self.PreviousValue = False
self.PreviousSpreading = False
@@ -493,7 +494,7 @@
text_width, text_height = self.Parent.GetTextExtent(self.Name)
# Calculate the bounding box size
- bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2)
+ bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) // 2) bbx_width = max(self.Size[0], text_width)
bbx_y = self.Pos.y - (text_height + 2)
bbx_height = self.Size[1] + (text_height + 2)
@@ -541,9 +542,9 @@
# Refresh the positions of the block connectors
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
- position = self.Size[1] / 2 + 1
+ position = self.Size[1] // 2 + 1 - position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y
+ position = round((self.Pos.y + position) / scaling[1]) * scaling[1] - self.Pos.y self.Input.SetPosition(wx.Point(0, position))
self.Output.SetPosition(wx.Point(self.Size[0], position))
@@ -670,13 +671,13 @@
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1)
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1)
- name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
+ name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, self.Pos.y - (name_size[1] + 2))
dc.DrawText(self.Name, name_pos[0], name_pos[1])
# Draw the modifier symbol in the middle of contact
- type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1,
- self.Pos.y + (self.Size[1] - type_size[1]) / 2)
+ type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) // 2 + 1, + self.Pos.y + (self.Size[1] - type_size[1]) // 2) dc.DrawText(typetext, type_pos[0], type_pos[1])
# Draw input and output connectors
@@ -709,8 +710,8 @@
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
# Create an input and output connector
- self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST)
- self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST)
+ self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] // 2 + 1), WEST) + self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] // 2 + 1), EAST) self.PreviousValue = False
@@ -813,7 +814,7 @@
text_width, text_height = self.Parent.GetTextExtent(self.Name)
# Calculate the bounding box size
- bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2)
+ bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) // 2) bbx_width = max(self.Size[0], text_width)
bbx_y = self.Pos.y - (text_height + 2)
bbx_height = self.Size[1] + (text_height + 2)
@@ -861,9 +862,9 @@
# Refresh the positions of the block connectors
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
- position = self.Size[1] / 2 + 1
+ position = self.Size[1] // 2 + 1 - position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y
+ position = round((self.Pos.y + position) / scaling[1]) * scaling[1] - self.Pos.y self.Input.SetPosition(wx.Point(0, position))
self.Output.SetPosition(wx.Point(self.Size[0], position))
@@ -993,19 +994,19 @@
dc.SetPen(MiterPen(wx.GREEN))
dc.SetPen(MiterPen(wx.BLACK))
- dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1)
+ dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] // 2 + 1) name_size = self.NameSize
type_size = self.TypeSize
- name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
+ name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, self.Pos.y - (name_size[1] + 2))
dc.DrawText(self.Name, name_pos[0], name_pos[1])
# Draw the modifier symbol in the middle of coil
- type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1,
- self.Pos.y + (self.Size[1] - type_size[1]) / 2)
+ type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) // 2 + 1, + self.Pos.y + (self.Size[1] - type_size[1]) // 2) dc.DrawText(typetext, type_pos[0], type_pos[1])
# Draw input and output connectors
--- a/graphics/SFC_Objects.py Fri Oct 05 13:48:54 2018 +0300
+++ b/graphics/SFC_Objects.py Fri Oct 05 14:22:01 2018 +0300
@@ -24,6 +24,7 @@
from __future__ import absolute_import
+from __future__ import division from six.moves import xrange
@@ -59,7 +60,7 @@
self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
# Create an input and output connector
- self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
+ self.Input = Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH) @@ -171,7 +172,7 @@
# Add output connector to step
- self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
+ self.Input = Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH) self.RefreshBoundingBox()
# Remove output connector from step
@@ -184,7 +185,7 @@
# Add output connector to step
- self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True)
+ self.Output = Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True) self.RefreshBoundingBox()
# Remove output connector from step
@@ -197,7 +198,7 @@
# Add action connector to step
- self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST, onlyone=True)
+ self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] // 2), EAST, onlyone=True) self.RefreshBoundingBox()
# Remove action connector from step
@@ -232,11 +233,11 @@
# Refresh the positions of the step connectors
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
- horizontal_pos = self.Size[0] / 2
- vertical_pos = self.Size[1] / 2
+ horizontal_pos = self.Size[0] // 2 + vertical_pos = self.Size[1] // 2 - horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
- vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y
+ horizontal_pos = round((self.Pos.x + horizontal_pos) / scaling[0]) * scaling[0] - self.Pos.x + vertical_pos = round((self.Pos.y + vertical_pos) / scaling[1]) * scaling[1] - self.Pos.y # Update input position if it exists
self.Input.SetPosition(wx.Point(horizontal_pos, 0))
@@ -363,7 +364,7 @@
def UpdateSize(self, width, height):
- diffx = self.Size.GetWidth() / 2 - width / 2
+ diffx = self.Size.GetWidth() // 2 - width // 2 diffy = height - self.Size.GetHeight()
Graphic_Element.SetSize(self, width, height)
@@ -463,8 +464,8 @@
movex = max(-self.BoundingBox.x, movex)
movey = max(-self.BoundingBox.y, movey)
- movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
- movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y
+ movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x + movey = round((self.Pos.y + movey) / scaling[1]) * scaling[1] - self.Pos.y if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -557,8 +558,8 @@
dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3)
- name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
- self.Pos.y + (self.Size[1] - name_size[1]) / 2)
+ name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, + self.Pos.y + (self.Size[1] - name_size[1]) // 2) dc.DrawText(self.Name, name_pos[0], name_pos[1])
# Draw input and output connectors
@@ -591,8 +592,8 @@
self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1])
# Create an input and output connector
- self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True)
- self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True)
+ self.Input = Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True) + self.Output = Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True) self.SetType(type, condition)
self.SetPriority(priority)
@@ -713,7 +714,7 @@
# Calculate the bounding box of the condition outside the transition
text_width, text_height = self.ConditionSize
text_bbx = wx.Rect(self.Pos.x + self.Size[0] + 5,
- self.Pos.y + (self.Size[1] - text_height) / 2,
+ self.Pos.y + (self.Size[1] - text_height) // 2, test_text = text_bbx.InsideXY(pt.x, pt.y)
@@ -735,8 +736,8 @@
text_width, text_height = self.ConditionSize
# Calculate the bounding box size
bbx_width = max(bbx_width, self.Size[0] + 5 + text_width)
- bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2))
- bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) / 2)
+ bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) // 2)) + bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) // 2) self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
# Returns the connector connected to input
@@ -756,11 +757,11 @@
# Refresh the positions of the transition connectors
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
- horizontal_pos = self.Size[0] / 2
- vertical_pos = self.Size[1] / 2
+ horizontal_pos = self.Size[0] // 2 + vertical_pos = self.Size[1] // 2 - horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
- vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y
+ horizontal_pos = round((self.Pos.x + horizontal_pos) / scaling[0]) * scaling[0] - self.Pos.x + vertical_pos = round((self.Pos.y + vertical_pos) / scaling[1]) * scaling[1] - self.Pos.y self.Input.SetPosition(wx.Point(horizontal_pos, 0))
@@ -822,7 +823,7 @@
self.Condition.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
- self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST)
+ self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] // 2), WEST) @@ -917,7 +918,7 @@
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
movex = max(-self.BoundingBox.x, movex)
- movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
+ movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x self.RefreshInputPosition()
self.RefreshOutputPosition()
@@ -1009,7 +1010,7 @@
# Draw plain rectangle for representing the transition
dc.DrawRectangle(self.Pos.x,
- self.Pos.y + (self.Size[1] - SFC_TRANSITION_SIZE[1])/2,
+ self.Pos.y + (self.Size[1] - SFC_TRANSITION_SIZE[1]) // 2, SFC_TRANSITION_SIZE[1] + 1)
vertical_line_x = self.Input.GetPosition()[0]
@@ -1021,7 +1022,7 @@
condition_pos = (self.Pos.x + self.Size[0] + 5,
- self.Pos.y + (self.Size[1] - condition_size[1]) / 2)
+ self.Pos.y + (self.Size[1] - condition_size[1]) // 2) dc.DrawText(condition, condition_pos[0], condition_pos[1])
@@ -1062,7 +1063,7 @@
self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1])
# Create an input and output connector
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
- self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True)]
+ self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True)] self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True))
@@ -1070,7 +1071,7 @@
self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True))
- self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True)]
+ self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] // 2, self.Size[1]), SOUTH, onlyone=True)] self.PreviousValue = None
@@ -1285,14 +1286,14 @@
input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0))
- input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0))
+ input.SetPosition(wx.Point(int(round(position.x*width / self.Size[0])), 0)) for i, output in enumerate(self.Outputs):
position = output.GetRelPosition()
output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), height))
- output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), height))
+ output.SetPosition(wx.Point(int(round(position.x*width / self.Size[0])), height)) self.Size = wx.Size(width, height)
self.RefreshBoundingBox()
@@ -1368,10 +1369,10 @@
self.RealConnectors = {"Inputs": [], "Outputs": []}
for input in self.Inputs:
position = input.GetRelPosition()
- self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0]))
+ self.RealConnectors["Inputs"].append(position.x / self.Size[0]) for output in self.Outputs:
position = output.GetRelPosition()
- self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0]))
+ self.RealConnectors["Outputs"].append(position.x / self.Size[0]) Graphic_Element.OnLeftDown(self, event, dc, scaling)
# Method called when a LeftUp event have been generated
@@ -1425,7 +1426,7 @@
if handle_type == HANDLE_CONNECTOR:
movex = max(-self.BoundingBox.x, movex)
- movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
+ movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x self.MoveConnector(handle, movex)
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
self.RefreshConnectedPosition(handle)
@@ -1519,7 +1520,7 @@
self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
# Create an input and output connector
- self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True)
+ self.Input = Connector(self, "", None, wx.Point(self.Size[0] // 2, 0), NORTH, onlyone=True) self.PreviousValue = None
@@ -1586,7 +1587,7 @@
# Calculate the bounding box of the condition outside the transition
text_width, text_height = self.TargetSize
text_bbx = wx.Rect(self.Pos.x + self.Size[0] + 2,
- self.Pos.y + (self.Size[1] - text_height) / 2,
+ self.Pos.y + (self.Size[1] - text_height) // 2, return text_bbx.InsideXY(pt.x, pt.y) or Graphic_Element.HitTest(self, pt, connectors)
@@ -1609,9 +1610,9 @@
# Refresh the element connectors position
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
- horizontal_pos = self.Size[0] / 2
+ horizontal_pos = self.Size[0] // 2 - horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
+ horizontal_pos = round((self.Pos.x + horizontal_pos) / scaling[0]) * scaling[0] - self.Pos.x self.Input.SetPosition(wx.Point(horizontal_pos, 0))
@@ -1685,7 +1686,7 @@
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
movex = max(-self.BoundingBox.x, movex)
- movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
+ movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x self.RefreshInputPosition()
@@ -1760,14 +1761,14 @@
target_size = self.TargetSize
# Draw plain rectangle for representing the divergence
- dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])
+ dc.DrawLine(self.Pos.x + self.Size[0] // 2, self.Pos.y, self.Pos.x + self.Size[0] // 2, self.Pos.y + self.Size[1]) points = [wx.Point(self.Pos.x, self.Pos.y),
- wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3),
+ wx.Point(self.Pos.x + self.Size[0] // 2, self.Pos.y + self.Size[1] // 3), wx.Point(self.Pos.x + self.Size[0], self.Pos.y),
- wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])]
+ wx.Point(self.Pos.x + self.Size[0] // 2, self.Pos.y + self.Size[1])] target_pos = (self.Pos.x + self.Size[0] + 2,
- self.Pos.y + (self.Size[1] - target_size[1]) / 2)
+ self.Pos.y + (self.Size[1] - target_size[1]) // 2) dc.DrawText(self.Target, target_pos[0], target_pos[1])
@@ -1795,7 +1796,7 @@
self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
# Create an input and output connector
- self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone=True)
+ self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] // 2), WEST, onlyone=True) self.PreviousValue = None
@@ -1843,7 +1844,7 @@
if len(self.Actions) > 0:
- return self.Size[1] / len(self.Actions)
+ return self.Size[1] // len(self.Actions) return SFC_ACTION_MIN_SIZE[1]
@@ -1889,9 +1890,9 @@
# Refresh the element connectors position
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
- vertical_pos = SFC_ACTION_MIN_SIZE[1] / 2
+ vertical_pos = SFC_ACTION_MIN_SIZE[1] // 2 - vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y
+ vertical_pos = round((self.Pos.y + vertical_pos) / scaling[1]) * scaling[1] - self.Pos.y self.Input.SetPosition(wx.Point(0, vertical_pos))
@@ -1962,7 +1963,7 @@
if handle_type == HANDLE_MOVE:
movex = max(-self.BoundingBox.x, movex)
- movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
+ movex = round((self.Pos.x + movex) / scaling[0]) * scaling[0] - self.Pos.x wires = self.Input.GetWires()
input_pos = wires[0][0].GetOtherConnected(self.Input).GetPosition(False)
@@ -2033,24 +2034,24 @@
self.Pos.x + self.Size[0], self.Pos.y + i * line_size)
qualifier_size = dc.GetTextExtent(action.qualifier)
if action.duration != "":
- qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2,
- self.Pos.y + i * line_size + line_size / 2 - qualifier_size[1])
+ qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) // 2, + self.Pos.y + i * line_size + line_size // 2 - qualifier_size[1]) duration_size = dc.GetTextExtent(action.duration)
- duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) / 2,
- self.Pos.y + i * line_size + line_size / 2)
+ duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) // 2, + self.Pos.y + i * line_size + line_size // 2) dc.DrawText(action.duration, duration_pos[0], duration_pos[1])
- qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2,
- self.Pos.y + i * line_size + (line_size - qualifier_size[1]) / 2)
+ qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) // 2, + self.Pos.y + i * line_size + (line_size - qualifier_size[1]) // 2) dc.DrawText(action.qualifier, qualifier_pos[0], qualifier_pos[1])
content_size = dc.GetTextExtent(action.value)
- content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) / 2,
- self.Pos.y + i * line_size + (line_size - content_size[1]) / 2)
+ content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) // 2, + self.Pos.y + i * line_size + (line_size - content_size[1]) // 2) dc.DrawText(action.value, content_pos[0], content_pos[1])
if action.indicator != "":
indicator_size = dc.GetTextExtent(action.indicator)
- indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2,
- self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2)
+ indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) // 2, + self.Pos.y + i * line_size + (line_size - indicator_size[1]) // 2) dc.DrawText(action.indicator, indicator_pos[0], indicator_pos[1])
if not getattr(dc, "printing", False):