how to make an iron python drop down menu - winforms

I've got this program made up But i want to change bacon to a drop down list instead of a text box. But i don't know what a drop down menu would be like in Iron python. I'm open to suggestions.
import clr
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
from System.Drawing import *
from System.Windows.Forms import *
class SimpleTextBoxForm(Form):
def __init__(self):
self.Text = "Production Plan Pull"
self.Width = 300
self.Height = 250
self.label = Label()
self.label.Text = "bacon"
self.label.Location = Point(25, 25)
self.label.Height = 25
self.label.Width = 75
self.textbox = TextBox()
self.textbox.Text = "Please Insert The bacon"
self.textbox.Location = Point(100, 25)
self.textbox.Width = 150
self.label2 = Label()
self.label2.Text = "soup"
self.label2.Location = Point(25, 50)
self.label2.Height = 25
self.label2.Width = 75
self.textbox2 = TextBox()
self.textbox2.Text = "Please Insert The Soup"
self.textbox2.Location = Point(100, 50)
self.textbox2.Width = 150
self.label3 = Label()
self.label3.Text = "dork"
self.label3.Location = Point(25, 75)
self.label3.Height = 25
self.label3.Width = 75
self.textbox3 = TextBox()
self.textbox3.Text = "Please Insert The dork"
self.textbox3.Location = Point(100, 75)
self.textbox3.Width = 150
self.button1 = Button()
self.button1.Text = 'Submit'
self.button1.Location = Point(50, 125)
self.button1.Click += self.update
self.button2 = Button()
self.button2.Text = 'Reset'
self.button2.Location = Point(150, 125)
self.button2.Click += self.reset
self.AcceptButton = self.button1
self.CancelButton = self.button2
self.Controls.Add(self.label)
self.Controls.Add(self.textbox)
self.Controls.Add(self.label2)
self.Controls.Add(self.textbox2)
self.Controls.Add(self.label3)
self.Controls.Add(self.textbox3)
self.Controls.Add(self.button1)
self.Controls.Add(self.button2)
def update(self, sender, event):
self.label.Text = self.textbox.Text
def reset(self, sender, event):
self.label.Text = "Nothing So Far"
self.textbox.Text = "The Default Text"
form = SimpleTextBoxForm()
Application.Run(form)

IronPython is the programming language you're using, text boxes or drop down menus are a product of the UI library you're using. They're not the same at all.
You're using Windows Forms for your UI. Get acquainted with the available controls or build one yourself.
What you're looking for is the ComboBox. Change your "bacon" control to use that instead.

Related

I want the raw data that can be accessed by further clicking on a link

