예제 #1
0
파일: Timer.py 프로젝트: soracoder/Apricot
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)
예제 #2
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)
예제 #3
0
 def OnMouseMove(self, sender, e):
     if self.mouse_down and self.snip_enabled:
         x1 = Math.Min(e.X, self.mouse_down.X)
         y1 = Math.Min(e.Y, self.mouse_down.Y)
         x2 = Math.Max(e.X, self.mouse_down.X)
         y2 = Math.Max(e.Y, self.mouse_down.Y)
         self.snip_rectangle = Rectangle(x1, y1, x2 - x1, y2 - y1)
         self.Invalidate()
예제 #4
0
	def get_geometys(element):
		if element.get_Geometry(geo_options):
			for geometry_inst in element.get_Geometry(geo_options):
				if geometry_inst.GetType() == Autodesk.Revit.DB.GeometryInstance:
					for geometry in geometry_inst.SymbolGeometry:
						if geometry.GetType() == Autodesk.Revit.DB.Solid and Math.Round(geometry.Volume,3) != 0:
							return geometry
				else:
					if geometry_inst.GetType() == Autodesk.Revit.DB.Solid and Math.Round(geometry_inst.Volume,3) != 0:
						return geometry_inst
예제 #5
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)
예제 #6
0
def onMouseLeftButtonUp(s, e):
	global y, storyboard

	if y is not None:
		if y > s.Top and storyboard is None:
			storyboard = Storyboard()
			da = DoubleAnimation(s.Top, y, TimeSpan.FromSeconds(Math.Sqrt(2 * ((y - s.Top) * 0.1) / 9.80665)))
			bounceEase = BounceEase()

			bounceEase.EasingMode = EasingMode.EaseOut
			bounceEase.Bounces = 5
			da.EasingFunction = bounceEase

			def onCurrentStateInvalidated(sender, args):
				global storyboard

				if sender.CurrentState == ClockState.Filling:
					s.Top = da.To
					storyboard.Remove(s)
					storyboard = None

			storyboard.CurrentStateInvalidated += onCurrentStateInvalidated
			storyboard.Children.Add(da)

			Storyboard.SetTargetProperty(da, PropertyPath(Window.TopProperty))
			s.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, True)

		y = None
예제 #7
0
def colorFromAhsb(a, h, s, b):
	if 0 > a or 255 < a:
		return Colors.Transparent

	if 0 > h or 360 < h:
		return Colors.Transparent

	if 0 > s or 1 < s:
		return Colors.Transparent

	if 0 > b or 1 < b:
		return Colors.Transparent;

	if 0 == s:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(b * Byte.MaxValue), Convert.ToByte(b * Byte.MaxValue), Convert.ToByte(b * Byte.MaxValue))
		
	fMax = b - (b * s) + s if 0.5 < b else b + (b * s)
	fMin = b + (b * s) - s if 0.5 < b else b - (b * s)
	iSextant = Convert.ToInt32(Math.Floor(h / 60.0))

	if 300 <= h:
		h -= 360

	h = h / 60.0
	h -= 2 * Convert.ToSingle(Math.Floor(((iSextant + 1) % 6.0) / 2))

	fMid = h * (fMax - fMin) + fMin if 0 == iSextant % 2 else fMin - h * (fMax - fMin)
	iMax = Convert.ToInt32(fMax * Byte.MaxValue)
	iMid = Convert.ToInt32(fMid * Byte.MaxValue)
	iMin = Convert.ToInt32(fMin * Byte.MaxValue)
	
	if iSextant == 1:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMid), Convert.ToByte(iMax), Convert.ToByte(iMin))

	elif iSextant == 2:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMin), Convert.ToByte(iMax), Convert.ToByte(iMid))

	elif iSextant == 3:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMin), Convert.ToByte(iMid), Convert.ToByte(iMax))

	elif iSextant == 4:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMid), Convert.ToByte(iMin), Convert.ToByte(iMax))

	elif iSextant == 5:
		return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMax), Convert.ToByte(iMin), Convert.ToByte(iMid))

	return Color.FromArgb(Convert.ToByte(a), Convert.ToByte(iMax), Convert.ToByte(iMid), Convert.ToByte(iMin))
예제 #8
0
    def CanPerform(self, event, universe):
        if (self._task.Type == TaskType.IMAGING):
            value = self._task.Target.Value
            pixels = self._lowQualityPixels
            timetocapture = self._lowQualityTime
            if (value <= self._highQualityTime
                    and value >= self._midQualityTime):
                pixels = self._midQualityPixels
                timetocapture = self._midQualityTime
            if (value > self._highQualityTime):
                pixels = self._highQualityPixels
                timetocapture = self._highQualityTime

            es = event.GetEventStart(self.Asset)
            ts = event.GetTaskStart(self.Asset)
            te = event.GetTaskEnd(self.Asset)
            if (ts > te):
                # Logger.Report("EOSensor lost access")
                return False
            te = ts + timetocapture
            event.SetTaskEnd(self.Asset, te)

            position = self.Asset.AssetDynamicState
            timage = ts + timetocapture / 2
            m_SC_pos_at_tf_ECI = position.PositionECI(timage)
            m_target_pos_at_tf_ECI = self._task.Target.DynamicState.PositionECI(
                timage)
            m_pv = m_target_pos_at_tf_ECI - m_SC_pos_at_tf_ECI
            pos_norm = -m_SC_pos_at_tf_ECI / Matrix[System.Double].Norm(
                -m_SC_pos_at_tf_ECI)
            pv_norm = m_pv / Matrix[System.Double].Norm(m_pv)

            incidenceang = 90 - 180 / Math.PI * Math.Acos(
                Matrix[System.Double].Dot(pos_norm, pv_norm))
            self._newState.AddValue(
                self.INCIDENCE_KEY, KeyValuePair[System.Double,
                                                 System.Double](timage,
                                                                incidenceang))
            self._newState.AddValue(
                self.INCIDENCE_KEY,
                KeyValuePair[System.Double, System.Double](timage + 1, 0.0))

            self._newState.AddValue(
                self.PIXELS_KEY, KeyValuePair[System.Double,
                                              System.Double](timage, pixels))
            self._newState.AddValue(
                self.PIXELS_KEY, KeyValuePair[System.Double,
                                              System.Double](timage + 1, 0.0))

            self._newState.AddValue(
                self.EOON_KEY, KeyValuePair[System.Double,
                                            System.Boolean](ts, True))
            self._newState.AddValue(
                self.EOON_KEY, KeyValuePair[System.Double,
                                            System.Boolean](te, False))
            return True
