myBlog

IronPython, Silverlight, WPF, XAML, HTML5, ...

PTVSで、IronPython WPFプログラム【赤い光沢(RedGlass)のあるボタン(Button)】を動かした

2016-04-23 15:54:42 | IronPython

Python Tools for Visual Studio v2.1で、IronPython 2.7 WPFプログラムを動かしてみました。
前にIromPython 2.6で作成した【赤い光沢(RedGlass)のあるボタン(Button)とプログレスバー(ProgressBar)】を新しい環境(Python Tools for Visual Studio)で動かした。


新しいプロジェクトで、IronPython WPF Applicationを選択します。
プロジェクト名を WpfApplicationRedGlass にしました。
そして作成して行きます。色々と便利になっています。XAMLエディッターが使えます。
GitHubにプログラムを投稿しています。参考にしてください。
https://github.com/softgarden137/RedGlass

GitHub実践入門
大塚 弘記
技術評論社

GitHubの教科書
インプレス

Gitポケットリファレンス
技術評論社

Python Tools for Visual Studioで、Art55 衝動アプリ!(IronPython 2.7 WPF)を動かした

2014-12-05 10:07:00 | IronPython
Python Tools for Visual Studio v2.1で、Art55 衝動アプリ!(IronPython 2.7 WPFプログラム)を動かしました。
オリジナルは、創造的プログラミングと粘土細工 ⇒
【WPF】衝動アプリ!アニメーションをふんだんに使ってみる!
http://pro.art55.jp/?eid=1119019 です。本当に衝動アプリだ!


新しいプロジェクトで、IronPython WPF Applicationを選択します。
プロジェクト名を WpfApplicationArt55 にしました。
WpfApplicationArt55.pyでは、
import wpf
wpf.LoadComponent(self, 'WpfApplicationArt55.xaml')
wpf.LoadComponent(myResourceDictionary,'Art55_Resouces.xaml')
を新しく使っています。
前に投稿した、IronPythonで、Art55~を実行する!と比べるとプログラムがすっきりして、見やすくなった。
GitHubにプログラムを投稿しています。参考にしてください。
https://github.com/softgarden137/WpfApplicationArt55





GitHub実践入門
大塚 弘記
技術評論社
GitHubの教科書
インプレス
Gitポケットリファレンス
技術評論社

Python Tools for Visual Studioで、IronPython WPFプログラム(clock and calc)を動かした

2014-12-02 11:31:38 | IronPython
Python Tools for Visual Studio v2.1で、IronPython 2.7 WPFプログラムを動かしてみました。
前にIromPython 2.6で動かした自由にドラッグできる時計自由にドラッグできる電卓を一つに、まとめました。
時計と電卓をドラッグすると、自由に動きます。


新しいプロジェクトで、IronPython WPF Applicationを選択します。
プロジェクト名を WpfApplicationClockCalc にしました。
WpfApplicationClockCalc.pyでは、
import wpf
wpf.LoadComponent(self, 'Calc.xaml')
wpf.LoadComponent(self, 'Clock.xaml')
wpf.LoadComponent(self, 'WpfApplicationClockCalc.xaml')
を新しく使っています。とても便利です。プログラムがすっきりしました。
GitHubにプログラムを投稿しています。参考にしてください。
https://github.com/softgarden137/WpfApplicationClockCalc





エッセンシャル WPF:Windows Presentation Foundation
(Programmer’s SLECTION―Microsoft .net Development Series)
Chris Anderson
翔泳社
プログラミングWindows 第6版 上 (Microsoft Press)
Charles Petzold
日経BP社
プログラミングWindows 第6版 下 (Microsoft Press)
Charles Petzold
日経BP社

Python Tools for Visual Studioで、IronPython WPFプログラム(Snow)を動かした

2014-12-01 15:57:11 | IronPython

Python Tools for Visual Studio v2.1で、IronPython 2.7 WPFプログラムを動かしてみました。
前にIromPython 2.6で作成したSnowを新しい環境(Python Tools for Visual Studio)で動かした。


新しいプロジェクトで、IronPython WPF Applicationを選択します。
プロジェクト名を WpfApplicationSnow にしました。
そして作成して行きます。色々と便利になっています。XAMLエディッターが使えます。
GitHubにプログラムを投稿しています。参考にしてください。
https://github.com/softgarden137/WpfApplicationSnow





GitHub実践入門 ~Pull Requestによる開発の変革 (WEB+DB PRESS plus)
大塚 弘記
技術評論社



IronPythonで、赤い光沢(RedGlass)のあるボタン(Button)とプログレスバー(ProgressBar)

2011-07-31 07:55:59 | IronPython
IronPython で、下記のBlogを参考にして、赤い光沢のあるボタン(Button)とプログレスバー(ProgressBar)を
作ってみました。
日向ぼっこデベロッパhandcraftの備忘録 ⇒
[WPF] StyleとTemplateを使用してWPFのButtonとProgressBarのUIを変更する
http://handcraft.blogsite.org/ComponentGeek/ShowArticle/115.aspx
http://www.pine4.net/Memo/Article/Archives/115
『WPFのStyle,Templateを使用してボタンとプログレスバーのUIを変更するサンプルを掲載します。
赤い光沢のあるボタンとプログレスバーを作ってみます。』

