How to use share button to share content of my app - kivy

I'm working with kivymd and using an MDFloatingActionButtonSpeedDial cannot figure out how to use it to share the content of the app with a link to download the like we share youtube video on WhatsApp, just like above
Here's my code
data = {
"facebook": "Facebook",
"whatsapp": "WhatsApp",
"instagram": "Instagram",
"twitter": "Twitter",
}
def callback(self, instance):
print('Hello')
print(instance.icon)
if instance.icon == "facebook":
print('Share it on Facebook')
elif instance.icon == 'whatsapp':
print('Share it on WhatsApp')
elif instance.icon == 'twitter':
print('Share it on Twitter')
else:
print('Share it on Instagram')

# Native method for Android.
def share(title, text):
from kivy import platform
if platform == 'android':
from jnius import autoclass
PythonActivity = autoclass('org.kivy.android.PythonActivity')
Intent = autoclass('android.content.Intent')
String = autoclass('java.lang.String')
intent = Intent()
intent.setAction(Intent.ACTION_SEND)
intent.putExtra(Intent.EXTRA_TEXT, String('{}'.format(text)))
intent.setType('text/plain')
chooser = Intent.createChooser(intent, String(title))
PythonActivity.mActivity.startActivity(chooser)

Related

Add sound to push notifications

I'm using django-push-notifications to send push to our ios users (using APNS).
from push_notifications.models import APNSDevice, APNSDeviceQuerySet
from apps.notifications.db.models import Notification
from apps.users.db.models import User
class APNSService:
def __init__(self, user: User, title: str, body: str, data: dict):
self.user = user
self.title = title
self.body = body
self.data = data
def get_devices(self) -> APNSDeviceQuerySet:
return APNSDevice.objects.filter(user=self.user)
def send_message(self):
return self.get_devices().send_message(
message=dict(
title=self.title,
body=self.body
),
badge=Notification.objects.filter(recipient=self.user, unread=True).count(),
extra=self.data
)
The problem is, that notifications comes without a sound. According to the docs, there should be extra field to execute the sound when notification is received.
How to do this?
There is param sound, example
def send_message(self):
return self.get_devices().send_message(
message=dict(
title=self.title,
body=self.body
),
extra=self.data,
sound="default",
)

Messages in Django Channels sent outside consumer not being received

I'm trying to send messages to specific websocket instances, but neither channel_layer.send, nor using channel_layer.group_send with unique groups for each instance seems to be working, no errors are being raised, they just aren't received by the instances.
The function that sends the message is:
def listRequest(auth_user, city):
request_country = city["country_name"]
request_city = city["city"]
request_location = request_city +", "+request_country
concatenate_service_email = auth_user.service + "-" + auth_user.email
this_request = LoginRequest(service_and_email=concatenate_service_email, location=request_location)
this_request.generate_challenge()
this_request.set_expiry(timezone.now() + timezone.timedelta(minutes=5))
this_request.save()
channel_layer = get_channel_layer()
print(auth_user.current_socket)
async_to_sync(channel_layer.group_send)(
auth_user.current_socket,{
"type": "new.request",
"service_and_email" : concatenate_service_email
},
)
My current working consumers.py (receive and scanrequest don't have anything that's likely to be relevant to the issue):
from asgiref.sync import async_to_sync
from channels.generic.websocket import WebsocketConsumer
from .helpers import verify_identity, unique_group
from django.utils import timezone
from .models import Authentication, LoginRequest
import json
import time
class AuthConsumer(WebsocketConsumer):
account_list =[]
def connect(self):
print("Connect attempted")
print(self.channel_name)
print(unique_group(self.channel_name))
async_to_sync(self.channel_layer.group_add)(unique_group(self.channel_name), self.channel_name)
self.accept()
def disconnect(self, close_code):
print("Disconnect attempted")
async_to_sync(self.channel_layer.group_discard)(unique_group(self.channel_name), self.channel_name)
for i in self.account_list:
serviceEmailSplit = i.split("-")
try:
auth_user = Authentication.objects.get(service=serviceEmailSplit[0],email=serviceEmailSplit[1])
auth_user.set_socket("NONE")
auth_user.save()
except:
print("Error user %s does not exist" %i)
pass
def receive(self, text_data):
print("Receiving data")
if text_data[0:7] == "APPROVE":
data_as_list = text_data.split(",")
serviceEmailSplit = data_as_list[1].split("-")
auth_user = Authentication.objects.get(service=serviceEmailSplit[0],email=serviceEmailSplit[1])
this_request = LoginRequest.objects.get(service_and_email=data_as_list[1],approved=False, expiry__gt=timezone.now())
if verify_identity(auth_user.public_key, data_as_list[2], this_request.challenge):
this_request.set_approved()
self.send("Request Approved!")
else:
self.send("ERROR: User verification failed")
else:
self.account_list = text_data.split(",")
self.account_list.pop(-1)
print(self.account_list)
for i in self.account_list:
serviceEmailSplit = i.split("-")
try:
auth_user = Authentication.objects.get(service=serviceEmailSplit[0],email=serviceEmailSplit[1])
auth_user.set_socket(unique_group(self.channel_name))
auth_user.save()
except:
self.send("Error user %s does not exist" %i)
self.scanRequest()
def scanRequest(self):
requestSet = LoginRequest.objects.filter(service_and_email__in = self.account_list, approved = False, request_expiry__gt = timezone.now())
if requestSet.count() > 0:
for request in requestSet:
self.send(request.service_and_email+","+request.location+","+str(request.challenge))
else:
self.send("NOREQUESTS")
def new_request(self,event):
print("NEW REQUEST!")
this_request = LoginRequest.objects.filter(service_and_email = event["service_and_email"]).latest('request_expiry')
self.send(this_request.service_and_email+","+this_request.location+","+str(this_request.challenge))
And my routing.py:
from django.urls import re_path
from . import consumers
from django.conf.urls import url
websocket_urlpatterns = [
url(r"^ws/$", consumers.AuthConsumer.as_asgi()),
]
"NEW REQUEST!" is never printed, having tried to call it both by sending a message directly, and neither does using groups like I have written above.
My redis server appears to be working from testing like the documentation for the channels tutorial suggests:
https://channels.readthedocs.io/en/stable/tutorial/part_2.html
I'm pretty stumped after attempts to fix it, and I've looked at the other posts on stackoverflow with the same/similar issues and I'm already following whatever solutions they have in my code.