예제 #9
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)
예제 #10
0
    def on_mouse_wheel(self, sender, event):
        delta = 0
        e = event.EventObject
        if e.GetProperty("detail"):
            delta = e.GetProperty("detail")
        elif e.GetProperty("wheelDelta"):
            delta = -e.GetProperty("wheelDelta")
        delta = Math.Sign(delta) * 40

        try:
            for scroller in self.scrollers:
                if self.mouse_over(scroller):
                    e.SetProperty('cancel', True)
                    e.SetProperty('cancelBubble', True)
                    e.SetProperty('returnValue', False)
                    if e.GetProperty('preventDefault'):
                        e.Invoke('preventDefault')
                    elif e.GetProperty('stopPropagation'):
                        e.Invoke('stopPropagation')
                    scroller.ScrollToVerticalOffset(scroller.VerticalOffset +
                                                    delta)
                    return
        except Exception, e:
            _debug('Error in mouse wheel handler', e)
예제 #11
0
파일: Clock.py 프로젝트: soracoder/Apricot
            def onLoaded(sender, args):
                global rectList, digits

                storyboard = Storyboard()

                def onCurrentStateInvalidated(sender, args):
                    if sender.CurrentState == ClockState.Filling:
                        for element in grid1.Children:
                            element.Opacity = 1

                        storyboard.Remove(contentControl)

                        if not grid1.Tag:
                            closeTimer.Start()

                storyboard.CurrentStateInvalidated += onCurrentStateInvalidated

                r = Random(Environment.TickCount)
                dateTime = DateTime.Now

                digits[0] = dateTime.Hour / 10
                digits[1] = dateTime.Hour % 10
                digits[2] = dateTime.Minute / 10
                digits[3] = dateTime.Minute % 10
                digits[4] = dateTime.Second / 10
                digits[5] = dateTime.Second % 10

                for i in range(digits.Length):
                    beginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(
                        r.Next(500)))

                    for element1 in grid1.Children:
                        if Grid.GetColumn(element1) == i:
                            doubleAnimation = DoubleAnimation(
                                element1.Opacity, 1,
                                TimeSpan.FromMilliseconds(500))
                            doubleAnimation.BeginTime = beginTime
                            sineEase = SineEase()

                            sineEase.EasingMode = EasingMode.EaseOut
                            doubleAnimation.EasingFunction = sineEase

                            storyboard.Children.Add(doubleAnimation)

                            Storyboard.SetTarget(doubleAnimation, element1)
                            Storyboard.SetTargetProperty(
                                doubleAnimation,
                                PropertyPath(UIElement.OpacityProperty))

                            if Grid.GetRow(element1) == 0:
                                scale1 = Math.Max(
                                    element1.ActualWidth / maxWidth,
                                    element1.ActualHeight / maxHeight)

                                if rectList[digits[Grid.GetColumn(
                                        element1
                                )]].Width > maxWidth and rectList[digits[
                                        Grid.GetColumn(
                                            element1)]].Height > maxHeight:
                                    translateX = Math.Round(
                                        -(rectList[digits[Grid.GetColumn(
                                            element1)]].X +
                                          (rectList[digits[Grid.GetColumn(
                                              element1)]].Width - maxWidth) /
                                          2.0))
                                    translateY = Math.Round(
                                        -(rectList[digits[Grid.GetColumn(
                                            element1)]].Y +
                                          (rectList[digits[Grid.GetColumn(
                                              element1)]].Height - maxHeight) /
                                          2.0))

                                elif rectList[digits[Grid.GetColumn(
                                        element1)]].Width > maxWidth:
                                    translateX = Math.Round(
                                        -(rectList[digits[Grid.GetColumn(
                                            element1)]].X +
                                          (rectList[digits[Grid.GetColumn(
                                              element1)]].Width - maxWidth) /
                                          2.0))
                                    translateY = Math.Round(-rectList[digits[
                                        Grid.GetColumn(element1)]].Y)

                                elif rectList[digits[Grid.GetColumn(
                                        element1)]].Height > maxHeight:
                                    translateX = Math.Round(-rectList[digits[
                                        Grid.GetColumn(element1)]].X)
                                    translateY = Math.Round(
                                        -(rectList[digits[Grid.GetColumn(
                                            element1)]].Y +
                                          (rectList[digits[Grid.GetColumn(
                                              element1)]].Height - maxHeight) /
                                          2.0))

                                else:
                                    translateX = Math.Round(-rectList[digits[
                                        Grid.GetColumn(element1)]].X)
                                    translateY = Math.Round(-rectList[digits[
                                        Grid.GetColumn(element1)]].Y)

                                scale2 = Math.Max(
                                    maxWidth / rectList[digits[Grid.GetColumn(
                                        element1)]].Width,
                                    maxHeight / rectList[digits[Grid.GetColumn(
                                        element1)]].Height)

                                if scale2 > 1:
                                    scale2 = 1

                                for element2 in element1.Child.Children:
                                    transformGroup1 = TransformGroup()
                                    transformGroup1.Children.Add(
                                        TranslateTransform(
                                            (element2.ActualWidth - maxWidth) /
                                            2,
                                            (element2.ActualHeight - maxHeight)
                                            / 2))
                                    transformGroup1.Children.Add(
                                        ScaleTransform(
                                            scale1, scale1,
                                            element2.ActualWidth / 2,
                                            element2.ActualHeight / 2))

                                    element2.RenderTransform = transformGroup1

                                    for element3 in element2.Children:
                                        transformGroup2 = TransformGroup()
                                        transformGroup2.Children.Add(
                                            TranslateTransform(
                                                translateX, translateY))
                                        transformGroup2.Children.Add(
                                            ScaleTransform(
                                                scale2, scale2, maxWidth / 2,
                                                maxHeight / 2))

                                        element3.RenderTransform = transformGroup2

                contentControl.BeginStoryboard(
                    storyboard, HandoffBehavior.SnapshotAndReplace, True)

                tickTimer.Start()
예제 #12
0
 def onLoaded(sender, args):
     stackPanel3.Width = Math.Ceiling(stackPanel3.ActualWidth)
