示例#1
0
 def get_element_coords(self, element):
     transform = element.TransformToVisual(self.root)
     topleft = transform.Transform(Point(0, 0))
     minX = topleft.X
     minY = topleft.Y
     maxX = minX + element.RenderSize.Width
     maxY = minY + element.RenderSize.Height
     return minX, maxX, minY, maxY
 def _get_offset_point(item, x_offset, y_offset):
     item_bounds = item.Bounds
     item_center = RectX.Center(item_bounds)
     offset_point = Point(
         int(item_center.X) + int(x_offset),
         int(item_center.Y) + int(y_offset))
     if not item_bounds.Contains(offset_point):
         raise AssertionError("click location out of bounds")
     return offset_point
示例#3
0
 def OnMouseDown(self, sender, e):
     self.mouse_down = Point(e.Location.X, e.Location.Y)
     self.mouse_down_button = e.Button
     self.mouse_down_seconds = 0
     if not self.snip_enabled:
         self.mouse_down_timer = Timer()
         self.mouse_down_timer.Interval = 1000
         self.mouse_down_timer.Tick += self.OnTimerTick
         self.mouse_down_timer.Start()
     self.snip_rectangle = Rectangle(e.Location, Size(0, 0))
示例#4
0
    def polylineShape(self):
        x = 0
        y = 0

        for steps in [
                Brushes.SteelBlue, Brushes.DarkOrange, Brushes.DarkSeaGreen,
                Brushes.Honeydew
        ]:
            polyline = Polyline()  #New Polyline for each iteration
            polyline.StrokeThickness = self.myCanvas.Height / 4  #Calculate the width of the line

            x = 0
            y = y + self.myCanvas.Height / 4  #Move the y coordinate down
            polyline.Points.Add(Point(x, y))  #Add x,y start point

            x = self.myCanvas.Width  #Move x coordinate to the end of canvas
            polyline.Points.Add(Point(x, y))  #Add x,y end point

            polyline.Stroke = steps  #Set the brush colour based on the steps value

            self.myCanvas.Children.Add(polyline)  #Draw the line on the canvas
示例#5
0
 def isCollision(self, x, y):
     width = self.Width
     height = self.Height
     if y <= 0 or y >= height:
         return True
     if x >= width:
         return not ((height / 2 + 15) > y > (height / 2 - 15))
     for star in self.stars:
         testX = x - Canvas.GetLeft(star)
         testY = y - Canvas.GetTop(star)
         if mvvm.CheckCollisionPoint(Point(testX, testY), star):
             return True
示例#6
0
 def isCollision(self, x, y):
     width = self.Width
     height = self.Height
     if y <= 0 or y >= height:
         return True
     if x >= width:
         return not ((height / 2 + 15) > y > (height / 2 - 15))
     testPoint = Point(x, y)
     hostPoint = self.canvas.TransformToVisual(
         self.rootVisual).Transform(testPoint)
     #Debug.WriteLine('Test Point: {0}, Host Point: {1}'.format(testPoint,hostPoint))
     if mvvm.CheckCollisionPoint(hostPoint, self.canvas):
         return True
示例#7
0
    def click_template(self, template, similarity=0.95):
        """Click center of the location best matching the given ``template`` if match with at least the given ``similarity`` threshold is found.

        Arguments:

        ``template``
            path to a image file used as the match template

        ``similarity``
            minimum accepted match similarity (default: 0.95).
        """
        assert os.path.isfile(template), f"File not found: {template}"
        x, y = self.match_template(template, similarity)
        Mouse.Instance.Click(Point(int(x), int(y)))
示例#8
0
    def getDisplayPosition(self, joint):
        depthX, depthY = self.nui.SkeletonEngine.SkeletonToDepthImage(
            joint.Position)
        depthX = depthX * 320
        depthY = depthY * 240
        iv = ImageViewArea()

        # only ImageResolution.Resolution640x480 is supported at this point
        colorX, colorY = self.nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(
            ImageResolution.Resolution640x480, iv, depthX, depthY, 0)

        # map back to skeleton.Width & skeleton.Height
        return Point((self.skeleton.Width * colorX / 640.0),
                     (self.skeleton.Height * colorY / 480))
示例#9
0
    def mouse_click(self, x=None, y=None):
        """Clicks mouse at given position.

        Position (``x``, ``y``) is relative to application window top left.
        If no coordinates are given it uses current mouse position.
        """
        self.check_valid_x_y(x, y)
        if (x is None) and (y is None):
            Mouse.Instance.Click(Mouse.Instance.Location)
        else:
            window_location = self.state.window.Bounds.TopLeft
            point = Point(
                int(x) + window_location.X,
                int(y) + window_location.Y)
            Mouse.Instance.Click(point)