I want the raw data that can be accessed by further clicking on a link.
Here is the process:
1) click on the link (https://earthquake.usgs.gov/hazards/interactive/)
2) Select "Dynamic : Conterminous " or second option from the Edition panel
3) import latitude and longitude as 35 and -90
4) hit Compute Hazard Curve
5) hit Compute Deaggregation
6) hit Download Deaggregation Report
Now I need all the information in the Deaggregation Report. It will be graet if I can download it as a text file to further process it with Python 3.7
Python
I only need the source data from the right URL
Output should be a text file that needs further evaluations!
Here is the code
from selenium import webdriver
driver = webdriver.Chrome(executable_path='C:\Program Files\Chrome driver\chromedriver.exe')
driver.get('https://earthquake.usgs.gov/hazards/interactive/')
xpath =' /html/body/main/div/div/section[2]/div/section/ul[1]/li[1]/label/select'
box = driver.find_element_by_xpath(xpath)
box.send_keys('Dynamic: Conterminous U.S. 2014 (v4.1.1)')
xpath = '//*[#id="input-latitude"]'
box = driver.find_element_by_xpath(xpath)
box.send_keys(35)
xpath = '//*[#id="input-longitude"]'
box = driver.find_element_by_xpath(xpath)
box.send_keys(-90)
xpath = '/html/body/main/div/div/section[4]/div/section/div[1]/p/button'
btn = driver.find_element_by_xpath(xpath)
btn.click()
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/button'
btn = driver.find_element_by_xpath(xpath)
btn.click()
Click button is no enabled facing following error:
Message: stale element reference: element is not attached to the page document
after further clicking I should be able to download the text!
from selenium import webdriver
# Inputs
Latitude = 34
Longitude = -90
Vs30 = 2000
Period = 0.2
Return_period = 2000
driver = webdriver.Chrome(executable_path='C:\Program Files\Chrome driver\chromedriver.exe')
driver.get('https://earthquake.usgs.gov/hazards/interactive/')
driver.implicitly_wait(15)
xpath = '/html/body/main/div/div/section[2]/div/section/ul[1]/li[1]/label/select'
box = driver.find_element_by_xpath(xpath)
box.send_keys('Dynamic: Conterminous U.S. 2014 (v4.1.1)')
xpath = '//*[#id="input-latitude"]'
box = driver.find_element_by_xpath(xpath)
box.send_keys(Latitude)
xpath = '//*[#id="input-longitude"]'
box = driver.find_element_by_xpath(xpath)
box.send_keys(Longitude)
xpath = '/html/body/main/div/div/section[2]/div/section/ul[1]/li[3]/label/select'
box = driver.find_element_by_xpath(xpath)
if Vs30 == 760:
Site_Class = '760 m/s (B/C boundary)'
else:
Site_Class = '2000 m/s (Site class A)'
box.send_keys(Site_Class)
xpath = '/html/body/main/div/div/section[2]/div/section/ul[2]/li[1]/label/select'
box = driver.find_element_by_xpath(xpath)
if Period == 0:
Spectral_period = 'Peak ground acceleration'
elif Period == 0.2:
Spectral_period = '0.2 sec spectral acceleration'
elif Period == 1.0:
Spectral_period = '1.0 sec spectral acceleration'
else:
Spectral_period = '2.0 sec spectral acceleration'
box.send_keys(Spectral_period)
xpath = '/html/body/main/div/div/section[2]/div/section/ul[2]/li[2]/label/input'
box = driver.find_element_by_xpath(xpath)
box.clear()
box.send_keys(Return_period)
xpath = '/html/body/main/div/div/section[4]/div/section/div[1]/p/button'
btn = driver.find_element_by_xpath(xpath)
btn.click()
xpath = '/html/body/main/div/div/section[4]/div/section/div[1]/p/button'
btn1 = driver.find_element_by_xpath(xpath)
btn1.click()
driver.implicitly_wait(15)
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[1]/dl/dd[3]'
Intensity = driver.find_element_by_xpath(xpath).text
Intensity = float(Intensity[0:-1])
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[4]/dl/dd[1]'
R_mean = driver.find_element_by_xpath(xpath).text
R_mean = float(R_mean[0:-2])
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[4]/dl/dd[2]'
M_mean = driver.find_element_by_xpath(xpath).text
M_mean = float(M_mean)
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[4]/dl/dd[3]'
Epsilon_mean = driver.find_element_by_xpath(xpath).text
Epsilon_mean = float(Epsilon_mean[0:-1])
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[5]/dl/dd[1]'
R_mode = driver.find_element_by_xpath(xpath).text
R_mode = float(R_mode[0:-2])
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[5]/dl/dd[2]'
M_mode = driver.find_element_by_xpath(xpath).text
M_mode = float(M_mode)
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[5]/dl/dd[3]'
Epsilon_mode = driver.find_element_by_xpath(xpath).text
Epsilon_mode = float(Epsilon_mode[0:-1])
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[6]/dl/dd[1]'
R_mode_eps = driver.find_element_by_xpath(xpath).text
R_mode_eps = float(R_mode_eps[0:-2])
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[6]/dl/dd[2]'
M_mode_eps = driver.find_element_by_xpath(xpath).text
M_mode_eps = float(M_mode_eps)
xpath = '/html/body/main/div/div/section[4]/div/section/div[3]/div/div[1]/div[6]/dl/dd[3]'
Epsilon_mode_eps = driver.find_element_by_xpath(xpath).text
Epsilon_mode_eps = float(Epsilon_mode_eps[0:-1])
driver.close()
[Latitude , Longitude , Return_period, Period , Site_Class, Intensity, M_mean , R_mean , Epsilon_mean, M_mode, R_mode, Epsilon_mode, M_mode_eps, R_mode_eps, Epsilon_mode_eps]

ListView not scrolling when items added pro-grammatically