예제 #13
0
    def CanPerform(self, event, universe):
        if (self._task.Type == TaskType.IMAGING):
            #large timestep so we have low enough torques
            # or prep for comms but very involved process

            #change weight for comms targets so that downlink > IMAGING

            timetocapture = 30
            # timetocapture = self._readtime		# this value is determined purely by size of ssdr
            es = event.GetEventStart(self.Asset)
            ts = event.GetTaskStart(self.Asset)
            te = event.GetTaskEnd(self.Asset)
            # datagen = self.datasize

            if (ts > te):
                # Logger.Report("EOSensor lost access")
                return False
            te = ts + timetocapture
            event.SetTaskEnd(self.Asset, te)

            position = self.Asset.AssetDynamicState
            timage = ts + timetocapture / 2
            m_SC_pos_at_tf_ECI = position.PositionECI(timage)
            # m_target_pos_at_tf_ECI = self._task.Target.DynamicState.PositionECI(timage)
            m_pv = -m_SC_pos_at_tf_ECI  # purely azimuth
            pos_norm = -m_SC_pos_at_tf_ECI / Matrix[System.Double].Norm(
                -m_SC_pos_at_tf_ECI)
            pv_norm = m_pv / Matrix[System.Double].Norm(m_pv)
            antincidenceang = Matrix[System.Double](4, 1)
            antincidenceang[1, 1] = 90 - 180 / Math.PI * Math.Acos(
                Matrix[System.Double].Dot(pos_norm, pv_norm))  #X
            antincidenceang[2, 1] = 90 - 180 / Math.PI * Math.Acos(
                Matrix[System.Double].Dot(pos_norm, pv_norm))  #Y
            antincidenceang[3, 1] = 90 - 180 / Math.PI * Math.Acos(
                Matrix[System.Double].Dot(pos_norm, pv_norm))  #Z
            antincidenceang[4, 1] = 90 - 180 / Math.PI * Math.Acos(
                Matrix[System.Double].Dot(pos_norm, pv_norm))  #quat
            #change to vector for rpy values
            E = 2.070 * Math.Pow(10, 11)
            density = 7860
            L = 3
            arc = 1
            r2 = .019127
            r1 = .01900
            I = (arc - Math.Sin(arc)) * (Math.Pow(r2, 4) - Math.Pow(r1, 4)) / 8
            area = (Math.Pow(r2, 2) - Math.Pow(r1, 2)) * (Math.PI)
            volume = area * L
            deltaangle = Math.Acos(Matrix[System.Double].Dot(
                position.PositionECI(te), position.PositionECI(ts))) / (
                    Matrix[System.Double].Norm(position.PositionECI(te)) *
                    Matrix[System.Double].Norm(position.PositionECI(ts)))
            a = deltaangle / (Math.Pow(te - ts, 2))
            M = density * volume
            force = a * M
            finaldeflection = force * Math.Pow(L / 2, 2) * ((5 * (L / 2)) /
                                                            (6 * E * I))
            antstress = (M * L / 2) / I

            #yield stress check for antstress

            self._newState.AddValue(
                self.Antenna_Incidence,
                KeyValuePair[System.Double,
                             Matrix[System.Double]](timage, antincidenceang))
            self._newState.AddValue(
                self.Antenna_Stress,
                KeyValuePair[System.Double, System.Double](timage, antstress))
            #	Set up in init the hsfsystem
            #self._newState.addValue(self.ANT_INCIDENCE_KEY, KeyValuePair[System.Double, System.Double](timage + 1, 0.0))

            #self._newState.addValue(self.ANT_DISPLACEMENT_KEY, KeyValuePair[System.Double, System.Double](timage, finaldeflection))

            #self._newState.addValue(self.ANT_DATA_KEY, KeyValuePair[System.Double, System.Double](timage, data))
            #self._newState.addValue(self.ANT_DATA_KEY, KeyValuePair[System.Double, System.Double](timage + 1, 0.0))

            # self._newState.addValue(self.ANTON_KEY, KeyValuePair[System.Double, System.Boolean](ts, True))
            #self._newState.addValue(self.ANTON_KEY, KeyValuePair[System.Double, System.Boolean](te, False))
            return True
