/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

  1. ##############################################################################
  2. #
  3. # Copyright (c) Microsoft Corporation. All rights reserved.
  4. #
  5. # This source code is subject to terms and conditions of the Apache License,
  6. # Version 2.0. A copy of the license can be found in the License.html file at
  7. # the root of this distribution. If you cannot locate the Apache License,
  8. # Version 2.0, please send an email to ironpy@microsoft.com. By using this
  9. # source code in any fashion, you are agreeing to be bound by the terms of
  10. # the Apache License, Version 2.0.
  11. #
  12. # You must not remove this notice, or any other, from this software.
  13. #
  14. #
  15. ##############################################################################
  16. import clr
  17. clr.AddReference("System.Windows.Forms")
  18. clr.AddReference("System.Drawing")
  19. from System.Windows.Forms import *
  20. from System.Drawing import Icon, Size
  21. clr.AddReferenceToFile("MapPointWebServiceProject.dll")
  22. from MapPointWebServiceProject import MapPointWebServiceHelper
  23. class FormV8(Form):
  24. def __init__(self):
  25. self.Text = "(" + __file__ + ")"
  26. # Create TableLayoutPanel and FlowLayoutPanel
  27. self._tableLayoutPanel1 = TableLayoutPanel(ColumnCount=1,
  28. Dock=DockStyle.Fill,
  29. RowCount=3)
  30. self._flowLayoutPanel1 = FlowLayoutPanel(Dock=DockStyle.Fill)
  31. self._flowLayoutPanel2 = FlowLayoutPanel(Dock=DockStyle.Fill)
  32. # controls for FlowLayout Start
  33. self._label1 = Label(Text="Enter start location:", AutoSize=True)
  34. self._txtFromLocation = TextBox()
  35. # controls for FlowLayout End
  36. self._label2 = Label(Text="Enter end location:", AutoSize=True)
  37. self._txtToLocation = TextBox()
  38. self._button1 = Button(Text="Get map", AutoSize=True)
  39. self._button1.Click += self.OnMsgButtonClick
  40. self.AcceptButton = self._button1
  41. # this will hold our route map
  42. self._pictureBox1 = PictureBox(Dock=DockStyle.Fill)
  43. # Setup TableLayoutPanel rows and columns and add controls
  44. self._tableLayoutPanel1.ColumnStyles.Add(ColumnStyle(SizeType.Percent,
  45. 100.0))
  46. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Absolute,
  47. 40.0))
  48. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Absolute,
  49. 60.0))
  50. self._tableLayoutPanel1.RowStyles.Add(RowStyle(SizeType.Percent,
  51. 100.0))
  52. self._tableLayoutPanel1.Controls.Add(self._flowLayoutPanel1, 0, 0)
  53. self._tableLayoutPanel1.Controls.Add(self._flowLayoutPanel2, 0, 1)
  54. self._tableLayoutPanel1.Controls.Add(self._pictureBox1, 0, 2)
  55. # Add controls to FlowLayoutPanel Start
  56. self._flowLayoutPanel1.Controls.Add(self._label1)
  57. self._flowLayoutPanel1.Controls.Add(self._txtFromLocation)
  58. # Add controls to FlowLayoutPanel End
  59. self._flowLayoutPanel2.Controls.Add(self._label2)
  60. self._flowLayoutPanel2.Controls.Add(self._txtToLocation)
  61. self._flowLayoutPanel2.Controls.Add(self._button1)
  62. # Setup ToolStrip and ToolStripProgresssBar
  63. # Maximum = 100 and step is 25
  64. self._statusStrip1 = StatusStrip()
  65. self._toolStripProgressBar1 = ToolStripProgressBar(Maximum=100,
  66. Step=25)
  67. self._statusStrip1.Items.Add(self._toolStripProgressBar1)
  68. self.Controls.Add(self._statusStrip1)
  69. self.Controls.Add(self._tableLayoutPanel1)
  70. def OnMsgButtonClick(self, *args):
  71. self._toolStripProgressBar1.Value = 0 # set progress to zero
  72. try:
  73. # increment progess to 25%
  74. self._toolStripProgressBar1.PerformStep()
  75. mapHelper = MapPointWebServiceHelper.GetInstance("5200", "ned68Fe")
  76. # increment progress to 50%
  77. self._toolStripProgressBar1.PerformStep()
  78. locFrom = mapHelper.FindLocation(self._txtFromLocation.Text)
  79. # increment progress to 75%
  80. self._toolStripProgressBar1.PerformStep()
  81. locTo = mapHelper.FindLocation(self._txtToLocation.Text)
  82. # increment progress to 100%
  83. self._toolStripProgressBar1.PerformStep()
  84. myRoute = mapHelper.GetRoute(locFrom, locTo)
  85. pb = self._pictureBox1
  86. pb.Image = mapHelper.GetRouteMap(myRoute, pb.Width, pb.Height)
  87. except Exception, e:
  88. MessageBox.Show(str(e), "MapPoint Exception")
  89. # set progress to back to zero
  90. self._toolStripProgressBar1.Value = 0
  91. Application.Run(FormV8())