예제 #1
0
    def AddCurveToPoint(self, cx1, cy1, cx2, cy2, x, y):
        """
        Adds a cubic Bezier curve from the current point, using two
        control points and an end point.

        :param `cx1`: ????
        :param `cy1`: ????
        :param `cx2`: ????
        :param `cy2`: ????
        :param `x`: ????
        :param `y`: ????
        
        """
        g = self.gstate
        clist = []
        clist.append(wx.RealPoint(self.xc, self.yc))
        clist.append(wx.RealPoint(g.Get_x(cx1, cy1), g.Get_y(cx1, cy1)))
        clist.append(wx.RealPoint(g.Get_x(cx2, cy2), g.Get_y(cx2, cy2)))
        clist.append(wx.RealPoint(g.Get_x(x, y), g.Get_y(x, y)))
        self.xc, self.yc = clist[-1]
        plist = bezier.compute_points(clist, 64)
        if self.isfilled:
            self.allpoints.extend(plist)
        else:
            self.commands.append(['DrawSpline', (plist, ), {}])
예제 #2
0
    def SetPointsFromControl(self, pt, end=0):
        dc = wx.ClientDC(self.GetCanvas())
        self.GetCanvas().PrepareDC(dc)

        x0, y0, w, h = self.GetCanvas().GetClientRect()

        self.Erase(dc)

        for i, control in enumerate(self._controlPoints):
            self._points[i] = wx.RealPoint(control.GetX() - self._xpos,
                                           control.GetY() - self._ypos)
            self._originalPoints[i] = wx.RealPoint(control.GetX() - self._xpos,
                                                   control.GetY() - self._ypos)
        self.CalculatePolygonCentre()
        self.CalculateBoundingBox()

        dc.SetLogicalFunction(ogl.OGLRBLF)

        dottedPen = wx.Pen(wx.Colour(0, 0, 0), 1, wx.DOT)
        dc.SetPen(dottedPen)
        dc.SetBrush(wx.TRANSPARENT_BRUSH)

        self.updateEraseRect()

        if not end:
            self.GetEventHandler().OnDrawOutline(dc, self.GetX(), self.GetY(),
                                                 self._originalWidth,
                                                 self._originalHeight)
        else:
            self.GetEventHandler().OnDraw(dc, self.GetX(), self.GetY())

        dc.DrawBitmap(self.GetCanvas().buffer, x0, y0)
        self.UpdateOriginalPoints()
예제 #3
0
def getMouseRestrictedToScreens(x, y, displays):
    """ Ensures that the mouse position is within the area of one of the displays, relative to (0,0) 
		but not necessarily positive (which is as expected for mouse coordinates)

		We need to first get the closest point on the edge of each display rectangle (if the mouse
		is outside the rectangle). This is done by clamping the mouse position to the extents of each
		screen. The distance from this point to the actual mouse position can then be calculated. The
		smallest adjustment to get the mouse within the screen bounds is desired.
	"""
    mpos = wx.RealPoint(x, y)
    closestDistValue = None
    newXY = None
    for screenRect in displays:
        halfWidth = wx.RealPoint(0.5 * screenRect.GetWidth(),
                                 0.5 * screenRect.GetHeight())
        tl = screenRect.GetTopLeft()
        # tl is an integer based wx.Point, so convert to float based wx.RealPoint
        screenMin = wx.RealPoint(tl.x, tl.y)
        screenCenter = screenMin + halfWidth
        scrCenterToMouse = mpos - screenCenter
        mouseLimitedToScreen = screenCenter + wx.RealPoint(  # relative to origin
            max(min(scrCenterToMouse.x, halfWidth.x), -halfWidth.x),
            max(min(scrCenterToMouse.y, halfWidth.y), -halfWidth.y))
        edgeToMouse = mpos - mouseLimitedToScreen
        distFromRectToMouseSqd = abs(edgeToMouse.x) + abs(edgeToMouse.y)
        if closestDistValue == None or closestDistValue > distFromRectToMouseSqd:
            closestDistValue = distFromRectToMouseSqd
            newXY = mouseLimitedToScreen

    # drop any partial position information. Even the 99% of the way to the edge of a
    # pixel is still in the pixel.
    return (int(floor(newXY.x)), int(floor(newXY.y)))