예제 #14
0
파일: Gmail.py 프로젝트: soracoder/Apricot
def onOpened(s, e):
    global menuItem

    menuItem.Items.Clear()

    def onSignInClick(source, rea):
        config = None
        directory = Path.Combine(
            Environment.GetFolderPath(
                Environment.SpecialFolder.ApplicationData),
            Assembly.GetEntryAssembly().GetName().Name)
        backgroundBrush = None
        textColor = SystemColors.ControlTextBrush

        if Directory.Exists(directory):
            fileName1 = Path.GetFileName(Assembly.GetEntryAssembly().Location)

            for fileName2 in Directory.EnumerateFiles(directory, "*.config"):
                if fileName1.Equals(
                        Path.GetFileNameWithoutExtension(fileName2)):
                    exeConfigurationFileMap = ExeConfigurationFileMap()
                    exeConfigurationFileMap.ExeConfigFilename = fileName2
                    config = ConfigurationManager.OpenMappedExeConfiguration(
                        exeConfigurationFileMap, ConfigurationUserLevel.None)

        if config is None:
            config = ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None)
            directory = None

        if config.AppSettings.Settings["BackgroundImage"] is not None:
            fileName = config.AppSettings.Settings[
                "BackgroundImage"].Value if directory is None else Path.Combine(
                    directory,
                    config.AppSettings.Settings["BackgroundImage"].Value)
            fs = None
            bi = BitmapImage()

            try:
                fs = FileStream(fileName, FileMode.Open, FileAccess.Read,
                                FileShare.Read)

                bi.BeginInit()
                bi.StreamSource = fs
                bi.CacheOption = BitmapCacheOption.OnLoad
                bi.CreateOptions = BitmapCreateOptions.None
                bi.EndInit()

            finally:
                if fs is not None:
                    fs.Close()

            backgroundBrush = ImageBrush(bi)
            backgroundBrush.TileMode = TileMode.Tile
            backgroundBrush.ViewportUnits = BrushMappingMode.Absolute
            backgroundBrush.Viewport = Rect(0, 0, bi.Width, bi.Height)
            backgroundBrush.Stretch = Stretch.None

            if backgroundBrush.CanFreeze:
                backgroundBrush.Freeze()

        if backgroundBrush is None and config.AppSettings.Settings[
                "BackgroundColor"] is not None:
            if config.AppSettings.Settings["BackgroundColor"].Value.Length > 0:
                backgroundBrush = SolidColorBrush(
                    ColorConverter.ConvertFromString(
                        config.AppSettings.Settings["BackgroundColor"].Value))

                if backgroundBrush.CanFreeze:
                    backgroundBrush.Freeze()

        if config.AppSettings.Settings["TextColor"] is not None:
            if config.AppSettings.Settings["TextColor"].Value.Length > 0:
                textColor = ColorConverter.ConvertFromString(
                    config.AppSettings.Settings["TextColor"].Value)

        textBrush = SolidColorBrush(textColor)

        if textBrush.CanFreeze:
            textBrush.Freeze()

        window = Window()

        def onClick(source, args):
            global username, password

            if not String.IsNullOrEmpty(
                    usernameTextBox.Text) and not String.IsNullOrEmpty(
                        passwordBox.Password):
                username = usernameTextBox.Text
                password = passwordBox.Password

                def onSave():
                    try:
                        fs = None
                        sr = None
                        sw = None

                        try:
                            fs = FileStream(__file__, FileMode.Open,
                                            FileAccess.ReadWrite,
                                            FileShare.Read)
                            encoding = UTF8Encoding(False)
                            sr = StreamReader(fs, encoding, True)
                            lines = Regex.Replace(
                                Regex.Replace(
                                    sr.ReadToEnd(), "username\\s*=\\s*\"\"",
                                    String.Format("username = \"{0}\"",
                                                  username),
                                    RegexOptions.CultureInvariant),
                                "password\\s*=\\s*\"\"",
                                String.Format("password = \"{0}\"", password),
                                RegexOptions.CultureInvariant)
                            fs.SetLength(0)
                            sw = StreamWriter(fs, encoding)
                            sw.Write(lines)

                        finally:
                            if sw is not None:
                                sw.Close()

                            if sr is not None:
                                sr.Close()

                            if fs is not None:
                                fs.Close()

                    except Exception, e:
                        Trace.WriteLine(e.clsException.Message)
                        Trace.WriteLine(e.clsException.StackTrace)

                def onCompleted(task):
                    global menuItem

                    for window in Application.Current.Windows:
                        if window is Application.Current.MainWindow and window.ContextMenu is not None:
                            if window.ContextMenu.Items.Contains(menuItem):
                                window.ContextMenu.Items.Remove(menuItem)
                                window.ContextMenu.Opened -= onOpened

                                if window.ContextMenu.Items[10].GetType(
                                ).IsInstanceOfType(window.ContextMenu.Items[
                                        window.ContextMenu.Items.Count - 4]):
                                    window.ContextMenu.Items.RemoveAt(10)

                    menuItem = None

                Task.Factory.StartNew(
                    onSave, TaskCreationOptions.LongRunning).ContinueWith(
                        onCompleted,
                        TaskScheduler.FromCurrentSynchronizationContext())

            window.Close()

        window.Owner = Application.Current.MainWindow
        window.Title = Application.Current.MainWindow.Title
        window.WindowStartupLocation = WindowStartupLocation.CenterScreen
        window.ResizeMode = ResizeMode.NoResize
        window.SizeToContent = SizeToContent.WidthAndHeight
        window.Background = SystemColors.ControlBrush

        stackPanel1 = StackPanel()
        stackPanel1.UseLayoutRounding = True
        stackPanel1.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel1.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel1.Orientation = Orientation.Vertical

        window.Content = stackPanel1

        stackPanel2 = StackPanel()
        stackPanel2.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel2.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel2.Orientation = Orientation.Vertical
        stackPanel2.Background = SystemColors.ControlBrush if backgroundBrush is None else backgroundBrush

        stackPanel1.Children.Add(stackPanel2)

        gradientStopCollection = GradientStopCollection()
        gradientStopCollection.Add(GradientStop(Color.FromArgb(0, 0, 0, 0), 0))
        gradientStopCollection.Add(
            GradientStop(Color.FromArgb(Byte.MaxValue, 0, 0, 0), 1))

        linearGradientBrush = LinearGradientBrush(gradientStopCollection,
                                                  Point(0.5, 0), Point(0.5, 1))
        linearGradientBrush.Opacity = 0.1

        if linearGradientBrush.CanFreeze:
            linearGradientBrush.Freeze()

        stackPanel3 = StackPanel()
        stackPanel3.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel3.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel3.Orientation = Orientation.Vertical
        stackPanel3.Background = linearGradientBrush

        stackPanel2.Children.Add(stackPanel3)

        solidColorBrush1 = SolidColorBrush(Colors.Black)
        solidColorBrush1.Opacity = 0.25

        if solidColorBrush1.CanFreeze:
            solidColorBrush1.Freeze()

        border1 = Border()
        border1.HorizontalAlignment = HorizontalAlignment.Stretch
        border1.VerticalAlignment = VerticalAlignment.Stretch
        border1.BorderThickness = Thickness(0, 0, 0, 1)
        border1.BorderBrush = solidColorBrush1

        stackPanel3.Children.Add(border1)

        stackPanel4 = StackPanel()
        stackPanel4.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel4.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel4.Orientation = Orientation.Vertical
        stackPanel4.Margin = Thickness(10, 10, 10, 20)

        border1.Child = stackPanel4

        stackPanel5 = StackPanel()
        stackPanel5.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel5.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel5.Orientation = Orientation.Vertical

        dropShadowEffect1 = DropShadowEffect()
        dropShadowEffect1.BlurRadius = 1
        dropShadowEffect1.Color = Colors.Black if Math.Max(
            Math.Max(textColor.R, textColor.G),
            textColor.B) > Byte.MaxValue / 2 else Colors.White
        dropShadowEffect1.Direction = 270
        dropShadowEffect1.Opacity = 0.5
        dropShadowEffect1.ShadowDepth = 1

        if dropShadowEffect1.CanFreeze:
            dropShadowEffect1.Freeze()

        stackPanel5.Effect = dropShadowEffect1

        stackPanel4.Children.Add(stackPanel5)

        usernameLabel = Label()
        usernameLabel.Foreground = textBrush

        if CultureInfo.CurrentCulture.Equals(
                CultureInfo.GetCultureInfo("ja-JP")):
            usernameLabel.Content = "ユーザ名"
        else:
            usernameLabel.Content = "Username"

        RenderOptions.SetClearTypeHint(usernameLabel, ClearTypeHint.Enabled)

        stackPanel5.Children.Add(usernameLabel)

        usernameTextBox = TextBox()
        usernameTextBox.Width = 240

        stackPanel4.Children.Add(usernameTextBox)

        dropShadowEffect2 = DropShadowEffect()
        dropShadowEffect2.BlurRadius = 1
        dropShadowEffect2.Color = Colors.Black if Math.Max(
            Math.Max(textColor.R, textColor.G),
            textColor.B) > Byte.MaxValue / 2 else Colors.White
        dropShadowEffect2.Direction = 270
        dropShadowEffect2.Opacity = 0.5
        dropShadowEffect2.ShadowDepth = 1

        if dropShadowEffect2.CanFreeze:
            dropShadowEffect2.Freeze()

        stackPanel6 = StackPanel()
        stackPanel6.HorizontalAlignment = HorizontalAlignment.Stretch
        stackPanel6.VerticalAlignment = VerticalAlignment.Stretch
        stackPanel6.Orientation = Orientation.Vertical
        stackPanel6.Effect = dropShadowEffect2

        stackPanel4.Children.Add(stackPanel6)

        passwordLabel = Label()
        passwordLabel.Foreground = textBrush

        if CultureInfo.CurrentCulture.Equals(
                CultureInfo.GetCultureInfo("ja-JP")):
            passwordLabel.Content = "パスワード"
        else:
            passwordLabel.Content = "Password"

        RenderOptions.SetClearTypeHint(passwordLabel, ClearTypeHint.Enabled)

        stackPanel6.Children.Add(passwordLabel)

        passwordBox = PasswordBox()
        passwordBox.Width = 240

        stackPanel4.Children.Add(passwordBox)

        solidColorBrush2 = SolidColorBrush(Colors.White)
        solidColorBrush2.Opacity = 0.5

        if solidColorBrush2.CanFreeze:
            solidColorBrush2.Freeze()

        border2 = Border()
        border2.HorizontalAlignment = HorizontalAlignment.Stretch
        border2.VerticalAlignment = VerticalAlignment.Stretch
        border2.BorderThickness = Thickness(0, 1, 0, 0)
        border2.BorderBrush = solidColorBrush2

        stackPanel1.Children.Add(border2)

        signInButton = Button()
        signInButton.HorizontalAlignment = HorizontalAlignment.Right
        signInButton.VerticalAlignment = VerticalAlignment.Center
        signInButton.Margin = Thickness(10, 10, 10, 10)
        signInButton.Padding = Thickness(10, 2, 10, 2)
        signInButton.IsDefault = True

        if CultureInfo.CurrentCulture.Equals(
                CultureInfo.GetCultureInfo("ja-JP")):
            signInButton.Content = "サインイン"
        else:
            signInButton.Content = "Sign in"

        signInButton.Click += onClick

        border2.Child = signInButton

        usernameTextBox.Focus()
        window.Show()
