I'm using Flet and I want for my app to launch a link when clicking on a button.
According to the docs, I can use launch_url method. But when I tried, I got the following error:
Exception in thread Thread-6 (open_repo):
Traceback (most recent call last):
File "C:\Users\Iqmal\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\Users\Iqmal\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "d:\Iqmal\Documents\Python Projects\flet-hello\main.py", line 58, in open_repo
ft.page.launch_url('https://github.com/iqfareez/flet-hello')
^^^^^^^^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'launch_url'
Code
import flet as ft
def main(page: ft.Page):
page.padding = ft.Padding(20, 35, 20, 20)
page.theme_mode = ft.ThemeMode.LIGHT
appbar = ft.AppBar(
title=ft.Text(value="Flutter using Flet"),
bgcolor=ft.colors.BLUE,
color=ft.colors.WHITE,
actions=[ft.IconButton(icon=ft.icons.CODE, on_click=open_repo)])
page.controls.append(appbar)
page.update()
def open_repo(e):
ft.page.launch_url('https://github.com/iqfareez/flet-hello')
ft.app(target=main, assets_dir='assets')
I 'solved' this issue by moving the open_repo() function inside the main() function block. Now, the link can be opened on a browser when clicked. Example:
def main(page: ft.Page):
def open_repo(e):
page.launch_url('https://github.com/iqfareez/flet-hello')
appbar = ft.AppBar(
title=ft.Text(value="Flutter using Flet"),
bgcolor=ft.colors.BLUE,
color=ft.colors.WHITE,
actions=[ft.IconButton(icon=ft.icons.CODE, on_click=open_repo)])
# code truncated for clarity
Full code here.
From what I'm seeing here and the errors you're getting it's just possible you might have a problem with the installation of Flet. Try installing running in a virtual environment and see if it changes.
Good Luck
Related
I am making a program that will allow my phone to share its clipboard with my PC. I am using Pyperclip as it appears to be the easiest and most cross-platform solution. However, when I run the code below:
...
elif "incoming_clipboard:" in server_command:
print(server_command)
pyperclip.copy(server_command.replace("incoming_clipboard: ", ""))
...
I get the error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "/home/chris/Documents/Programming/Synchrony/Desktop/Phone.py", line 30, in do_sync
self.handle_commands(bluetooth_socket)
File "/home/chris/Documents/Programming/Synchrony/Desktop/Phone.py", line 65, in handle_commands
pyperclip.copy(server_command.replace("incoming_clipboard: ", ""))
File "/usr/lib/python3.9/site-packages/pyperclip/__init__.py", line 659, in lazy_load_stub_copy
return copy(text)
File "/usr/lib/python3.9/site-packages/pyperclip/__init__.py", line 158, in copy_gtk
cb = gtk.Clipboard()
File "/usr/lib/python3.9/site-packages/gi/__init__.py", line 69, in __getattr__
raise AttributeError(_static_binding_error)
AttributeError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183
I know its not due to the string being invalid or anything, because 1) I am explicitly converting it from bytes to a string, and 2) it prints perfectly fine. I don't know if this is relevant, but I am using Linux, so perhaps that is affecting Pyperclip?
Do you guys have any solutions?
https://github.com/dynobo/normcap/issues/100
After going to the Github page for PyperClip, I found a similar issue that someone else had that suggested switching to PyClip. After installing PyClip and implementing it in project, I can confirm that it works perfectly without any issues.
After searching I am not able to find a good response:
I am trying to automate company software using pywinauto. I try to use app.print_control_identifiers() wherever possible. And it has been a God send! Thanks to folks on Youtube and Vasily's posts. See code below.
During the install, it wants to install a MS VC++ redistributable and I can handle that.
The next issue is telling me that the version of Adobe Flash Player (I know right?) is incompatible. I have used Inspect to ID the OK button I need to click to move on. Here is the code (cleaned up for public consumption):
from pywinauto.application import Application
import time
app = Application(backend="uia").start("C:\\Users\\me\\program.exe")
time.sleep(5)
#This addresses the need to install Microsoft C++ Redistributable
dlg = app['program - InstallShield Wizard']
dlg.Install.click()
time.sleep(5)
#This is to get past an install failure and to move on
dlg.Yes.click()
time.sleep(10)
#This is a dialog box saying that some component is incompatible and this is where I am stuck
# And the window title now just says 'program' vs. 'program - InstallShield Wizard'
new_dlg = app['program']
new_dlg.OK.click()
Here is the failure info:
C:\Python37\python.exe C:/Users/me/PycharmProjects/myProject/pywinauto_install.py
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 258, in __resolve_control
criteria)
File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/me/PycharmProjects/myProject/pywinauto_install.py", line 23, in <module>
new_dlg.OK.click()
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
raise e.original_exception
File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 203, in __get_ctrl
dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'best_match': 'program', 'backend': 'uia', 'process': 22184}
Process finished with exit code 1
I am creating new_dlg based on an SO post I saw, so if this is wrong, please slap my hand. I am not a trained developer.
Thanks
To check texts of the top level dialog windows print this:
print([w.window_text() for w in app.windows()])
Then just copy the correct one to your code as a dict key instead of app['program']. More flexible way looks so:
new_dlg = app.window(title_re="Program - .*")
I recently tried to automate a windows application using a pywinauto since it enables automation with using python. I just started it and encountered a problem which hinders me to continue.
I get this error whenever I try to find the relevant element:
Traceback (most recent call last):
File "test.py", line 14, in <module>
app.findwindows.find_elements().click_input()
File "C:\Users\Bar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywinauto\application.py", line 173, in __call__
format(self.criteria[-1]['best_match']))
AttributeError: WindowSpecification class has no 'find_elements' method
This is my code:
from pywinauto.application import Application
import pywinauto
import time
app = Application(backend='uia').start(r"C:\Program
Files\Intellech\Analyzer\Suite.exe")
time.sleep(3)
app.findwindows.find_windows(auto_id='btQuick').click_input()
Can you help me to find out the reason of this error?
findwindows is a module name, not an attribute of Application object. This is correct code for the last line:
app.window(title="Your Main Window").child_window(auto_id='btQuick').click_input()
where "Your Main Window" should be changed to correct text of the top level window.
I have Asterisk 13.20 set up and running fine on Ubuntu 16.04,calls are going well through a Softphone(Zoiper), I came across a Library in Python "Pycall" which lets you make calls through a Python Script.So I tried testing a snippet from the site Pycall
The code that I used:
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()
Just made changes in the extension,wherein I used one from my server
However I am getting the following error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
c.spool()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 131, in spool
self.writefile()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 119, in writefile
f.write(self.contents)
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 114, in contents
return '\n'.join(self.buildfile())
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
raise ValidationError
pycall.errors.ValidationError
Tried searching online for the solution but coudnt find one,What am I doing wrong?
This question not related to PBX, it is just incorrect use of LIB.
General instruction how to solve ANY issue with availible source code.
You have error
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
Go that file and line, check code, add more debug if needed, fix your app.
Run as asterisk user.
sudo su asterisk -s /bin/bash
python
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()
I want to use IPython notebook's IPython.display.display from within a thread, as such:
def foo():
display(HTML('<div id="foobar">foobarbaz</div>'))
threading.Thread(target=foo).start()
IPython notebook spits out the following error:
Exception in thread Thread-17:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "<ipython-input-47-921e56bac735>", line 2, in foo
display(HTML('<div id="foobar">foobarbaz</div>'))
File "/usr/local/lib/python3.5/dist-packages/IPython/core/display.py", line 171, in display
publish_display_data(data=format_dict, metadata=md_dict)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/display.py", line 121, in publish_display_data
metadata=metadata,
File "/usr/local/lib/python3.5/dist-packages/ipykernel/zmqshell.py", line 111, in publish
for hook in self.thread_local.hooks:
AttributeError: '_thread._local' object has no attribute 'hooks'
I figure IPython's display is not thread safe? Is there a way to get it to point to the main thread instead of the local thread? Or perhaps a way to get the IPython.display.DisplayHandle? Maybe the thing to do is to have a loop around a queue.Queue on the main thread and display objects as they get added into that queue?
Thank you!
You can use an Output widget to display your HTML. This worked for me:
import ipywidgets as widgets
from IPython.display import display, HTML
import threading
out = widgets.Output()
def foo():
with out:
display(HTML('<div id="foobar">foobarbaz</div>'))
threading.Thread(target=foo).start()
out