Пример #1
0
def test_correct_overload_selection():
    """Test correct overloading selection for common types."""
    from System import (String, Double, Single,
                        Int16, Int32, Int64)
    from System import Math

    substr = String("substring")
    assert substr.Substring(2) == substr.Substring.__overloads__[Int32](
        Int32(2))
    assert substr.Substring(2, 3) == substr.Substring.__overloads__[Int32, Int32](
        Int32(2), Int32(3))

    for atype, value1, value2 in zip([Double, Single, Int16, Int32, Int64],
                                     [1.0, 1.0, 1, 1, 1],
                                     [2.0, 0.5, 2, 0, -1]):
        assert Math.Abs(atype(value1)) == Math.Abs.__overloads__[atype](atype(value1))
        assert Math.Abs(value1) == Math.Abs.__overloads__[atype](atype(value1))
        assert Math.Max(atype(value1),
                        atype(value2)) == Math.Max.__overloads__[atype, atype](
            atype(value1), atype(value2))
        assert Math.Max(atype(value1),
                        value2) == Math.Max.__overloads__[atype, atype](
            atype(value1), atype(value2))

    clr.AddReference("System.Runtime.InteropServices")
    from System.Runtime.InteropServices import GCHandle, GCHandleType
    from System import Array, Byte
    cs_array = Array.CreateInstance(Byte, 1000)
    handler = GCHandle.Alloc(cs_array, GCHandleType.Pinned)
Пример #2
0
def onTick(timer, e):
	global ts

	ts = ts.Add(timer.Interval)
	entry = Entry()
	
	if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")):
		entry.Title = String.Format("予定の{0}分前になりました", Math.Abs(ts.Minutes).ToString())
	else:
		if Math.Abs(ts.Minutes) == 1:
			entry.Title = String.Format("{0} minute remaining", Math.Abs(ts.Minutes).ToString())
		else:
			entry.Title = String.Format("{0} minutes remaining", Math.Abs(ts.Minutes).ToString())

	if ts.TotalMilliseconds >= 0:
		timer.Stop()
		ts = TimeSpan.Zero

		if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")):
			entry.Title = "予定の時間になりました"
		else:
			entry.Title= "Time expired"

	entryList = List[Entry]()
	entryList.Add(entry)
	Script.Instance.Alert(entryList)
Пример #3
0
    def area_MouseMove(self, sender, e):
        if self.StartPoint is not None:
            currentPoint = e.GetPosition(self.Content.FractalArea)

            if currentPoint.X < 0: currentPoint.X = 0
            if currentPoint.Y < 0: currentPoint.Y = 0
            if currentPoint.X > self.Content.FractalArea.Width:
                currentPoint.X = self.Content.FractalArea.Width
            if currentPoint.Y > self.Content.FractalArea.Height:
                currentPoint.Y = self.Content.FractalArea.Height

            self.Content.selection.Width = Math.Abs(currentPoint.X -
                                                    self.StartPoint.X)
            self.Content.selection.Height = self.Content.selection.Width / (
                self.Content.FractalArea.Width /
                self.Content.FractalArea.Height)

            if currentPoint.X > self.StartPoint.X:
                canvasLeft = self.StartPoint.X
            else:
                canvasLeft = currentPoint.X

            if currentPoint.Y > self.StartPoint.Y:
                canvasTop = self.StartPoint.Y
            else:
                canvasTop = currentPoint.Y

            Canvas.SetLeft(self.Content.selection, canvasLeft)
            Canvas.SetTop(self.Content.selection, canvasTop)
Пример #4
0
    def testCorrectOverloadSelection(self):
        """
        Test correct overloading selection for common types.
        """
        from System.Drawing import Font

        from System import (String, Double, Single, Int16, Int32, Int64)
        from System import Math

        substr = String("substring")
        self.assertTrue(
            substr.Substring(2) == substr.Substring.__overloads__[Int32](Int32(
                2)))
        self.assertTrue(
            substr.Substring(2, 3) == substr.Substring.__overloads__[
                Int32, Int32](Int32(2), Int32(3)))

        for atype, value1, value2 in zip([Double, Single, Int16, Int32, Int64],
                                         [1.0, 1.0, 1, 1, 1],
                                         [2.0, 0.5, 2, 0, -1]):
            self.assertTrue(
                Math.Abs(atype(value1)) == Math.Abs.__overloads__[atype](atype(
                    value1)))
            self.assertTrue(
                Math.Abs(value1) == Math.Abs.__overloads__[atype](atype(
                    value1)))
            self.assertTrue(
                Math.Max(atype(value1), atype(value2)) ==
                Math.Max.__overloads__[atype,
                                       atype](atype(value1), atype(value2)))
            if (atype is Int64) and six.PY2:
                value2 = long(value2)
            self.assertTrue(
                Math.Max(atype(value1), value2) == Math.Max.__overloads__[
                    atype, atype](atype(value1), atype(value2)))

        clr.AddReference("System.Runtime.InteropServices")
        from System.Runtime.InteropServices import GCHandle, GCHandleType
        from System import Array, Byte
        CSArray = Array.CreateInstance(Byte, 1000)
        handler = GCHandle.Alloc(CSArray, GCHandleType.Pinned)