예제 #15
0
 def background_import(self):
     if 'System' in sys.modules: sys.modules.pop('System')
     from System import Math
     return Math.Floor(4.4)
예제 #16
0
def attachStackPanel(stackPanel, brush, text):
    stackPanel1 = StackPanel()
    stackPanel1.HorizontalAlignment = HorizontalAlignment.Stretch
    stackPanel1.VerticalAlignment = VerticalAlignment.Stretch
    stackPanel1.Orientation = Orientation.Vertical
    stackPanel1.Background = brush

    stackPanel.Children.Add(stackPanel1)

    gradientStopCollection = GradientStopCollection()
    gradientStopCollection.Add(GradientStop(Color.FromArgb(0, 0, 0, 0), 0))
    gradientStopCollection.Add(
        GradientStop(Color.FromArgb(Byte.MaxValue, 0, 0, 0), 1))

    linearGradientBrush = LinearGradientBrush(gradientStopCollection,
                                              Point(0.5, 0), Point(0.5, 1))
    linearGradientBrush.Opacity = 0.1

    if linearGradientBrush.CanFreeze:
        linearGradientBrush.Freeze()

    stackPanel2 = StackPanel()
    stackPanel2.HorizontalAlignment = HorizontalAlignment.Stretch
    stackPanel2.VerticalAlignment = VerticalAlignment.Stretch
    stackPanel2.Orientation = Orientation.Vertical
    stackPanel2.Background = linearGradientBrush

    stackPanel1.Children.Add(stackPanel2)

    solidColorBrush1 = SolidColorBrush(Colors.White)
    solidColorBrush1.Opacity = 0.5

    if solidColorBrush1.CanFreeze:
        solidColorBrush1.Freeze()

    border1 = Border()
    border1.HorizontalAlignment = HorizontalAlignment.Stretch
    border1.VerticalAlignment = VerticalAlignment.Stretch
    border1.Padding = Thickness(0)
    border1.BorderThickness = Thickness(0, 1, 0, 0)
    border1.BorderBrush = solidColorBrush1

    solidColorBrush2 = SolidColorBrush(Colors.Black)
    solidColorBrush2.Opacity = 0.25

    if solidColorBrush2.CanFreeze:
        solidColorBrush2.Freeze()

    stackPanel2.Children.Add(border1)

    border2 = Border()
    border2.HorizontalAlignment = HorizontalAlignment.Stretch
    border2.VerticalAlignment = VerticalAlignment.Stretch
    border2.Padding = Thickness(10, 5, 10, 5)
    border2.BorderThickness = Thickness(0, 0, 0, 1)
    border2.BorderBrush = solidColorBrush2

    border1.Child = border2

    dropShadowEffect = DropShadowEffect()
    dropShadowEffect.BlurRadius = 1
    dropShadowEffect.Color = Colors.Black if Math.Max(
        Math.Max(SystemColors.ControlTextColor.R,
                 SystemColors.ControlTextColor.G),
        SystemColors.ControlTextColor.B) > Byte.MaxValue / 2 else Colors.White
    dropShadowEffect.Direction = 270
    dropShadowEffect.Opacity = 0.5
    dropShadowEffect.ShadowDepth = 1

    if dropShadowEffect.CanFreeze:
        dropShadowEffect.Freeze()

    border3 = Border()
    border3.HorizontalAlignment = HorizontalAlignment.Stretch
    border3.VerticalAlignment = VerticalAlignment.Stretch
    border3.Padding = Thickness(0)
    border3.Effect = dropShadowEffect

    border2.Child = border3

    label = Label()
    label.Foreground = SystemColors.ControlTextBrush
    label.Content = text

    RenderOptions.SetClearTypeHint(label, ClearTypeHint.Enabled)

    border3.Child = label
