Continually check process and show Button/TextBox - if-statement

I am attempting to create a form using VB.Net that checks if the IExplorer process is running and then display a RichTextBox (which advises the user to close IE) is the process = 1 and a Button to proceed to the next form if the process = 0.
That's the easy part, the hard part is that if the process was = 0 when the form was loaded then the user opens IE, I want to remove the button and show the RichTextBox (which advises the user to close IE) and once again if they close IE the Button reappears.
I have the button and RichTextBox in the form_load with an If statement that shows depending on IE being open or not, but i cannot get them to swap over if IE is closed or opened, any help will be greatly appreciated.
Here is the code I have in the Form_load for the RTB and Button
aProc = Process.GetProcessesByName("iexplore")
If aProc.Length = 0 Then
Dim b1 As New Button
b1.Location = New System.Drawing.Point(274, 244)
b1.Name = "btnOK"
b1.Size = New System.Drawing.Size(75, 29)
b1.TabIndex = 5
b1.Text = "OK"
b1.UseVisualStyleBackColor = False
Me.Controls.Add(b1)
AddHandler b1.Click, AddressOf btn_OK
Else
Dim t1 As New RichTextBox
t1.Location = New System.Drawing.Point(170, 233)
t1.Name = "rtbMessage2"
t1.ReadOnly = True
t1.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
t1.Size = New System.Drawing.Size(293, 40)
t1.TabIndex = 5
t1.Text = ("Internet Explorer is Running - Please Close Internet Explorer to Continue")
Me.Controls.Add(t1)
AddHandler t1.Click, AddressOf btn_OK
End If

Two changes I would make:
Add a timer that continually calls the logic (show/hide the Button/RichTextBox)
Make the Button and RichTextBox always there, but initially invisible.
To do this, I would (on load) create the Button and RichTextBox with .Visible = false. Then create a timer that runs every 500 milliseconds (+/-). That timer would call a function that contains the logic you have above. However, instead of creating the controls (with that logic) just reference them and set their visibility.
In essence, create the controls once, run the logic multiple times.

Related

button always return the last ID, not the correct one

