I am running a code with PYSIMPLEGUI, and I have followed all the instructions to set application icon but it seems to be not working, instead the the icon I see is python,
any suggestions?
below is my code:
###################### GUI
sg.theme('LightGrey1')
layout = [
[sg.Text("Input Serial:")],
[sg.Multiline(enter_submits=False,key='serial',size=(13,20))], # serial numbers
[sg.Text("Name outfile file:"),sg.Input(key='filename')],
[sg.CalendarButton("Date From:", format=('%m/%d/%Y')),sg.Input(key='datefrom',size=10)],
[sg.CalendarButton("Date To:",format=('%m/%d/%Y')),sg.Input(key='dateto',size=10)], # date from
[sg.FolderBrowse(button_text="Select Folder",key='file_save_path'),sg.Button("Save File")],# file name input
[sg.Button('Copy Command',button_color='#097969'), sg.Button('Exit',button_color='#9A2A2A')],
]
window = sg.Window('Name of Application',icon='interstate.ico',layout=layout)
window()
while True:
event, values = window.read()
print(event, values) # runs the window
if event in (None, 'Exit'):
break # if exit breaks
if event == 'Copy Command':
mile_state_command()
if event =="Save File":
file_creator()
'''
if event =='Copy':
copy()
'''
window.close()
Answer, I reserached but could not find
Related
The following code works fine ONLY when I look at the Web page (aka the Chrome tab being manipulated by Selenium).
Is there a way to make it work even when I'm browsing another tab/window?
(I wonder how the website knows I'm actually looking at the web page or not...)
#This is a job website in Japanese
login_url = "https://mypage.levtech.jp/"
driver = selenium.webdriver.Chrome("./chromedriver")
#Account and password are required to log in.
#I logged in and got to the following page, which displays a list of companies that I have applied for:
#https://mypage.levtech.jp/recruits/screening
#Dictionary to store company names and their job postings
jobs = {}
for i, company in enumerate(company_names):
time.sleep(1)
element = driver.find_elements_by_class_name("ScreeningRecruits_ListItem")[i]
while element.text == "":
#While loops and time.sleep() are there because the webpage seems to take a while to load
time.sleep(0.1)
element = driver.find_elements_by_class_name("ScreeningRecruits_ListItem")[i]
td = element.find_element_by_tag_name("td")
while td.text == "":
time.sleep(0.1)
td = element.find_element_by_tag_name("td")
if td.text == company:
td.click()
time.sleep(1)
jobs[company] = get_job_desc(driver) #The get_job_desc function checks HTML tags and extract info from certain elements
time.sleep(1)
driver.back()
time.sleep(1)
print(jobs)
By the way, I have tried adding a user agent and scroll down the page using the following code, in the hope that the Web page would believe that I'm "looking at it." Well, I failed :(
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
So, I think the answer to your question is due to window_handles. Whenever we open a new tab, Selenium changes the window's focus on us ( obviously ). Because the focus is on another page, we need to use the driver.switch_to.window(handle_here) method. This way, we can switch to our proper tab. In order to do this, I found a website that has a similar functionality ( also in Japanese / Kanji? ) that might help you out.
MAIN PROGRAM - For Reference
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver as ChromeDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as DriverWait
from selenium.webdriver.support import expected_conditions as DriverConditions
from selenium.common.exceptions import WebDriverException
import time
def get_chrome_driver():
"""This sets up our Chrome Driver and returns it as an object"""
path_to_chrome = "F:\Selenium_Drivers\Windows_Chrome85_Driver\chromedriver.exe"
chrome_options = webdriver.ChromeOptions()
# Browser is displayed in a custom window size
chrome_options.add_argument("window-size=1500,1000")
return webdriver.Chrome(executable_path = path_to_chrome,
options = chrome_options)
def wait_displayed(driver : ChromeDriver, xpath: str, int = 5):
try:
DriverWait(driver, int).until(
DriverConditions.presence_of_element_located(locator = (By.XPATH, xpath))
)
except:
raise WebDriverException(f'Timeout: Failed to find {xpath}')
# Gets our chrome driver and opens our site
chrome_driver = get_chrome_driver()
chrome_driver.get("https://freelance.levtech.jp/project/search/?keyword=&srchbtn=top_search")
wait_displayed(chrome_driver, "//div[#class='l-contentWrap']//ul[#class='asideCta']")
wait_displayed(chrome_driver, "//div[#class='l-main']//ul[#class='prjList']")
wait_displayed(chrome_driver, "//div[#class='l-main']//ul[#class='prjList']//li[contains(#class, 'prjList__item')][1]")
# Click on the first item title link
titleLinkXpath = "(//div[#class='l-main']//ul[#class='prjList']//li[contains(#class, 'prjList__item')][1]//a[contains(#href, '/project/detail/')])[1]"
chrome_driver.find_element(By.XPATH, titleLinkXpath).click()
time.sleep(2)
# Get the currently displayed window handles
tabs_open = chrome_driver.window_handles
if tabs_open.__len__() != 2:
raise Exception("Failed to click on our Link's Header")
else:
print(f'You have: {tabs_open.__len__()} tabs open')
# Switch to the 2nd tab and then close it
chrome_driver.switch_to.window(tabs_open[1])
chrome_driver.close()
# Check how many tabs we have open
tabs_open = chrome_driver.window_handles
if tabs_open.__len__() != 1:
raise Exception("Failed to close our 2nd tab")
else:
print(f'You have: {tabs_open.__len__()} tabs open')
# Switch back to our main tab
chrome_driver.switch_to.window(tabs_open[0])
chrome_driver.quit()
chrome_driver.service.stop()
For scrolling, you could use this method
def scroll_to_element(driver : ChromeDriver, xpath : str, int = 5):
try:
webElement = DriverWait(driver, int).until(
DriverConditions.presence_of_element_located(locator = (By.XPATH, xpath))
)
driver.execute_script("arguments[0].scrollIntoView();", webElement)
except:
raise WebDriverException(f'Timeout: Failed to find element using xpath {xpath}\nResult: Could not scroll')
I'm writing a simple Automator script in Javascript.
I want to send a key-code(or key-storke) to an OS X application that is not in front.
Basically, I want to run this code and do my things while the script opens a certain application, write text, and hit enter - all of this without bothering my other work.
I want something like this:
Application("System Events").processes['someApp'].windows[0].textFields[0].keyCode(76);
In Script Dictionary, there is keyCode method under Processes Suite.
The above code, however, throws an error that follows:
execution error: Error on line 16: Error: Named parameters must be passed as an object. (-2700)
I understand that the following code works fine, but it require the application to be running in front:
// KeyCode 76 => "Enter"
Application("System Events").keyCode(76);
UPDATE: I'm trying to search something on iTunes(Apple Music). Is this possible without bringing iTunes app upfront?
It's possible to write text in application that is not in front with the help of the GUI Scripting (accessibility), but :
You need to know what UI elements are in the window of your specific
application, and to know the attributes and properties of the
specific element.
You need to add your script in the System Preferences --> Security
& Privacy --> Accessibility.
Here's a sample script (tested on macOS Sierra) to write some text at the position of the cursor in the front document of the "TextEdit" application.
Application("System Events").processes['TextEdit'].windows[0].scrollAreas[0].textAreas[0].attributes["AXSelectedText"].value = "some text" + "\r" // r is the return KEY
Update
To send some key code to a background application, you can use the CGEventPostToPid() method of the Carbon framework.
Here's the script to search some text in iTunes (Works on my computer, macOS Sierra and iTunes Version 10.6.2).
ObjC.import('Carbon')
iPid = Application("System Events").processes['iTunes'].unixId()
searchField = Application("System Events").processes['iTunes'].windows[0].textFields[0]
searchField.buttons[0].actions['AXPress'].perform()
delay(0.1) // increase it, if no search
searchField.focused = true
delay(0.3) // increase it, if no search
searchField.value = "world" // the searching text
searchField.actions["AXConfirm"].perform()
delay(0.1) // increase it, if no search
// ** carbon methods to send the enter key to a background application ***
enterDown = $.CGEventCreateKeyboardEvent($(), 76, true);
enterUp = $.CGEventCreateKeyboardEvent($(), 76, false);
$.CGEventPostToPid(iPid, enterDown);
delay(0.1)
$.CGEventPostToPid(iPid, enterUp);
I am writing an AutoHotkey script to enter data into an Oracle PeopleSoft application. Rather than trying to locate specific elements on the page, I want to try execute JavaScript commands directly instead.
So instead of using a hardcoded MouseClick, left, 205, 281 to click the "Add New Values" button, I want to directly run submitAction_win0(document.win0,'#ICSwitchMode')
I've tried entering commands directly into the address bar, but this doesn't seem to have any effect.
#k::
jsCommand = javascript:submitAction_win0(document.win0,'#ICSwitchMode');
Send, !d ; places cursor in URL field
Send, %jsCommand%{Enter} ; submit JS command (doesn't work)
Return
According to this AHK thread, it should be possible to accomplish this using a ScriptControl object, but I'm a bit unsure how to use them.
How can I execute JavaScript commands using AutoHotkey?
Per an example I used in a previous question's answer for controlling IE, walking the DOM, etc:
F3::
wb := ComObjCreate("InternetExplorer.Application") ; Create a IE instance
wb.Visible := True
wb.Navigate("http://google.com")
Sleep, 5000
SendInput, This is test.{Enter}
Sleep, 5000
wb.document.getElementById("lst-ib").value := "This is another test."
wb.document.getElementById("_fZl").click()
return
I have a ASP.net user control with the below CKEditor
<%# Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
<CKEditor:CKEditorControl ID="txtHtmlText" BasePath="~/Scripts/ckeditor/"
Toolbar="Bold|Italic|Underline|Strike|Subscript|Superscript|- |TextColor|BGColor|Font|FontSize
JustifyLeft|JustifyCenter|JustifyRight|Justify|-|Outdent|Indent|- |NumberedList|BulletedList
Cut|Copy|Paste|PasteText|PasteFromWord|-|HorizontalRule|Link|Unlink|- |Source|About"runat="server"></CKEditor:CKEditorControl>
I'm trying to override word count limit defined in config.js of CKEditor. I used the below code int the .ascx file and is getting the Error
"Uncaught ReferenceError: CKEDITOR is not defined". Please help
<script type="text/javascript">
CKEDITOR.replace('txtHtmlText',
{
wordcount: {
// Whether or not you want to show the Paragraphs Count
showParagraphs: false,
// Whether or not you want to show the Word Count
showWordCount: false,
// Whether or not you want to show the Char Count
showCharCount: true,
// Whether or not you want to count Spaces as Chars
countSpacesAsChars: false,
// Whether or not to include Html chars in the Char Count
countHTML: false,
// Maximum allowed Word Count, -1 is default for unlimited
maxWordCount: 500,
// Maximum allowed Char Count, -1 is default for unlimited
maxCharCount: 500
}
});
</script>
I tried today for my requirement and I was able to successfully add the feature.
If I would have been in your place, I would have checked couple of things
Is the reference to CKEditor is added (I know its obvious)
Add extraPlugins : 'wordcount', just above wordcount: {
Check developer console for any further investigation.
This link helped me solve my problem # https://github.com/w8tcha/CKEditor-WordCount-Plugin/blob/master/wordcount/samples/wordcountWithMaxCount.html
#Vinayak Prabha,
Try as suggested by Vikram. However a question ?
CKEditor ID "txtHtmlText" is server id, if you have to use in java script you should use client Id.
Try like this
var ckEditorClientID = "#<%=txtHtmlText.ClientID %>";
CKEDITOR.replace(ckEditorClientID,
I'm using Visual Studio 2003. In debug mode, whenever I add a break point in my javascript (js) file, the file then becomes locked so that it can't be edited.
Closing the tab and reopening it seems to unlock it.
What I'd like to know is: why does this happen and is there some kind of setting that would prevent this from happening?
I think this is by design. When you hit a breakpoint Visual Studio shows a copy of the actual file. You cannot edit it during debugging.
Found this macro which automatically closes and reopens the js page you are on, and moves the cursor back to the line you are on. Hope it comes in useful to someone.
Imports EnvDTE
Imports System.Diagnostics
Public Module AllowJSModify
Sub ReOpenWindow()
Try
'get line no
Dim objCursorTxtPoint As EnvDTE.TextPoint = GetCursorTxtPnt()
Dim intLine As Integer = objCursorTxtPoint.Line
'get current filename
Dim strActiveWindow = DTE.ActiveWindow.Document.FullName
'close open file (auto-save)
DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesYes)
're-open file
Dim item As EnvDTE.ProjectItem = DTE.Solution.FindProjectItem(strActiveWindow)
item.Open()
item.Document.Activate()
'go to prev line no
DTE.ActiveDocument.Selection.GotoLine(intLine)
Catch ex As System.Exception
MsgBox("You are not focused on a line of code.", MsgBoxStyle.Critical, "Error")
End Try
End Sub
Private Function GetCursorTxtPnt() As EnvDTE.TextPoint
Dim objTextDocument As EnvDTE.TextDocument
Dim objCursorTxtPoint As EnvDTE.TextPoint
Try
objTextDocument = CType(DTE.ActiveDocument.Object, EnvDTE.TextDocument)
objCursorTxtPoint = objTextDocument.Selection.ActivePoint()
Catch ex As System.Exception
End Try
Return objCursorTxtPoint
End Function
End Module