예제 #4
0
 def test_GetIM(self):
     # Test the immutable version returned by GetIM
     obj = wx.RealPoint(1, 2)
     im = obj.GetIM()
     assert isinstance(im, tuple)
     assert im.x == obj.x
     assert im.y == obj.y
     obj2 = wx.RealPoint(im)
     assert obj == obj2
예제 #5
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition,
                          wx.DefaultSize)
        self.ztv_frame = self.GetTopLevelParent()
        self.ztv_frame.primary_image_panel.popup_menu_cursor_modes.append(
            'Slice plot')
        self.ztv_frame.primary_image_panel.available_cursor_modes[
            'Slice plot'] = {
                'set-to-mode': self.set_cursor_to_plot_mode,
                'on_button_press': self.on_button_press,
                'on_motion': self.on_motion,
                'on_button_release': self.on_button_release
            }
        for cur_key in ['c', 'C', 'v', 'V', 'y', 'Y']:
            self.ztv_frame.primary_image_panel.available_key_presses[
                cur_key] = self.do_column_plot
        for cur_key in ['r', 'R', 'h', 'H', 'x', 'X']:
            self.ztv_frame.primary_image_panel.available_key_presses[
                cur_key] = self.do_row_plot
        for cur_key in ['z', 'Z']:
            self.ztv_frame.primary_image_panel.available_key_presses[
                cur_key] = self.do_stack_plot

        self.primary_image_patch = None

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.plot_panel = PlotPlotPanel(self)
        self.sizer.Add(self.plot_panel, 1, wx.LEFT | wx.TOP | wx.EXPAND)

        self.hideshow_button = wx.Button(self, wx.ID_ANY, u"Hide",
                                         wx.DefaultPosition, wx.DefaultSize, 0)
        self.sizer.Add(self.hideshow_button, 0,
                       wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM, 2)
        self.hideshow_button.Bind(wx.EVT_BUTTON, self.on_hideshow_button)

        self.SetSizer(self.sizer)
        self.Fit()
        self.start_pt = wx.RealPoint(0., 0.)
        self.end_pt = wx.RealPoint(0., 0.)
        self.redraw()
        pub.subscribe(self.on_new_xy0, 'set-new-slice-plot-xy0')
        pub.subscribe(self.on_new_xy1, 'set-new-slice-plot-xy1')
        pub.subscribe(self.queue_redraw, 'primary-xy-limits-changed')
        pub.subscribe(self.queue_redraw, 'recalc-display-image-called')
        pub.subscribe(self.remove_overplot_on_image,
                      'hide-plot-panel-overplot')
        pub.subscribe(self.redraw_overplot_on_image,
                      'show-plot-panel-overplot')
        pub.subscribe(self.publish_xy0xy1_to_stream, 'get-slice-plot-coords')
예제 #6
0
 def GetEndPoint(self, kidNo):
     if self.kidCount > 1:
         koffs = round(self.GetBitmap().GetHeight() * 2. / 3. * kidNo /
                       (2 * self.kidCount - 2))
     else:
         koffs = 0
     _sh = self.GetHeight()
     _bh = self.GetBitmap().GetHeight()
     pt = wx.RealPoint(
         self.GetX() - self.GetBitmap().GetWidth() / 2.0 - ARROWMARGIN,
         self.GetY() + koffs)
     return pt
예제 #7
0
    def test_floatingMultiply(self):
        v0 = wx.RealPoint(3, 4)
        v1 = v0 * 4
        v2 = v0 * 4.0
        v3 = v0 * 4.4
        v4 = v0 * 4.9

        assert v1 == (12.0, 16.0)
        assert v2 == (12.0, 16.0)
        assert round(v3.x, 2) == 13.20
        assert round(v3.y, 2) == 17.60
        assert round(v4.x, 2) == 14.70
        assert round(v4.y, 2) == 19.60
