/Languages/IronPython/Samples/WinFormsMapPoint/WinForms/formv8.py
https://github.com/kumaryu/IronLanguages-main · Python · 113 lines · 62 code · 22 blank · 29 comment · 2 complexity · 59c33984ad740465662ac99c60634784 MD5 · raw file
- ##############################################################################
- #
- # Copyright (c) Microsoft Corporation. All rights reserved.
- #
- # This source code is subject to terms and conditions of the Apache License,
- # Version 2.0. A copy of the license can be found in the License.html file at
- # the root of this distribution. If you cannot locate the Apache License,
- # Version 2.0, please send an email to ironpy@microsoft.com. By using this
- # source code in any fashion, you are agreeing to be bound by the terms of
- # the Apache License, Version 2.0.
- #
- # You must not remove this notice, or any other, from this software.
- #
- #
- ##############################################################################
- import clr
- clr.AddReference("System.Windows.Forms")
- clr.AddReference("System.Drawing")
- from System.Windows.Forms import *
- from System.Drawing import Icon, Size
- clr.AddReferenceToFile("MapPointWebServiceProject.dll")
- from MapPointWebServiceProject import MapPointWebServiceHelper
- class FormV8(Form):
- def __init__(self):
- self.Text = "(" + __file__ + ")"
- # Create TableLayoutPanel and FlowLayoutPanel
- self._tableLayoutPanel1 = TableLayoutPanel(ColumnCount=1,
- Dock=DockStyle.Fill,
- RowCount=3)
- self._flowLayoutPanel1 = FlowLayoutPanel(Dock=DockStyle.Fill)
- self._flowLayoutPanel2 = FlowLayoutPanel(Dock=DockStyle.Fill)
- # controls for FlowLayout Start
- self._label1 = Label(Text="Enter start location:", AutoSize=True)
- self._txtFromLocation = TextBox()
- # controls for FlowLayout End
- self._label2 = Label(Text="Enter end location:", AutoSize=True)
- self._txtToLocation = TextBox()
- self._button1 = Button(Text="Get map", AutoSize=True)
- self._button1.Click += self.OnMsgButtonClick
- self.AcceptButton = self._button1
- # this will hold our route map
- self._pictureBox1 = PictureBox(Dock=DockStyle.Fill)
- # Setup TableLayoutPanel rows and columns and add controls
- self._tableLayoutPanel1.ColumnStyles.Add(ColumnStyle(SizeType.Percent,
- 100.0))
- self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Absolute,
- 40.0))
- self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Absolute,
- 60.0))
- self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Percent,
- 100.0))
- self._tableLayoutPanel1.Controls.Add(self._flowLayoutPanel1, 0, 0)
- self._tableLayoutPanel1.Controls.Add(self._flowLayoutPanel2, 0, 1)
- self._tableLayoutPanel1.Controls.Add(self._pictureBox1, 0, 2)
- # Add controls to FlowLayoutPanel Start
- self._flowLayoutPanel1.Controls.Add(self._label1)
- self._flowLayoutPanel1.Controls.Add(self._txtFromLocation)
- # Add controls to FlowLayoutPanel End
- self._flowLayoutPanel2.Controls.Add(self._label2)
- self._flowLayoutPanel2.Controls.Add(self._txtToLocation)
- self._flowLayoutPanel2.Controls.Add(self._button1)
- # Setup ToolStrip and ToolStripProgresssBar
- # Maximum = 100 and step is 25
- self._statusStrip1 = StatusStrip()
- self._toolStripProgressBar1 = ToolStripProgressBar(Maximum=100,
- Step=25)
- self._statusStrip1.Items.Add(self._toolStripProgressBar1)
- self.Controls.Add(self._statusStrip1)
- self.Controls.Add(self._tableLayoutPanel1)
- def OnMsgButtonClick(self, *args):
- self._toolStripProgressBar1.Value = 0 # set progress to zero
- try:
- # increment progess to 25%
- self._toolStripProgressBar1.PerformStep()
- mapHelper = MapPointWebServiceHelper.GetInstance("5200", "ned68Fe")
- # increment progress to 50%
- self._toolStripProgressBar1.PerformStep()
- locFrom = mapHelper.FindLocation(self._txtFromLocation.Text)
- # increment progress to 75%
- self._toolStripProgressBar1.PerformStep()
- locTo = mapHelper.FindLocation(self._txtToLocation.Text)
- # increment progress to 100%
- self._toolStripProgressBar1.PerformStep()
- myRoute = mapHelper.GetRoute(locFrom, locTo)
- pb = self._pictureBox1
- pb.Image = mapHelper.GetRouteMap(myRoute, pb.Width, pb.Height)
- except Exception, e:
- MessageBox.Show(str(e), "MapPoint Exception")
- # set progress to back to zero
- self._toolStripProgressBar1.Value = 0
- Application.Run(FormV8())