示例#10
0
    def polylineShape(self, sides):
        self.myCanvas.Children.Clear()
        h = self.myCanvas.Width/2
        k = self.myCanvas.Height/2              #Calculate the center of the canvas
        r = 100                                 #r is the radius from the center of the canvas
        step = 2 * math.pi/sides                #the location of each point around the circumference
        theta = 0                               #theta starts at 0' anticlockwise to 360'
        polyline = Polyline()
        polyline.StrokeThickness = 1
        polyline.Stroke = Brushes.Blue

        while theta <= 360:                     #While loop, terminates after one rotation
            _x  =  h + r * math.cos(theta)
            _y  =  k + r * math.sin(theta)
            polyline.Points.Add(Point(_x,_y))   #add the new x and y point to the line drawing
            theta = theta + step

        self.myCanvas.Children.Add(polyline)    #finaly add the line we've generated to the canvas
示例#11
0
    def set_mouse_location(self, x, y):
        """Sets mouse position to (``x``, ``y``).

         Position is relative to application window top left.
        """
        window_location = self.state.window.Bounds.TopLeft
        x_target = int(x) + window_location.X
        y_target = int(y) + window_location.Y
        point = Point(x_target, y_target)
        Mouse.Instance.Location = point

        if int(x_target) != int(Mouse.Instance.Location.X):
            logger.warn(
                "Mouse X position tried to be set outside of the screen. Wanted: "
                + str(int(x_target)) + " result:" +
                str(Mouse.Instance.Location.X), True)
        if int(y_target) != int(Mouse.Instance.Location.Y):
            logger.warn(
                "Mouse Y position tried to be set outside of the screen. Wanted: "
                + str(y_target) + " result:" + str(Mouse.Instance.Location.Y),
                True)
示例#12
0
    def __init__(self):
        self.mouse_drag = False
        self.animal_window = None
        self.selected_animal = None
        self.mouse_start_point = Point(0, 0)
        self.start_time = time()

        self.world = world.World(500, 200, constants=WorldConstants())

        self.window = wpf.LoadComponent(self,
                                        'iron_unconditioned_reflexes.xaml')
        self._create_and_start_timer()

        self._renderer = Renderer(self.canvas, self.world)

        self.world.food_timer = self.food_slider.Value

        self._renderer.draw_food_smell = self.food_smell_checkBox.IsChecked
        self._renderer.draw_eat_distance = self.eat_distance_checkBox.IsChecked
        self._renderer.draw_chunks = self.chunks_checkBox.IsChecked
        self._renderer.draw_animal_smell = self.animal_smell_checkBox.IsChecked

        self._simulation_scenario = SimulationScenario(self)
示例#13
0
 def OnMouseUp(self, sender, e):
     self.mouse_up = Point(e.Location.X, e.Location.Y)
     if self.mouse_down_timer is not None:
         self.mouse_down_timer.Stop()
     self.DialogResult = DialogResult.OK
示例#14
0
 def AddNewPosition(self, x, y):
     self.polyline.Points.Add(Point(x, y))
     if self.isCollision(x, y):
         return False
     return True
示例#15
0
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()
示例#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
                                            "top"):
                                        y = Double.Parse(
                                            attribute.Value,
                                            CultureInfo.InvariantCulture)
                                    elif attribute.Name.LocalName.Equals(
                                            "width"):
                                        width = Double.Parse(
                                            attribute.Value,
                                            CultureInfo.InvariantCulture)
                                    elif attribute.Name.LocalName.Equals(
                                            "height"):
                                        height = Double.Parse(
                                            attribute.Value,
                                            CultureInfo.InvariantCulture)

                                character.Origin = Point(originX, originY)
                                character.BaseLocation = Point(x, y)
                                character.Size = Size(width, height)
                                character.Script = fileName

                                characterList.Add(character)

                                break

                except Exception, e:
                    continue

                finally:
                    if fs is not None:
                        fs.Close()
 def _create_body_shape(self):
     self._body_canvas = Canvas()
     self._create_body_ellipse()
     self._create_angle_line()
     self._body_canvas.RenderTransformOrigin = Point(0, 0)
     self.canvas.Children.Add(self._body_canvas)
示例#19
0
 def move_mouse(self, x, y):  # pylint: disable=no-self-use
     """Add (``x``, ``y``) to current mouse location."""
     current_location = Mouse.Instance.Location
     point = Point(int(x) + current_location.X, int(y) + current_location.Y)
     Mouse.Instance.Location = point
示例#20
0
 def set_mouse_point(self, x, y):
     window_location = self.state.window.Bounds.TopLeft
     point = Point(int(x) + window_location.X, int(y) + window_location.Y)
     Mouse.Instance.Location = point
示例#21
0
 def move_mouse(x, y):
     """Add (``x``, ``y``) to current mouse location."""
     current_location = Mouse.Instance.Location
     point = Point(int(x) + current_location.X, int(y) + current_location.Y)
     Mouse.Instance.Location = point