예제 #8
0
    def test_zero_dimension_line(self):
        app = wx.App()
        OGLInitialize()
        shape = LineShape()
        if PRO_EDITION:
            self.assertEqual([0,0], shape.x)
            self.assertEqual([0,0], shape.y)
        self.assertFalse(hasattr(shape, "_width"))  # Line shapes don't have these, use boundingbox
        self.assertFalse(hasattr(shape, "_height"))

        # ogltwo fails this because for a line without line control points, xpos and ypos
        # which are derived from boundingbox, end up in -2000 land - yikes!
        # perhaps we re-implement xpos and ypos for Lines? to be based on .x.y point lists?
        # OK I did that - and these tests pass - but what implications for the rest of the system?
        self.assertEqual(0, shape._xpos)
        self.assertEqual(0, shape._ypos)

        self.assertEqual((-20000, -20000), shape.GetBoundingBoxMax())  # cos no _lineControlPoints
        # self.assertEqual((0, 0), getpos(shape))

        shape._xpos = 50
        shape._ypos = 50
        shape._lineControlPoints = [wx.RealPoint(40, 60), wx.RealPoint(60, 40)]

        if PRO_EDITION:
            self.assertEqual([50,50], shape.x)
            self.assertEqual([50,50], shape.y)

        # Lines don't have ._width, ._height attributes, according to wx.ogl
        # self.assertEqual(0, shape._width)
        # self.assertEqual(0, shape._height)

        self.assertEqual(50, shape._xpos)
        self.assertEqual(50, shape._ypos)
        self.assertEqual((20, 20), shape.GetBoundingBoxMax())
        self.assertEqual((40, 40), getpos(shape))
예제 #9
0
파일: khetWx.py 프로젝트: EstebanMar/khet
    def DrawPiece(self, dc, piece, rect):
        """Draws the piece on the given DC, in a square that occupies the given rect."""
        rect = self.DrawSquareBase(dc, piece, rect)
        if isinstance(piece, Pharaoh):
            startAngle, endAngle = 0 + piece.rotation, 180 + piece.rotation
            rect.Inflate(-5, -5)
            dc.DrawEllipticArc(rect.x + 5, rect.y + 5, rect.width - 10,
                               rect.height - 10, startAngle, endAngle)
            dc.DrawLine(rect.x, rect.y + rect.height / 2, rect.x + rect.width,
                        rect.y + rect.height / 2)
        if isinstance(piece, Obelisk):
            rect.Inflate(-5, -5)

            # Inner box
            dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)

            # Draw even smaller box.
            if piece.stacked:
                dc.SetBrush(stackedObeliskBrush)
            rect.Inflate(-10, -10)
            dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)
            rect.Inflate(10, 10)

            # X
            dc.DrawLine(rect.x, rect.y, rect.x + rect.width - 1,
                        rect.y + rect.height - 1)
            dc.DrawLine(rect.x + rect.width - 1, rect.y, rect.x,
                        rect.y + rect.height - 1)
        if isinstance(piece, Pyramid):
            rect.Inflate(-1, -1)

            self.DrawTransformedLine(dc, rect, piece, wx.RealPoint(-1, 1),
                                     wx.RealPoint(1, -1))
            self.DrawTransformedLine(dc, rect, piece, wx.RealPoint(0, 0),
                                     wx.RealPoint(1, 1))
        if isinstance(piece, Djed):
            rect.Inflate(-1, -1)

            m = 0.75
            self.DrawTransformedLine(dc, rect, piece, wx.RealPoint(-1, m),
                                     wx.RealPoint(m, -1))
            self.DrawTransformedLine(dc, rect, piece, wx.RealPoint(1, -m),
                                     wx.RealPoint(-m, 1))
