How can I listen for global mouse events in Elm 0.19? - onclick

To listen for mouse events on an HTML element in Elm, we can use Html.Events.onClick. However, I want to listen for mouse clicks anywhere on the document.
I found the elm-lang/mouse package that provides Mouse.clicks which seems to be intended for just that. On Elm 0.18, it can be installed like this:
elm-package install elm-lang/mouse
And imported like this:
import Mouse exposing (clicks)
But on Elm 0.19, the command
elm install elm-lang/mouse
does not work:
The following packages do not work with Elm 0.19.0 right now:
elm-lang/mouse
No reason is given in the console output. The documentation does not seem to indicate anything about this module has changed with version 0.19.
How can I install the module? Or alternatively, how can I use Elm's standard library to listen for mouse clicks globally (on the document)?

The package has been merged into elm/browser.
So rather than Mouse.clicks, you now use Browser.Events.onClick.
See the documentation for the browser package here.
To retrieve the mouse position, use Json.Decode:
import Browser.Events exposing (onClick)
import Json.Decode as Decode
type alias Msg =
{ x : Int, y : Int }
subscriptions : Model -> Sub Msg
subscriptions model =
onClick
(Decode.map2 Msg
(Decode.field "pageX" Decode.int)
(Decode.field "pageY" Decode.int)
)
For other attributes, see the documentation on MouseEvent.
Quick online demo for click and move.

Related

Does clouds.yaml work with python-api cinderclient as well?

I noticed by accident that openstack.connect() automatically tries to access the clouds.yaml file. I tried to replicate this for the cinderclient, but it didn't work. I know of no documentation of that feature, therefore I just guessed:
from cinderclient import client
from keystoneauth1 import loading
loader = loading.get_plugin_loader('password')
auth_cinder = loader.load_from_options()
I also tried the other load commands given by loading, but none of them worked without further parameters like openstack.connect() did.
If I just missed the full documentation of this feature, I would love to be pointed towards the right direction.

How to make pyqt app stay on bottom of all windows like Rainmeter?

I need to have my window stay on bottom.
I tried using WindowStaysOnBottomHint but when Win+D or Show Desktop is clicked the app minimizes.
I researched and found that Rainmeter reorders the Z-index when Show Desktop is clicked using Win32 Api SetWindowPos but I am unable to find a solution for python QT.
Please give me solution!!
A simple workaround is to check for the hideEvent() and ensure that the event is spontaneous (meaning that the event was originated from outside the application, like from the system in your case), and then call showNormal():
class MyWindow(QtWidgets.QWidget):
# ...
def hideEvent(self, event):
if event.spontaneous():
self.showNormal()
Just to be safe, you can also check for changeEvent() and filter for WindowStateChange events:
def changeEvent(self, event):
if (event.type() == QtCore.QEvent.WindowStateChange and
event.spontaneous() and
self.windowState() == QtCore.Qt.WindowMinimized):
self.showNormal()
I found the solution using win32 API for python (Only for windows) . Refer SetWindowPos, SetWindowLong, win32gui
if sys.platform=='win32':
from ctypes import windll
import win32gui,win32con
win32gui.SetWindowPos(window.winId(),win32con.HWND_BOTTOM, 0,0,0,0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_NOACTIVATE )
hwnd=win32gui.GetWindow(win32gui.GetWindow(windll.user32.GetTopWindow(0),win32con.GW_HWNDLAST),win32con.GW_CHILD);
win32gui.SetWindowLong(window.winId(),win32con.GWL_HWNDPARENT,hwnd)
window is the QTWidget window

Creating a macro of mouse clicks

Is it possible to create an automated python script/macro for a series of mouse clicks? The goal is to open a webpage, click button to open upload data window, and finally hit save button to crate a process.I am thinking of something equivalent to automated VBA macros which are recorded as operations are performed on sheets.
In past I have used pyautogui package for this activity but it requires hard coding of co-ordinates for mouse click and hence tedious to code.
Maybe try to use selenium with python...
Check the docs and examples.
Any easy example would be:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
To download a file with firefox try:
from selenium import webdriver
# To prevent download dialog
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', '/tmp')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv')
browser = webdriver.Firefox(profile)
browser.get("http://www.drugcite.com/?q=ACTIMMUNE")
browser.find_element_by_id('exportpt').click()
browser.find_element_by_id('exporthlgt').click()
Another option would be the usage of pythons webbrowser.
Automatetheboringstuff gives some good examples.

"Required module not found" for module that exists in node_modules

Some modules just seem to be invisible to Flow. For example I have react-native-overlay installed via npm into my node_modules directory but I get a whole bunch of errors like this from Flow:
[js/components/DatePickerOverlay.js:18
18: let Overlay = require('react-native-overlay');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ react-native-overlay. Required module not found
This module doesn't have types so it would be fine if I could just get Flow to ignore it entirely.
Here's my .flowconfig (based on React Native's one):
https://gist.github.com/almost/20c6caf6d18d0e5c689f
As you can see I'm on flow 0.20.1 and I have module.system=haste (as required by React Native)
I tried adding a //$FlowIgnore comment to the import lines but then Flow complains about an unneeded ignore comment! I also tried creating a react-native-flow.js.flow file with a dummy export which seemed to work at first but then after a flow restart stopped working.
Any ideas for how to either help Flow find this module or make it ignore the import line completely?
Looks like you're ignoring it here: https://gist.github.com/almost/20c6caf6d18d0e5c689f#file-flowconfig-L42-L50
If you don't mind manually typing it up, add a react-native-overlay.js to your interfaces and type up a couple signatures.
This is happening because the library doesn't exist in flow-typed.
A simple fix could be creating the following entry in the .flowconfig file:
[ignore]
<PROJECT_ROOT>/libdefs.js
[libs]
./libdefs.js
If using flowtype < 0.60.0 add in libdefs.js
// #flow
declare module "react-native-overlay" {
declare var exports: any;
}
Or if using flowtype > 0.60.0
declare module 'react-native-overlay' {
declare module.exports: any;
}
Note: any is an unsafe type so you can always take advantage of improve the definition of the library
Hope that helps,

porting ipython widget to newer ipywidget API

I was trying to port the euroscipy2014 tutorial (which is also the base for the ipython cookbook) to the newer ipywidget API. I succesfully converted 3 of the 4 notebooks following the directions I found on the relative ipython documentation but i'm having troubles in porting the 3rd notebook (03_custom.ipynb).
I changed the js code from:
%%javascript
// We import the WidgetManager.
require(["widgets/js/widget"], function(WidgetManager){
// We define the NumberSelector view here.
var NumberSelector = widget.DOMWidgetView.extend({
// Function for rendering the view.
render: function(){
to:
%%javascript
// We import the WidgetManager.
require(["widget"], function(WidgetManager){
// We define the NumberSelector view here.
var NumberSelector = widget.DOMWidgetView.extend({
// Function for rendering the view.
render: function(){
using require(["widget”] … instead of require(["widgets/js/widget … and widget.DOMWidgetView.extend instead of IPython.DOMWidgetView.extend
but when testing the widget at the code cell 4 I have (log from the js console):
Couldn't create a view for model id '8727d6f51f804c7aa582b3d95b3c630d' -- Error: Class NumberSelector not found in registry (…)
I guess the last line in the js code:
WidgetManager.register_widget_view('NumberSelector', NumberSelector);
didn’t worked. (maybe .register_widget_view is no more a valid call).
Have you any idea on how to fix this? thanks!
I opened an issue here but i thought the proting of such API can be a topic of general interest, so i'm posting a question here as well.
https://github.com/rossant/euroscipy2014/issues/2

Resources