本文整理汇总了Python中future.builtins.round方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.round方法的具体用法?Python builtins.round怎么用?Python builtins.round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类future.builtins
的用法示例。
在下文中一共展示了builtins.round方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RefreshConnectors
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
height = self.Size[1] - self.Extensions[0] - self.Extensions[1]
interval = height / max(len(self.Connectors) - 1, 1)
for i, connector in enumerate(self.Connectors):
if self.RealConnectors:
position = self.Extensions[0] + int(round(self.RealConnectors[i] * height))
else:
position = self.Extensions[0] + int(round(i * interval))
if scaling is not None:
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:
connector.SetPosition(wx.Point(0, position))
self.RefreshConnected()
# Refresh the position of wires connected to power rail
示例2: DrawHighlightment
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (3 * scalex + 5), wx.SOLID))
dc.SetBrush(wx.TRANSPARENT_BRUSH)
dc.SetLogicalFunction(wx.AND)
# Draw a two circle arcs for representing the coil
dc.DrawEllipticArc(round(self.Pos.x * scalex),
round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
round(self.Size[0] * scalex),
round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
135, 225)
dc.DrawEllipticArc(round(self.Pos.x * scalex),
round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
round(self.Size[0] * scalex),
round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
-45, 45)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
# Adds an highlight to the connection
示例3: DrawHighlightment
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
pen = MiterPen(HIGHLIGHTCOLOR, 2 * scalex + 5)
pen.SetCap(wx.CAP_BUTT)
dc.SetPen(pen)
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
dc.SetLogicalFunction(wx.AND)
parent_pos = self.ParentBlock.GetPosition()
xstart = parent_pos[0] + self.Pos.x
ystart = parent_pos[1] + self.Pos.y
if self.Direction[0] < 0:
xstart += 1
if self.Direction[1] < 0:
ystart += 1
xend = xstart + CONNECTOR_SIZE * self.Direction[0]
yend = ystart + CONNECTOR_SIZE * self.Direction[1]
dc.DrawLine(round((xstart + self.Direction[0]) * scalex), round((ystart + self.Direction[1]) * scaley),
round(xend * scalex), round(yend * scaley))
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
# Adds an highlight to the connector
示例4: RefreshConnectors
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
horizontal_pos = self.Size[0] // 2
vertical_pos = self.Size[1] // 2
if scaling is not None:
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
if self.Input:
self.Input.SetPosition(wx.Point(horizontal_pos, 0))
# Update output position
if self.Output:
self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1]))
# Update action position if it exists
if self.Action:
self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos))
self.RefreshConnected()
# Refresh the position of wires connected to step
示例5: SetSize
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def SetSize(self, width, height):
height = self.GetMinSize()[1]
for i, input in enumerate(self.Inputs):
position = input.GetRelPosition()
if self.RealConnectors:
input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0))
else:
input.SetPosition(wx.Point(int(round(position.x*width / self.Size[0])), 0))
input.MoveConnected()
for i, output in enumerate(self.Outputs):
position = output.GetRelPosition()
if self.RealConnectors:
output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), height))
else:
output.SetPosition(wx.Point(int(round(position.x*width / self.Size[0])), height))
output.MoveConnected()
self.Size = wx.Size(width, height)
self.RefreshBoundingBox()
# Returns the divergence minimum size
示例6: DrawHighlightment
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
dc.SetUserScale(1, 1)
dc.SetPen(MiterPen(HIGHLIGHTCOLOR))
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
dc.SetLogicalFunction(wx.AND)
# Draw two rectangles for representing the contact
posx = self.Pos.x
width = self.Size[0]
if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA
width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2
dc.DrawRectangle(int(round((posx - 1) * scalex)) - 2,
int(round((self.Pos.y - 1) * scaley)) - 2,
int(round((width + 3) * scalex)) + 5,
int(round((self.Size.height + 3) * scaley)) + 5)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
# Draws divergence
示例7: RefreshScrollBars
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def RefreshScrollBars(self, width_incr=0, height_incr=0):
xstart, ystart = self.GetViewStart()
window_size = self.Editor.GetClientSize()
maxx, maxy = self.GetMaxSize()
maxx = max(maxx + WINDOW_BORDER, (xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[0])
maxy = max(maxy + WINDOW_BORDER, (ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[1])
if self.rubberBand.IsShown():
extent = self.rubberBand.GetCurrentExtent()
maxx = max(maxx, extent.x + extent.width)
maxy = max(maxy, extent.y + extent.height)
maxx = int(maxx * self.ViewScale[0])
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,
xstart, ystart, True)
示例8: EnsureVisible
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def EnsureVisible(self, block):
xstart, ystart = self.GetViewStart()
window_size = self.Editor.GetClientSize()
block_bbx = block.GetBoundingBox()
screen_minx, screen_miny = xstart * SCROLLBAR_UNIT, ystart * SCROLLBAR_UNIT
screen_maxx, screen_maxy = screen_minx + window_size[0], screen_miny + window_size[1]
block_minx = int(block_bbx.x * self.ViewScale[0])
block_miny = int(block_bbx.y * self.ViewScale[1])
block_maxx = int(round((block_bbx.x + block_bbx.width) * self.ViewScale[0]))
block_maxy = int(round((block_bbx.y + block_bbx.height) * self.ViewScale[1]))
xpos, ypos = xstart, ystart
if block_minx < screen_minx and block_maxx < screen_maxx:
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
if block_miny < screen_miny and block_maxy < screen_maxy:
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
self.Scroll(xpos, ypos)
示例9: AddVariableBlock
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def AddVariableBlock(self, x, y, scaling, var_class, var_name, var_type):
id = self.GetNewId()
variable = FBD_Variable(self, var_class, var_name, var_type, id)
width, height = variable.GetMinSize()
if scaling is not None:
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)
self.AddBlock(variable)
self.Controler.AddEditedElementVariable(self.GetTagName(), id, var_class)
self.RefreshVariableModel(variable)
self.RefreshBuffer()
self.RefreshScrollBars()
self.RefreshVisibleElements()
self.Editor.Refresh(False)
# -------------------------------------------------------------------------------
# Model adding functions
# -------------------------------------------------------------------------------
示例10: ProcessDragging
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def ProcessDragging(self, movex, movey, event, scaling):
handle_type, handle = self.Handle
# A connector has been handled
if handle_type == HANDLE_CONNECTOR:
movey = max(-self.BoundingBox.y, movey)
if scaling is not None:
position = handle.GetRelPosition()
movey = round((self.Pos.y + position.y + movey) / scaling[1]) * scaling[1] - self.Pos.y - position.y
self.MoveConnector(handle, movey)
return 0, movey
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling)
return 0, 0
# Refreshes the power rail model
示例11: GetScaledEventPosition
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def GetScaledEventPosition(event, dc, scaling):
"""
Function that calculates the nearest point of the grid defined by scaling for the given point
"""
pos = event.GetLogicalPosition(dc)
if scaling:
pos.x = round(pos.x / scaling[0]) * scaling[0]
pos.y = round(pos.y / scaling[1]) * scaling[1]
return pos
示例12: ProcessDragging
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def ProcessDragging(self, movex, movey, event, scaling):
handle_type, _handle = self.Handle
if handle_type == HANDLE_MOVE:
movex = max(-self.BoundingBox.x, movex)
movey = max(-self.BoundingBox.y, movey)
if scaling is not None:
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:
self.Move(movex, movey)
self.RefreshConnected()
return movex, movey
elif self.Initial:
self.MoveActionBlock((movex, movey))
self.Move(movex, movey, self.Parent.Wires)
self.RefreshOutputPosition((movex, movey))
return movex, movey
else:
self.MoveActionBlock((movex, 0))
self.Move(movex, 0)
self.RefreshInputPosition()
self.RefreshOutputPosition()
return movex, 0
else:
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling)
# Refresh input element model
示例13: SetScale
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def SetScale(self, scale_number, refresh=True, mouse_event=None):
new_scale = max(0, min(scale_number, len(ZOOM_FACTORS) - 1))
if self.CurrentScale != new_scale:
if refresh:
dc = self.GetLogicalDC()
self.CurrentScale = new_scale
self.ViewScale = (ZOOM_FACTORS[self.CurrentScale], ZOOM_FACTORS[self.CurrentScale])
if refresh:
self.Editor.Freeze()
if mouse_event is None:
client_size = self.Editor.GetClientSize()
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
else:
mouse_pos = mouse_event.GetPosition()
pos = mouse_event.GetLogicalPosition(dc)
xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
scrollx = max(0, round(pos.x * self.ViewScale[0] - mouse_pos.x) / SCROLLBAR_UNIT)
scrolly = max(0, round(pos.y * self.ViewScale[1] - mouse_pos.y) / SCROLLBAR_UNIT)
if scrollx > xmax or scrolly > ymax:
self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax))
self.Scroll(scrollx, scrolly)
else:
self.Scroll(scrollx, scrolly)
self.RefreshScrollBars()
self.RefreshScaling(refresh)
self.Editor.Thaw()
示例14: GetScaledSize
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def GetScaledSize(self, width, height):
if self.Scaling is not None:
width = round(width / self.Scaling[0] + 0.4) * self.Scaling[0]
height = round(height / self.Scaling[1] + 0.4) * self.Scaling[1]
return width, height
示例15: Resize
# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import round [as 别名]
def Resize(self, x, y, width, height):
if len(self.Points) > 1:
# Calculate the new position of each point for testing the new size
minx, miny = self.Pos.x, self.Pos.y
lastwidth, lastheight = self.Size.width, self.Size.height
for i, point in enumerate(self.RealPoints):
# If start or end point is connected, it's not calculate
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected):
if i == 0:
dir = self.StartPoint[1]
elif i == len(self.Points) - 1:
dir = self.EndPoint[1]
else:
dir = (0, 0)
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 / 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]
self.EndPoint[0] = self.Points[-1]
self.GeneratePoints(False)
# Test if the wire position or size have changed
if x != 0 and minx == self.Pos.x:
x = 0
width = lastwidth
if y != 0 and miny == self.Pos.y:
y = 0
height = lastwidth
if width != lastwidth and lastwidth == self.Size.width:
width = lastwidth
if height != lastheight and lastheight == self.Size.height:
height = lastheight
# Calculate the real points from the new size, it's important for
# keeping a proportionality in the points position with the size
# 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 / 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):
if i == 0:
dir = self.StartPoint[1]
elif i == len(self.Points) - 1:
dir = self.EndPoint[1]
else:
dir = (0, 0)
realpointx = max(-dir[0] * MIN_SEGMENT_SIZE,
min(int(round(point[0])),
width - dir[0] * MIN_SEGMENT_SIZE))
realpointy = max(-dir[1] * MIN_SEGMENT_SIZE,
min(int(round(point[1])),
height - dir[1] * MIN_SEGMENT_SIZE))
self.Points[i] = wx.Point(minx + x + realpointx, miny + y + realpointy)
self.StartPoint[0] = self.Points[0]
self.EndPoint[0] = self.Points[-1]
self.GeneratePoints(False)
# Moves the wire start point and update the wire points