예제 #10
0
def main():
    # app
    app = wx.App()

    # frame
    frame = wx.Frame(title='Hello wx', parent=None)

    # panel
    panel = wx.Panel(parent=frame, pos=wx.RealPoint(53, 66))
    customize_panel(panel)

    # menu bar
    bar = wx.MenuBar()
    frame.SetMenuBar(bar)
    customize_bar(bar)

    # run
    frame.Show()
    app.MainLoop()
예제 #11
0
 def test_properties(self):
     p = wx.RealPoint(12.3, 45.6)
     p.x += 2
     p.y += 2
예제 #12
0
 def test_copy_ctor(self):
     p1 = wx.RealPoint(12.3, 45.6)
     p2 = wx.RealPoint(p1)
예제 #13
0
 def test_Point_ctor(self):
     p = wx.RealPoint(wx.Point(3, 5))
     p = wx.RealPoint((3, 5))
예제 #14
0
 def test_xy_ctor(self):
     p = wx.RealPoint(12.3, 34.5)
예제 #15
0
 def test_default_ctor(self):
     p = wx.RealPoint()
예제 #16
0
 def test_RealPoint_ctor(self):
     p = wx.Point(wx.RealPoint(1.2, 2.9))
     self.assertTrue(p == (1, 2))
예제 #17
0
파일: plot_panel.py 프로젝트: legolason/ztv
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition,
                          wx.DefaultSize)
        self.ztv_frame = self.GetTopLevelParent()
        self.ztv_frame.primary_image_panel.popup_menu_cursor_modes.append(
            'Slice plot')
        self.ztv_frame.primary_image_panel.available_cursor_modes[
            'Slice plot'] = {
                'set-to-mode': self.set_cursor_to_plot_mode,
                'on_button_press': self.on_button_press,
                'on_motion': self.on_motion,
                'on_button_release': self.on_button_release
            }
        for cur_key in ['c', 'C', 'v', 'V', 'y', 'Y']:
            self.ztv_frame.primary_image_panel.available_key_presses[
                cur_key] = self.do_column_plot
        for cur_key in ['r', 'R', 'h', 'H', 'x', 'X']:
            self.ztv_frame.primary_image_panel.available_key_presses[
                cur_key] = self.do_row_plot
        for cur_key in ['z', 'Z']:
            self.ztv_frame.primary_image_panel.available_key_presses[
                cur_key] = self.do_stack_plot

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.plot_panel = PlotPlotPanel(self)
        self.sizer.Add(self.plot_panel, 1, wx.LEFT | wx.TOP | wx.EXPAND)

        self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.cursor_position_textctrl = wx.TextCtrl(self, wx.ID_ANY,
                                                    wx.EmptyString,
                                                    wx.DefaultPosition,
                                                    (200, -1), wx.TE_READONLY)
        self.textentry_font = wx.Font(14, wx.FONTFAMILY_MODERN, wx.NORMAL,
                                      wx.FONTWEIGHT_LIGHT, False)
        self.cursor_position_textctrl.SetFont(self.textentry_font)
        self.cursor_position_textctrl.SetBackgroundColour(
            textctrl_output_only_background_color)
        self.h_sizer.Add(self.cursor_position_textctrl, 0)
        self.h_sizer.AddStretchSpacer(1)
        self.hideshow_button = wx.Button(self, wx.ID_ANY, u"Hide",
                                         wx.DefaultPosition, wx.DefaultSize, 0)
        self.h_sizer.Add(self.hideshow_button, 0)
        self.hideshow_button.Bind(wx.EVT_BUTTON, self.on_hideshow_button)

        self.sizer.Add(self.h_sizer, 0, wx.EXPAND)

        self.SetSizer(self.sizer)
        self.Fit()
        self.start_pt = wx.RealPoint(0., 0.)
        self.end_pt = wx.RealPoint(0., 0.)
        self.redraw()
        pub.subscribe(self.on_new_xy0, 'set-new-slice-plot-xy0')
        pub.subscribe(self.on_new_xy1, 'set-new-slice-plot-xy1')
        pub.subscribe(self.queue_redraw, 'primary-xy-limits-changed')
        pub.subscribe(self.queue_redraw, 'recalc-display-image-called')
        pub.subscribe(self.remove_overplot_on_image,
                      'hide-plot-panel-overplot')
        pub.subscribe(self.redraw_overplot_on_image,
                      'show-plot-panel-overplot')
        pub.subscribe(self.publish_xy0xy1_to_stream, 'get-slice-plot-coords')
        self.cursor_drag_active = False