I have a listView which I add a number of buttons to in a for loop. However the listView isn't scrollable even if I set it to be scrollable. I'm not sure why this is happening. I'm simply adding a button every time I enter the for loop however once there is too many buttons to view on the listview no scroll bar appears. My code is as follows.
ListViewTemplates.HeaderStyle = ColumnHeaderStyle.None
For i As Integer = 1 To level3Cat.Count
counter = i Mod 2
If counter = 0 Then
Dim picture As Button = New Button()
picture.Location = New System.Drawing.Point(165, topForNextControl)
picture.Size = New System.Drawing.Size(90, layoutTemplateHeight)
picture.TabStop = False
picture.BackgroundImageLayout = BackgroundImageLayout.Stretch
picture.BackgroundImage = My.Resources.XButton
ListViewTemplates.Controls.Add(picture)
topForNextControl += layoutTemplateHeight + HeighScaleFactor
Else
Dim picture As Button = New Button()
picture.Location = New System.Drawing.Point(35, topForNextControl)
picture.Size = New System.Drawing.Size(90, layoutTemplateHeight)
picture.TabStop = False
picture.BackgroundImageLayout = BackgroundImageLayout.Stretch
picture.BackgroundImage = My.Resources.XButton
ListViewTemplates.Controls.Add(picture)
End If
ListViewTemplates.Scrollable = True
ListViewTemplates.View = View.Details
counter += 1
Next

Remove Bing Maps Pushpins with separate button

currently I can display pushpins onto my Bing Maps but I would simply like to remove them when another button is pressed, in this case I would be calling it BTNReset. This is just to make the maps a little more tidy when it becomes clustered so the user can remove all uneccessary pushpins.
Private Sub Berwickshire() Handles BTNCounty.Click
If TXTCounty.Text = "Berwickshire" Then
Dim CountyLocation(20) As Microsoft.Maps.MapControl.WPF.Location
CountyLocation(0) = New Microsoft.Maps.MapControl.WPF.Location(55.705617, -2.4676497)
CountyLocation(1) = New Microsoft.Maps.MapControl.WPF.Location(55.780619, -2.3413039)
CountyLocation(2) = New Microsoft.Maps.MapControl.WPF.Location(55.720304, -2.2638738)
CountyLocation(3) = New Microsoft.Maps.MapControl.WPF.Location(55.746443, -2.2271899)
CountyLocation(4) = New Microsoft.Maps.MapControl.WPF.Location(55.808939, -2.4924539)
CountyLocation(5) = New Microsoft.Maps.MapControl.WPF.Location(55.882232, -2.3064212)
CountyLocation(6) = New Microsoft.Maps.MapControl.WPF.Location(55.852663, -2.3889276)
CountyLocation(7) = New Microsoft.Maps.MapControl.WPF.Location(55.802325, -2.2096172)
CountyLocation(8) = New Microsoft.Maps.MapControl.WPF.Location(55.651853, -2.252035)
CountyLocation(9) = New Microsoft.Maps.MapControl.WPF.Location(55.690431, -2.3361588)
CountyLocation(10) = New Microsoft.Maps.MapControl.WPF.Location(55.645024, -2.3311619)
CountyLocation(11) = New Microsoft.Maps.MapControl.WPF.Location(55.932739, -2.3614317)
CountyLocation(12) = New Microsoft.Maps.MapControl.WPF.Location(55.870455, -2.0969097)
CountyLocation(13) = New Microsoft.Maps.MapControl.WPF.Location(55.852035, -2.1896638)
CountyLocation(14) = New Microsoft.Maps.MapControl.WPF.Location(55.887334, -2.1601164)
CountyLocation(15) = New Microsoft.Maps.MapControl.WPF.Location(55.841716, -2.1222754)
CountyLocation(16) = New Microsoft.Maps.MapControl.WPF.Location(55.771675, -2.803132)
CountyLocation(17) = New Microsoft.Maps.MapControl.WPF.Location(55.719837, -2.750872)
CountyLocation(18) = New Microsoft.Maps.MapControl.WPF.Location(55.680163, -2.5615687)
CountyLocation(19) = New Microsoft.Maps.MapControl.WPF.Location(55.741492, -2.5838242)
CountyLocation(20) = New Microsoft.Maps.MapControl.WPF.Location(55.637369, -2.6798897)
Dim names = New String() {
"Greenlaw",
"Duns",
"Swinton",
"Whitsome",
"Longformacus",
"Grantshouse",
"Abbey St Bathans",
"Chirnside",
"Coldstream",
"Leitholm",
"Birgham",
"Cockburnspath",
"Eyemouth",
"Reston",
"Coldingham",
"Ayton",
"Oxton",
"Lauder",
"Gordon",
"Westruther",
"Earlston"}
For index = 0 To CountyLocation.Length - 1
Dim Pin = New Microsoft.Maps.MapControl.WPF.Pushpin()
Dim CoordinateTip = New System.Windows.Controls.ToolTip()
CoordinateTip.Content = names(index)
Pin.Location = CountyLocation(index)
Pin.ToolTip = CoordinateTip
BingMap.Children.Add(Pin)
Next
End If
End Sub
You can do BingMap.Children.Clear() to remove all data on the map.