そして、Nine WorksさんのBlogを参考にして、プログレス処理を追加しました。
Nine Works ⇒ ProgressBarとBackgroundWorker
http://nine-works.blog.ocn.ne.jp/blog/2011/06/progressbarback.html

赤い光沢のあるボタン XAML ⇒ RedButton.xaml
http://softgarden.lovepop.jp/myBlog/xaml/RedButton.xaml
赤い光沢のあるプログレスバー XAML ⇒ RedProgressBar.xaml
http://softgarden.lovepop.jp/myBlog/xaml/RedProgressBar.xaml
共通リソース XAML ⇒ CommonResource.xaml
http://softgarden.lovepop.jp/myBlog/xaml/CommonResource.xaml

Redglass

#
# RedGlass.py
#
import clr
clr.AddReferenceByPartialName("PresentationFramework")
clr.AddReferenceByPartialName("PresentationCore")
clr.AddReference('WindowsBase')
from System import Object
from System.Windows.Markup import XamlReader
from System.Windows import Window, Application, MessageBox
from System.ComponentModel import BackgroundWorker

xaml_str="""
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="RedGlass.py" Width="300" Height="110">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="http://softgarden137.github.io/RedGlass/RedButton.xaml" />
                <ResourceDictionary Source="http://softgarden137.github.io/RedGlass/RedProgressBar.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Canvas>
        <ProgressBar Name="progressBar"
            Canvas.Left="0" Canvas.Top="0"
            Minimum="0" Maximum="10000"
            Margin="5" Width="200" Height="25"/>
        <TextBlock Name="statusTextBlock" Width="100"
            Canvas.Left="215" Canvas.Top="10"/>
        <Button Name="startButton"  
            Canvas.Left="110" Canvas.Top="35"
            Margin="5" Width="80" Height="25" Content="Start"
            Style="{StaticResource RedButton}"/>
        <Button Name="stopButton"
            Canvas.Left="200" Canvas.Top="35"
            Margin="5" Width="80" Height="25" Content="Stop" IsEnabled="False"
            Style="{StaticResource RedButton}"/>
    </Canvas>
</Window>
"""
class ExWindow(Object):
    def __init__(self):
        self.Root = win = XamlReader.Parse(xaml_str)

        self.progressBar = win.FindName("progressBar")
        self.statusTextBlock = win.FindName("statusTextBlock")
        self.startButton = win.FindName("startButton")
        self.stopButton = win.FindName("stopButton")

        self.startButton.Click += self.startButton_Click
        self.stopButton.Click += self.stopButton_Click 

        self.bw = BackgroundWorker()
        #// 進捗状況の更新を可能にする
        self.bw.WorkerReportsProgress = True
        #// キャンセルを可能にする
        self.bw.WorkerSupportsCancellation = True

        #// バックグラウンド行う処理
        self.bw.DoWork += self.bw_DoWork
        #// 進捗状況の更新を行う処理
        self.bw.ProgressChanged += self.bw_ProgressChanged
        #// バックグラウンドでの処理が終了後の処理
        self.bw.RunWorkerCompleted += self.bw_RunWorkerCompleted

    #// 時間のかかる処理
    def bw_DoWork(self, sender, e):
        import System
        for i in range(1,10001):
            if (self.bw.CancellationPending == True):
                #// キャンセルされたので処理を終了
                e.Cancel = True
                break

            #// 現在の進捗状況(数値)
            currentValue = i

            #// currentValue以外の進捗状況を表す情報(オプション)
            status = str(i) + " / 10000"

            #// 進捗状況を報告
            self.bw.ReportProgress(currentValue, status)

            #// 何らかの処理(ここではスリープさせるだけ)
            System.Threading.Thread.Sleep(1)

        #// 操作の結果を渡したい場合はe.Resultを使う
        e.Result = "[終了結果]"

    #// 進捗状況の更新処理
    def bw_ProgressChanged(self, sender, e):
        #// プログレスバーの値を更新
        self.progressBar.Value = e.ProgressPercentage

        #// プログレスバー以外の状況更新
        self.statusTextBlock.Text = e.UserState.ToString()

    #// 時間のかかる処理が終わった後の後処理
    def bw_RunWorkerCompleted(self, sender, e):
        self.statusTextBlock.Text = ""
        self.progressBar.Value = 0

        if (e.Cancelled == True):
            MessageBox.Show("処理を中断しました。")
        else:
            MessageBox.Show("処理が終了しました。" + e.Result.ToString())

        self.startButton.IsEnabled = True
        self.stopButton.IsEnabled = False

    #// 処理開始
    def startButton_Click(self, sender, e):
        self.startButton.IsEnabled = False
        self.stopButton.IsEnabled = True

        #// 時間のかかる処理を実行する
        self.bw.RunWorkerAsync()
    
    #// 作業を途中で止める
    def stopButton_Click(self, sender, e):
       self.bw.CancelAsync()

if __name__ == "__main__":
    win = ExWindow()
    Application().Run(win.Root)

IronPythonの世界 (Windows Script Programming)
荒井 省三
ソフトバンク クリエイティブ
エキスパートPythonプログラミング
Tarek Ziade
アスキー・メディアワークス
Pythonスタートブック
辻 真吾
技術評論社