예제 #18
0
 def GetStartPoint(self):
     pt = wx.RealPoint(
         self.GetX() + self.GetBitmap().GetWidth() / 2.0 + ARROWMARGIN,
         self.GetY())
     return pt
예제 #19
0
    def Run(self,
            keyFormat,
            diodeFormat,
            routeTracks=False,
            rotateModules=True,
            useNorthFacingSwitches=False,
            relativeDiodePosition=wx.RealPoint(0, 0),
            relativeDiodeRotation=270,
            useCustomAnnotationFormat=False):
        for key in self.layout["keys"]:

            position = wxPoint(
                self.referenceCoordinate.x + (self.keyDistance * key["x"]) +
                (self.keyDistance * key["width"] // 2),
                self.referenceCoordinate.y + (self.keyDistance * key["y"]) +
                (self.keyDistance * key["height"] // 2))

            keyModule = None
            if useCustomAnnotationFormat == True:
                keyModule = self.GetCurrentKeyCustom(keyFormat)
            else:
                keyModule = self.GetCurrentKey(keyFormat)

            self.SetPosition(keyModule, position)

            diodeModule = None
            if useCustomAnnotationFormat == True:
                diodeModule = self.GetCurrentDiodeCustom(diodeFormat)
            else:
                diodeModule = self.GetCurrentDiode(diodeFormat)

            self.SetRelativePositionMM(
                diodeModule, position,
                [relativeDiodePosition.x, relativeDiodePosition.y])

            if not diodeModule.IsFlipped():
                diodeModule.Flip(diodeModule.GetPosition())

            if rotateModules == True:

                rotationReference = wxPoint(
                    self.referenceCoordinate.x +
                    (self.keyDistance * key["rotation_x"]),
                    self.referenceCoordinate.y +
                    (self.keyDistance * key["rotation_y"]))

                angle = key["rotation_angle"] * -10

                if useNorthFacingSwitches == True:
                    keyModule.SetOrientationDegrees(0)
                else:
                    keyModule.SetOrientationDegrees(180)
                keyModule.Rotate(rotationReference, angle)
                self.logger.info('Rotated key module to {}'.format(angle))

                diodeModule.SetOrientationDegrees(relativeDiodeRotation)
                diodeModule.Rotate(rotationReference, angle)
                self.logger.info('Rotated diode module to {}'.format(angle))

            if routeTracks == True:
                self.RouteKeyWithDiode(keyModule, diodeModule)
                self.RouteColumn(keyModule)
예제 #20
0
 def GetRelativeDiodePosition(self):
     return wx.RealPoint(self.diodePositionX.GetValue(),
                         self.diodePositionY.GetValue())
예제 #21
0
import wx


def onButton(event):
    print("Button Pressed.")


app = wx.App()
frame = wx.Frame(None, -1, title="Hello World", size=(450, 200), pos=(50, 50))
#frame = wx.Frame(None, -1,title="Hello World")
#frame.SetSize(0,0,500,150)

panel = wx.Panel(frame, -1)
#panel = wx.Panel(frame, wx.ID_ANY)

rp = wx.RealPoint(170, 50)
p = wx.Point(int(round(rp.x)), int(round(rp.y)))

button = wx.Button(panel, -1, 'Test', pos=p)
button.Bind(wx.EVT_BUTTON, onButton)

frame.Show()
#frame.Centre()
app.MainLoop()