ViberApp is existing in IONIC IOS

Now I'm developing IOS App and I want to check if the Viber App is existing in the Phone or not.
I already use Viber:\\ URL scheme and https://ionicframework.com/docs/native/app-availability/ to check the app but the app is not detecting
There's any possible implementation?
Thanks
Try this;
import { AppAvailability } from '#ionic-native/app-availability';
import { Platform } from 'ionic-angular';
constructor(private appAvailability: AppAvailability, private platform: Platform) { }
let app;
if (this.platform.is('ios')) {
app = 'Viber://';
} else if (this.platform.is('android')) {
app = 'com.viber.voip ';
}
this.appAvailability.check(app)
.then(
(yes: boolean) => console.log(app + ' is available'),
(no: boolean) => console.log(app + ' is NOT available')
);
the URLScheme must be declared publicly in Info.plist file first
visit this UseYourLoaf tutorial for more details
i fixed it by check if these is exist
viber = "https://itunes.apple.com/ph/app/viber-messenger-chats-calls/id382617920?mt=8"
and
use app-availability
this.appAvailability.check(viber)

JIRA do I have a way to get the list all ID of my transition steps?

I want to synchronize between two systems. However, to update the transition status of the bug I have to send a JSON file with my arguments (new status) something like this:
{
"update": {
"comment": [
{
"add": {
"body": "Comment added when resolving issue"
}
}
]
},
"transition": {
"id": "5"
}
}
To set a new status I have to set it's id, How can I get the list of all the IDs and the description of each one.
You can get a list of the transitions possible for this issue by the current user, along with fields that are required and their types by url /rest/api/2/issue/{issueIdOrKey}/transitions (get request)
You can use the following python script to get the information you want.
#!/usr/bin/env python
from __future__ import print_function
import ConfigParser
import requests
import json
import base64
import sys
def print_error(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def get_issue(user,password,search_url):
user_auth = base64.b64encode(user+':'+password)
headers = {'Authorization': 'Basic ' + user_auth}
return requests.get(search_url, headers=headers)
def main():
if len(sys.argv) < 2:
usage_message = 'Usage: ' + sys.argv[0] + ' issue_number'
print_error(usage_message)
sys.exit(1)
config = ConfigParser.RawConfigParser()
config.read('config.properties')
jira_user = config.get('Global', 'jira_user')
jira_pass = config.get('Global', 'jira_pass')
jira_base_url = config.get('Global', 'jira_base_url')
issue_url = config.get('Global', 'issue_url')
issue = sys.argv[1]
issue_search_url = jira_base_url + issue_url + issue + '/transitions'
response = get_issue(jira_user,jira_pass,issue_search_url)
if response.status_code == 404:
print_error(issue + ' NOT FOUND!')
sys.exit(1)
data = response.json()
for transition in data['transitions']:
print("%s %s" % (transition['id'], transition['name']))
main()
You need to have a configuration file (config.properties) in the same directory as the script with the following content:
[Global]
jira_user=username
jira_pass=pass
jira_base_url=http://your_jira_url.com
issue_url=/rest/api/2/issue/
Then you call the script like this:
./get_transitions.py your_ticket_number

adding context QMenu to left click on a button in PySide

I want to add context menu to left click of mouse button pressed over emailbtn
from PySide import QtCore,QtGui
import sys
class ToolBarUI(QtGui.QWidget):
def __init__(self,*args,**kwargs):
super(ToolBarUI,self).__init__(*args,**kwargs)
self.createActions()
self.floatingToolBar()
pass
def sizeHint(self):
return QtCore.QSize(65,45)
def buttons(self):
x,y=15,35
self.btnVLay=QtGui.QVBoxLayout(self)
self.setLayout(self.btnVLay)
self.btnVLay.setContentsMargins(0,0,0,0)
self.incSavbtn=QtGui.QPushButton("Save")
self.incSavbtn.setMinimumSize(QtCore.QSize(x,y))
self.emailbtn=QtGui.QPushButton("Email")
self.emailbtn.setMinimumSize(QtCore.QSize(x,y))
self.upldbtn=QtGui.QPushButton("Upload")
self.upldbtn.setMinimumSize(QtCore.QSize(x,y))
self.setPrjbtn=QtGui.QPushButton("Set Project")
self.setPrjbtn.setMinimumSize(QtCore.QSize(x,y))
self.setThumb=QtGui.QPushButton("Set thumb")
self.setThumb.setMinimumSize(QtCore.QSize(x,y))
self.shwMatbtn=QtGui.QPushButton("Show Material")
self.shwMatbtn.setMinimumSize(QtCore.QSize(x,y))
self.fixtexbtn=QtGui.QPushButton("Fix Texture Paths")
self.fixtexbtn.setMinimumSize(QtCore.QSize(x,y))
btns = [self.incSavbtn,self.emailbtn,self.upldbtn,self.setPrjbtn,self.setPrjbtn,self.setThumb,self.shwMatbtn,self.fixtexbtn]
[self.btnVLay.addWidget(each) for each in btns]
def contextMenuEvent(self, event):
menu = QtGui.QMenu(self)
menu.addAction(self.emlSel)
menu.addAction(self.emlScn)
menu.addAction(self.emlBufr)
#menu.exec_(self.emailbtn.mapToGlobal(QtCore.QPoint(0,0)))
#menu.exec_(event.globalPos())
def createActions(self):
self.emlSel = QtGui.QAction("Email Selected", self)
self.emlScn = QtGui.QAction("Email this Scene", self)
self.emlBufr = QtGui.QAction("Email Current Frame Buffer", self)
def floatingToolBar(self):
self.buttons()
self.setLayout(self.btnVLay)
self.show()
pass
if __name__ =='__main__':
app = QtGui.QApplication(sys.argv)
win = ToolBarUI()
win.show()
sys.exit(app.exec_())
I have tried in contextMenuEvent method but that gives me on right click :/
What am i missing ? Any help will be appreciated.
It works in Linux but not in windows.
Below is code I used for systemtrayicon with left click support in windows. This might work for you as well.
QtCore.QObject.connect(self, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.iconActivated)
def iconActivated(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger: // left click, right click is Context
self.contextMenu().activateWindow() // menu will disappear on clicking any where other than menu
self.contextMenu().popup(QtGui.QCursor.pos()) // display menu at cursor location
Looks like you could use the setMenu method:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from PyQt4 import QtCore, QtGui
class myWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)
self.actionHello = QtGui.QAction(self)
self.actionHello.setText("Hello")
self.menu = QtGui.QMenu(self)
self.menu.addAction(self.actionHello)
self.buttonShow = QtGui.QPushButton(self)
self.buttonShow.setText("Button with menu")
self.buttonShow.setMenu(self.menu)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.buttonShow)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('myWindow')
main = myWindow()
main.show()
sys.exit(app.exec_())

Resources