예제 #17
0
	def onCompleted(task):
		global idList

		if task.Result.Key.Count > 0:
			sequenceList = List[Sequence]()

			for sequence in Script.Instance.Sequences:
				if sequence.Name.Equals("Weather"):
					sequenceList.Add(sequence)

			for s in task.Result.Key:
				Script.Instance.TryEnqueue(Script.Instance.Prepare(sequenceList, s))

		if Application.Current.MainWindow.IsVisible and task.Result.Value.Value.Value.Value.Count > 0 and not Enumerable.SequenceEqual[Double](idList, task.Result.Value.Value.Value.Key):
			width = 128
			height = 128
			max = 4
			window = Window()
			contentControl = ContentControl()
			grid = Grid()
			storyboard = Storyboard()

			def onCurrentStateInvalidated(sender, args):
				if sender.CurrentState == ClockState.Filling:
					window.Close()

			storyboard.CurrentStateInvalidated += onCurrentStateInvalidated
		
			def onLoaded(sender, args):
				time = 0
				speed = task.Result.Value.Value.Key.Key * 1000 / 60 / 60

				contentControl.Width = contentControl.ActualWidth * 1.5 if contentControl.ActualWidth > contentControl.ActualHeight else contentControl.ActualHeight * 1.5 
				contentControl.Height = contentControl.ActualWidth * 1.5 if contentControl.ActualWidth > contentControl.ActualHeight else contentControl.ActualHeight * 1.5
				contentControl.RenderTransform.CenterX = contentControl.Width / 2
				contentControl.RenderTransform.CenterY = contentControl.Height / 2

				doubleAnimation1 = DoubleAnimation(contentControl.Opacity, 1, TimeSpan.FromMilliseconds(500))
				doubleAnimation2 = DoubleAnimation(1.5, 1, TimeSpan.FromMilliseconds(500))
				doubleAnimation3 = DoubleAnimation(1.5, 1, TimeSpan.FromMilliseconds(500))
				doubleAnimation4 = DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(500))
				doubleAnimation5 = DoubleAnimation(1, 1.5, TimeSpan.FromMilliseconds(500))
				doubleAnimation6 = DoubleAnimation(1, 1.5, TimeSpan.FromMilliseconds(500))
				sineEase1 = SineEase()
				sineEase2 = SineEase()

				sineEase1.EasingMode = EasingMode.EaseOut
				sineEase2.EasingMode = EasingMode.EaseIn
				doubleAnimation1.EasingFunction = doubleAnimation2.EasingFunction = doubleAnimation3.EasingFunction = sineEase1
				doubleAnimation4.EasingFunction = doubleAnimation5.EasingFunction = doubleAnimation6.EasingFunction = sineEase2

				doubleAnimation4.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500))
				doubleAnimation5.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500))
				doubleAnimation6.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds((250 * (max - 1) * 2 + 1000 + 3000) * task.Result.Value.Value.Value.Value.Count - 500))

				storyboard.Children.Add(doubleAnimation1)
				storyboard.Children.Add(doubleAnimation2)
				storyboard.Children.Add(doubleAnimation3)
				storyboard.Children.Add(doubleAnimation4)
				storyboard.Children.Add(doubleAnimation5)
				storyboard.Children.Add(doubleAnimation6)

				Storyboard.SetTarget(doubleAnimation1, contentControl)
				Storyboard.SetTarget(doubleAnimation2, contentControl)
				Storyboard.SetTarget(doubleAnimation3, contentControl)
				Storyboard.SetTarget(doubleAnimation4, contentControl)
				Storyboard.SetTarget(doubleAnimation5, contentControl)
				Storyboard.SetTarget(doubleAnimation6, contentControl)
				Storyboard.SetTargetProperty(doubleAnimation1, PropertyPath(ContentControl.OpacityProperty))
				Storyboard.SetTargetProperty(doubleAnimation2, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleXProperty))
				Storyboard.SetTargetProperty(doubleAnimation3, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleYProperty))
				Storyboard.SetTargetProperty(doubleAnimation4, PropertyPath(ContentControl.OpacityProperty))
				Storyboard.SetTargetProperty(doubleAnimation5, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleXProperty))
				Storyboard.SetTargetProperty(doubleAnimation6, PropertyPath("(0).(1)", ContentControl.RenderTransformProperty, ScaleTransform.ScaleYProperty))

				for element1 in grid.Children:
					for element2 in element1.Children:
						w = element2.Width / 2 if speed > 15 else element2.Width / 2 * speed / 15;
						da1 = DoubleAnimation(element2.Opacity, 1, TimeSpan.FromMilliseconds(1000))
						da2 = DoubleAnimation(-w if Convert.ToInt32(task.Result.Value.Value.Key.Value / 180) % 2 == 0 else w, 0, TimeSpan.FromMilliseconds(1000))
						da3 = DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(1000))
						da4 = DoubleAnimation(0, w if Convert.ToInt32(task.Result.Value.Value.Key.Value / 180) % 2 == 0 else -w, TimeSpan.FromMilliseconds(1000))
						se1 = SineEase()
						se2 = SineEase()

						da1.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag))
						da2.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag))
						da3.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag * 2 + 250 * (max - 1) - 250 * element2.Tag + 3000))
						da4.BeginTime = Nullable[TimeSpan](TimeSpan.FromMilliseconds(time + 250 * element2.Tag * 2 + 250 * (max - 1) - 250 * element2.Tag + 3000))

						se1.EasingMode = EasingMode.EaseOut
						se2.EasingMode = EasingMode.EaseIn
						da1.EasingFunction = da2.EasingFunction = se1
						da3.EasingFunction = da4.EasingFunction = se2

						storyboard.Children.Add(da1)
						storyboard.Children.Add(da2)
						storyboard.Children.Add(da3)
						storyboard.Children.Add(da4)

						Storyboard.SetTarget(da1, element2)
						Storyboard.SetTarget(da2, element2)
						Storyboard.SetTarget(da3, element2)
						Storyboard.SetTarget(da4, element2)
						Storyboard.SetTargetProperty(da1, PropertyPath(Rectangle.OpacityProperty))
						Storyboard.SetTargetProperty(da2, PropertyPath("(0).(1)", Rectangle.RenderTransformProperty, TranslateTransform.XProperty))
						Storyboard.SetTargetProperty(da3, PropertyPath(Rectangle.OpacityProperty))
						Storyboard.SetTargetProperty(da4, PropertyPath("(0).(1)", Rectangle.RenderTransformProperty, TranslateTransform.XProperty))

					time += 250 * (max - 1) + 1000 + 3000

				storyboard.Begin()
			
			fs = None
			bi = BitmapImage()

			try:
				fs = FileStream("Assets\\Background-Popup.png", FileMode.Open, FileAccess.Read, FileShare.Read)

				bi.BeginInit()
				bi.StreamSource = fs
				bi.CacheOption = BitmapCacheOption.OnLoad
				bi.CreateOptions = BitmapCreateOptions.None
				bi.EndInit()

			finally:
				if fs is not None:
					fs.Close()

			window.Owner = Application.Current.MainWindow
			window.Title = Application.Current.MainWindow.Title
			window.WindowStartupLocation = WindowStartupLocation.CenterOwner
			window.AllowsTransparency = True
			window.WindowStyle = WindowStyle.None
			window.ResizeMode = ResizeMode.NoResize
			window.ShowActivated = False
			window.ShowInTaskbar = Application.Current.MainWindow.ContextMenu.Items[5].IsChecked
			window.Topmost = True
			window.SizeToContent = SizeToContent.WidthAndHeight
			window.Background = Brushes.Transparent
			window.Loaded += onLoaded
			
			contentControl.UseLayoutRounding = True
			contentControl.HorizontalAlignment = HorizontalAlignment.Stretch
			contentControl.VerticalAlignment = VerticalAlignment.Stretch
			contentControl.Opacity = 0
			contentControl.RenderTransform = ScaleTransform(1, 1)

			window.Content = contentControl

			imageBrush = ImageBrush(bi)
			imageBrush.TileMode = TileMode.None
			imageBrush.Stretch = Stretch.Fill
			imageBrush.ViewboxUnits = BrushMappingMode.Absolute
			imageBrush.Viewbox = Rect(0, 0, bi.Width, bi.Height)
			imageBrush.AlignmentX = AlignmentX.Left
			imageBrush.AlignmentY = AlignmentY.Top
			imageBrush.Opacity = 0.5

			dg = DrawingGroup()
			dc = dg.Open()
			dc.DrawRectangle(SolidColorBrush(Color.FromArgb(Byte.MaxValue * 50 / 100, 0, 0, 0)), None, Rect(0, 0, bi.Width, bi.Height))
			dc.DrawRectangle(imageBrush, None, Rect(0, 0, bi.Width, bi.Height))
			dc.Close()

			backgroundBrush = ImageBrush(DrawingImage(dg))
			backgroundBrush.TileMode = TileMode.Tile
			backgroundBrush.ViewportUnits = BrushMappingMode.Absolute
			backgroundBrush.Viewport = Rect(0, 0, bi.Width, bi.Height)
			backgroundBrush.Stretch = Stretch.None

			if backgroundBrush.CanFreeze:
				backgroundBrush.Freeze()

			grid.HorizontalAlignment = HorizontalAlignment.Stretch
			grid.VerticalAlignment = VerticalAlignment.Stretch
			grid.Background = backgroundBrush
			grid.Width = 150
			grid.Height = 150
			grid.Clip = EllipseGeometry(Rect(0, 0, 150, 150))

			dropShadowEffect = DropShadowEffect()
			dropShadowEffect.BlurRadius = 1
			dropShadowEffect.Color = Colors.Black
			dropShadowEffect.Direction = 270
			dropShadowEffect.Opacity = 0.5
			dropShadowEffect.ShadowDepth = 1

			if dropShadowEffect.CanFreeze:
				dropShadowEffect.Freeze()

			grid.Effect = dropShadowEffect

			contentControl.Content = grid

			solidColorBrush = SolidColorBrush(colorFromAhsb(Byte.MaxValue, 60, 1.0, 1.0) if task.Result.Value.Key < 0 else colorFromAhsb(Byte.MaxValue, 0, 1.0, 0.4) if task.Result.Value.Key > 37 else colorFromAhsb(Byte.MaxValue, 60 - 60 * task.Result.Value.Key / 37, 1.0, 0.4 + 0.6 * Math.Pow(Math.E, (37 / 5 - task.Result.Value.Key) - 37 / 5) if task.Result.Value.Key < 37 / 5 else 0.4))

			if solidColorBrush.CanFreeze:
				solidColorBrush.Freeze()


			for stream in task.Result.Value.Value.Value.Value:
				try:
					bi = BitmapImage()
					bi.BeginInit()
					bi.StreamSource = stream
					bi.CacheOption = BitmapCacheOption.OnLoad
					bi.CreateOptions = BitmapCreateOptions.None
					bi.EndInit()

				finally:
					stream.Close()

				imageBrush = ImageBrush(bi)
				imageBrush.TileMode = TileMode.None
				imageBrush.ViewportUnits = BrushMappingMode.Absolute
				imageBrush.Viewport = Rect(0, 0, width, height)
				imageBrush.Stretch = Stretch.Uniform

				if imageBrush.CanFreeze:
					imageBrush.Freeze()

				g = Grid()
				g.HorizontalAlignment = HorizontalAlignment.Center
				g.VerticalAlignment = VerticalAlignment.Center
				g.Background = Brushes.Transparent
				g.Width = width
				g.Height = height

				grid.Children.Add(g)

				for i in range(max):
					rectangle = Rectangle()
					rectangle.HorizontalAlignment = HorizontalAlignment.Left
					rectangle.VerticalAlignment = VerticalAlignment.Top
					rectangle.Width = width
					rectangle.Height = height
					rectangle.Fill = solidColorBrush
					rectangle.Opacity = 0
					rectangle.OpacityMask = imageBrush
					rectangle.Clip = RectangleGeometry(Rect(0, height / max * i, width, height / max))
					rectangle.RenderTransform = TranslateTransform(0, 0)
					rectangle.Tag = i
					
					g.Children.Add(rectangle)

			window.Show()

			idList.Clear()
			idList.AddRange(task.Result.Value.Value.Value.Key)
