def get_text(self, text): tb = TextBlock() tb.Text = text tb.Width = self.canvas.ActualWidth tb.Height = 40 tb.FontSize = 30 tb.Background = SolidColorBrush(Colors.Black) tb.Foreground = SolidColorBrush(Colors.White) tb.TextAlignment = TextAlignment.Center return tb
def __init__(self, width, height, xpos, ypos, direction, speed): self.width = width self.height = height self.xpos = xpos self.ypos = ypos self.xdir, self.ydir = self.normalize(direction[0], direction[1]) self.speed = speed self.destroyed = False self.edges = self.get_edges() self.shape = Rectangle() self.shape.Width = width self.shape.Height = height self.shape.Stroke = SolidColorBrush(Colors.White) self.shape.Fill = SolidColorBrush(Colors.Black)
def draw_animal_brain(self): self.canvas.Children.Clear() brain = self.animal.brain width_count = max(len(brain.layers[0]), len(brain.layers[1]), len(brain.layers[-1])) neuron_size = min(self.canvas.ActualWidth / (width_count * 1.5), self.canvas.ActualHeight / (3.0 * 2.0)) for layer_index, layer in enumerate(brain): neuron_margin = (self.canvas.ActualWidth - len(layer) * neuron_size) / (len(layer) + 1) for neuron_index, neuron in enumerate(layer): el = Ellipse() el.Height = neuron_size el.Width = neuron_size el.Fill = SolidColorBrush(get_color(neuron.out)) self.canvas.AddChild(el) self.canvas.SetTop(el, layer_index * neuron_size * 2) self.canvas.SetLeft( el, neuron_index * (neuron_size + neuron_margin) + neuron_margin) for i in range(len(brain) - 1): self.draw_layers_connections(brain, i, i + 1, neuron_size)
def line(x1, y1, x2, y2, widget): line = Line() line.Stroke = SolidColorBrush(Colors.Blue) line.X1 = float(x1) line.X2 = float(x2) line.Y1 = float(y1) line.Y2 = float(y2) widget.Children.Add(line)
def rect(w, h, widget): rect = Rectangle() rect.Fill = SolidColorBrush(Colors.Red) rect.Width = w rect.Height = h rect.SetValue(widget.LeftProperty, 10.0) rect.SetValue(widget.TopProperty, 50.0) widget.Children.Add(rect)
def generate_rect_image(self): rect = Rectangle() rect.Width = 16 rect.Height = 16 rect.RadiusX = 2 rect.RadiusY = 2 rect.Fill = SolidColorBrush( ColorConverter.ConvertFromString(self.fill_color)) self.img_drawing = rect
def addLine(self, _from, to): line = Line() line.X1 = _from[0] line.Y1 = _from[1] line.X2 = to[0] line.Y2 = to[1] line.Stroke = SolidColorBrush(Color.FromArgb(255, 255, 255, 255)) # Brushes.White line.StrokeThickness = 2.0 self.canvas.Children.Add(line)
def __init__(self, printer, context, root): self._input_data = [] self.original_context = context self.printer = printer self.prompt = root.prompt self.root = root self.done_first_run = False self._sync = ManualResetEvent(False) self.ff3 = False self.FontSize = 15 self.Margin = Thickness(0) self.FontFamily = FontFamily( "Consolas, Monaco, Lucida Console, Global Monospace") self.AcceptsReturn = True self.BorderThickness = Thickness(0) self.VerticalScrollBarVisibility = ScrollBarVisibility.Auto self.MinWidth = 300 def reset(): "Clear the console, its history and the execution context." self._reset_needed = True return 'resetting' def input(prompt='Input:'): 'input([prompt]) -> value\n\nEquivalent to eval(raw_input(prompt)).' return eval(self.context['raw_input'](prompt), self.context, self.context) self.original_context['reset'] = reset self.original_context['gohome'] = gohome self.original_context['exit'] = 'There is no escape...' self.original_context['raw_input'] = self.raw_input self.original_context['input'] = input # for debugging only! self.original_context['root'] = root self.context = {} self.history = None self._reset_needed = False self._thread = None self._thread_reset = None self._raw_input_text = '' self._temp_context = None self.engine = Python.CreateEngine() self.scope = self.engine.CreateScope() self._original_caret = None if hasattr(self, 'CaretBrush'): self._original_caret = self.CaretBrush self._disabled = SolidColorBrush(Colors.White) self.KeyDown += self.handle_key self.TextChanged += self.text_changed
def RedrawScreen(self, level): self.canvas.Children.Clear() self.drawBorders(self.Width, self.Height) self.stars = [] for n in range(level * 3): star = mvvm.XamlLoader(self.starXaml).Root self.stars.append(star) Canvas.SetLeft(star, self.rand.Next(10, self.Width - 10)) Canvas.SetTop(star, self.rand.Next(2, self.Height - 10)) self.canvas.Children.Add(star) self.polyline = Polyline() self.polyline.Stroke = SolidColorBrush(Color.FromArgb( 255, 255, 255, 0)) # Brushes.Yellow self.polyline.StrokeThickness = 2.0 self.canvas.Children.Add(self.polyline)
def __init__(self, xpos, ypos, length, direction): self.xpos = xpos self.ypos = ypos self.length = length self.direction = direction self.xdir = direction[0] self.ydir = direction[1] self.destroyed = False self.edges = self.get_edges() self.shape = Line() self.shape.Stroke = SolidColorBrush(Colors.Black) self.shape.X1 = 0 self.shape.Y1 = 0 if direction in (Direction.LEFT, Direction.RIGHT): self.shape.X2 = self.length self.shape.Y2 = 0 else: self.shape.X2 = 0 self.shape.Y2 = self.length self.shape.StrokeThickness = 1
def draw_layers_connections(self, brain, first_layer_index, second_layer_index, neuron_size): first_layer_margin = ( self.canvas.ActualWidth - len(brain.layers[first_layer_index]) * neuron_size) / (len(brain.layers[first_layer_index]) + 1) second_layer_margin = ( self.canvas.ActualWidth - len(brain.layers[second_layer_index]) * neuron_size) / (len(brain.layers[second_layer_index]) + 1) for second_layer_neuron_index, second_layer_neuron in enumerate( brain.layers[second_layer_index]): for first_layer_neuron_index, first_layer_neuron in enumerate( brain.layers[first_layer_index]): line = Line() line.X1 = second_layer_margin + second_layer_neuron_index * ( neuron_size + second_layer_margin) + neuron_size / 2.0 line.Y1 = second_layer_index * neuron_size * 2.0 + neuron_size / 2.0 line.X2 = first_layer_margin + first_layer_neuron_index * ( neuron_size + first_layer_margin) + neuron_size / 2.0 line.Y2 = first_layer_index * neuron_size * 2.0 + neuron_size / 2.0 line.StrokeThickness = 2 line.Stroke = SolidColorBrush( get_color(second_layer_neuron.w[first_layer_neuron_index])) self.canvas.AddChild(line)
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()
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()
def __init__(self): super(RUI, self).__init__() self.Width = 2400 self.Height = 2400 self.Background = SolidColorBrush(Colors.Beige) pass
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()
from IronPython.Hosting import Python from IronPython.Compiler import Tokenizer from Microsoft.Scripting.Hosting.Providers import HostingHelpers from Microsoft.Scripting import SourceCodeKind, TokenCategory from System.Windows.Documents import Run from System.Windows.Media import Color, SolidColorBrush from utils import _debug styles = { TokenCategory.NumericLiteral: SolidColorBrush(Color.FromArgb(255, 102, 102, 102)), TokenCategory.Operator: SolidColorBrush(Color.FromArgb(255, 102, 102, 102)), TokenCategory.Keyword: SolidColorBrush(Color.FromArgb(255, 0, 128, 0)), TokenCategory.Identifier: SolidColorBrush(Color.FromArgb(255, 25, 23, 124)), TokenCategory.StringLiteral: SolidColorBrush(Color.FromArgb(255, 186, 33, 33)), TokenCategory.Comment: SolidColorBrush(Color.FromArgb(255, 64, 128, 128)), TokenCategory.Error: SolidColorBrush(Color.FromArgb(255, 255, 0, 0)), TokenCategory.None: SolidColorBrush(Color.FromArgb(255, 255, 255, 255)), } default_style = SolidColorBrush(Color.FromArgb(255, 0, 0, 0)) blue = SolidColorBrush(Color.FromArgb(255, 0, 0, 128))
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)
def onOpened(s, e): global appId, appSecret, accessToken, menuItem menuItem.Items.Clear() if accessToken is None: def onLogInClick(source, rea): window = Window() webBrowser = WebBrowser() def onWebBrowserNavigated(sender, nea): if Regex.IsMatch(nea.Uri.AbsoluteUri, "^http(s)?://www\\.facebook\\.com/connect/login_success\\.html", RegexOptions.CultureInvariant): for match in Regex.Matches(nea.Uri.Query, "\\??(?<1>.+?)=(?<2>.*?)(?:&|$)", RegexOptions.CultureInvariant | RegexOptions.Singleline): if match.Groups[1].Value.Equals("code"): sb = StringBuilder() d = Dictionary[String, String]() d.Add("client_id", appId) d.Add("redirect_uri", "https://www.facebook.com/connect/login_success.html") d.Add("client_secret", appSecret) d.Add("code", match.Groups[2].Value) for kvp in d: if sb.Length > 0: sb.Append('&') sb.AppendFormat("{0}={1}", kvp.Key, urlEncode(kvp.Value)) request = WebRequest.Create(String.Concat("https://graph.facebook.com/oauth/access_token?", sb.ToString())) dictionary = Dictionary[String, String]() def onAuth(): if NetworkInterface.GetIsNetworkAvailable(): try: response = None stream = None streamReader = None shortLivedAccessToken = None try: response = request.GetResponse() stream = response.GetResponseStream() streamReader = StreamReader(stream) for m in Regex.Matches(streamReader.ReadToEnd(), "(?<1>.+?)=(?<2>.*?)(?:&|$)", RegexOptions.CultureInvariant | RegexOptions.Singleline): if m.Groups[1].Value.Equals("access_token"): shortLivedAccessToken = m.Groups[2].Value finally: if streamReader is not None: streamReader.Close() streamReader = None if stream is not None: stream.Close() stream = None if response is not None: response.Close() response = None if shortLivedAccessToken is not None: d.Remove("redirect_uri") d.Remove("code") d.Add("grant_type", "fb_exchange_token") d.Add("fb_exchange_token", shortLivedAccessToken) sb.Clear() for kvp in d: if sb.Length > 0: sb.Append('&') sb.AppendFormat("{0}={1}", kvp.Key, urlEncode(kvp.Value)) r = WebRequest.Create(String.Concat("https://graph.facebook.com/oauth/access_token?", sb.ToString())) try: response = r.GetResponse() stream = response.GetResponseStream() streamReader = StreamReader(stream) for m in Regex.Matches(streamReader.ReadToEnd(), "(?<1>.+?)=(?<2>.*?)(?:&|$)", RegexOptions.CultureInvariant | RegexOptions.Singleline): if not dictionary.ContainsKey(m.Groups[1].Value): dictionary.Add(m.Groups[1].Value, m.Groups[2].Value) finally: if streamReader is not None: streamReader.Close() if stream is not None: stream.Close() if response is not None: response.Close() if dictionary.ContainsKey("access_token"): 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(sr.ReadToEnd(), String.Concat("(?<=", Environment.NewLine, "accessToken\\s*=\\s*(?(?=\")(?<Open>\")|(?<Open>\")?))\\S*?(?=(?(?<=\")(?<Close-Open>\")|(?<Close-Open>\")?)", Environment.NewLine, "(?(Open)(?!))(?!\"))"), MatchEvaluator(lambda x: dictionary["access_token"] if x.Groups["Close"].Success else String.Format("\"{0}\"", dictionary["access_token"])), 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 accessToken if dictionary.ContainsKey("access_token"): accessToken = dictionary["access_token"] Task.Factory.StartNew(onAuth, TaskCreationOptions.LongRunning).ContinueWith(onCompleted, TaskScheduler.FromCurrentSynchronizationContext()) break def onWindowLoaded(sender, args): sb = StringBuilder() d = Dictionary[String, String]() d.Add("client_id", appId) d.Add("redirect_uri", "https://www.facebook.com/connect/login_success.html") d.Add("scope", "read_stream, publish_stream") d.Add("display", "popup") for kvp in d: if sb.Length > 0: sb.Append('&') sb.AppendFormat("{0}={1}", kvp.Key, urlEncode(kvp.Value)) webBrowser.Navigate(Uri(String.Concat("https://www.facebook.com/dialog/oauth?", sb.ToString()))) def onCloseClick(source, args): 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 window.Loaded += onWindowLoaded stackPanel = StackPanel() stackPanel.UseLayoutRounding = True stackPanel.HorizontalAlignment = HorizontalAlignment.Stretch stackPanel.VerticalAlignment = VerticalAlignment.Stretch stackPanel.Orientation = Orientation.Vertical window.Content = stackPanel 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 stackPanel.Children.Add(border1) webBrowser.HorizontalAlignment = HorizontalAlignment.Stretch webBrowser.VerticalAlignment = VerticalAlignment.Stretch webBrowser.Width = 640 webBrowser.Height = 480 webBrowser.Navigated += onWebBrowserNavigated border1.Child = webBrowser 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 stackPanel.Children.Add(border2) closeButton = Button() closeButton.HorizontalAlignment = HorizontalAlignment.Right closeButton.VerticalAlignment = VerticalAlignment.Center closeButton.Margin = Thickness(10, 10, 10, 10) closeButton.Padding = Thickness(10, 2, 10, 2) closeButton.IsDefault = True if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): closeButton.Content = "閉じる" else: closeButton.Content = "Close" closeButton.Click += onCloseClick border2.Child = closeButton window.Show() logInMenuItem = MenuItem() if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): logInMenuItem.Header = "ログイン..." else: logInMenuItem.Header = "Log In..." logInMenuItem.Click += onLogInClick menuItem.Items.Add(logInMenuItem)
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
def onCompleted(task): window = Window() stackPanel3 = StackPanel() def onLoaded(sender, args): stackPanel3.Width = Math.Ceiling(stackPanel3.ActualWidth) def onCloseClick(sender, args): window.Close() window.Owner = Application.Current.MainWindow if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): window.Title = "バリデータ" else: window.Title = "Validator" window.WindowStartupLocation = WindowStartupLocation.CenterOwner window.ResizeMode = ResizeMode.NoResize window.SizeToContent = SizeToContent.WidthAndHeight window.Background = SystemColors.ControlBrush window.Loaded += onLoaded 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.WindowBrush stackPanel1.Children.Add(stackPanel2) stackPanel3.HorizontalAlignment = HorizontalAlignment.Stretch stackPanel3.VerticalAlignment = VerticalAlignment.Stretch stackPanel3.Orientation = Orientation.Vertical if errorList.Count == 0: if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): attachStackPanel(stackPanel3, Brushes.Lime, "有効なスクリプトです。") else: attachStackPanel(stackPanel3, Brushes.Lime, "Valid.") for warning in warningList: attachStackPanel(stackPanel3, Brushes.Yellow, warning) for error in errorList: attachStackPanel(stackPanel3, Brushes.Red, error) stackPanel2.Children.Add(stackPanel3) solidColorBrush = SolidColorBrush(Colors.White) solidColorBrush.Opacity = 0.5 if solidColorBrush.CanFreeze: solidColorBrush.Freeze() border = Border() border.HorizontalAlignment = HorizontalAlignment.Stretch border.VerticalAlignment = VerticalAlignment.Stretch border.BorderThickness = Thickness(0, 1, 0, 0) border.BorderBrush = solidColorBrush stackPanel1.Children.Add(border) closeButton = Button() closeButton.HorizontalAlignment = HorizontalAlignment.Right closeButton.VerticalAlignment = VerticalAlignment.Center closeButton.Margin = Thickness(10, 10, 10, 10) closeButton.Padding = Thickness(10, 2, 10, 2) closeButton.IsDefault = True if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): closeButton.Content = "閉じる" else: closeButton.Content = "Close" closeButton.Click += onCloseClick border.Child = closeButton window.Show()
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
def onCompleted(task): window = Window() stackPanel3 = StackPanel() def onLoaded(sender, args): stackPanel3.Width = Math.Ceiling(stackPanel3.ActualWidth) def onCloseClick(sender, args): window.Close() window.Owner = Application.Current.MainWindow if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): window.Title = "バリデータ" else: window.Title = "Validator" window.WindowStartupLocation = WindowStartupLocation.CenterOwner window.ResizeMode = ResizeMode.NoResize window.SizeToContent = SizeToContent.WidthAndHeight window.Background = SystemColors.ControlBrush window.Loaded += onLoaded 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.WindowBrush stackPanel1.Children.Add(stackPanel2) stackPanel3.HorizontalAlignment = HorizontalAlignment.Stretch stackPanel3.VerticalAlignment = VerticalAlignment.Stretch stackPanel3.Orientation = Orientation.Vertical if errorList.Count == 0: if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): attachStackPanel(stackPanel3, Brushes.Lime, "有効なスクリプトです。") else: attachStackPanel(stackPanel3, Brushes.Lime, "Valid.") for warning in warningList: attachStackPanel(stackPanel3, Brushes.Yellow, warning) for error in errorList: attachStackPanel(stackPanel3, Brushes.Red, error) stackPanel2.Children.Add(stackPanel3) solidColorBrush = SolidColorBrush(Colors.White) solidColorBrush.Opacity = 0.5 if solidColorBrush.CanFreeze: solidColorBrush.Freeze() border = Border() border.HorizontalAlignment = HorizontalAlignment.Stretch border.VerticalAlignment = VerticalAlignment.Stretch border.BorderThickness = Thickness(0, 1, 0, 0) border.BorderBrush = solidColorBrush stackPanel1.Children.Add(border) closeButton = Button() closeButton.HorizontalAlignment = HorizontalAlignment.Right closeButton.VerticalAlignment = VerticalAlignment.Center closeButton.Margin = Thickness(10, 10, 10, 10) closeButton.Padding = Thickness(10, 2, 10, 2) closeButton.IsDefault = True if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): closeButton.Content = "閉じる" else: closeButton.Content = "Close" closeButton.Click += onCloseClick border.Child = closeButton window.Show()