setting label value on checkbox click event in wxPython

On checkbox click event set label as some text. If we click on Text checkbox it should set the label named abt_Metric as Text Collected.
boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
#adding checkBox
c1 = wx.CheckBox(panel, label="Text")
#c1.SetValue(True)
#abt_Metric= wx.StaticText(panel, label='')
#boxsizer.Add(abt_Metric, flag=wx.LEFT|wx.TOP,border=10)
#result.GetValue()
url_entered.SetForegroundColour(wx.BLUE)
c2 = wx.CheckBox(panel, label="HTML ")
#c2.SetValue(True)
c3 = wx.CheckBox(panel, label="NLP")
#c3.SetValue(True)
boxsizer.Add(c1,flag=wx.LEFT|wx.TOP, border=5)
boxsizer.Add(c2,flag=wx.LEFT, border=5)
boxsizer.Add(c3,flag=wx.LEFT|wx.BOTTOM, border=5)
sizer.Add(boxsizer, pos=(6, 0), span=(1, 5),flag=wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT , border=10)
abt_Metric= wx.StaticText(panel, label='')
sizer.Add(abt_Metric, pos=(7, 0), flag=wx.LEFT|wx.TOP,border=10)
Checkbox event handler
c1.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c1),c1)
c2.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c2),c2)
c3.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c3),c3)
Implementation of def OntextMetric(self,e,c)
if c.GetValue() == True:
self.panel.abt_Metric.SetLabel(" Text collected")
elif c.GetValue() == True:
self.panel.abt_Metric.SetLabel("HTML collected")
elif c.GetValue() == True:
self.panel.abt_Metric.SetLabel("NLP Collected")
else:
self.panel.abt_Metric.SetLabel("")
Iam not able to understand your question clearly, but is this what you are looking for?
import wx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.NewId(), "Main")
panel = wx.Panel(self,1)
#sizer = wx.BoxSizer(wx.HORIZONTAL)
boxsizer = wx.BoxSizer(wx.VERTICAL)
c1 = wx.CheckBox(panel, label="Text")
c2 = wx.CheckBox(panel, label="HTML ")
c3 = wx.CheckBox(panel, label="NLP")
c1.Bind(wx.EVT_CHECKBOX, self.OntextMetric, c1)
c2.Bind(wx.EVT_CHECKBOX, self.OntextMetric,c2)
c3.Bind(wx.EVT_CHECKBOX, self.OntextMetric,c3)
self.abt_Metric= wx.StaticText(panel, label='')
boxsizer.Add(c1,flag=wx.LEFT, border=5)
boxsizer.Add(c2,flag=wx.LEFT, border=5)
boxsizer.Add(c3,flag=wx.LEFT, border=5)
boxsizer.Add(self.abt_Metric, flag = wx.LEFT)
panel.SetSizer(boxsizer)
def OntextMetric(self,event):
if event.IsChecked():
self.abt_Metric.SetLabel(event.GetEventObject().GetLabel() + "collected")
class MyApp(wx.App):
def OnInit(self):
frame = MainFrame()
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()

StageText - How to use more than 1 StageText field?

I'm using Flash CS 6 and Air 3.6 to build an Android app.
I would like to use StageText for the input fields.
The code below is only working for the first textfield. What do I need change to make it work for both text fields?
// NO. 1
var firstfield:StageText = new StageText();
firstfield.softKeyboardType = SoftKeyboardType.DEFAULT
firstfield.stage = foobar.stage
firstfield.viewPort = new Rectangle(foobar.x, foobar.y, foobar.width, foobar.height);
// NO. 2
var secondfield:StageText = new StageText();
secondfield.softKeyboardType = SoftKeyboardType.DEFAULT
secondfield.stage = example.stage
secondfield.viewPort = new Rectangle(example.x, example.y, example.width, example.height);
Try something like this:
var firstfield:StageText = new StageText();
firstfield.softKeyboardType = SoftKeyboardType.DEFAULT
firstfield.stage = this.stage;
firstfield.viewPort = new Rectangle(0, 0, 200, 30);
firstfield.x = 0;
firstfield.y = 0;
firstfield.width = 200;
firstfield.height = 30;
addChild(firstfield);
var secondfield:StageText = new StageText();
secondfield.softKeyboardType = SoftKeyboardType.DEFAULT
secondfield.stage = this.stage;
secondfield.viewPort = new Rectangle(0, 40, 200, 30);
secondfield.x = 0;
secondfield.y = 40;
secondfield.width = 200;
secondfield.height = 30;
addChild(secondfield);

Resources