예제 #18
0
파일: Clock.py 프로젝트: soracoder/Apricot
            def onTick(sender, args):
                global rectList, digits

                if rectList.Count > 0:
                    dateTime = DateTime.Now

                    for element1 in grid1.Children:
                        if Grid.GetRow(element1) == 0:
                            if Grid.GetColumn(element1) == 0:
                                digit = dateTime.Hour / 10
                            elif Grid.GetColumn(element1) == 1:
                                digit = dateTime.Hour % 10
                            elif Grid.GetColumn(element1) == 2:
                                digit = dateTime.Minute / 10
                            elif Grid.GetColumn(element1) == 3:
                                digit = dateTime.Minute % 10
                            elif Grid.GetColumn(element1) == 4:
                                digit = dateTime.Second / 10
                            else:
                                digit = dateTime.Second % 10

                            if digit != digits[Grid.GetColumn(element1)]:
                                for element2 in element1.Child.Children:
                                    for element3 in element2.Children:
                                        storyboard = Storyboard()

                                        for transform in element3.RenderTransform.Children:
                                            if clr.GetClrType(
                                                    TranslateTransform
                                            ).IsInstanceOfType(transform):
                                                if rectList[
                                                        digit].Width > maxWidth and rectList[
                                                            digit].Height > maxHeight:
                                                    translateX = Math.Round(-(
                                                        rectList[digits[
                                                            Grid.GetColumn(
                                                                element1)]].X +
                                                        (rectList[digit].X +
                                                         (rectList[digit].Width
                                                          - maxWidth) / 2.0 -
                                                         rectList[digits[
                                                             Grid.GetColumn(
                                                                 element1)]].X)
                                                    ))
                                                    translateY = Math.Round(-(
                                                        rectList[digits[
                                                            Grid.GetColumn(
                                                                element1)]].Y +
                                                        (rectList[digit].Y +
                                                         (rectList[digit].
                                                          Height - maxHeight) /
                                                         2.0 - rectList[digits[
                                                             Grid.GetColumn(
                                                                 element1)]].Y)
                                                    ))

                                                elif rectList[
                                                        digit].Width > maxWidth:
                                                    translateX = Math.Round(-(
                                                        rectList[digits[
                                                            Grid.GetColumn(
                                                                element1)]].X +
                                                        (rectList[digit].X +
                                                         (rectList[digit].Width
                                                          - maxWidth) / 2.0 -
                                                         rectList[digits[
                                                             Grid.GetColumn(
                                                                 element1)]].X)
                                                    ))
                                                    translateY = Math.Round(-(
                                                        rectList[digits[
                                                            Grid.GetColumn(
                                                                element1)]].Y +
                                                        (rectList[digit].Y -
                                                         rectList[digits[
                                                             Grid.GetColumn(
                                                                 element1)]].Y)
                                                    ))

                                                elif rectList[
                                                        digit].Height > maxHeight:
                                                    translateX = Math.Round(-(
                                                        rectList[digits[
                                                            Grid.GetColumn(
                                                                element1)]].X +
                                                        (rectList[digit].X -
                                                         rectList[digits[
                                                             Grid.GetColumn(
                                                                 element1)]].X)
                                                    ))
                                                    translateY = Math.Round(-(
                                                        rectList[digits[
                                                            Grid.GetColumn(
                                                                element1)]].Y +
                                                        (rectList[digit].Y +
                                                         (rectList[digit].
                                                          Height - maxHeight) /
                                                         2.0 - rectList[digits[
                                                             Grid.GetColumn(
                                                                 element1)]].Y)
                                                    ))

                                                else:
                                                    translateX = Math.Round(-(
                                                        rectList[digits[
                                                            Grid.GetColumn(
                                                                element1)]].X +
                                                        (rectList[digit].X -
                                                         rectList[digits[
                                                             Grid.GetColumn(
                                                                 element1)]].X)
                                                    ))
                                                    translateY = Math.Round(-(
                                                        rectList[digits[
                                                            Grid.GetColumn(
                                                                element1)]].Y +
                                                        (rectList[digit].Y -
                                                         rectList[digits[
                                                             Grid.GetColumn(
                                                                 element1)]].Y)
                                                    ))

                                                doubleAnimation1 = DoubleAnimation(
                                                    translateX,
                                                    TimeSpan.FromMilliseconds(
                                                        500))
                                                doubleAnimation2 = DoubleAnimation(
                                                    translateY,
                                                    TimeSpan.FromMilliseconds(
                                                        500))
                                                sineEase = SineEase()

                                                sineEase.EasingMode = EasingMode.EaseInOut
                                                doubleAnimation1.EasingFunction = sineEase
                                                doubleAnimation2.EasingFunction = sineEase

                                                storyboard.Children.Add(
                                                    doubleAnimation1)
                                                storyboard.Children.Add(
                                                    doubleAnimation2)

                                                Storyboard.SetTarget(
                                                    doubleAnimation1, element3)
                                                Storyboard.SetTarget(
                                                    doubleAnimation2, element3)
                                                Storyboard.SetTargetProperty(
                                                    doubleAnimation1,
                                                    PropertyPath(
                                                        "(0).(1)[0].(2)",
                                                        Canvas.
                                                        RenderTransformProperty,
                                                        TransformGroup.
                                                        ChildrenProperty,
                                                        TranslateTransform.
                                                        XProperty))
                                                Storyboard.SetTargetProperty(
                                                    doubleAnimation2,
                                                    PropertyPath(
                                                        "(0).(1)[0].(2)",
                                                        Canvas.
                                                        RenderTransformProperty,
                                                        TransformGroup.
                                                        ChildrenProperty,
                                                        TranslateTransform.
                                                        YProperty))

                                            else:
                                                scale1 = Math.Max(
                                                    maxWidth / rectList[digits[
                                                        Grid.GetColumn(
                                                            element1)]].Width,
                                                    maxHeight / rectList[
                                                        digits[Grid.GetColumn(
                                                            element1)]].Height)
                                                scale2 = Math.Max(
                                                    maxWidth /
                                                    rectList[digit].Width,
                                                    maxHeight /
                                                    rectList[digit].Height)

                                                if scale1 > 1:
                                                    scale1 = 1

                                                if scale2 > 1:
                                                    scale2 = 1

                                                transform.ScaleX = transform.ScaleY = scale1 + (
                                                    scale2 - scale1)

                                                doubleAnimation1 = DoubleAnimation(
                                                    scale1 + (scale2 - scale1),
                                                    TimeSpan.FromMilliseconds(
                                                        500))
                                                doubleAnimation2 = DoubleAnimation(
                                                    scale1 + (scale2 - scale1),
                                                    TimeSpan.FromMilliseconds(
                                                        500))
                                                sineEase = SineEase()

                                                sineEase.EasingMode = EasingMode.EaseInOut
                                                doubleAnimation1.EasingFunction = sineEase
                                                doubleAnimation2.EasingFunction = sineEase

                                                storyboard.Children.Add(
                                                    doubleAnimation1)
                                                storyboard.Children.Add(
                                                    doubleAnimation2)

                                                Storyboard.SetTarget(
                                                    doubleAnimation1, element3)
                                                Storyboard.SetTarget(
                                                    doubleAnimation2, element3)
                                                Storyboard.SetTargetProperty(
                                                    doubleAnimation1,
                                                    PropertyPath(
                                                        "(0).(1)[1].(2)",
                                                        Canvas.
                                                        RenderTransformProperty,
                                                        TransformGroup.
                                                        ChildrenProperty,
                                                        ScaleTransform.
                                                        ScaleXProperty))
                                                Storyboard.SetTargetProperty(
                                                    doubleAnimation2,
                                                    PropertyPath(
                                                        "(0).(1)[1].(2)",
                                                        Canvas.
                                                        RenderTransformProperty,
                                                        TransformGroup.
                                                        ChildrenProperty,
                                                        ScaleTransform.
                                                        ScaleYProperty))

                                        element3.BeginStoryboard(
                                            storyboard,
                                            HandoffBehavior.SnapshotAndReplace)

                                digits[Grid.GetColumn(element1)] = digit