I'm creating a menu in gaffer that populate automatically from a string list called "shotlist"
the idea is to have a custom menu for each entry of the list and have an action relative to each entry too, like :
click on sh001 = sh001
click on sh002 = sh002
click on sh003 = sh003
my problem is that my code return :
click on sh001 = sh003
click on sh002 = sh003
click on sh003 = sh003
I understand that when I click on a button, it always return the 3rd value of "shotlist", as it's the last one than the loop worked on, but I dont understand how to set the loop differently to have the right result
actually my code is :
def shotSelection( menu ):
shotVar=str(shotName)
print shotName
scriptWindow = menu.ancestor( GafferUI.ScriptWindow )
root = scriptWindow.scriptNode()
root["variables"]["projectshot"]["value"].setValue( shotVar )
root=application.root()
shotlist=["sh001","sh002","sh003"]
for shotName in shotlist:
GafferUI.ScriptWindow.menuDefinition(application).append("/Pipeline/ShotSwitcher/{0}".format(shotName), { "command" : shotSelection } )
I have also tried with the method described here but i dont understand well enough how it's work to apply it to my script.
the menu creation part from gaffer works well. but I dont found a way to set up my menu from the list and have the right action on it at the same time
thank you
EDIT:
actually I found the problem but not sure how to fix it
GafferUI.ScriptWindow.menuDefinition(application).append("/Pipeline/ShotSwitcher/{0}".format(shotName), { "command" : shotSelection }
shotSelection does not transmit any info of the shot clicked on
i fixed my issue with functools(), allowing to transmit the value in each loop

[Python2.7 TKinter]How to gray out a option in optionmenu that has been selected by older instances?

Here's my code:
class DefaultServiceClassWidget(ServiceClassWidget):
def __init__(self, mpet_widget, sc_data, idx):
super(DefaultServiceClassWidget, self).__init__(mpet_widget, sc_data, idx, DefaultServiceClassRow.number)
delete_default_sc_button = Button(mpet_widget.listFrame,justify=LEFT,text="x",fg="red",command= lambda: mpet_widget.delete_sc(self.idx))
delete_default_sc_button.grid(column=4,row=DefaultServiceClassRow.number)
self.select_default_class_label = Label(mpet_widget.listFrame,anchor=W,justify=LEFT,text="Select a Class")
self.select_default_class_label.grid(column=0,row=DefaultServiceClassRow.number)
options = ["All","CS Registration","GPRS Attach","PDP Activation","SMS","Reset","USSD","LTE"]
self.menu_pick_a_class = OptionMenu(mpet_widget.listFrame, sc_data.get_name(), *options, command=lambda event: sc_data.set_id())
self.menu_pick_a_class.grid(column=1,row=DefaultServiceClassRow.number)
self.row = DefaultServiceClassRow.number
DefaultServiceClassRow.number = DefaultServiceClassRow.number+2
def delete(self):
DefaultServiceClassRow.number = DefaultServiceClassRow.number - 2
default_list = (list(self.mpet_widget.listFrame.grid_slaves(row=self.row)) +
list(self.mpet_widget.listFrame.grid_slaves(row=self.row+1)))
for l in default_list:
l.grid_remove()
What happens is that there's a button connected to this function, every time the button is clicked, this function gets called and created a new grid on the GUI. What I want is that if for example "SMS" in optionmenu is selected, the next time this function gets called, "SMS" option will be grayed out (i.e. each option can be only selected once in the program)
I've tried updating status of the selected option by using status = "disabled" but it only works for the same grid, once a new grid(instance) is created, everything gets reset and all the options became available again :(
Also, in the same grid, if I disabled an option by selecting it and then changed to something else, the original selection is still grayed and cannot be selected again - I know why this happens but how do I fix it?
Sorry for the long question but I can't seem to find a solution online :(
Thank you in advance!

Clicking the links having same link text in a loop using Seleneium webdriver in Python

I am using following code to scroll the page and follow the users on quora (Link to the page : http://www.quora.com/Kevin-Rose/followers), certain number of users are loaded after scrolling down, i am using the code given below :
# find all the follow buttons that are loaded
button = driver.find_elements_by_xpath("//a[contains(text(), 'Follow')]")
#number of users loaded
no_of_followers = len(button)
#execute the code till all the users are followed
while(no_of_followers > 0):
count = 0
#follow all the users loaded by clicking follow button in a loop
while(count < no_of_followers):
button[count].click()
time.sleep(30)
print count
count = count + 1
#scroll down
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(30)'
#find newly loaded users
button = driver.find_elements_by_xpath("//a[contains(text(), 'Follow')]")
time.sleep(30)
#tracking no of users left unfollowed
no_of_followers = len(button)
I am getting following error:
StaleElementReferenceException: Message: u'Element is no longer attached to the DOM' ; Stacktrace:
Edit 1: I tried using find_element_by_link _text, but apparently output object of the function is not a list of links which can be iterated.
The possible problem is # button[count].click().
I suggest you to use a for loop instead of while and increament that with an iterator.
Do something like
//you basically need to click on the first item all the time. The iterator should only control the number of iteration
Driver.FindElement(By.Xpath("Your Xpath")).Click();
Sorry, not an expert on python.

Tkinter bind executes immediately when script is run

I've laid out a frame, part of which is:
ticketID = IntVar()
ticketID.set(ticket)
ticketfield = Label(titleframe, text = 'Ticket : ')
ticketfield.grid(row=0, column=0)
ticketfieldentry = Entry(titleframe, textvariable=ticketID)
ticketfieldentry.grid(row=0, column=1)
ticketfieldentry.bind("<Double-Button-1>", searchforticket(ticketfieldentry.get()))
And a placeholder:
def searchforticket(ticket):
searchforstring = "This would search for ticket %s" % ticket
tkMessageBox.showinfo('Search by ticket', message = searchforstring)
Ticket is passed to the script at run time, or is assumed None. What I thought the above would do is create an Entry box that would display the ticket number, or could have one entered directly. After being entered, double clicking would bring up the searchforticket function.
However, when I run the script, searchforticket is run immediately, with whatever is being assigned to ticket and then after I click past the tkMessageBox is when the window containing the ticketfieldentry and everything else renders.
I am not seeing at all what could be causing this, but I assume it is something dead obvious to someone else.
searchforticket(ticketfieldentry.get() cause immediate call. Change as follow:
ticketfieldentry.bind("<Double-Button-1>", lambda e: searchforticket(ticketfieldentry.get()))

how to clear textbox text in C++/XAML

im new to C++/XAML, using VS2012, working on my first Windows 8 app.
I have created a textbox1 that take a number, another textbox2 that display the results, another button that once it is clicked, it does the calculation. everything works, my question is when user want to do the calculation again, he will need to click on textbox1, press the backspace to erased the last entered number, how can i make it when textbox1 is clicked and tapped, it will auto clear the previously entered text? or how do i use/make a "CLEAR" button to handle the text clearing for textbox1 and textbox2? Thank You!
With button:
<Button Content="Clear" Name="button1" Click="button1_Click" />
Code behind:
void YourClass::button1_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ args)
{
textBox1->Text = "";
textBox2->Text = "";
}
If you want to use some logic when you tap or something else you should take a look at Tapped event. I'd do it another way: Whenever it got focus(GotFocus event) then select all the text in text box(textBox1->SelectAll(); in GotEvent handler).
You can use
SetWindowText is a function to set the contents of a Edit Control
m_myEditCtrl.SetWindowText(_T("")); // if using MFC
SetWindowText(hWndMyEditCtrl,_T("")); // When using plain Win32 API
myEditCtrl.Text = ""; // When using C++CLI
You can use it from the "On Click" handler also if needed!
I think that could be useful, if you just add in the end of the program that apply to your textboxes a new button with:
textBox2->Text = String::Empty;
textBox1->Text = String::Empty;
OR
…you could add these code lines before start the procedure of the program, just in the beginning of the program. Each time it would start over with blank.
Cheers.