python GTK webview not reloading HTML file - python

using python Im trying to open my HTML file.
parallel Im loading data to my HTML but it is not reflecting in GTK webkit.
but GTK web view is not loading the runtime data but.
we have option to load data
map_webview.is_controlled_by_automation()
but is is not refreshing the page. any alternate option to refresh the webkit with new data.
below is my Code
self.map_window = self.builder.get_object("map_window")
self.map_webview = self.builder.get_object("webkit")
# self.map_window.fullscreen()
#self.map_webview = WebKit2.WebView()
self.data_file = "file://" + os.getcwd() + "/TrainMap/steptracker.html"
self.map_webview.load_uri(self.data_file)
# self.map_window.add(self.map_webview)
self.map_window.show_all()
self.map_webview.is_controlled_by_automation()

issue is resolved
used another approach(Pycario) to develop the web-view

Related

Progress bar for Python Script in HTML

I've been working on a project running an NMAP scan in a web app using flask and displaying the results back to the UI. The NMAP scan seems to take a while to run. Can anyone tell me how I can add a progress bar to the HTML UI?
The script I am running Discovery1.py
import nmap
import pandas as pd
ns = nmap.PortScanner()
ns.scan('10.0.0.0/24')
print(ns._scan_result)
print(ns.csv(),file=open('results.csv','w'))
df = pd.read_csv("results.csv", delimiter=";")
df.to_csv("results.csv", index=None)
And the section of the HTML page Network.html cannot be displayed here for some odd reason. How can I achieve this and display in the HTML page.

Python: How to open map created with folium in browser when running application

I have a very small application written in PyCharm using python3:
import folium
map = folium.Map(location=[58.1, 23.3], zoom_start=10)
map.save('map2.html')
This will create a map2.html which I can access in my browser by using pycharm and the url looks like: http://localhost:63342/iss-country/map2.html?_ijt=dcsefdg8om4ddfovlt5ooq6ro5
How can I automatically open this in my browser? So when I run the application it does not only generate the html page but also visits it immediatley. I found the webbrowser module which can be useful but how do I know the correct localhost url?
I don't see the issue with using the webbrowser module. Just make the file name and path a variable and call the webbrowser open method.
output_file = "map2.html"
map = folium.Map(location=[58.1, 23.3], zoom_start=10)
map.save(output_file)
webbrowser.open(output_file, new=2) # open in new tab

python webdriver os window

I need to upload a file using Python and Selenium. When I click the upload HTML element a "File Upload" window is opened and the click() method does not return since it waits to fully load the page. Therefore I cannot continue using pywinauto code to control the window.
The first method clicks the HTML element (an img) to upload a new file:
def add_file(self):
return self.selenium.find_element(By.ID, "add_file").click()
and the second method is using pywinauto to type the path to the file and then click open
def upload(self):
from pywinauto import application
app = application.Application()
app.connect_(title_re = "File Upload")
app.file_upload.TypeKeys("C:\\Path\\To\\FIle")
app.file_upload.Open.Click()
How can I force add_file method to return and to be able to run the upload method?
Solve it. There was an iframe dealing with the upload but was hidden and didn't see it in the first place. The iframe contains an input of type file also hidden. To solve it make the iframe visible using javascript:
selenium.execute_script("document.getElementById('iframe_id').style.display = 'block';")
then switch to the iframe and make the input visible also:
selenium.switch_to_frame(0)
selenium.execute_script("document.getElementById('input_field_id').type = 'visible';")
and simply send the path to the input:
selenium.find_element(By.ID, 'input_field_id').send_keys("path\\\\to\\\\file")
For windows use 4 '\\\\' as path separator.

Automating acrobat using Python pywinauto

I tried to open a pdf file and save it as xml1.0 using pywinauto. i have started writting the below code but i am not able to find the controls for menu and saving it as xml. i am new to pywinauto. can you help me in this. and also please suggest where can i get the tutorial for python pywinauto.
from pywinauto import application
In_File = "sample.pdf"
Ap = "C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe"
app = application.Application()
app.start_(Ap)
app.
Thanks
Here is an example for Adobe Reader X
import pywinauto
pwa_app = pywinauto.application.Application()
w_handle = pywinauto.findwindows.find_windows(title=u'Adobe Reader', class_name='AcrobatSDIWindow')[0]
window = pwa_app.window_(handle=w_handle)
window.MenuItem(u'&File->#0').Click()
By the way am the author of GUI tool for pywinauto - SWAPY. It can generate some code.
I hope it would help your automation.

How to load user CSS in a WebKit WebView using PyObjC?

I'd like to have a small browser that uses my own CSS.
The problem is that CSS is not loaded or, I guess, it loads but without any effect.
Here is the full code (I don't use an Interface Builder):
import Foundation
import WebKit
import AppKit
import objc
def main():
app = AppKit.NSApplication.sharedApplication()
rect = Foundation.NSMakeRect(100,350,600,800)
win = AppKit.NSWindow.alloc()
win.initWithContentRect_styleMask_backing_defer_(rect, AppKit.NSTitledWindowMask | AppKit.NSClosableWindowMask | AppKit.NSResizableWindowMask | AppKit.NSMiniaturizableWindowMask, AppKit.NSBackingStoreBuffered, False)
win.display()
win.orderFrontRegardless()
webview = WebKit.WebView.alloc()
webview.initWithFrame_(rect)
webview.preferences().setUserStyleSheetEnabled_(objc.YES)
print webview.preferences().userStyleSheetEnabled()
cssurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/user.css")
webview.preferences().setUserStyleSheetLocation_(cssurl)
print webview.preferences().userStyleSheetLocation()
pageurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/index.html")
req = Foundation.NSURLRequest.requestWithURL_(pageurl)
webview.mainFrame().loadRequest_(req)
win.setContentView_(webview)
app.run()
if __name__ == '__main__':
main()
The code runs without errors. Prints
True
http://dev.stanpol.ru/user.css
but there is no effect of my CSS in the WebView.
I tried different solutions like adding a link to the DOM:
pageurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/index.html")
req = Foundation.NSURLRequest.requestWithURL_(pageurl)
webview.mainFrame().loadRequest_(req)
dom = webview.mainFrame().DOMDocument()
link = dom.createElement_("link")
link.setAttribute_value_("rel", "StyleSheet")
link.setAttribute_value_("type", "text/css")
link.setAttribute_value_("href", "http://dev.stanpol.ru/user.css")
head = dom.getElementsByTagName_(u"head")
hf = head.item_(0)
hf.appendChild_(link)
but in either case it doesn't work.
I don't want to use javascript to load CSS.
Can anybody tell me what's wrong with setting user CSS in my code?
Apple doesn't properly document that setUserStyleSheetLocation can only be a local path or data: URL. Qt does explain this in their documentation of the corresponding setting in QtWebKit:
http://doc.qt.nokia.com/latest/qwebsettings.html#setUserStyleSheetUrl
Specifies the location of a user stylesheet to load with every web
page.
The location must be either a path on the local filesystem, or a
data URL with UTF-8 and Base64 encoded data, such as:
"data:text/css;charset=utf-8;base64,cCB7IGJhY2tncm91bmQtY29sb3I6IHJlZCB9Ow=="
Note: If the base64 data is not valid, the style will not be applied.

Categories