Compare commits
No commits in common. "v0.6" and "python3" have entirely different histories.
3
.gitattributes
vendored
|
@ -1,3 +0,0 @@
|
|||
# Pickle files (for testing) should always have UNIX line endings.
|
||||
# Windows issue like here https://stackoverflow.com/questions/556269
|
||||
knownnodes.dat text eol=lf
|
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "packages/flatpak/shared-modules"]
|
||||
path = packages/flatpak/shared-modules
|
||||
url = https://github.com/flathub/shared-modules.git
|
|
@ -1,9 +1,6 @@
|
|||
language: python
|
||||
cache: pip
|
||||
dist: bionic
|
||||
python:
|
||||
- "2.7_with_system_site_packages"
|
||||
- "3.7"
|
||||
- "2.7"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
|
@ -14,9 +11,9 @@ addons:
|
|||
- xvfb
|
||||
install:
|
||||
- pip install -r requirements.txt
|
||||
- ln -s src pybitmessage # tests environment
|
||||
- python setup.py install
|
||||
- export PYTHONWARNINGS=all
|
||||
script:
|
||||
- python checkdeps.py
|
||||
- xvfb-run src/bitmessagemain.py -t
|
||||
- python -bm tests
|
||||
- python setup.py test
|
||||
|
|
26
Dockerfile
|
@ -6,37 +6,43 @@ RUN apt-get update
|
|||
|
||||
# Install dependencies
|
||||
RUN apt-get install -yq --no-install-suggests --no-install-recommends \
|
||||
build-essential libcap-dev libssl-dev \
|
||||
python-all-dev python-msgpack python-pip python-setuptools
|
||||
python-msgpack dh-python python-all-dev build-essential libssl-dev \
|
||||
python-stdeb fakeroot python-pip libcap-dev
|
||||
|
||||
RUN pip2 install --upgrade pip
|
||||
RUN pip install --upgrade pip
|
||||
|
||||
EXPOSE 8444 8442
|
||||
|
||||
ENV HOME /home/bitmessage
|
||||
ENV BITMESSAGE_HOME ${HOME}
|
||||
|
||||
ENV VER 0.6.3.2
|
||||
|
||||
WORKDIR ${HOME}
|
||||
ADD . ${HOME}
|
||||
|
||||
# Install tests dependencies
|
||||
RUN pip2 install -r requirements.txt
|
||||
# Install
|
||||
RUN python2 setup.py install
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
# Build and install deb
|
||||
RUN python2 setup.py sdist \
|
||||
&& py2dsc-deb dist/pybitmessage-${VER}.tar.gz \
|
||||
&& dpkg -i deb_dist/python-pybitmessage_${VER}-1_amd64.deb
|
||||
|
||||
# Create a user
|
||||
RUN useradd bitmessage && chown -R bitmessage ${HOME}
|
||||
|
||||
USER bitmessage
|
||||
|
||||
# Generate default config
|
||||
RUN src/bitmessagemain.py -t && mv keys.dat /tmp
|
||||
|
||||
# Clean HOME
|
||||
RUN rm -rf ${HOME}/*
|
||||
|
||||
# Generate default config
|
||||
RUN pybitmessage -t
|
||||
|
||||
# Setup environment
|
||||
RUN APIPASS=$(tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo) \
|
||||
RUN mv /tmp/keys.dat . \
|
||||
&& APIPASS=$(tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo) \
|
||||
&& echo "\napiusername: api\napipassword: $APIPASS" \
|
||||
&& echo "apienabled = true\napiinterface = 0.0.0.0\napiusername = api\napipassword = $APIPASS" >> keys.dat
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
FROM ubuntu:bionic AS pybm-travis-bionic
|
||||
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
ENV TRAVIS_SKIP_APT_UPDATE 1
|
||||
|
||||
RUN apt-get update
|
||||
|
||||
RUN apt-get install -yq --no-install-suggests --no-install-recommends \
|
||||
software-properties-common
|
||||
|
||||
RUN dpkg --add-architecture i386
|
||||
|
||||
RUN add-apt-repository ppa:deadsnakes/ppa
|
||||
|
||||
RUN apt-get -y install sudo
|
||||
|
||||
RUN apt-get install -yq --no-install-suggests --no-install-recommends \
|
||||
# travis xenial bionic
|
||||
python-setuptools libssl-dev libpq-dev python-prctl python-dev \
|
||||
python-dev python-virtualenv python-pip virtualenv \
|
||||
# dpkg
|
||||
python-minimal python-setuptools python-all python openssl libssl-dev \
|
||||
dh-apparmor debhelper dh-python python-msgpack python-qt4 python-stdeb \
|
||||
python-all-dev python-crypto python-psutil \
|
||||
fakeroot python-pytest \
|
||||
# Code quality
|
||||
pylint python-pycodestyle python3-pycodestyle pycodestyle python-flake8 \
|
||||
python3-flake8 flake8 python-pyflakes python3-pyflakes pyflakes pyflakes3 \
|
||||
curl \
|
||||
# Wine
|
||||
python python-pip wget wine-stable winetricks mingw-w64 wine32 wine64 xvfb \
|
||||
# Buildbot
|
||||
python3-dev libffi-dev python3-setuptools \
|
||||
python3-pip \
|
||||
# python 3.7
|
||||
python3.7 python3.7-dev \
|
||||
# .travis.yml
|
||||
build-essential libcap-dev tor \
|
||||
language-pack-en
|
||||
|
||||
# cleanup
|
||||
RUN rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN useradd -m -U builder
|
||||
|
||||
RUN echo 'builder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||
|
||||
# travis2bash
|
||||
RUN wget -O /usr/local/bin/travis2bash.sh https://git.bitmessage.org/Bitmessage/buildbot-scripts/raw/branch/master/travis2bash.sh
|
||||
RUN chmod +x /usr/local/bin/travis2bash.sh
|
||||
|
||||
# copy sources
|
||||
COPY . /home/builder/src
|
||||
RUN chown -R builder.builder /home/builder/src
|
||||
|
||||
USER builder
|
||||
|
||||
ENV LANG en_US.UTF-8
|
||||
ENV LANGUAGE en_US:en
|
||||
ENV LC_ALL en_US.UTF-8
|
||||
|
||||
WORKDIR /home/builder/src
|
||||
|
||||
ENTRYPOINT /usr/local/bin/travis2bash.sh
|
43
android_instruction.rst
Normal file
|
@ -0,0 +1,43 @@
|
|||
PyBitmessage(Android)
|
||||
|
||||
This sample aims to be as close to a real world example of a mobile. It has a more refined design and also provides a practical example of how a mobile app would interact and communicate with its addresses.
|
||||
|
||||
Steps for trying out this sample:
|
||||
|
||||
Compile and install the mobile app onto your mobile device or emulator.
|
||||
|
||||
|
||||
Getting Started
|
||||
|
||||
This sample uses the kivy as Kivy is an open source, cross-platform Python framework for the development of applications that make use of innovative, multi-touch user interfaces. The aim is to allow for quick and easy interaction design and rapid prototyping whilst making your code reusable and deployable.
|
||||
|
||||
Kivy is written in Python and Cython, supports various input devices and has an extensive widget library. With the same codebase, you can target Windows, OS X, Linux, Android and iOS. All Kivy widgets are built with multitouch support.
|
||||
|
||||
Kivy in support take Buildozer which is a tool that automates the entire build process. It downloads and sets up all the prerequisite for python-for-android, including the android SDK and NDK, then builds an apk that can be automatically pushed to the device.
|
||||
|
||||
Buildozer currently works only in Linux, and is an alpha release, but it already works well and can significantly simplify the apk build.
|
||||
|
||||
To build this project, use the "Buildozer android release deploy run" command or use.
|
||||
Buildozer ue=sed for creating application packages easily.The goal is to have one "buildozer.spec" file in your app directory, describing your application requirements and settings such as title, icon, included modules etc. Buildozer will use that spec to create a package for Android, iOS, Windows, OSX and/or Linux.
|
||||
|
||||
Installing Requirements
|
||||
|
||||
You can create a package for android using the python-for-android project as with using the Buildozer tool to automate the entire process. You can also see Packaging your application for the Kivy Launcher to run kivy programs without compiling them.
|
||||
|
||||
You can get buildozer at https://github.com/kivy/buildozer or you can directly install using pip install buildozer
|
||||
|
||||
This will install buildozer in your system. Afterwards, navigate to your project directory and run:
|
||||
|
||||
buildozer init
|
||||
|
||||
This creates a buildozer.spec file controlling your build configuration. You should edit it appropriately with your app name etc. You can set variables to control most or all of the parameters passed to python-for-android.
|
||||
|
||||
Install buildozer’s dependencies.
|
||||
|
||||
Finally, plug in your android device and run:
|
||||
|
||||
buildozer android debug deploy run >> To build, push and automatically run the apk on your device. Here we used debug as tested in debug mode for now.
|
||||
|
||||
Packaging your application for the Kivy Launcher
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
# INIT
|
||||
MACHINE_TYPE=$(uname -m)
|
||||
MACHINE_TYPE=`uname -m`
|
||||
BASE_DIR=$(pwd)
|
||||
PYTHON_VERSION=2.7.17
|
||||
PYQT_VERSION=4-4.11.4-gpl-Py2.7-Qt4.8.7
|
||||
|
@ -34,7 +34,7 @@ function download_sources_64 {
|
|||
}
|
||||
|
||||
function download_sources {
|
||||
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
download_sources_64
|
||||
else
|
||||
download_sources_32
|
||||
|
@ -43,18 +43,18 @@ function download_sources {
|
|||
|
||||
function install_wine {
|
||||
echo "Setting up wine"
|
||||
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
export WINEPREFIX=${HOME}/.wine64 WINEARCH=win64
|
||||
else
|
||||
export WINEPREFIX=${HOME}/.wine32 WINEARCH=win32
|
||||
fi
|
||||
rm -rf "${WINEPREFIX}"
|
||||
rm -rf ${WINEPREFIX}
|
||||
rm -rf packages/pyinstaller/{build,dist}
|
||||
}
|
||||
|
||||
function install_python(){
|
||||
cd ${SRCPATH} || exit 1
|
||||
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
|
||||
cd ${SRCPATH}
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
echo "Installing Python ${PYTHON_VERSION} 64b"
|
||||
wine msiexec -i python-${PYTHON_VERSION}.amd64.msi /q /norestart
|
||||
echo "Installing vcredist for 64 bit"
|
||||
|
@ -63,19 +63,20 @@ function install_python(){
|
|||
echo "Installing Python ${PYTHON_VERSION} 32b"
|
||||
wine msiexec -i python-${PYTHON_VERSION}.msi /q /norestart
|
||||
# MSVCR 2008 required for Windows XP
|
||||
cd ${SRCPATH} || exit 1
|
||||
cd ${SRCPATH}
|
||||
echo "Installing vc_redist (2008) for 32 bit "
|
||||
wine vcredist_x86.exe /Q
|
||||
fi
|
||||
echo "Installing pytools 2020.2"
|
||||
# last version compatible with python 2
|
||||
wine python -m pip install pytools==2020.2
|
||||
# add cert
|
||||
if [ -f /usr/local/share/ca-certificates/bitmessage-proxy.crt ]; then
|
||||
wine python -m pip config set global.cert 'z:\usr\local\share\ca-certificates\bitmessage-proxy.crt'
|
||||
fi
|
||||
echo "Upgrading pip"
|
||||
wine python -m pip install --upgrade pip
|
||||
}
|
||||
|
||||
function install_pyqt(){
|
||||
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
echo "Installing PyQt-${PYQT_VERSION} 64b"
|
||||
wine PyQt${PYQT_VERSION}-x64.exe /S /WX
|
||||
else
|
||||
|
@ -85,7 +86,7 @@ function install_pyqt(){
|
|||
}
|
||||
|
||||
function install_openssl(){
|
||||
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
echo "Installing OpenSSL ${OPENSSL_VERSION} 64b"
|
||||
wine Win64OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes
|
||||
else
|
||||
|
@ -96,11 +97,10 @@ function install_openssl(){
|
|||
|
||||
function install_pyinstaller()
|
||||
{
|
||||
cd "${BASE_DIR}" || exit 1
|
||||
cd ${BASE_DIR}
|
||||
echo "Installing PyInstaller"
|
||||
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
|
||||
# 3.6 is the last version to support python 2.7
|
||||
wine python -m pip install -I pyinstaller==3.6
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
wine python -m pip install pyinstaller
|
||||
else
|
||||
# 3.2.1 is the last version to work on XP
|
||||
# see https://github.com/pyinstaller/pyinstaller/issues/2931
|
||||
|
@ -110,60 +110,40 @@ function install_pyinstaller()
|
|||
|
||||
function install_msgpack()
|
||||
{
|
||||
cd "${BASE_DIR}" || exit 1
|
||||
cd ${BASE_DIR}
|
||||
echo "Installing msgpack"
|
||||
wine python -m pip install msgpack-python
|
||||
}
|
||||
|
||||
function install_pyopencl()
|
||||
{
|
||||
cd "${SRCPATH}" || exit 1
|
||||
cd ${SRCPATH}
|
||||
echo "Installing PyOpenCL"
|
||||
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
wine python -m pip install pyopencl-2015.1-cp27-none-win_amd64.whl
|
||||
else
|
||||
wine python -m pip install pyopencl-2015.1-cp27-none-win32.whl
|
||||
fi
|
||||
sed -Ei 's/_DEFAULT_INCLUDE_OPTIONS = .*/_DEFAULT_INCLUDE_OPTIONS = [] /' \
|
||||
"$WINEPREFIX/drive_c/Python27/Lib/site-packages/pyopencl/__init__.py"
|
||||
sed -Ei 's/_DEFAULT_INCLUDE_OPTIONS = .*/_DEFAULT_INCLUDE_OPTIONS = [] /' $WINEPREFIX/drive_c/Python27/Lib/site-packages/pyopencl/__init__.py
|
||||
}
|
||||
|
||||
function build_dll(){
|
||||
cd "${BASE_DIR}" || exit 1
|
||||
cd src/bitmsghash || exit 1
|
||||
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
|
||||
cd ${BASE_DIR}
|
||||
cd src/bitmsghash
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
echo "Create dll"
|
||||
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native \
|
||||
"-I$HOME/.wine64/drive_c/OpenSSL-Win64/include" \
|
||||
-I/usr/x86_64-w64-mingw32/include \
|
||||
"-L$HOME/.wine64/drive_c/OpenSSL-Win64/lib" \
|
||||
-c bitmsghash.cpp
|
||||
x86_64-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o \
|
||||
-D_WIN32 -O3 -march=native \
|
||||
"-I$HOME/.wine64/drive_c/OpenSSL-Win64/include" \
|
||||
"-L$HOME/.wine64/drive_c/OpenSSL-Win64" \
|
||||
-L/usr/lib/x86_64-linux-gnu/wine \
|
||||
-fPIC -shared -lcrypt32 -leay32 -lwsock32 \
|
||||
-o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a
|
||||
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -I/usr/x86_64-w64-mingw32/include -L$HOME/.wine64/drive_c/OpenSSL-Win64/lib -c bitmsghash.cpp
|
||||
x86_64-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -L$HOME/.wine64/drive_c/OpenSSL-Win64 -L/usr/lib/x86_64-linux-gnu/wine -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a
|
||||
else
|
||||
echo "Create dll"
|
||||
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native \
|
||||
"-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \
|
||||
-I/usr/i686-w64-mingw32/include \
|
||||
"-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib" \
|
||||
-c bitmsghash.cpp
|
||||
i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o \
|
||||
-D_WIN32 -O3 -march=native \
|
||||
"-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \
|
||||
"-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW" \
|
||||
-fPIC -shared -lcrypt32 -leay32 -lwsock32 \
|
||||
-o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a
|
||||
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -I/usr/i686-w64-mingw32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib -c bitmsghash.cpp
|
||||
i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a
|
||||
fi
|
||||
}
|
||||
|
||||
function build_exe(){
|
||||
cd "${BASE_DIR}" || exit 1
|
||||
cd packages/pyinstaller || exit 1
|
||||
cd ${BASE_DIR}
|
||||
cd packages/pyinstaller
|
||||
wine pyinstaller bitmessagemain.spec
|
||||
}
|
||||
|
||||
|
|
33
checkdeps.py
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python2
|
||||
"""
|
||||
Check dependencies and give recommendations about how to satisfy them
|
||||
|
||||
|
@ -144,23 +144,20 @@ for lhs, rhs in EXTRAS_REQUIRE.items():
|
|||
for x in rhs
|
||||
if x in EXTRAS_REQUIRE_DEPS
|
||||
]):
|
||||
try:
|
||||
import_module(lhs)
|
||||
except Exception as e:
|
||||
rhs_cmd = ''.join([
|
||||
CMD,
|
||||
' ',
|
||||
' '.join([
|
||||
''. join([
|
||||
xx for xx in EXTRAS_REQUIRE_DEPS[x][OPSYS]
|
||||
])
|
||||
for x in rhs
|
||||
if x in EXTRAS_REQUIRE_DEPS
|
||||
]),
|
||||
])
|
||||
print(
|
||||
"Optional dependency `pip install .[{}]` would require `{}`"
|
||||
" to be run as root".format(lhs, rhs_cmd))
|
||||
rhs_cmd = ''.join([
|
||||
CMD,
|
||||
' ',
|
||||
' '.join([
|
||||
''. join([
|
||||
xx for xx in EXTRAS_REQUIRE_DEPS[x][OPSYS]
|
||||
])
|
||||
for x in rhs
|
||||
if x in EXTRAS_REQUIRE_DEPS
|
||||
]),
|
||||
])
|
||||
print(
|
||||
"Optional dependency `pip install .[{}]` would require `{}`"
|
||||
" to be run as root".format(lhs, rhs_cmd))
|
||||
|
||||
if (not compiler or prereqs) and OPSYS in PACKAGE_MANAGER:
|
||||
print("You can install the missing dependencies by running, as root:")
|
||||
|
|
|
@ -6,4 +6,4 @@ Comment=Send encrypted messages
|
|||
Exec=pybitmessage %F
|
||||
Icon=pybitmessage
|
||||
Terminal=false
|
||||
Categories=Office;Email;Network;
|
||||
Categories=Office;Email;
|
||||
|
|
14
docs/_static/custom.css
vendored
|
@ -2,17 +2,3 @@
|
|||
li.wy-breadcrumbs-aside > a.fa {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Override table width restrictions */
|
||||
/* @media screen and (min-width: 700px) { */
|
||||
|
||||
.wy-table-responsive table td {
|
||||
/* !important prevents the common CSS stylesheets from overriding
|
||||
this as on RTD they are loaded after this stylesheet */
|
||||
white-space: normal !important;
|
||||
}
|
||||
|
||||
.wy-table-responsive {
|
||||
overflow: visible !important;
|
||||
}
|
||||
/* } */
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
# Last Modified: Wed Apr 29 21:04:08 2020
|
||||
#include <tunables/global>
|
||||
|
||||
/usr/bin/pybitmessage {
|
||||
#include <abstractions/base>
|
||||
#include <abstractions/fonts>
|
||||
#include <abstractions/lightdm>
|
||||
#include <abstractions/python>
|
||||
#include <abstractions/user-tmp>
|
||||
|
||||
owner /home/*/.ICEauthority r,
|
||||
owner /home/*/.Xauthority r,
|
||||
owner /home/*/.config/PyBitmessage/ rw,
|
||||
owner /home/*/.config/PyBitmessage/* rwk,
|
||||
owner /home/*/.config/Trolltech.conf rwk,
|
||||
owner /home/*/.config/Trolltech.conf.* rw,
|
||||
owner /proc/*/mounts r,
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
{
|
||||
"id": "org.bitmessage.BaseApp",
|
||||
"branch": "19.08",
|
||||
"runtime": "org.freedesktop.Platform",
|
||||
"sdk": "org.freedesktop.Sdk",
|
||||
"runtime-version": "19.08",
|
||||
"separate-locales": false,
|
||||
"modules": [
|
||||
"shared-modules/python2.7/python-2.7.json",
|
||||
"shared-modules/qt4/qt4-4.8.7-minimal.json",
|
||||
{
|
||||
"name": "python-sip",
|
||||
"sources": [
|
||||
{
|
||||
"type": "archive",
|
||||
"url": "https://www.riverbankcomputing.com/static/Downloads/sip/4.19.25/sip-4.19.25.tar.gz",
|
||||
"sha256": "b39d93e937647807bac23579edbff25fe46d16213f708370072574ab1f1b4211"
|
||||
}
|
||||
],
|
||||
"buildsystem": "simple",
|
||||
"build-commands": [
|
||||
"python configure.py --sip-module PyQt4.sip --no-dist-info",
|
||||
"make",
|
||||
"make install"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "python-qt4",
|
||||
"sources": [
|
||||
{
|
||||
"type": "archive",
|
||||
"url": "http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.12.3/PyQt4_gpl_x11-4.12.3.tar.gz",
|
||||
"sha256": "a00f5abef240a7b5852b7924fa5fdf5174569525dc076cd368a566619e56d472"
|
||||
}
|
||||
],
|
||||
"buildsystem": "simple",
|
||||
"build-commands": [
|
||||
"python configure.py -w --confirm-license",
|
||||
"make",
|
||||
"make install"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "PyBitmessage-dependencies",
|
||||
"buildsystem" : "simple",
|
||||
"build-options": {
|
||||
"build-args": [
|
||||
"--share=network"
|
||||
]
|
||||
},
|
||||
"build-commands": [
|
||||
"pip --version",
|
||||
"pip install setuptools msgpack"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
{
|
||||
"app-id": "org.bitmessage.PyBitmessage",
|
||||
"runtime": "org.freedesktop.Platform",
|
||||
"runtime-version": "19.08",
|
||||
"branch": "stable",
|
||||
"sdk": "org.freedesktop.Sdk",
|
||||
"base": "org.bitmessage.BaseApp",
|
||||
"command": "pybitmessage",
|
||||
"base-version":"stable",
|
||||
"finish-args" : [
|
||||
"--share=network",
|
||||
"--socket=x11",
|
||||
"--share=ipc",
|
||||
"--filesystem=xdg-config/PyBitmessage:create"
|
||||
],
|
||||
"modules": [
|
||||
{
|
||||
"name" : "PyBitmessage",
|
||||
"buildsystem" : "simple",
|
||||
"build-options": {
|
||||
"build-args": [
|
||||
"--share=network"
|
||||
]
|
||||
},
|
||||
"build-commands": [
|
||||
"python --version",
|
||||
"pwd",
|
||||
"ls",
|
||||
"python checkdeps.py",
|
||||
"python setup.py install --prefix=/app --exec-prefix=/app",
|
||||
"sed -i 's~/usr/bin/~/app/bin/~' /app/bin/pybitmessage",
|
||||
"cat /app/bin/pybitmessage",
|
||||
"mv /app/share/applications/pybitmessage.desktop /app/share/applications/org.bitmessage.PyBitmessage.desktop",
|
||||
"sed -i 's~Icon=pybitmessage~Icon=org.bitmessage.PyBitmessage~' /app/share/applications/org.bitmessage.PyBitmessage.desktop",
|
||||
"mv /app/share/icons/hicolor/scalable/apps/pybitmessage.svg /app/share/icons/hicolor/scalable/apps/org.bitmessage.PyBitmessage.svg",
|
||||
"mv /app/share/icons/hicolor/24x24/apps/pybitmessage.png /app/share/icons/hicolor/24x24/apps/org.bitmessage.PyBitmessage.png",
|
||||
"which pybitmessage"
|
||||
],
|
||||
"sources" : [
|
||||
{
|
||||
"type" : "dir",
|
||||
"path" : "../../"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
Subproject commit fd4d38328ccb078b88ad4a891807e593ae8de806
|
|
@ -1,54 +1,52 @@
|
|||
# -*- mode: python -*-
|
||||
import ctypes
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import sys
|
||||
|
||||
|
||||
if ctypes.sizeof(ctypes.c_voidp) == 4:
|
||||
arch=32
|
||||
else:
|
||||
arch=64
|
||||
|
||||
sslName = 'OpenSSL-Win%s' % ("32" if arch == 32 else "64")
|
||||
site_root = os.path.abspath(HOMEPATH)
|
||||
spec_root = os.path.abspath(SPECPATH)
|
||||
arch = 32 if ctypes.sizeof(ctypes.c_voidp) == 4 else 64
|
||||
cdrivePath = site_root[0:3]
|
||||
srcPath = os.path.join(spec_root[:-20], "src")
|
||||
sslName = 'OpenSSL-Win%i' % arch
|
||||
qtBase = "PyQt4"
|
||||
openSSLPath = os.path.join(cdrivePath, sslName)
|
||||
msvcrDllPath = os.path.join(cdrivePath, "windows", "system32")
|
||||
pythonDllPath = os.path.join(cdrivePath, "Python27")
|
||||
outPath = os.path.join(spec_root, "bitmessagemain")
|
||||
qtBase = "PyQt4"
|
||||
|
||||
sys.path.insert(0, srcPath)
|
||||
os.chdir(srcPath)
|
||||
importPath = srcPath
|
||||
sys.path.insert(0,importPath)
|
||||
os.chdir(sys.path[0])
|
||||
from version import softwareVersion
|
||||
|
||||
today = time.strftime("%Y%m%d")
|
||||
snapshot = False
|
||||
|
||||
os.rename(
|
||||
os.path.join(srcPath, '__init__.py'),
|
||||
os.path.join(srcPath, '__init__.py.backup'))
|
||||
os.rename(os.path.join(srcPath, '__init__.py'), os.path.join(srcPath, '__init__.py.backup'))
|
||||
|
||||
# -*- mode: python -*-
|
||||
a = Analysis(
|
||||
[os.path.join(srcPath, 'bitmessagemain.py')],
|
||||
pathex=[outPath],
|
||||
hiddenimports=[
|
||||
'bitmessageqt.languagebox', 'pyopencl', 'numpy', 'win32com',
|
||||
'setuptools.msvc', '_cffi_backend'
|
||||
],
|
||||
hookspath=None,
|
||||
runtime_hooks=None,
|
||||
excludes=['bsddb', 'bz2', 'tcl', 'tk', 'Tkinter']
|
||||
)
|
||||
|
||||
os.rename(
|
||||
os.path.join(srcPath, '__init__.py.backup'),
|
||||
os.path.join(srcPath, '__init__.py'))
|
||||
[os.path.join(srcPath, 'bitmessagemain.py')],
|
||||
pathex=[outPath],
|
||||
hiddenimports=['bitmessageqt.languagebox', 'pyopencl','numpy', 'win32com' , 'setuptools.msvc' ,'_cffi_backend'],
|
||||
hookspath=None,
|
||||
runtime_hooks=None
|
||||
)
|
||||
|
||||
os.rename(os.path.join(srcPath, '__init__.py.backup'), os.path.join(srcPath, '__init__.py'))
|
||||
|
||||
def addTranslations():
|
||||
import os
|
||||
extraDatas = []
|
||||
for file_ in os.listdir(os.path.join(srcPath, 'translations')):
|
||||
if file_[-3:] != ".qm":
|
||||
continue
|
||||
extraDatas.append((
|
||||
os.path.join('translations', file_),
|
||||
extraDatas.append((os.path.join('translations', file_),
|
||||
os.path.join(srcPath, 'translations', file_), 'DATA'))
|
||||
for libdir in sys.path:
|
||||
qtdir = os.path.join(libdir, qtBase, 'translations')
|
||||
|
@ -59,74 +57,57 @@ def addTranslations():
|
|||
for file_ in os.listdir(qtdir):
|
||||
if file_[0:3] != "qt_" or file_[5:8] != ".qm":
|
||||
continue
|
||||
extraDatas.append((
|
||||
os.path.join('translations', file_),
|
||||
extraDatas.append((os.path.join('translations', file_),
|
||||
os.path.join(qtdir, file_), 'DATA'))
|
||||
return extraDatas
|
||||
|
||||
|
||||
dir_append = os.path.join(srcPath, 'bitmessageqt')
|
||||
|
||||
a.datas += [
|
||||
(os.path.join('ui', file_), os.path.join(dir_append, file_), 'DATA')
|
||||
for file_ in os.listdir(dir_append) if file_.endswith('.ui')
|
||||
]
|
||||
def addUIs():
|
||||
import os
|
||||
extraDatas = []
|
||||
for file_ in os.listdir(os.path.join(srcPath, 'bitmessageqt')):
|
||||
if file_[-3:] != ".ui":
|
||||
continue
|
||||
extraDatas.append((os.path.join('ui', file_), os.path.join(srcPath,
|
||||
'bitmessageqt', file_), 'DATA'))
|
||||
return extraDatas
|
||||
|
||||
# append the translations directory
|
||||
a.datas += addTranslations()
|
||||
a.datas += addUIs()
|
||||
|
||||
|
||||
excluded_binaries = [
|
||||
'QtOpenGL4.dll',
|
||||
'QtSvg4.dll',
|
||||
'QtXml4.dll',
|
||||
]
|
||||
a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries])
|
||||
|
||||
a.binaries += [
|
||||
# No effect: libeay32.dll will be taken from PyQt if installed
|
||||
('libeay32.dll', os.path.join(openSSLPath, 'libeay32.dll'), 'BINARY'),
|
||||
(os.path.join('bitmsghash', 'bitmsghash%i.dll' % arch),
|
||||
os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % arch),
|
||||
'BINARY'),
|
||||
(os.path.join('bitmsghash', 'bitmsghash.cl'),
|
||||
os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'),
|
||||
(os.path.join('sslkeys', 'cert.pem'),
|
||||
os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'),
|
||||
(os.path.join('sslkeys', 'key.pem'),
|
||||
os.path.join(srcPath, 'sslkeys', 'key.pem'), 'BINARY')
|
||||
]
|
||||
|
||||
|
||||
from version import softwareVersion
|
||||
|
||||
today = time.strftime("%Y%m%d")
|
||||
|
||||
fname = '%s_%%s_%s.exe' % (
|
||||
('Bitmessagedev', today) if snapshot else ('Bitmessage', softwareVersion)
|
||||
) % ("x86" if arch == 32 else "x64")
|
||||
|
||||
a.binaries += [('libeay32.dll', os.path.join(openSSLPath, 'libeay32.dll'), 'BINARY'),
|
||||
('python27.dll', os.path.join(pythonDllPath, 'python27.dll'), 'BINARY'),
|
||||
(os.path.join('bitmsghash', 'bitmsghash%i.dll' % (arch)), os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % (arch)), 'BINARY'),
|
||||
(os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'),
|
||||
(os.path.join('sslkeys', 'cert.pem'), os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'),
|
||||
(os.path.join('sslkeys', 'key.pem'), os.path.join(srcPath, 'sslkeys', 'key.pem'), 'BINARY')
|
||||
]
|
||||
|
||||
|
||||
fname = 'Bitmessage_%s_%s.exe' % ("x86" if arch == 32 else "x64", softwareVersion)
|
||||
if snapshot:
|
||||
fname = 'Bitmessagedev_%s_%s.exe' % ("x86" if arch == 32 else "x64", today)
|
||||
|
||||
pyz = PYZ(a.pure)
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
a.zipfiles,
|
||||
a.datas,
|
||||
name=fname,
|
||||
debug=False,
|
||||
strip=None,
|
||||
upx=False,
|
||||
console=False, icon=os.path.join(srcPath, 'images', 'can-icon.ico')
|
||||
)
|
||||
exe = EXE(pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
a.zipfiles,
|
||||
a.datas,
|
||||
a.binaries,
|
||||
[],
|
||||
name=fname,
|
||||
debug=False,
|
||||
strip=None,
|
||||
upx=False,
|
||||
console=False, icon= os.path.join(srcPath, 'images', 'can-icon.ico'))
|
||||
|
||||
coll = COLLECT(exe,
|
||||
a.binaries,
|
||||
a.zipfiles,
|
||||
a.datas,
|
||||
strip=False,
|
||||
upx=False,
|
||||
name='main')
|
||||
|
||||
coll = COLLECT(
|
||||
exe,
|
||||
a.binaries,
|
||||
a.zipfiles,
|
||||
a.datas,
|
||||
strip=False,
|
||||
upx=False,
|
||||
name='main'
|
||||
)
|
||||
|
|
48
packages/unmaintained/debian.sh
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash
|
||||
|
||||
APP=pybitmessage
|
||||
PREV_VERSION=0.4.4
|
||||
VERSION=0.6.0
|
||||
RELEASE=1
|
||||
ARCH_TYPE=all
|
||||
DIR=${APP}-${VERSION}
|
||||
CURDIR=`pwd`
|
||||
SHORTDIR=`basename ${CURDIR}`
|
||||
|
||||
if [ $ARCH_TYPE == "x86_64" ]; then
|
||||
ARCH_TYPE="amd64"
|
||||
fi
|
||||
if [ $ARCH_TYPE == "i686" ]; then
|
||||
ARCH_TYPE="i386"
|
||||
fi
|
||||
|
||||
|
||||
# Update version numbers automatically - so you don't have to
|
||||
sed -i 's/VERSION='${PREV_VERSION}'/VERSION='${VERSION}'/g' Makefile rpm.sh arch.sh puppy.sh ebuild.sh slack.sh
|
||||
sed -i 's/Version: '${PREV_VERSION}'/Version: '${VERSION}'/g' rpmpackage/${APP}.spec
|
||||
sed -i 's/Release: '${RELEASE}'/Release: '${RELEASE}'/g' rpmpackage/${APP}.spec
|
||||
sed -i 's/pkgrel='${RELEASE}'/pkgrel='${RELEASE}'/g' archpackage/PKGBUILD
|
||||
sed -i 's/pkgver='${PREV_VERSION}'/pkgver='${VERSION}'/g' archpackage/PKGBUILD
|
||||
sed -i "s/-${PREV_VERSION}-/-${VERSION}-/g" puppypackage/*.specs
|
||||
sed -i "s/|${PREV_VERSION}|/|${VERSION}|/g" puppypackage/*.specs
|
||||
sed -i 's/VERSION='${PREV_VERSION}'/VERSION='${VERSION}'/g' puppypackage/pinstall.sh puppypackage/puninstall.sh
|
||||
sed -i 's/-'${PREV_VERSION}'.so/-'${VERSION}'.so/g' debian/*.links
|
||||
|
||||
make clean
|
||||
make
|
||||
|
||||
# Change the parent directory name to Debian format
|
||||
mv ../${SHORTDIR} ../${DIR}
|
||||
|
||||
# Create a source archive
|
||||
make sourcedeb
|
||||
|
||||
# Build the package
|
||||
dpkg-buildpackage -F -us -uc
|
||||
|
||||
# Sign files
|
||||
gpg -ba ../${APP}_${VERSION}-1_${ARCH_TYPE}.deb
|
||||
gpg -ba ../${APP}_${VERSION}.orig.tar.gz
|
||||
|
||||
# Restore the parent directory name
|
||||
mv ../${DIR} ../${SHORTDIR}
|
483
packages/unmaintained/debian/changelog
Normal file
|
@ -0,0 +1,483 @@
|
|||
pybitmessage (0.6.0-1) trusty; urgency=low
|
||||
|
||||
* Bugfixes
|
||||
* UI improvements
|
||||
* performance and security improvements
|
||||
* integration with email gateway (mailchuck.com)
|
||||
|
||||
-- Peter Surda <dev@mailchuck.com> Mon, 2 May 2016 16:25:00 +0200
|
||||
|
||||
pybitmessage (0.4.4-1) utopic; urgency=low
|
||||
|
||||
* Added ability to limit network transfer rate
|
||||
* Updated to Protocol Version 3
|
||||
* Removed use of memoryview so that we can support python 2.7.3
|
||||
* Make use of l10n for localizations
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sun, 2 November 2014 12:55:00 +0100
|
||||
|
||||
pybitmessage (0.4.3-1) saucy; urgency=low
|
||||
|
||||
* Support pyelliptic's updated HMAC algorithm. We'll remove support for the old method after an upgrade period.
|
||||
* Improved version check
|
||||
* Refactored decodeBase58 function
|
||||
* Ignore duplicate messages
|
||||
* Added bytes received/sent counts and rate on the network information tab
|
||||
* Fix unicode handling in 'View HTML code as formatted text'
|
||||
* Refactor handling of packet headers
|
||||
* Use pointMult function instead of arithmetic.privtopub since it is faster
|
||||
* Fixed issue where client wasn't waiting for a verack before continuing on with the conversation
|
||||
* Fixed CPU hogging by implementing tab-based refresh improvements
|
||||
* Added curses interface
|
||||
* Added support for IPv6
|
||||
* Added a 'trustedpeer' option to keys.dat
|
||||
* Limit maximum object size to 20 MB
|
||||
* Support email-like > quote characters and reply-below-quote
|
||||
* Added Japanese and Dutch language files; updated Norwegian and Russian languages files
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Thu, 6 March 2014 20:23:00 +0100
|
||||
|
||||
pybitmessage (0.4.2-1) saucy; urgency=low
|
||||
|
||||
* Exclude debian directory from orig.tar.gz
|
||||
|
||||
* Added Norwegian, Chinese, and Arabic translations
|
||||
|
||||
* sock.sendall function isn't atomic.
|
||||
Let sendDataThread be the only thread which sends data.
|
||||
|
||||
* Moved API code to api.py
|
||||
|
||||
* Populate comboBoxSendFrom when replying
|
||||
|
||||
* Added option to show recent broadcasts when subscribing
|
||||
|
||||
* Fixed issue: If Windows username contained an international character,
|
||||
Bitmessage wouldn't start
|
||||
|
||||
* Added some code for FreeBSD compatibility
|
||||
|
||||
* Moved responsibility for processing network objects
|
||||
to the new ObjectProcessorThread
|
||||
|
||||
* Refactored main QT module
|
||||
Moved popup menus initialization to separate methods
|
||||
Simplified inbox loading
|
||||
Moved magic strings to the model scope constants so they won't
|
||||
be created every time.
|
||||
|
||||
* Updated list of defaultKnownNodes
|
||||
|
||||
* Fixed issue: [Linux] When too many messages arrive too quickly,
|
||||
exception occurs: "Exceeded maximum number of notifications"
|
||||
|
||||
* Fixed issue: creating then deleting an Address in short time crashes
|
||||
class_singleWorker.py
|
||||
|
||||
* Refactored code which displays messages to improve code readability
|
||||
|
||||
* load "Sent To" label from subscriptions if available
|
||||
|
||||
* Removed code to add chans to our address book as it is no longer necessary
|
||||
|
||||
* Added identicons
|
||||
|
||||
* Modified addresses.decodeAddress so that API command decodeAddress
|
||||
works properly
|
||||
|
||||
* Added API commands createChan, joinChan, leaveChan, deleteAddress
|
||||
|
||||
* In pyelliptic, check the return value of RAND_bytes to make sure enough
|
||||
random data was generated
|
||||
|
||||
* Don't store messages in UI table (and thus in memory), pull from SQL
|
||||
inventory as needed
|
||||
|
||||
* Fix typos in API commands addSubscription and getInboxMessagesByAddress
|
||||
|
||||
* Add feature in settings menu to give up resending a message after a
|
||||
specified period of time
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Thu, 6 March 2014 20:23:00 +0100
|
||||
|
||||
pybitmessage (0.4.1-1) raring; urgency=low
|
||||
|
||||
* Fixed whitelist bug
|
||||
|
||||
* Fixed chan bug
|
||||
Added addressversion field to pubkeys table
|
||||
Sending messages to a chan no longer uses anything in the pubkeys table
|
||||
Sending messages to yourself is now fully supported
|
||||
|
||||
* Change _verifyAddress function to support v4 addresses
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sun, 29 September 2013 09:54:00 +0100
|
||||
|
||||
pybitmessage (0.4.0-1) raring; urgency=low
|
||||
|
||||
* Raised default demanded difficulty from 1 to 2 for new addresses
|
||||
|
||||
* Added v4 addresses:
|
||||
pubkeys are now encrypted and tagged in the inventory
|
||||
|
||||
* Use locks when accessing dictionary inventory
|
||||
|
||||
* Refactored the way inv and addr messages are shared
|
||||
|
||||
* Give user feedback when disk is full
|
||||
|
||||
* Added chan true/false to listAddresses results
|
||||
|
||||
* When replying using chan address, send to whole chan not just sender
|
||||
|
||||
* Refactored of the way PyBitmessage looks for interesting new objects
|
||||
in large inv messages from peers
|
||||
|
||||
* Show inventory lookup rate on Network Status tab
|
||||
|
||||
* Added SqlBulkExecute class
|
||||
so we can update inventory with only one commit
|
||||
|
||||
* Updated Russian translations
|
||||
|
||||
* Move duplicated SQL code into helper
|
||||
|
||||
* Allow specification of alternate settings dir
|
||||
via BITMESSAGE_HOME environment variable
|
||||
|
||||
* Removed use of gevent. Removed class_bgWorker.py
|
||||
|
||||
* Added Sip and PyQt to includes in build_osx.py
|
||||
|
||||
* Show number of each message type processed
|
||||
in the API command clientStatus
|
||||
|
||||
* Use fast PoW
|
||||
unless we're explicitly a frozen (binary) version of the code
|
||||
|
||||
* Enable user-set localization in settings
|
||||
|
||||
* Fix Archlinux package creation
|
||||
|
||||
* Fallback to language only localization when region doesn't match
|
||||
|
||||
* Fixed brew install instructions
|
||||
|
||||
* Added German translation
|
||||
|
||||
* Made inbox and sent messages table panels read-only
|
||||
|
||||
* Allow inbox and sent preview panels to resize
|
||||
|
||||
* Count RE: as a reply header, just like Re: so we don't chain Re: RE:
|
||||
|
||||
* Fix for traceback on OSX
|
||||
|
||||
* Added backend ability to understand shorter addresses
|
||||
|
||||
* Convert 'API Error' to raise APIError()
|
||||
|
||||
* Added option in settings to allow sending to a mobile device
|
||||
(app not yet done)
|
||||
|
||||
* Added ability to start daemon mode when using Bitmessage as a module
|
||||
|
||||
* Improved the way client detects locale
|
||||
|
||||
* Added API commands:
|
||||
getInboxMessageIds, getSentMessageIds, listAddressBookEntries,
|
||||
trashSentMessageByAckData, addAddressBookEntry,
|
||||
deleteAddressBookEntry, listAddresses2, listSubscriptions
|
||||
|
||||
* Set a maximum frequency for playing sounds
|
||||
|
||||
* Show Invalid Method error in same format as other API errors
|
||||
|
||||
* Update status of separate broadcasts separately
|
||||
even if the sent data is identical
|
||||
|
||||
* Added Namecoin integration
|
||||
|
||||
* Internally distinguish peers by IP and port
|
||||
|
||||
* Inbox message retrieval API
|
||||
functions now also returns read status
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sat, 28 September 2013 09:54:00 +0100
|
||||
|
||||
pybitmessage (0.3.5-1) raring; urgency=low
|
||||
|
||||
* Inbox message retrieval API functions now also returns read status
|
||||
|
||||
* Added right-click option to mark a message as unread
|
||||
|
||||
* Prompt user to connect at first startup
|
||||
|
||||
* Install into /usr/local by default
|
||||
|
||||
* Add a missing rm -f to the uninstall task.
|
||||
|
||||
* Use system text color for enabled addresses instead of black
|
||||
|
||||
* Added support for Chans
|
||||
|
||||
* Start storing msgid in sent table
|
||||
|
||||
* Optionally play sounds on connection/disconnection or when messages arrive
|
||||
|
||||
* Adding configuration option to listen for connections when using SOCKS
|
||||
|
||||
* Added packaging for multiple distros (Arch, Puppy, Slack, etc.)
|
||||
|
||||
* Added Russian translation
|
||||
|
||||
* Added search support in the UI
|
||||
|
||||
* Added 'make uninstall'
|
||||
|
||||
* To improve OSX support, use PKCS5_PBKDF2_HMAC_SHA1
|
||||
if PKCS5_PBKDF2_HMAC is unavailable
|
||||
|
||||
* Added better warnings for OSX users who are using old versions of Python
|
||||
|
||||
* Repaired debian packaging
|
||||
|
||||
* Altered Makefile to avoid needing to chase changes
|
||||
|
||||
* Added logger module
|
||||
|
||||
* Added bgWorker class for background tasks
|
||||
|
||||
* Added use of gevent module
|
||||
|
||||
* On not-Windows: Fix insecure keyfile permissions
|
||||
|
||||
* Fix 100% CPU usage issue
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Mon, 29 July 2013 22:11:00 +0100
|
||||
|
||||
pybitmessage (0.3.4-1) raring; urgency=low
|
||||
|
||||
* Switched addr, msg, broadcast, and getpubkey message types
|
||||
to 8 byte time. Last remaining type is pubkey.
|
||||
|
||||
* Added tooltips to show the full subject of messages
|
||||
|
||||
* Added Maximum Acceptable Difficulty fields in the settings
|
||||
|
||||
* Send out pubkey immediately after generating deterministic
|
||||
addresses rather than waiting for a request
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sun, 30 June 2013 11:23:00 +0100
|
||||
|
||||
pybitmessage (0.3.3-1) raring; urgency=low
|
||||
|
||||
* Remove inbox item from GUI when using API command trashMessage
|
||||
|
||||
* Add missing trailing semicolons to pybitmessage.desktop
|
||||
|
||||
* Ensure $(DESTDIR)/usr/bin exists
|
||||
|
||||
* Update Makefile to correct sandbox violations when built
|
||||
via Portage (Gentoo)
|
||||
|
||||
* Fix message authentication bug
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sat, 29 June 2013 11:23:00 +0100
|
||||
|
||||
pybitmessage (0.3.211-1) raring; urgency=low
|
||||
|
||||
* Removed multi-core proof of work
|
||||
as the multiprocessing module does not work well with
|
||||
pyinstaller's --onefile option.
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Fri, 28 June 2013 11:23:00 +0100
|
||||
|
||||
pybitmessage (0.3.2-1) raring; urgency=low
|
||||
|
||||
* Bugfix: Remove remaining references to the old myapp.trayIcon
|
||||
|
||||
* Refactored message status-related code. API function getStatus
|
||||
now returns one of these strings: notfound, msgqueued,
|
||||
broadcastqueued, broadcastsent, doingpubkeypow, awaitingpubkey,
|
||||
doingmsgpow, msgsent, or ackreceived
|
||||
|
||||
* Moved proof of work to low-priority multi-threaded child
|
||||
processes
|
||||
|
||||
* Added menu option to delete all trashed messages
|
||||
|
||||
* Added inv flooding attack mitigation
|
||||
|
||||
* On Linux, when selecting Show Bitmessage, do not maximize
|
||||
automatically
|
||||
|
||||
* Store tray icons in bitmessage_icons_rc.py
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Mon, 03 June 2013 20:17:00 +0100
|
||||
|
||||
pybitmessage (0.3.1-1) raring; urgency=low
|
||||
|
||||
* Added new API commands: getDeterministicAddress,
|
||||
addSubscription, deleteSubscription
|
||||
|
||||
* TCP Connection timeout for non-fully-established connections
|
||||
now 20 seconds
|
||||
|
||||
* Don't update the time we last communicated with a node unless
|
||||
the connection is fully established. This will allow us to
|
||||
forget about active but non-Bitmessage nodes which have made
|
||||
it into our knownNodes file.
|
||||
|
||||
* Prevent incoming connection flooding from crashing
|
||||
singleListener thread. Client will now only accept one
|
||||
connection per remote node IP
|
||||
|
||||
* Bugfix: Worker thread crashed when doing a POW to send out
|
||||
a v2 pubkey (bug introduced in 0.3.0)
|
||||
|
||||
* Wrap all sock.shutdown functions in error handlers
|
||||
|
||||
* Put all 'commit' commands within SQLLocks
|
||||
|
||||
* Bugfix: If address book label is blank, Bitmessage wouldn't
|
||||
show message (bug introduced in 0.3.0)
|
||||
|
||||
* Messaging menu item selects the oldest unread message
|
||||
|
||||
* Standardize on 'Quit' rather than 'Exit'
|
||||
|
||||
* [OSX] Try to seek homebrew installation of OpenSSL
|
||||
|
||||
* Prevent multiple instances of the application from running
|
||||
|
||||
* Show 'Connected' or 'Connection Lost' indicators
|
||||
|
||||
* Use only 9 half-open connections on Windows but 32 for
|
||||
everyone else
|
||||
|
||||
* Added appIndicator (a more functional tray icon) and Ubuntu
|
||||
Messaging Menu integration
|
||||
|
||||
* Changed Debian install directory and run script name based
|
||||
on Github issue #135
|
||||
|
||||
-- Jonathan Warren (4096 bits) <jonathan@bitmessage.org> Sat, 25 May 2013 12:06:00 +0100
|
||||
|
||||
pybitmessage (0.3.0-1) raring; urgency=low
|
||||
|
||||
* Added new API function: getStatus
|
||||
|
||||
* Added error-handling around all sock.sendall() functions
|
||||
in the receiveData thread so that if there is a problem
|
||||
sending data, the threads will close gracefully
|
||||
|
||||
* Abandoned and removed the connectionsCount data structure;
|
||||
use the connectedHostsList instead because it has proved to be
|
||||
more accurate than trying to maintain the connectionsCount
|
||||
|
||||
* Added daemon mode. All UI code moved into a module and many
|
||||
shared objects moved into shared.py
|
||||
|
||||
* Truncate display of very long messages to avoid freezing the UI
|
||||
|
||||
* Added encrypted broadcasts for v3 addresses or v2 addresses
|
||||
after 2013-05-28 10:00 UTC
|
||||
|
||||
* No longer self.sock.close() from within receiveDataThreads,
|
||||
let the sendDataThreads do it
|
||||
|
||||
* Swapped out the v2 announcements subscription address for a v3
|
||||
announcements subscription address
|
||||
|
||||
* Vacuum the messages.dat file once a month:
|
||||
will greatly reduce the file size
|
||||
|
||||
* Added a settings table in message.dat
|
||||
|
||||
* Implemented v3 addresses:
|
||||
pubkey messages must now include two var_ints: nonce_trials_per_byte
|
||||
and extra_bytes, and also be signed. When sending a message to a v3
|
||||
address, the sender must use these values in calculating its POW or
|
||||
else the message will not be accepted by the receiver.
|
||||
|
||||
* Display a privacy warning when selecting 'Send Broadcast from this address'
|
||||
|
||||
* Added gitignore file
|
||||
|
||||
* Added code in preparation for a switch from 32-bit time to 64-bit time.
|
||||
Nodes will now advertise themselves as using protocol version 2.
|
||||
|
||||
* Don't necessarily delete entries from the inventory after 2.5 days;
|
||||
leave pubkeys there for 28 days so that we don't process the same ones
|
||||
many times throughout a month. This was causing the 'pubkeys processed'
|
||||
indicator on the 'Network Status' tab to not accurately reflect the
|
||||
number of truly new addresses on the network.
|
||||
|
||||
* Use 32 threads for outgoing connections in order to connect quickly
|
||||
|
||||
* Fix typo when calling os.environ in the sys.platform=='darwin' case
|
||||
|
||||
* Allow the cancelling of a message which is in the process of being
|
||||
sent by trashing it then restarting Bitmessage
|
||||
|
||||
* Bug fix: can't delete address from address book
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@sluggish.dyndns.org> Mon, 6 May 2013 12:06:00 +0100
|
||||
|
||||
pybitmessage (0.2.8-1) unstable; urgency=low
|
||||
|
||||
* Fixed Ubuntu & OS X issue:
|
||||
Bitmessage wouldn't receive any objects from peers after restart.
|
||||
|
||||
* Inventory flush to disk when exiting program now vastly faster.
|
||||
|
||||
* Fixed address generation bug (kept Bitmessage from restarting).
|
||||
|
||||
* Improve deserialization of messages
|
||||
before processing (a 'best practice').
|
||||
|
||||
* Change to help Macs find OpenSSL the way Unix systems find it.
|
||||
|
||||
* Do not share or accept IPs which are in the private IP ranges.
|
||||
|
||||
* Added time-fuzzing
|
||||
to the embedded time in pubkey and getpubkey messages.
|
||||
|
||||
* Added a knownNodes lock
|
||||
to prevent an exception from sometimes occurring when saving
|
||||
the data-structure to disk.
|
||||
|
||||
* Show unread messages in bold
|
||||
and do not display new messages automatically.
|
||||
|
||||
* Support selecting multiple items
|
||||
in the inbox, sent box, and address book.
|
||||
|
||||
* Use delete key to trash Inbox or Sent messages.
|
||||
|
||||
* Display richtext(HTML) messages
|
||||
from senders in address book or subscriptions (although not
|
||||
pseudo-mailing-lists; use new right-click option).
|
||||
|
||||
* Trim spaces
|
||||
from the beginning and end of addresses when adding to
|
||||
address book, subscriptions, and blacklist.
|
||||
|
||||
* Improved the display of the time for foreign language users.
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@sluggish.dyndns.org> Tue, 9 Apr 2013 17:44:00 +0100
|
||||
|
||||
pybitmessage (0.2.7-1) unstable; urgency=low
|
||||
|
||||
* Added debian packaging
|
||||
|
||||
* Script to generate debian packages
|
||||
|
||||
* SVG icon for Gnome shell, etc
|
||||
|
||||
* Source moved int src directory for debian standards compatibility
|
||||
|
||||
* Trailing carriage return on COPYING LICENSE and README.md
|
||||
|
||||
-- Bob Mottram (4096 bits) <bob@sluggish.dyndns.org> Mon, 1 Apr 2013 17:12:14 +0100
|
1
packages/unmaintained/debian/compat
Normal file
|
@ -0,0 +1 @@
|
|||
9
|
21
packages/unmaintained/debian/control
Normal file
|
@ -0,0 +1,21 @@
|
|||
Source: pybitmessage
|
||||
Section: mail
|
||||
Priority: extra
|
||||
Maintainer: Bob Mottram (4096 bits) <bob@robotics.uk.to>
|
||||
Build-Depends: debhelper (>= 9.0.0), libqt4-dev (>= 4.8.0), python-qt4-dev, libsqlite3-dev
|
||||
Standards-Version: 3.9.4
|
||||
Homepage: https://github.com/Bitmessage/PyBitmessage
|
||||
Vcs-Git: https://github.com/Bitmessage/PyBitmessage.git
|
||||
|
||||
Package: pybitmessage
|
||||
Architecture: all
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, python (>= 2.7), openssl, python-qt4, sqlite3, gst123
|
||||
Suggests: libmessaging-menu-dev
|
||||
Description: Send encrypted messages
|
||||
Bitmessage is a P2P communications protocol used to send encrypted
|
||||
messages to another person or to many subscribers. It is decentralized and
|
||||
trustless, meaning that you need-not inherently trust any entities like
|
||||
root certificate authorities. It uses strong authentication which means
|
||||
that the sender of a message cannot be spoofed, and it aims to hide
|
||||
"non-content" data, like the sender and receiver of messages, from passive
|
||||
eavesdroppers like those running warrantless wiretapping programs.
|
30
packages/unmaintained/debian/copyright
Normal file
|
@ -0,0 +1,30 @@
|
|||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name:
|
||||
Source:
|
||||
|
||||
Files: *
|
||||
Copyright: Copyright 2016 Bob Mottram (4096 bits) <bob@robotics.uk.to>
|
||||
License: MIT
|
||||
|
||||
Files: debian/*
|
||||
Copyright: Copyright 2016 Bob Mottram (4096 bits) <bob@robotics.uk.to>
|
||||
License: MIT
|
||||
|
||||
License: MIT
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
.
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
packages/unmaintained/debian/docs
Normal file
|
@ -0,0 +1 @@
|
|||
|
1
packages/unmaintained/debian/manpages
Normal file
|
@ -0,0 +1 @@
|
|||
man/pybitmessage.1.gz
|
4
packages/unmaintained/debian/pybm
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
cd /usr/share/pybitmessage
|
||||
exec python bitmessagemain.py
|
||||
|
43
packages/unmaintained/debian/rules
Executable file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/make -f
|
||||
|
||||
APP=pybitmessage
|
||||
PREFIX=/usr
|
||||
build: build-stamp
|
||||
make
|
||||
build-arch: build-stamp
|
||||
build-indep: build-stamp
|
||||
build-stamp:
|
||||
dh_testdir
|
||||
touch build-stamp
|
||||
|
||||
clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -f build-stamp
|
||||
dh_clean
|
||||
|
||||
install: build clean
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_prep
|
||||
dh_installdirs
|
||||
${MAKE} install -B DESTDIR=${CURDIR}/debian/${APP} PREFIX=/usr
|
||||
binary-indep: build install
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installchangelogs
|
||||
dh_installdocs
|
||||
dh_installexamples
|
||||
dh_installman
|
||||
dh_link
|
||||
dh_compress
|
||||
dh_fixperms
|
||||
dh_installdeb
|
||||
dh_gencontrol
|
||||
dh_md5sums
|
||||
dh_builddeb
|
||||
|
||||
binary-arch: build install
|
||||
|
||||
binary: binary-indep binary-arch
|
||||
.PHONY: build clean binary-indep binary-arch binary install
|
1
packages/unmaintained/debian/source/format
Normal file
|
@ -0,0 +1 @@
|
|||
3.0 (quilt)
|
18
packages/unmaintained/debian/source/include-binaries
Normal file
|
@ -0,0 +1,18 @@
|
|||
src/images/sent.png
|
||||
src/images/can-icon-16px.png
|
||||
src/images/addressbook.png
|
||||
src/images/networkstatus.png
|
||||
src/images/redicon.png
|
||||
src/images/subscriptions.png
|
||||
src/images/blacklist.png
|
||||
src/images/can-icon-24px.png
|
||||
src/images/can-icon-24px-red.png
|
||||
src/images/can-icon-24px-yellow.png
|
||||
src/images/can-icon-24px-green.png
|
||||
src/images/identities.png
|
||||
src/images/yellowicon.png
|
||||
src/images/inbox.png
|
||||
src/images/greenicon.png
|
||||
src/images/can-icon.ico
|
||||
src/images/send.png
|
||||
desktop/can-icon.svg
|
|
@ -1,4 +1,3 @@
|
|||
coverage
|
||||
python_prctl
|
||||
psutil
|
||||
pycrypto
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
docker build -t pybm-travis-bionic -f Dockerfile.travis .
|
||||
docker run pybm-travis-bionic
|
44
setup.py
|
@ -1,9 +1,7 @@
|
|||
#!/usr/bin/env python2.7
|
||||
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from setuptools import setup, Extension
|
||||
from setuptools.command.install import install
|
||||
|
@ -12,17 +10,14 @@ from src.version import softwareVersion
|
|||
|
||||
|
||||
EXTRAS_REQUIRE = {
|
||||
'docs': ['sphinx', 'sphinxcontrib-apidoc', 'm2r'],
|
||||
'gir': ['pygobject'],
|
||||
'json': ['jsonrpclib'],
|
||||
'notify2': ['notify2'],
|
||||
'opencl': ['pyopencl', 'numpy'],
|
||||
'prctl': ['python_prctl'], # Named threads
|
||||
'qrcode': ['qrcode'],
|
||||
'sound;platform_system=="Windows"': ['winsound'],
|
||||
'tor': ['stem'],
|
||||
'xdg': ['pyxdg'],
|
||||
'xml': ['defusedxml']
|
||||
'docs': ['sphinx', 'sphinxcontrib-apidoc', 'm2r']
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,24 +81,6 @@ if __name__ == "__main__":
|
|||
except ImportError:
|
||||
packages += ['pybitmessage.fallback.umsgpack']
|
||||
|
||||
data_files = [
|
||||
('share/applications/',
|
||||
['desktop/pybitmessage.desktop']),
|
||||
('share/icons/hicolor/scalable/apps/',
|
||||
['desktop/icons/scalable/pybitmessage.svg']),
|
||||
('share/icons/hicolor/24x24/apps/',
|
||||
['desktop/icons/24x24/pybitmessage.png'])
|
||||
]
|
||||
|
||||
try:
|
||||
if platform.dist()[0] in ('Debian', 'Ubuntu'):
|
||||
data_files += [
|
||||
("etc/apparmor.d/",
|
||||
['packages/apparmor/pybitmessage'])
|
||||
]
|
||||
except AttributeError:
|
||||
pass # FIXME: use distro for more recent python
|
||||
|
||||
dist = setup(
|
||||
name='pybitmessage',
|
||||
version=softwareVersion,
|
||||
|
@ -119,7 +96,6 @@ if __name__ == "__main__":
|
|||
#keywords='',
|
||||
install_requires=installRequires,
|
||||
tests_require=requirements,
|
||||
test_suite='tests.unittest_discover',
|
||||
extras_require=EXTRAS_REQUIRE,
|
||||
classifiers=[
|
||||
"License :: OSI Approved :: MIT License"
|
||||
|
@ -136,7 +112,14 @@ if __name__ == "__main__":
|
|||
'translations/*.ts', 'translations/*.qm',
|
||||
'images/*.png', 'images/*.ico', 'images/*.icns'
|
||||
]},
|
||||
data_files=data_files,
|
||||
data_files=[
|
||||
('share/applications/',
|
||||
['desktop/pybitmessage.desktop']),
|
||||
('share/icons/hicolor/scalable/apps/',
|
||||
['desktop/icons/scalable/pybitmessage.svg']),
|
||||
('share/icons/hicolor/24x24/apps/',
|
||||
['desktop/icons/24x24/pybitmessage.png'])
|
||||
],
|
||||
ext_modules=[bitmsghash],
|
||||
zip_safe=False,
|
||||
entry_points={
|
||||
|
@ -158,15 +141,12 @@ if __name__ == "__main__":
|
|||
'libmessaging ='
|
||||
'pybitmessage.plugins.indicator_libmessaging [gir]'
|
||||
],
|
||||
'bitmessage.desktop': [
|
||||
'freedesktop = pybitmessage.plugins.desktop_xdg [xdg]'
|
||||
],
|
||||
'bitmessage.proxyconfig': [
|
||||
'stem = pybitmessage.plugins.proxyconfig_stem [tor]'
|
||||
],
|
||||
'console_scripts': [
|
||||
'pybitmessage = pybitmessage.bitmessagemain:main'
|
||||
] if sys.platform[:3] == 'win' else []
|
||||
# 'console_scripts': [
|
||||
# 'pybitmessage = pybitmessage.bitmessagemain:main'
|
||||
# ]
|
||||
},
|
||||
scripts=['src/pybitmessage'],
|
||||
cmdclass={'install': InstallCmd},
|
||||
|
|
|
@ -3,12 +3,10 @@ Operations with addresses
|
|||
"""
|
||||
# pylint: disable=redefined-outer-name,inconsistent-return-statements
|
||||
import hashlib
|
||||
import logging
|
||||
from binascii import hexlify, unhexlify
|
||||
from struct import pack, unpack
|
||||
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
from debug import logger
|
||||
|
||||
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||
|
||||
|
@ -25,7 +23,8 @@ def encodeBase58(num, alphabet=ALPHABET):
|
|||
arr = []
|
||||
base = len(alphabet)
|
||||
while num:
|
||||
num, rem = divmod(num, base)
|
||||
rem = num % base
|
||||
num = num // base
|
||||
arr.append(alphabet[rem])
|
||||
arr.reverse()
|
||||
return ''.join(arr)
|
||||
|
@ -149,16 +148,16 @@ def encodeAddress(version, stream, ripe):
|
|||
'Programming error in encodeAddress: The length of'
|
||||
' a given ripe hash was not 20.'
|
||||
)
|
||||
if ripe[:2] == b'\x00\x00':
|
||||
if ripe[:2] == '\x00\x00':
|
||||
ripe = ripe[2:]
|
||||
elif ripe[:1] == b'\x00':
|
||||
elif ripe[:1] == '\x00':
|
||||
ripe = ripe[1:]
|
||||
elif version == 4:
|
||||
if len(ripe) != 20:
|
||||
raise Exception(
|
||||
'Programming error in encodeAddress: The length of'
|
||||
' a given ripe hash was not 20.')
|
||||
ripe = ripe.lstrip(b'\x00')
|
||||
ripe = ripe.lstrip('\x00')
|
||||
|
||||
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe
|
||||
|
||||
|
@ -192,8 +191,8 @@ def decodeAddress(address):
|
|||
status = 'invalidcharacters'
|
||||
return status, 0, 0, ''
|
||||
# after converting to hex, the string will be prepended
|
||||
# with a 0x and appended with a L in python2
|
||||
hexdata = hex(integer)[2:].rstrip('L')
|
||||
# with a 0x and appended with a L
|
||||
hexdata = hex(integer)[2:-1]
|
||||
|
||||
if len(hexdata) % 2 != 0:
|
||||
hexdata = '0' + hexdata
|
||||
|
@ -243,13 +242,13 @@ def decodeAddress(address):
|
|||
data[bytesUsedByVersionNumber + bytesUsedByStreamNumber:-4]
|
||||
if len(embeddedRipeData) == 19:
|
||||
return status, addressVersionNumber, streamNumber, \
|
||||
b'\x00' + embeddedRipeData
|
||||
'\x00' + embeddedRipeData
|
||||
elif len(embeddedRipeData) == 20:
|
||||
return status, addressVersionNumber, streamNumber, \
|
||||
embeddedRipeData
|
||||
elif len(embeddedRipeData) == 18:
|
||||
return status, addressVersionNumber, streamNumber, \
|
||||
b'\x00\x00' + embeddedRipeData
|
||||
'\x00\x00' + embeddedRipeData
|
||||
elif len(embeddedRipeData) < 18:
|
||||
return 'ripetooshort', 0, 0, ''
|
||||
elif len(embeddedRipeData) > 20:
|
||||
|
@ -258,7 +257,7 @@ def decodeAddress(address):
|
|||
elif addressVersionNumber == 4:
|
||||
embeddedRipeData = \
|
||||
data[bytesUsedByVersionNumber + bytesUsedByStreamNumber:-4]
|
||||
if embeddedRipeData[0:1] == b'\x00':
|
||||
if embeddedRipeData[0:1] == '\x00':
|
||||
# In order to enforce address non-malleability, encoded
|
||||
# RIPE data must have NULL bytes removed from the front
|
||||
return 'encodingproblem', 0, 0, ''
|
||||
|
@ -266,7 +265,7 @@ def decodeAddress(address):
|
|||
return 'ripetoolong', 0, 0, ''
|
||||
elif len(embeddedRipeData) < 4:
|
||||
return 'ripetooshort', 0, 0, ''
|
||||
x00string = b'\x00' * (20 - len(embeddedRipeData))
|
||||
x00string = '\x00' * (20 - len(embeddedRipeData))
|
||||
return status, addressVersionNumber, streamNumber, \
|
||||
x00string + embeddedRipeData
|
||||
|
||||
|
|
1652
src/api.py
|
@ -1,73 +1,19 @@
|
|||
"""
|
||||
This is not what you run to run the Bitmessage API. Instead, enable the API
|
||||
( https://bitmessage.org/wiki/API ) and optionally enable daemon mode
|
||||
( https://bitmessage.org/wiki/Daemon ) then run bitmessagemain.py.
|
||||
"""
|
||||
# Copyright (c) 2012-2016 Jonathan Warren
|
||||
# Copyright (c) 2012-2020 The Bitmessage developers
|
||||
# pylint: disable=too-many-lines,no-self-use,unused-variable,unused-argument
|
||||
|
||||
"""
|
||||
This is not what you run to start the Bitmessage API.
|
||||
Instead, `enable the API <https://bitmessage.org/wiki/API>`_
|
||||
and optionally `enable daemon mode <https://bitmessage.org/wiki/Daemon>`_
|
||||
then run the PyBitmessage.
|
||||
|
||||
The PyBitmessage API is provided either as
|
||||
`XML-RPC <http://xmlrpc.scripting.com/spec.html>`_ or
|
||||
`JSON-RPC <https://www.jsonrpc.org/specification>`_ like in bitcoin.
|
||||
It's selected according to 'apivariant' setting in config file.
|
||||
|
||||
Special value ``apivariant=legacy`` is to mimic the old pre 0.6.3
|
||||
behaviour when any results are returned as strings of json.
|
||||
|
||||
.. list-table:: All config settings related to API:
|
||||
:header-rows: 0
|
||||
|
||||
* - apienabled = true
|
||||
- if 'false' the `singleAPI` wont start
|
||||
* - apiinterface = 127.0.0.1
|
||||
- this is the recommended default
|
||||
* - apiport = 8442
|
||||
- the API listens apiinterface:apiport if apiport is not used,
|
||||
random in range (32767, 65535) otherwice
|
||||
* - apivariant = xml
|
||||
- current default for backward compatibility, 'json' is recommended
|
||||
* - apiusername = username
|
||||
- set the username
|
||||
* - apipassword = password
|
||||
- and the password
|
||||
* - apinotifypath =
|
||||
- not really the API setting, this sets a path for the executable to be ran
|
||||
when certain internal event happens
|
||||
|
||||
To use the API concider such simple example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import jsonrpclib
|
||||
|
||||
from pybitmessage import bmconfigparser, helper_startup
|
||||
|
||||
helper_startup.loadConfig() # find and load local config file
|
||||
conf = bmconfigparser.BMConfigParser()
|
||||
api_uri = "http://%s:%s@127.0.0.1:8442/" % (
|
||||
conf.safeGet('bitmessagesettings', 'apiusername'),
|
||||
conf.safeGet('bitmessagesettings', 'apipassword')
|
||||
)
|
||||
api = jsonrpclib.ServerProxy(api_uri)
|
||||
print(api.clientStatus())
|
||||
|
||||
|
||||
For further examples please reference `.tests.test_api`.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import ConfigParser
|
||||
import errno
|
||||
import hashlib
|
||||
import httplib
|
||||
import json
|
||||
import random # nosec
|
||||
import socket
|
||||
import subprocess
|
||||
import time
|
||||
import xmlrpclib
|
||||
from binascii import hexlify, unhexlify
|
||||
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
|
||||
from struct import pack
|
||||
|
@ -81,6 +27,7 @@ import queues
|
|||
import shared
|
||||
import shutdown
|
||||
import state
|
||||
import threads
|
||||
from addresses import (
|
||||
addBMIfNotPresent,
|
||||
calculateInventoryHash,
|
||||
|
@ -90,93 +37,36 @@ from addresses import (
|
|||
)
|
||||
from bmconfigparser import BMConfigParser
|
||||
from debug import logger
|
||||
from helper_ackPayload import genAckPayload
|
||||
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure
|
||||
from inventory import Inventory
|
||||
from network.threads import StoppableThread
|
||||
from version import softwareVersion
|
||||
|
||||
try: # TODO: write tests for XML vulnerabilities
|
||||
from defusedxml.xmlrpc import monkey_patch
|
||||
except ImportError:
|
||||
logger.warning(
|
||||
'defusedxml not available, only use API on a secure, closed network.')
|
||||
else:
|
||||
monkey_patch()
|
||||
|
||||
|
||||
str_chan = '[chan]'
|
||||
str_broadcast_subscribers = '[Broadcast subscribers]'
|
||||
|
||||
|
||||
class ErrorCodes(type):
|
||||
"""Metaclass for :class:`APIError` documenting error codes."""
|
||||
_CODES = {
|
||||
0: 'Invalid command parameters number',
|
||||
1: 'The specified passphrase is blank.',
|
||||
2: 'The address version number currently must be 3, 4, or 0'
|
||||
' (which means auto-select).',
|
||||
3: 'The stream number must be 1 (or 0 which means'
|
||||
' auto-select). Others aren\'t supported.',
|
||||
4: 'Why would you ask me to generate 0 addresses for you?',
|
||||
5: 'You have (accidentally?) specified too many addresses to'
|
||||
' make. Maximum 999. This check only exists to prevent'
|
||||
' mischief; if you really want to create more addresses than'
|
||||
' this, contact the Bitmessage developers and we can modify'
|
||||
' the check or you can do it yourself by searching the source'
|
||||
' code for this message.',
|
||||
6: 'The encoding type must be 2 or 3.',
|
||||
7: 'Could not decode address',
|
||||
8: 'Checksum failed for address',
|
||||
9: 'Invalid characters in address',
|
||||
10: 'Address version number too high (or zero)',
|
||||
11: 'The address version number currently must be 2, 3 or 4.'
|
||||
' Others aren\'t supported. Check the address.',
|
||||
12: 'The stream number must be 1. Others aren\'t supported.'
|
||||
' Check the address.',
|
||||
13: 'Could not find this address in your keys.dat file.',
|
||||
14: 'Your fromAddress is disabled. Cannot send.',
|
||||
15: 'Invalid ackData object size.',
|
||||
16: 'You are already subscribed to that address.',
|
||||
17: 'Label is not valid UTF-8 data.',
|
||||
18: 'Chan name does not match address.',
|
||||
19: 'The length of hash should be 32 bytes (encoded in hex'
|
||||
' thus 64 characters).',
|
||||
20: 'Invalid method:',
|
||||
21: 'Unexpected API Failure',
|
||||
22: 'Decode error',
|
||||
23: 'Bool expected in eighteenByteRipe',
|
||||
24: 'Chan address is already present.',
|
||||
25: 'Specified address is not a chan address.'
|
||||
' Use deleteAddress API call instead.',
|
||||
26: 'Malformed varint in address: ',
|
||||
27: 'Message is too long.'
|
||||
}
|
||||
class APIError(Exception):
|
||||
"""APIError exception class"""
|
||||
|
||||
def __new__(mcs, name, bases, namespace):
|
||||
result = super(ErrorCodes, mcs).__new__(mcs, name, bases, namespace)
|
||||
for code in mcs._CODES.iteritems():
|
||||
# beware: the formatting is adjusted for list-table
|
||||
result.__doc__ += """ * - %04i
|
||||
- %s
|
||||
""" % code
|
||||
return result
|
||||
|
||||
|
||||
class APIError(xmlrpclib.Fault):
|
||||
"""
|
||||
APIError exception class
|
||||
|
||||
.. list-table:: Possible error values
|
||||
:header-rows: 1
|
||||
:widths: auto
|
||||
|
||||
* - Error Number
|
||||
- Message
|
||||
"""
|
||||
__metaclass__ = ErrorCodes
|
||||
def __init__(self, error_number, error_message):
|
||||
super(APIError, self).__init__()
|
||||
self.error_number = error_number
|
||||
self.error_message = error_message
|
||||
|
||||
def __str__(self):
|
||||
return "API Error %04i: %s" % (self.faultCode, self.faultString)
|
||||
return "API Error %04i: %s" % (self.error_number, self.error_message)
|
||||
|
||||
|
||||
class StoppableXMLRPCServer(SimpleXMLRPCServer):
|
||||
"""A SimpleXMLRPCServer that honours state.shutdown"""
|
||||
allow_reuse_address = True
|
||||
|
||||
def serve_forever(self):
|
||||
"""Start the SimpleXMLRPCServer"""
|
||||
# pylint: disable=arguments-differ
|
||||
while state.shutdown == 0:
|
||||
self.handle_request()
|
||||
|
||||
|
||||
# This thread, of which there is only one, runs the API.
|
||||
|
@ -199,52 +89,22 @@ class singleAPI(StoppableThread):
|
|||
pass
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
The instance of `SimpleXMLRPCServer.SimpleXMLRPCServer` or
|
||||
:class:`jsonrpclib.SimpleJSONRPCServer` is created and started here
|
||||
with `BMRPCDispatcher` dispatcher.
|
||||
"""
|
||||
port = BMConfigParser().getint('bitmessagesettings', 'apiport')
|
||||
try:
|
||||
getattr(errno, 'WSAEADDRINUSE')
|
||||
except AttributeError:
|
||||
errno.WSAEADDRINUSE = errno.EADDRINUSE
|
||||
|
||||
RPCServerBase = SimpleXMLRPCServer
|
||||
ct = 'text/xml'
|
||||
if BMConfigParser().safeGet(
|
||||
'bitmessagesettings', 'apivariant') == 'json':
|
||||
try:
|
||||
from jsonrpclib.SimpleJSONRPCServer import (
|
||||
SimpleJSONRPCServer as RPCServerBase)
|
||||
except ImportError:
|
||||
logger.warning(
|
||||
'jsonrpclib not available, failing back to XML-RPC')
|
||||
else:
|
||||
ct = 'application/json-rpc'
|
||||
|
||||
# Nested class. FIXME not found a better solution.
|
||||
class StoppableRPCServer(RPCServerBase):
|
||||
"""A SimpleXMLRPCServer that honours state.shutdown"""
|
||||
allow_reuse_address = True
|
||||
content_type = ct
|
||||
|
||||
def serve_forever(self, poll_interval=None):
|
||||
"""Start the RPCServer"""
|
||||
while state.shutdown == 0:
|
||||
self.handle_request()
|
||||
|
||||
for attempt in range(50):
|
||||
try:
|
||||
if attempt > 0:
|
||||
logger.warning(
|
||||
'Failed to start API listener on port %s', port)
|
||||
port = random.randint(32767, 65535)
|
||||
se = StoppableRPCServer(
|
||||
se = StoppableXMLRPCServer(
|
||||
(BMConfigParser().get(
|
||||
'bitmessagesettings', 'apiinterface'),
|
||||
port),
|
||||
BMXMLRPCRequestHandler, True, encoding='UTF-8')
|
||||
MySimpleXMLRPCRequestHandler, True, True)
|
||||
except socket.error as e:
|
||||
if e.errno in (errno.EADDRINUSE, errno.WSAEADDRINUSE):
|
||||
continue
|
||||
|
@ -255,8 +115,6 @@ class singleAPI(StoppableThread):
|
|||
'bitmessagesettings', 'apiport', str(port))
|
||||
BMConfigParser().save()
|
||||
break
|
||||
|
||||
se.register_instance(BMRPCDispatcher())
|
||||
se.register_introspection_functions()
|
||||
|
||||
apiNotifyPath = BMConfigParser().safeGet(
|
||||
|
@ -276,69 +134,16 @@ class singleAPI(StoppableThread):
|
|||
se.serve_forever()
|
||||
|
||||
|
||||
class CommandHandler(type):
|
||||
class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||
"""
|
||||
The metaclass for `BMRPCDispatcher` which fills _handlers dict by
|
||||
methods decorated with @command
|
||||
This is one of several classes that constitute the API
|
||||
|
||||
This class was written by Vaibhav Bhatia.
|
||||
Modified by Jonathan Warren (Atheros).
|
||||
http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/
|
||||
"""
|
||||
def __new__(mcs, name, bases, namespace):
|
||||
# pylint: disable=protected-access
|
||||
result = super(CommandHandler, mcs).__new__(
|
||||
mcs, name, bases, namespace)
|
||||
result.config = BMConfigParser()
|
||||
result._handlers = {}
|
||||
apivariant = result.config.safeGet('bitmessagesettings', 'apivariant')
|
||||
for func in namespace.values():
|
||||
try:
|
||||
for alias in getattr(func, '_cmd'):
|
||||
try:
|
||||
prefix, alias = alias.split(':')
|
||||
if apivariant != prefix:
|
||||
continue
|
||||
except ValueError:
|
||||
pass
|
||||
result._handlers[alias] = func
|
||||
except AttributeError:
|
||||
pass
|
||||
return result
|
||||
# pylint: disable=too-many-public-methods
|
||||
|
||||
|
||||
class command(object): # pylint: disable=too-few-public-methods
|
||||
"""Decorator for API command method"""
|
||||
def __init__(self, *aliases):
|
||||
self.aliases = aliases
|
||||
|
||||
def __call__(self, func):
|
||||
if BMConfigParser().safeGet(
|
||||
'bitmessagesettings', 'apivariant') == 'legacy':
|
||||
def wrapper(*args):
|
||||
"""
|
||||
A wrapper for legacy apivariant which dumps the result
|
||||
into string of json
|
||||
"""
|
||||
result = func(*args)
|
||||
return result if isinstance(result, (int, str)) \
|
||||
else json.dumps(result, indent=4)
|
||||
wrapper.__doc__ = func.__doc__
|
||||
else:
|
||||
wrapper = func
|
||||
# pylint: disable=protected-access
|
||||
wrapper._cmd = self.aliases
|
||||
wrapper.__doc__ = """Commands: *%s*
|
||||
|
||||
""" % ', '.join(self.aliases) + wrapper.__doc__.lstrip()
|
||||
return wrapper
|
||||
|
||||
|
||||
# This is one of several classes that constitute the API
|
||||
# This class was written by Vaibhav Bhatia.
|
||||
# Modified by Jonathan Warren (Atheros).
|
||||
# Further modified by the Bitmessage developers
|
||||
# http://code.activestate.com/recipes/501148
|
||||
class BMXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||
"""The main API handler"""
|
||||
|
||||
# pylint: disable=protected-access
|
||||
def do_POST(self):
|
||||
"""
|
||||
Handles the HTTP POST request.
|
||||
|
@ -346,9 +151,8 @@ class BMXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
Attempts to interpret all HTTP POST requests as XML-RPC calls,
|
||||
which are forwarded to the server's _dispatch method for handling.
|
||||
|
||||
.. note:: this method is the same as in
|
||||
`SimpleXMLRPCServer.SimpleXMLRPCRequestHandler`,
|
||||
just hacked to handle cookies
|
||||
Note: this method is the same as in SimpleXMLRPCRequestHandler,
|
||||
just hacked to handle cookies
|
||||
"""
|
||||
|
||||
# Check that the path is legal
|
||||
|
@ -370,35 +174,23 @@ class BMXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
size_remaining -= len(L[-1])
|
||||
data = ''.join(L)
|
||||
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
self.cookies = []
|
||||
|
||||
validuser = self.APIAuthenticateClient()
|
||||
if not validuser:
|
||||
time.sleep(2)
|
||||
self.send_response(httplib.UNAUTHORIZED)
|
||||
self.end_headers()
|
||||
return
|
||||
# "RPC Username or password incorrect or HTTP header"
|
||||
# " lacks authentication at all."
|
||||
else:
|
||||
# In previous versions of SimpleXMLRPCServer, _dispatch
|
||||
# could be overridden in this class, instead of in
|
||||
# SimpleXMLRPCDispatcher. To maintain backwards compatibility,
|
||||
# check to see if a subclass implements _dispatch and dispatch
|
||||
# using that method if present.
|
||||
|
||||
response = self.server._marshaled_dispatch(
|
||||
data, getattr(self, '_dispatch', None)
|
||||
)
|
||||
except Exception: # This should only happen if the module is buggy
|
||||
# In previous versions of SimpleXMLRPCServer, _dispatch
|
||||
# could be overridden in this class, instead of in
|
||||
# SimpleXMLRPCDispatcher. To maintain backwards compatibility,
|
||||
# check to see if a subclass implements _dispatch and dispatch
|
||||
# using that method if present.
|
||||
# pylint: disable=protected-access
|
||||
response = self.server._marshaled_dispatch(
|
||||
data, getattr(self, '_dispatch', None)
|
||||
)
|
||||
except BaseException: # This should only happen if the module is buggy
|
||||
# internal error, report as HTTP server error
|
||||
self.send_response(httplib.INTERNAL_SERVER_ERROR)
|
||||
self.send_response(500)
|
||||
self.end_headers()
|
||||
else:
|
||||
# got a valid XML RPC response
|
||||
self.send_response(httplib.OK)
|
||||
self.send_header("Content-type", self.server.content_type)
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/xml")
|
||||
self.send_header("Content-length", str(len(response)))
|
||||
|
||||
# HACK :start -> sends cookies here
|
||||
|
@ -419,19 +211,18 @@ class BMXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
shutdown.doCleanShutdown()
|
||||
|
||||
def APIAuthenticateClient(self):
|
||||
"""
|
||||
Predicate to check for valid API credentials in the request header
|
||||
"""
|
||||
"""Predicate to check for valid API credentials in the request header"""
|
||||
|
||||
if 'Authorization' in self.headers:
|
||||
# handle Basic authentication
|
||||
encstr = self.headers.get('Authorization').split()[1]
|
||||
_, encstr = self.headers.get('Authorization').split()
|
||||
emailid, password = encstr.decode('base64').split(':')
|
||||
return (
|
||||
emailid == BMConfigParser().get(
|
||||
'bitmessagesettings', 'apiusername'
|
||||
) and password == BMConfigParser().get(
|
||||
'bitmessagesettings', 'apipassword'))
|
||||
'bitmessagesettings', 'apiusername') and
|
||||
password == BMConfigParser().get(
|
||||
'bitmessagesettings', 'apipassword')
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
'Authentication failed because header lacks'
|
||||
|
@ -440,14 +231,7 @@ class BMXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
|
||||
return False
|
||||
|
||||
|
||||
# pylint: disable=no-self-use,no-member,too-many-public-methods
|
||||
class BMRPCDispatcher(object):
|
||||
"""This class is used to dispatch API commands"""
|
||||
__metaclass__ = CommandHandler
|
||||
|
||||
@staticmethod
|
||||
def _decode(text, decode_type):
|
||||
def _decode(self, text, decode_type):
|
||||
try:
|
||||
if decode_type == 'hex':
|
||||
return unhexlify(text)
|
||||
|
@ -455,22 +239,29 @@ class BMRPCDispatcher(object):
|
|||
return base64.b64decode(text)
|
||||
except Exception as e:
|
||||
raise APIError(
|
||||
22, 'Decode error - %s. Had trouble while decoding string: %r'
|
||||
22, "Decode error - %s. Had trouble while decoding string: %r"
|
||||
% (e, text)
|
||||
)
|
||||
return None
|
||||
|
||||
def _verifyAddress(self, address):
|
||||
status, addressVersionNumber, streamNumber, ripe = \
|
||||
decodeAddress(address)
|
||||
if status != 'success':
|
||||
logger.warning(
|
||||
'API Error 0007: Could not decode address %s. Status: %s.',
|
||||
address, status
|
||||
)
|
||||
|
||||
if status == 'checksumfailed':
|
||||
raise APIError(8, 'Checksum failed for address: ' + address)
|
||||
if status == 'invalidcharacters':
|
||||
raise APIError(9, 'Invalid characters in address: ' + address)
|
||||
if status == 'versiontoohigh':
|
||||
raise APIError(
|
||||
10, 'Address version number too high (or zero) in address: '
|
||||
+ address)
|
||||
10,
|
||||
'Address version number too high (or zero) in address: ' +
|
||||
address)
|
||||
if status == 'varintmalformed':
|
||||
raise APIError(26, 'Malformed varint in address: ' + address)
|
||||
raise APIError(
|
||||
|
@ -486,108 +277,70 @@ class BMRPCDispatcher(object):
|
|||
' Check the address.'
|
||||
)
|
||||
|
||||
return {
|
||||
'status': status,
|
||||
'addressVersion': addressVersionNumber,
|
||||
'streamNumber': streamNumber,
|
||||
'ripe': base64.b64encode(ripe)
|
||||
} if self._method == 'decodeAddress' else (
|
||||
status, addressVersionNumber, streamNumber, ripe)
|
||||
|
||||
@staticmethod
|
||||
def _dump_inbox_message( # pylint: disable=too-many-arguments
|
||||
msgid, toAddress, fromAddress, subject, received,
|
||||
message, encodingtype, read):
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
return {
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'receivedTime': received,
|
||||
'read': read
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _dump_sent_message( # pylint: disable=too-many-arguments
|
||||
msgid, toAddress, fromAddress, subject, lastactiontime,
|
||||
message, encodingtype, status, ackdata):
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
return {
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'lastActionTime': lastactiontime,
|
||||
'status': status,
|
||||
'ackData': hexlify(ackdata)
|
||||
}
|
||||
return (status, addressVersionNumber, streamNumber, ripe)
|
||||
|
||||
# Request Handlers
|
||||
|
||||
@command('decodeAddress')
|
||||
def HandleDecodeAddress(self, address):
|
||||
"""
|
||||
Decode given address and return dict with
|
||||
status, addressVersion, streamNumber and ripe keys
|
||||
"""
|
||||
return self._verifyAddress(address)
|
||||
|
||||
@command('listAddresses', 'listAddresses2')
|
||||
def HandleListAddresses(self):
|
||||
"""
|
||||
Returns dict with a list of all used addresses with their properties
|
||||
in the *addresses* key.
|
||||
"""
|
||||
data = []
|
||||
for address in self.config.addresses():
|
||||
streamNumber = decodeAddress(address)[2]
|
||||
label = self.config.get(address, 'label')
|
||||
if self._method == 'listAddresses2':
|
||||
def HandleListAddresses(self, method):
|
||||
"""Handle a request to list addresses"""
|
||||
data = '{"addresses":['
|
||||
for addressInKeysFile in BMConfigParser().addresses():
|
||||
status, addressVersionNumber, streamNumber, hash01 = decodeAddress(
|
||||
addressInKeysFile)
|
||||
if len(data) > 20:
|
||||
data += ','
|
||||
if BMConfigParser().has_option(addressInKeysFile, 'chan'):
|
||||
chan = BMConfigParser().getboolean(addressInKeysFile, 'chan')
|
||||
else:
|
||||
chan = False
|
||||
label = BMConfigParser().get(addressInKeysFile, 'label')
|
||||
if method == 'listAddresses2':
|
||||
label = base64.b64encode(label)
|
||||
data.append({
|
||||
data += json.dumps({
|
||||
'label': label,
|
||||
'address': address,
|
||||
'address': addressInKeysFile,
|
||||
'stream': streamNumber,
|
||||
'enabled': self.config.safeGetBoolean(address, 'enabled'),
|
||||
'chan': self.config.safeGetBoolean(address, 'chan')
|
||||
})
|
||||
return {'addresses': data}
|
||||
'enabled':
|
||||
BMConfigParser().getboolean(addressInKeysFile, 'enabled'),
|
||||
'chan': chan
|
||||
}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
# the listAddressbook alias should be removed eventually.
|
||||
@command('listAddressBookEntries', 'legacy:listAddressbook')
|
||||
def HandleListAddressBookEntries(self, label=None):
|
||||
"""
|
||||
Returns dict with a list of all address book entries (address and label)
|
||||
in the *addresses* key.
|
||||
"""
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT label, address from addressbook WHERE label = ?",
|
||||
label
|
||||
) if label else sqlQuery("SELECT label, address from addressbook")
|
||||
data = []
|
||||
for label, address in queryreturn:
|
||||
def HandleListAddressBookEntries(self, params):
|
||||
"""Handle a request to list address book entries"""
|
||||
|
||||
if len(params) == 1:
|
||||
label, = params
|
||||
label = self._decode(label, "base64")
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT label, address from addressbook WHERE label = ?",
|
||||
label)
|
||||
elif len(params) > 1:
|
||||
raise APIError(0, "Too many paremeters, max 1")
|
||||
else:
|
||||
queryreturn = sqlQuery("SELECT label, address from addressbook")
|
||||
data = '{"addresses":['
|
||||
for row in queryreturn:
|
||||
label, address = row
|
||||
label = shared.fixPotentiallyInvalidUTF8Data(label)
|
||||
data.append({
|
||||
if len(data) > 20:
|
||||
data += ','
|
||||
data += json.dumps({
|
||||
'label': base64.b64encode(label),
|
||||
'address': address
|
||||
})
|
||||
return {'addresses': data}
|
||||
'address': address}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
# the addAddressbook alias should be deleted eventually.
|
||||
@command('addAddressBookEntry', 'legacy:addAddressbook')
|
||||
def HandleAddAddressBookEntry(self, address, label):
|
||||
"""Add an entry to address book. label must be base64 encoded."""
|
||||
def HandleAddAddressBookEntry(self, params):
|
||||
"""Handle a request to add an address book entry"""
|
||||
|
||||
if len(params) != 2:
|
||||
raise APIError(0, "I need label and address")
|
||||
address, label = params
|
||||
label = self._decode(label, "base64")
|
||||
address = addBMIfNotPresent(address)
|
||||
self._verifyAddress(address)
|
||||
# TODO: add unique together constraint in the table
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT address FROM addressbook WHERE address=?", address)
|
||||
if queryreturn != []:
|
||||
|
@ -600,10 +353,12 @@ class BMRPCDispatcher(object):
|
|||
queues.UISignalQueue.put(('rerenderAddressBook', ''))
|
||||
return "Added address %s to address book" % address
|
||||
|
||||
# the deleteAddressbook alias should be deleted eventually.
|
||||
@command('deleteAddressBookEntry', 'legacy:deleteAddressbook')
|
||||
def HandleDeleteAddressBookEntry(self, address):
|
||||
"""Delete an entry from address book."""
|
||||
def HandleDeleteAddressBookEntry(self, params):
|
||||
"""Handle a request to delete an address book entry"""
|
||||
|
||||
if len(params) != 1:
|
||||
raise APIError(0, "I need an address")
|
||||
address, = params
|
||||
address = addBMIfNotPresent(address)
|
||||
self._verifyAddress(address)
|
||||
sqlExecute('DELETE FROM addressbook WHERE address=?', address)
|
||||
|
@ -612,42 +367,49 @@ class BMRPCDispatcher(object):
|
|||
queues.UISignalQueue.put(('rerenderAddressBook', ''))
|
||||
return "Deleted address book entry for %s if it existed" % address
|
||||
|
||||
@command('createRandomAddress')
|
||||
def HandleCreateRandomAddress(
|
||||
self, label, eighteenByteRipe=False, totalDifficulty=0,
|
||||
smallMessageDifficulty=0
|
||||
):
|
||||
"""
|
||||
Create one address using the random number generator.
|
||||
def HandleCreateRandomAddress(self, params):
|
||||
"""Handle a request to create a random address"""
|
||||
|
||||
:param str label: base64 encoded label for the address
|
||||
:param bool eighteenByteRipe: is telling Bitmessage whether to
|
||||
generate an address with an 18 byte RIPE hash
|
||||
(as opposed to a 19 byte hash).
|
||||
"""
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
|
||||
nonceTrialsPerByte = self.config.get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte'
|
||||
) if not totalDifficulty else int(
|
||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte
|
||||
* totalDifficulty)
|
||||
payloadLengthExtraBytes = self.config.get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes'
|
||||
) if not smallMessageDifficulty else int(
|
||||
defaults.networkDefaultPayloadLengthExtraBytes
|
||||
* smallMessageDifficulty)
|
||||
|
||||
if not isinstance(eighteenByteRipe, bool):
|
||||
raise APIError(
|
||||
23, 'Bool expected in eighteenByteRipe, saw %s instead'
|
||||
% type(eighteenByteRipe))
|
||||
elif len(params) == 1:
|
||||
label, = params
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 2:
|
||||
label, eighteenByteRipe = params
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 3:
|
||||
label, eighteenByteRipe, totalDifficulty = params
|
||||
nonceTrialsPerByte = int(
|
||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte *
|
||||
totalDifficulty)
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 4:
|
||||
label, eighteenByteRipe, totalDifficulty, \
|
||||
smallMessageDifficulty = params
|
||||
nonceTrialsPerByte = int(
|
||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte *
|
||||
totalDifficulty)
|
||||
payloadLengthExtraBytes = int(
|
||||
defaults.networkDefaultPayloadLengthExtraBytes *
|
||||
smallMessageDifficulty)
|
||||
else:
|
||||
raise APIError(0, 'Too many parameters!')
|
||||
label = self._decode(label, "base64")
|
||||
try:
|
||||
unicode(label, 'utf-8')
|
||||
except UnicodeDecodeError:
|
||||
except BaseException:
|
||||
raise APIError(17, 'Label is not valid UTF-8 data.')
|
||||
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
# FIXME hard coded stream no
|
||||
streamNumberForAddress = 1
|
||||
queues.addressGeneratorQueue.put((
|
||||
'createRandomAddress', 4, streamNumberForAddress, label, 1, "",
|
||||
|
@ -655,53 +417,98 @@ class BMRPCDispatcher(object):
|
|||
))
|
||||
return queues.apiAddressGeneratorReturnQueue.get()
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
@command('createDeterministicAddresses')
|
||||
def HandleCreateDeterministicAddresses(
|
||||
self, passphrase, numberOfAddresses=1, addressVersionNumber=0,
|
||||
streamNumber=0, eighteenByteRipe=False, totalDifficulty=0,
|
||||
smallMessageDifficulty=0
|
||||
):
|
||||
"""
|
||||
Create many addresses deterministically using the passphrase.
|
||||
def HandleCreateDeterministicAddresses(self, params):
|
||||
"""Handle a request to create a deterministic address"""
|
||||
# pylint: disable=too-many-branches, too-many-statements
|
||||
|
||||
:param str passphrase: base64 encoded passphrase
|
||||
:param int numberOfAddresses: number of addresses to create,
|
||||
up to 999
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
|
||||
*addressVersionNumber* and *streamNumber* may be set to 0
|
||||
which will tell Bitmessage to use the most up-to-date
|
||||
address version and the most available stream.
|
||||
"""
|
||||
elif len(params) == 1:
|
||||
passphrase, = params
|
||||
numberOfAddresses = 1
|
||||
addressVersionNumber = 0
|
||||
streamNumber = 0
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
|
||||
nonceTrialsPerByte = self.config.get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte'
|
||||
) if not totalDifficulty else int(
|
||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte
|
||||
* totalDifficulty)
|
||||
payloadLengthExtraBytes = self.config.get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes'
|
||||
) if not smallMessageDifficulty else int(
|
||||
defaults.networkDefaultPayloadLengthExtraBytes
|
||||
* smallMessageDifficulty)
|
||||
elif len(params) == 2:
|
||||
passphrase, numberOfAddresses = params
|
||||
addressVersionNumber = 0
|
||||
streamNumber = 0
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
|
||||
elif len(params) == 3:
|
||||
passphrase, numberOfAddresses, addressVersionNumber = params
|
||||
streamNumber = 0
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
|
||||
elif len(params) == 4:
|
||||
passphrase, numberOfAddresses, addressVersionNumber, \
|
||||
streamNumber = params
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
|
||||
elif len(params) == 5:
|
||||
passphrase, numberOfAddresses, addressVersionNumber, \
|
||||
streamNumber, eighteenByteRipe = params
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
|
||||
elif len(params) == 6:
|
||||
passphrase, numberOfAddresses, addressVersionNumber, \
|
||||
streamNumber, eighteenByteRipe, totalDifficulty = params
|
||||
nonceTrialsPerByte = int(
|
||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte *
|
||||
totalDifficulty)
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
|
||||
elif len(params) == 7:
|
||||
passphrase, numberOfAddresses, addressVersionNumber, \
|
||||
streamNumber, eighteenByteRipe, totalDifficulty, \
|
||||
smallMessageDifficulty = params
|
||||
nonceTrialsPerByte = int(
|
||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte *
|
||||
totalDifficulty)
|
||||
payloadLengthExtraBytes = int(
|
||||
defaults.networkDefaultPayloadLengthExtraBytes *
|
||||
smallMessageDifficulty)
|
||||
else:
|
||||
raise APIError(0, 'Too many parameters!')
|
||||
if not passphrase:
|
||||
raise APIError(1, 'The specified passphrase is blank.')
|
||||
if not isinstance(eighteenByteRipe, bool):
|
||||
raise APIError(
|
||||
23, 'Bool expected in eighteenByteRipe, saw %s instead'
|
||||
% type(eighteenByteRipe))
|
||||
23, 'Bool expected in eighteenByteRipe, saw %s instead' %
|
||||
type(eighteenByteRipe))
|
||||
passphrase = self._decode(passphrase, "base64")
|
||||
# 0 means "just use the proper addressVersionNumber"
|
||||
if addressVersionNumber == 0:
|
||||
addressVersionNumber = 4
|
||||
if addressVersionNumber not in (3, 4):
|
||||
if addressVersionNumber != 3 and addressVersionNumber != 4:
|
||||
raise APIError(
|
||||
2, 'The address version number currently must be 3, 4, or 0'
|
||||
' (which means auto-select). %i isn\'t supported.'
|
||||
% addressVersionNumber)
|
||||
' (which means auto-select). %i isn\'t supported.' %
|
||||
addressVersionNumber)
|
||||
if streamNumber == 0: # 0 means "just use the most available stream"
|
||||
streamNumber = 1 # FIXME hard coded stream no
|
||||
streamNumber = 1
|
||||
if streamNumber != 1:
|
||||
raise APIError(
|
||||
3, 'The stream number must be 1 (or 0 which means'
|
||||
|
@ -726,24 +533,27 @@ class BMRPCDispatcher(object):
|
|||
'unused API address', numberOfAddresses, passphrase,
|
||||
eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes
|
||||
))
|
||||
data = '{"addresses":['
|
||||
queueReturn = queues.apiAddressGeneratorReturnQueue.get()
|
||||
for item in queueReturn:
|
||||
if len(data) > 20:
|
||||
data += ','
|
||||
data += "\"" + item + "\""
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
return {'addresses': queues.apiAddressGeneratorReturnQueue.get()}
|
||||
|
||||
@command('getDeterministicAddress')
|
||||
def HandleGetDeterministicAddress(
|
||||
self, passphrase, addressVersionNumber, streamNumber):
|
||||
"""
|
||||
Similar to *createDeterministicAddresses* except that the one
|
||||
address that is returned will not be added to the Bitmessage
|
||||
user interface or the keys.dat file.
|
||||
"""
|
||||
def HandleGetDeterministicAddress(self, params):
|
||||
"""Handle a request to get a deterministic address"""
|
||||
|
||||
if len(params) != 3:
|
||||
raise APIError(0, 'I need exactly 3 parameters.')
|
||||
passphrase, addressVersionNumber, streamNumber = params
|
||||
numberOfAddresses = 1
|
||||
eighteenByteRipe = False
|
||||
if not passphrase:
|
||||
raise APIError(1, 'The specified passphrase is blank.')
|
||||
passphrase = self._decode(passphrase, "base64")
|
||||
if addressVersionNumber not in (3, 4):
|
||||
if addressVersionNumber != 3 and addressVersionNumber != 4:
|
||||
raise APIError(
|
||||
2, 'The address version number currently must be 3 or 4. %i'
|
||||
' isn\'t supported.' % addressVersionNumber)
|
||||
|
@ -761,14 +571,16 @@ class BMRPCDispatcher(object):
|
|||
))
|
||||
return queues.apiAddressGeneratorReturnQueue.get()
|
||||
|
||||
@command('createChan')
|
||||
def HandleCreateChan(self, passphrase):
|
||||
"""
|
||||
Creates a new chan. passphrase must be base64 encoded.
|
||||
Returns the corresponding Bitmessage address.
|
||||
"""
|
||||
def HandleCreateChan(self, params):
|
||||
"""Handle a request to create a chan"""
|
||||
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters.')
|
||||
|
||||
elif len(params) == 1:
|
||||
passphrase, = params
|
||||
passphrase = self._decode(passphrase, "base64")
|
||||
|
||||
if not passphrase:
|
||||
raise APIError(1, 'The specified passphrase is blank.')
|
||||
# It would be nice to make the label the passphrase but it is
|
||||
|
@ -776,7 +588,7 @@ class BMRPCDispatcher(object):
|
|||
try:
|
||||
unicode(passphrase, 'utf-8')
|
||||
label = str_chan + ' ' + passphrase
|
||||
except UnicodeDecodeError:
|
||||
except BaseException:
|
||||
label = str_chan + ' ' + repr(passphrase)
|
||||
|
||||
addressVersionNumber = 4
|
||||
|
@ -789,17 +601,18 @@ class BMRPCDispatcher(object):
|
|||
passphrase, True
|
||||
))
|
||||
queueReturn = queues.apiAddressGeneratorReturnQueue.get()
|
||||
try:
|
||||
return queueReturn[0]
|
||||
except IndexError:
|
||||
if not queueReturn:
|
||||
raise APIError(24, 'Chan address is already present.')
|
||||
address = queueReturn[0]
|
||||
return address
|
||||
|
||||
@command('joinChan')
|
||||
def HandleJoinChan(self, passphrase, suppliedAddress):
|
||||
"""
|
||||
Join a chan. passphrase must be base64 encoded. Returns 'success'.
|
||||
"""
|
||||
def HandleJoinChan(self, params):
|
||||
"""Handle a request to join a chan"""
|
||||
|
||||
if len(params) < 2:
|
||||
raise APIError(0, 'I need two parameters.')
|
||||
elif len(params) == 2:
|
||||
passphrase, suppliedAddress = params
|
||||
passphrase = self._decode(passphrase, "base64")
|
||||
if not passphrase:
|
||||
raise APIError(1, 'The specified passphrase is blank.')
|
||||
|
@ -808,287 +621,373 @@ class BMRPCDispatcher(object):
|
|||
try:
|
||||
unicode(passphrase, 'utf-8')
|
||||
label = str_chan + ' ' + passphrase
|
||||
except UnicodeDecodeError:
|
||||
except BaseException:
|
||||
label = str_chan + ' ' + repr(passphrase)
|
||||
|
||||
self._verifyAddress(suppliedAddress)
|
||||
status, addressVersionNumber, streamNumber, toRipe = (
|
||||
self._verifyAddress(suppliedAddress))
|
||||
suppliedAddress = addBMIfNotPresent(suppliedAddress)
|
||||
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
queues.addressGeneratorQueue.put((
|
||||
'joinChan', suppliedAddress, label, passphrase, True
|
||||
))
|
||||
queueReturn = queues.apiAddressGeneratorReturnQueue.get()
|
||||
try:
|
||||
if queueReturn[0] == 'chan name does not match address':
|
||||
raise APIError(18, 'Chan name does not match address.')
|
||||
except IndexError:
|
||||
raise APIError(24, 'Chan address is already present.')
|
||||
addressGeneratorReturnValue = \
|
||||
queues.apiAddressGeneratorReturnQueue.get()
|
||||
|
||||
if addressGeneratorReturnValue[0] == \
|
||||
'chan name does not match address':
|
||||
raise APIError(18, 'Chan name does not match address.')
|
||||
if not addressGeneratorReturnValue:
|
||||
raise APIError(24, 'Chan address is already present.')
|
||||
return "success"
|
||||
|
||||
@command('leaveChan')
|
||||
def HandleLeaveChan(self, address):
|
||||
"""
|
||||
Leave a chan. Returns 'success'.
|
||||
def HandleLeaveChan(self, params):
|
||||
"""Handle a request to leave a chan"""
|
||||
|
||||
.. note:: at this time, the address is still shown in the UI
|
||||
until a restart.
|
||||
"""
|
||||
self._verifyAddress(address)
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters.')
|
||||
elif len(params) == 1:
|
||||
address, = params
|
||||
status, addressVersionNumber, streamNumber, toRipe = (
|
||||
self._verifyAddress(address))
|
||||
address = addBMIfNotPresent(address)
|
||||
if not self.config.safeGetBoolean(address, 'chan'):
|
||||
if not BMConfigParser().has_section(address):
|
||||
raise APIError(
|
||||
13, 'Could not find this address in your keys.dat file.')
|
||||
if not BMConfigParser().safeGetBoolean(address, 'chan'):
|
||||
raise APIError(
|
||||
25, 'Specified address is not a chan address.'
|
||||
' Use deleteAddress API call instead.')
|
||||
try:
|
||||
self.config.remove_section(address)
|
||||
except ConfigParser.NoSectionError:
|
||||
raise APIError(
|
||||
13, 'Could not find this address in your keys.dat file.')
|
||||
self.config.save()
|
||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
||||
queues.UISignalQueue.put(('rerenderMessagelistToLabels', ''))
|
||||
return "success"
|
||||
BMConfigParser().remove_section(address)
|
||||
with open(state.appdata + 'keys.dat', 'wb') as configfile:
|
||||
BMConfigParser().write(configfile)
|
||||
return 'success'
|
||||
|
||||
@command('deleteAddress')
|
||||
def HandleDeleteAddress(self, address):
|
||||
"""
|
||||
Permanently delete the address from keys.dat file. Returns 'success'.
|
||||
"""
|
||||
self._verifyAddress(address)
|
||||
def HandleDeleteAddress(self, params):
|
||||
"""Handle a request to delete an address"""
|
||||
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters.')
|
||||
elif len(params) == 1:
|
||||
address, = params
|
||||
status, addressVersionNumber, streamNumber, toRipe = (
|
||||
self._verifyAddress(address))
|
||||
address = addBMIfNotPresent(address)
|
||||
try:
|
||||
self.config.remove_section(address)
|
||||
except ConfigParser.NoSectionError:
|
||||
if not BMConfigParser().has_section(address):
|
||||
raise APIError(
|
||||
13, 'Could not find this address in your keys.dat file.')
|
||||
self.config.save()
|
||||
BMConfigParser().remove_section(address)
|
||||
with open(state.appdata + 'keys.dat', 'wb') as configfile:
|
||||
BMConfigParser().write(configfile)
|
||||
queues.UISignalQueue.put(('writeNewAddressToTable', ('', '', '')))
|
||||
shared.reloadMyAddressHashes()
|
||||
return "success"
|
||||
return 'success'
|
||||
|
||||
@command('getAllInboxMessages')
|
||||
def HandleGetAllInboxMessages(self):
|
||||
"""
|
||||
Returns a dict with all inbox messages in the *inboxMessages* key.
|
||||
The message is a dict with such keys:
|
||||
*msgid*, *toAddress*, *fromAddress*, *subject*, *message*,
|
||||
*encodingType*, *receivedTime*, *read*.
|
||||
*msgid* is hex encoded string.
|
||||
*subject* and *message* are base64 encoded.
|
||||
"""
|
||||
def HandleGetAllInboxMessages(self, params):
|
||||
"""Handle a request to get all inbox messages"""
|
||||
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid, toaddress, fromaddress, subject, received, message,"
|
||||
" encodingtype, read FROM inbox WHERE folder='inbox'"
|
||||
" encodingtype, read FROM inbox where folder='inbox'"
|
||||
" ORDER BY received"
|
||||
)
|
||||
return {"inboxMessages": [
|
||||
self._dump_inbox_message(*data) for data in queryreturn
|
||||
]}
|
||||
data = '{"inboxMessages":['
|
||||
for row in queryreturn:
|
||||
msgid, toAddress, fromAddress, subject, received, message, \
|
||||
encodingtype, read = row
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
if len(data) > 25:
|
||||
data += ','
|
||||
data += json.dumps({
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'receivedTime': received,
|
||||
'read': read}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
@command('getAllInboxMessageIds', 'getAllInboxMessageIDs')
|
||||
def HandleGetAllInboxMessageIds(self):
|
||||
"""
|
||||
The same as *getAllInboxMessages* but returns only *msgid*s,
|
||||
result key - *inboxMessageIds*.
|
||||
"""
|
||||
def HandleGetAllInboxMessageIds(self, params):
|
||||
"""Handle a request to get all inbox message IDs"""
|
||||
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid FROM inbox where folder='inbox' ORDER BY received")
|
||||
data = '{"inboxMessageIds":['
|
||||
for row in queryreturn:
|
||||
msgid = row[0]
|
||||
if len(data) > 25:
|
||||
data += ','
|
||||
data += json.dumps(
|
||||
{'msgid': hexlify(msgid)}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
return {"inboxMessageIds": [
|
||||
{'msgid': hexlify(msgid)} for msgid, in queryreturn
|
||||
]}
|
||||
def HandleGetInboxMessageById(self, params):
|
||||
"""Handle a request to get an inbox messsage by ID"""
|
||||
|
||||
@command('getInboxMessageById', 'getInboxMessageByID')
|
||||
def HandleGetInboxMessageById(self, hid, readStatus=None):
|
||||
"""
|
||||
Returns a dict with list containing single message in the result
|
||||
key *inboxMessage*. May also return None if message was not found.
|
||||
|
||||
:param str hid: hex encoded msgid
|
||||
:param bool readStatus: sets the message's read status if present
|
||||
"""
|
||||
|
||||
msgid = self._decode(hid, "hex")
|
||||
if readStatus is not None:
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
elif len(params) == 1:
|
||||
msgid = self._decode(params[0], "hex")
|
||||
elif len(params) >= 2:
|
||||
msgid = self._decode(params[0], "hex")
|
||||
readStatus = params[1]
|
||||
if not isinstance(readStatus, bool):
|
||||
raise APIError(
|
||||
23, 'Bool expected in readStatus, saw %s instead.'
|
||||
% type(readStatus))
|
||||
23, 'Bool expected in readStatus, saw %s instead.' %
|
||||
type(readStatus))
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT read FROM inbox WHERE msgid=?", msgid)
|
||||
# UPDATE is slow, only update if status is different
|
||||
try:
|
||||
if (queryreturn[0][0] == 1) != readStatus:
|
||||
sqlExecute(
|
||||
"UPDATE inbox set read = ? WHERE msgid=?",
|
||||
readStatus, msgid)
|
||||
queues.UISignalQueue.put(('changedInboxUnread', None))
|
||||
except IndexError:
|
||||
pass
|
||||
if queryreturn != [] and (queryreturn[0][0] == 1) != readStatus:
|
||||
sqlExecute(
|
||||
"UPDATE inbox set read = ? WHERE msgid=?",
|
||||
readStatus, msgid)
|
||||
queues.UISignalQueue.put(('changedInboxUnread', None))
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid, toaddress, fromaddress, subject, received, message,"
|
||||
" encodingtype, read FROM inbox WHERE msgid=?", msgid
|
||||
)
|
||||
try:
|
||||
return {"inboxMessage": [
|
||||
self._dump_inbox_message(*queryreturn[0])]}
|
||||
except IndexError:
|
||||
pass # FIXME inconsistent
|
||||
data = '{"inboxMessage":['
|
||||
for row in queryreturn:
|
||||
msgid, toAddress, fromAddress, subject, received, message, \
|
||||
encodingtype, read = row
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
data += json.dumps({
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'receivedTime': received,
|
||||
'read': read}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
@command('getAllSentMessages')
|
||||
def HandleGetAllSentMessages(self):
|
||||
"""
|
||||
The same as *getAllInboxMessages* but for sent,
|
||||
result key - *sentMessages*. Message dict keys are:
|
||||
*msgid*, *toAddress*, *fromAddress*, *subject*, *message*,
|
||||
*encodingType*, *lastActionTime*, *status*, *ackData*.
|
||||
*ackData* is also a hex encoded string.
|
||||
"""
|
||||
def HandleGetAllSentMessages(self, params):
|
||||
"""Handle a request to get all sent messages"""
|
||||
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid, toaddress, fromaddress, subject, lastactiontime,"
|
||||
" message, encodingtype, status, ackdata FROM sent"
|
||||
" WHERE folder='sent' ORDER BY lastactiontime"
|
||||
)
|
||||
return {"sentMessages": [
|
||||
self._dump_sent_message(*data) for data in queryreturn
|
||||
]}
|
||||
data = '{"sentMessages":['
|
||||
for row in queryreturn:
|
||||
msgid, toAddress, fromAddress, subject, lastactiontime, message, \
|
||||
encodingtype, status, ackdata = row
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
if len(data) > 25:
|
||||
data += ','
|
||||
data += json.dumps({
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'lastActionTime': lastactiontime,
|
||||
'status': status,
|
||||
'ackData': hexlify(ackdata)}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
@command('getAllSentMessageIds', 'getAllSentMessageIDs')
|
||||
def HandleGetAllSentMessageIds(self):
|
||||
"""
|
||||
The same as *getAllInboxMessageIds* but for sent,
|
||||
result key - *sentMessageIds*.
|
||||
"""
|
||||
def HandleGetAllSentMessageIds(self, params):
|
||||
"""Handle a request to get all sent message IDs"""
|
||||
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid FROM sent WHERE folder='sent'"
|
||||
"SELECT msgid FROM sent where folder='sent'"
|
||||
" ORDER BY lastactiontime"
|
||||
)
|
||||
return {"sentMessageIds": [
|
||||
{'msgid': hexlify(msgid)} for msgid, in queryreturn
|
||||
]}
|
||||
data = '{"sentMessageIds":['
|
||||
for row in queryreturn:
|
||||
msgid = row[0]
|
||||
if len(data) > 25:
|
||||
data += ','
|
||||
data += json.dumps(
|
||||
{'msgid': hexlify(msgid)}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
# after some time getInboxMessagesByAddress should be removed
|
||||
@command('getInboxMessagesByReceiver', 'legacy:getInboxMessagesByAddress')
|
||||
def HandleInboxMessagesByReceiver(self, toAddress):
|
||||
"""
|
||||
The same as *getAllInboxMessages* but returns only messages
|
||||
for toAddress.
|
||||
"""
|
||||
def HandleInboxMessagesByReceiver(self, params):
|
||||
"""Handle a request to get inbox messages by receiver"""
|
||||
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
toAddress = params[0]
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid, toaddress, fromaddress, subject, received,"
|
||||
" message, encodingtype, read FROM inbox WHERE folder='inbox'"
|
||||
" AND toAddress=?", toAddress)
|
||||
return {"inboxMessages": [
|
||||
self._dump_inbox_message(*data) for data in queryreturn
|
||||
]}
|
||||
"SELECT msgid, toaddress, fromaddress, subject, received, message,"
|
||||
" encodingtype FROM inbox WHERE folder='inbox' AND toAddress=?",
|
||||
toAddress)
|
||||
data = '{"inboxMessages":['
|
||||
for row in queryreturn:
|
||||
msgid, toAddress, fromAddress, subject, received, message, \
|
||||
encodingtype = row
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
if len(data) > 25:
|
||||
data += ','
|
||||
data += json.dumps({
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'receivedTime': received}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
@command('getSentMessageById', 'getSentMessageByID')
|
||||
def HandleGetSentMessageById(self, hid):
|
||||
"""
|
||||
Similiar to *getInboxMessageById* but doesn't change message's
|
||||
read status (sent messages have no such field).
|
||||
Result key is *sentMessage*
|
||||
"""
|
||||
def HandleGetSentMessageById(self, params):
|
||||
"""Handle a request to get a sent message by ID"""
|
||||
|
||||
msgid = self._decode(hid, "hex")
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
msgid = self._decode(params[0], "hex")
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid, toaddress, fromaddress, subject, lastactiontime,"
|
||||
" message, encodingtype, status, ackdata FROM sent WHERE msgid=?",
|
||||
msgid
|
||||
)
|
||||
try:
|
||||
return {"sentMessage": [
|
||||
self._dump_sent_message(*queryreturn[0])
|
||||
]}
|
||||
except IndexError:
|
||||
pass # FIXME inconsistent
|
||||
data = '{"sentMessage":['
|
||||
for row in queryreturn:
|
||||
msgid, toAddress, fromAddress, subject, lastactiontime, message, \
|
||||
encodingtype, status, ackdata = row
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
data += json.dumps({
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'lastActionTime': lastactiontime,
|
||||
'status': status,
|
||||
'ackData': hexlify(ackdata)}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
@command('getSentMessagesByAddress', 'getSentMessagesBySender')
|
||||
def HandleGetSentMessagesByAddress(self, fromAddress):
|
||||
"""
|
||||
The same as *getAllSentMessages* but returns only messages
|
||||
from fromAddress.
|
||||
"""
|
||||
def HandleGetSentMessagesByAddress(self, params):
|
||||
"""Handle a request to get sent messages by address"""
|
||||
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
fromAddress = params[0]
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid, toaddress, fromaddress, subject, lastactiontime,"
|
||||
" message, encodingtype, status, ackdata FROM sent"
|
||||
" WHERE folder='sent' AND fromAddress=? ORDER BY lastactiontime",
|
||||
fromAddress
|
||||
)
|
||||
return {"sentMessages": [
|
||||
self._dump_sent_message(*data) for data in queryreturn
|
||||
]}
|
||||
data = '{"sentMessages":['
|
||||
for row in queryreturn:
|
||||
msgid, toAddress, fromAddress, subject, lastactiontime, message, \
|
||||
encodingtype, status, ackdata = row
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
if len(data) > 25:
|
||||
data += ','
|
||||
data += json.dumps({
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'lastActionTime': lastactiontime,
|
||||
'status': status,
|
||||
'ackData': hexlify(ackdata)}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
@command('getSentMessageByAckData')
|
||||
def HandleGetSentMessagesByAckData(self, ackData):
|
||||
"""
|
||||
Similiar to *getSentMessageById* but searches by ackdata
|
||||
(also hex encoded).
|
||||
"""
|
||||
def HandleGetSentMessagesByAckData(self, params):
|
||||
"""Handle a request to get sent messages by ack data"""
|
||||
|
||||
ackData = self._decode(ackData, "hex")
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
ackData = self._decode(params[0], "hex")
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT msgid, toaddress, fromaddress, subject, lastactiontime,"
|
||||
" message, encodingtype, status, ackdata FROM sent"
|
||||
" WHERE ackdata=?", ackData
|
||||
)
|
||||
data = '{"sentMessage":['
|
||||
for row in queryreturn:
|
||||
msgid, toAddress, fromAddress, subject, lastactiontime, message, \
|
||||
encodingtype, status, ackdata = row
|
||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||
data += json.dumps({
|
||||
'msgid': hexlify(msgid),
|
||||
'toAddress': toAddress,
|
||||
'fromAddress': fromAddress,
|
||||
'subject': base64.b64encode(subject),
|
||||
'message': base64.b64encode(message),
|
||||
'encodingType': encodingtype,
|
||||
'lastActionTime': lastactiontime,
|
||||
'status': status,
|
||||
'ackData': hexlify(ackdata)}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
try:
|
||||
return {"sentMessage": [
|
||||
self._dump_sent_message(*queryreturn[0])
|
||||
]}
|
||||
except IndexError:
|
||||
pass # FIXME inconsistent
|
||||
def HandleTrashMessage(self, params):
|
||||
"""Handle a request to trash a message by ID"""
|
||||
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
msgid = self._decode(params[0], "hex")
|
||||
|
||||
@command('trashMessage')
|
||||
def HandleTrashMessage(self, msgid):
|
||||
"""
|
||||
Trash message by msgid (encoded in hex). Returns a simple message
|
||||
saying that the message was trashed assuming it ever even existed.
|
||||
Prior existence is not checked.
|
||||
"""
|
||||
msgid = self._decode(msgid, "hex")
|
||||
# Trash if in inbox table
|
||||
helper_inbox.trash(msgid)
|
||||
# Trash if in sent table
|
||||
sqlExecute("UPDATE sent SET folder='trash' WHERE msgid=?", msgid)
|
||||
sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid)
|
||||
return 'Trashed message (assuming message existed).'
|
||||
|
||||
@command('trashInboxMessage')
|
||||
def HandleTrashInboxMessage(self, msgid):
|
||||
"""Trash inbox message by msgid (encoded in hex)."""
|
||||
msgid = self._decode(msgid, "hex")
|
||||
def HandleTrashInboxMessage(self, params):
|
||||
"""Handle a request to trash an inbox message by ID"""
|
||||
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
msgid = self._decode(params[0], "hex")
|
||||
helper_inbox.trash(msgid)
|
||||
return 'Trashed inbox message (assuming message existed).'
|
||||
|
||||
@command('trashSentMessage')
|
||||
def HandleTrashSentMessage(self, msgid):
|
||||
"""Trash sent message by msgid (encoded in hex)."""
|
||||
msgid = self._decode(msgid, "hex")
|
||||
def HandleTrashSentMessage(self, params):
|
||||
"""Handle a request to trash a sent message by ID"""
|
||||
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
msgid = self._decode(params[0], "hex")
|
||||
sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid)
|
||||
return 'Trashed sent message (assuming message existed).'
|
||||
|
||||
@command('sendMessage')
|
||||
def HandleSendMessage(
|
||||
self, toAddress, fromAddress, subject, message,
|
||||
encodingType=2, TTL=4 * 24 * 60 * 60
|
||||
):
|
||||
"""
|
||||
Send the message and return ackdata (hex encoded string).
|
||||
subject and message must be encoded in base64 which may optionally
|
||||
include line breaks. TTL is specified in seconds; values outside
|
||||
the bounds of 3600 to 2419200 will be moved to be within those
|
||||
bounds. TTL defaults to 4 days.
|
||||
"""
|
||||
# pylint: disable=too-many-locals
|
||||
if encodingType not in (2, 3):
|
||||
def HandleSendMessage(self, params): # pylint: disable=too-many-locals
|
||||
"""Handle a request to send a message"""
|
||||
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
|
||||
elif len(params) == 4:
|
||||
toAddress, fromAddress, subject, message = params
|
||||
encodingType = 2
|
||||
TTL = 4 * 24 * 60 * 60
|
||||
|
||||
elif len(params) == 5:
|
||||
toAddress, fromAddress, subject, message, encodingType = params
|
||||
TTL = 4 * 24 * 60 * 60
|
||||
|
||||
elif len(params) == 6:
|
||||
toAddress, fromAddress, subject, message, encodingType, TTL = \
|
||||
params
|
||||
|
||||
if encodingType not in [2, 3]:
|
||||
raise APIError(6, 'The encoding type must be 2 or 3.')
|
||||
subject = self._decode(subject, "base64")
|
||||
message = self._decode(message, "base64")
|
||||
|
@ -1100,9 +999,11 @@ class BMRPCDispatcher(object):
|
|||
TTL = 28 * 24 * 60 * 60
|
||||
toAddress = addBMIfNotPresent(toAddress)
|
||||
fromAddress = addBMIfNotPresent(fromAddress)
|
||||
status, addressVersionNumber, streamNumber, toRipe = \
|
||||
self._verifyAddress(toAddress)
|
||||
self._verifyAddress(fromAddress)
|
||||
try:
|
||||
fromAddressEnabled = self.config.getboolean(
|
||||
fromAddressEnabled = BMConfigParser().getboolean(
|
||||
fromAddress, 'enabled')
|
||||
except BaseException:
|
||||
raise APIError(
|
||||
|
@ -1110,31 +1011,58 @@ class BMRPCDispatcher(object):
|
|||
if not fromAddressEnabled:
|
||||
raise APIError(14, 'Your fromAddress is disabled. Cannot send.')
|
||||
|
||||
ackdata = helper_sent.insert(
|
||||
toAddress=toAddress, fromAddress=fromAddress,
|
||||
subject=subject, message=message, encoding=encodingType, ttl=TTL)
|
||||
stealthLevel = BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
|
||||
t = ('',
|
||||
toAddress,
|
||||
toRipe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this won't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'msgqueued',
|
||||
0,
|
||||
'sent',
|
||||
2,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
|
||||
toLabel = ''
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT label FROM addressbook WHERE address=?", toAddress)
|
||||
try:
|
||||
toLabel, = queryreturn[0][0]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
if queryreturn != []:
|
||||
for row in queryreturn:
|
||||
toLabel, = row
|
||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||
toAddress, toLabel, fromAddress, subject, message, ackdata)))
|
||||
|
||||
queues.workerQueue.put(('sendmessage', toAddress))
|
||||
|
||||
return hexlify(ackdata)
|
||||
|
||||
@command('sendBroadcast')
|
||||
def HandleSendBroadcast(
|
||||
self, fromAddress, subject, message, encodingType=2,
|
||||
TTL=4 * 24 * 60 * 60):
|
||||
"""Send the broadcast message. Similiar to *sendMessage*."""
|
||||
def HandleSendBroadcast(self, params):
|
||||
"""Handle a request to send a broadcast message"""
|
||||
|
||||
if encodingType not in (2, 3):
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
|
||||
if len(params) == 3:
|
||||
fromAddress, subject, message = params
|
||||
encodingType = 2
|
||||
TTL = 4 * 24 * 60 * 60
|
||||
|
||||
elif len(params) == 4:
|
||||
fromAddress, subject, message, encodingType = params
|
||||
TTL = 4 * 24 * 60 * 60
|
||||
elif len(params) == 5:
|
||||
fromAddress, subject, message, encodingType, TTL = params
|
||||
|
||||
if encodingType not in [2, 3]:
|
||||
raise APIError(6, 'The encoding type must be 2 or 3.')
|
||||
|
||||
subject = self._decode(subject, "base64")
|
||||
|
@ -1148,61 +1076,81 @@ class BMRPCDispatcher(object):
|
|||
fromAddress = addBMIfNotPresent(fromAddress)
|
||||
self._verifyAddress(fromAddress)
|
||||
try:
|
||||
self.config.getboolean(fromAddress, 'enabled')
|
||||
BMConfigParser().getboolean(fromAddress, 'enabled')
|
||||
except BaseException:
|
||||
raise APIError(
|
||||
13, 'Could not find your fromAddress in the keys.dat file.')
|
||||
toAddress = str_broadcast_subscribers
|
||||
13, 'could not find your fromAddress in the keys.dat file.')
|
||||
streamNumber = decodeAddress(fromAddress)[2]
|
||||
ackdata = genAckPayload(streamNumber, 0)
|
||||
toAddress = '[Broadcast subscribers]'
|
||||
ripe = ''
|
||||
|
||||
ackdata = helper_sent.insert(
|
||||
fromAddress=fromAddress, subject=subject,
|
||||
message=message, status='broadcastqueued',
|
||||
encoding=encodingType)
|
||||
t = ('',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this doesn't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'broadcastqueued',
|
||||
0,
|
||||
'sent',
|
||||
2,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
|
||||
toLabel = str_broadcast_subscribers
|
||||
toLabel = '[Broadcast subscribers]'
|
||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||
toAddress, toLabel, fromAddress, subject, message, ackdata)))
|
||||
queues.workerQueue.put(('sendbroadcast', ''))
|
||||
|
||||
return hexlify(ackdata)
|
||||
|
||||
@command('getStatus')
|
||||
def HandleGetStatus(self, ackdata):
|
||||
"""
|
||||
Get the status of sent message by its ackdata (hex encoded).
|
||||
Returns one of these strings: notfound, msgqueued,
|
||||
broadcastqueued, broadcastsent, doingpubkeypow, awaitingpubkey,
|
||||
doingmsgpow, forcepow, msgsent, msgsentnoackexpected or ackreceived.
|
||||
"""
|
||||
def HandleGetStatus(self, params):
|
||||
"""Handle a request to get the status of a sent message"""
|
||||
|
||||
if len(params) != 1:
|
||||
raise APIError(0, 'I need one parameter!')
|
||||
ackdata, = params
|
||||
if len(ackdata) < 76:
|
||||
# The length of ackData should be at least 38 bytes (76 hex digits)
|
||||
raise APIError(15, 'Invalid ackData object size.')
|
||||
ackdata = self._decode(ackdata, "hex")
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT status FROM sent where ackdata=?", ackdata)
|
||||
try:
|
||||
return queryreturn[0][0]
|
||||
except IndexError:
|
||||
if queryreturn == []:
|
||||
return 'notfound'
|
||||
for row in queryreturn:
|
||||
status, = row
|
||||
return status
|
||||
|
||||
@command('addSubscription')
|
||||
def HandleAddSubscription(self, address, label=''):
|
||||
"""Subscribe to the address. label must be base64 encoded."""
|
||||
def HandleAddSubscription(self, params):
|
||||
"""Handle a request to add a subscription"""
|
||||
|
||||
if label:
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
if len(params) == 1:
|
||||
address, = params
|
||||
label = ''
|
||||
if len(params) == 2:
|
||||
address, label = params
|
||||
label = self._decode(label, "base64")
|
||||
try:
|
||||
unicode(label, 'utf-8')
|
||||
except UnicodeDecodeError:
|
||||
except BaseException:
|
||||
raise APIError(17, 'Label is not valid UTF-8 data.')
|
||||
self._verifyAddress(address)
|
||||
if len(params) > 2:
|
||||
raise APIError(0, 'I need either 1 or 2 parameters!')
|
||||
address = addBMIfNotPresent(address)
|
||||
self._verifyAddress(address)
|
||||
# First we must check to see if the address is already in the
|
||||
# subscriptions list.
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT * FROM subscriptions WHERE address=?", address)
|
||||
if queryreturn:
|
||||
if queryreturn != []:
|
||||
raise APIError(16, 'You are already subscribed to that address.')
|
||||
sqlExecute(
|
||||
"INSERT INTO subscriptions VALUES (?,?,?)", label, address, True)
|
||||
|
@ -1211,43 +1159,36 @@ class BMRPCDispatcher(object):
|
|||
queues.UISignalQueue.put(('rerenderSubscriptions', ''))
|
||||
return 'Added subscription.'
|
||||
|
||||
@command('deleteSubscription')
|
||||
def HandleDeleteSubscription(self, address):
|
||||
"""
|
||||
Unsubscribe from the address. The program does not check whether
|
||||
you were subscribed in the first place.
|
||||
"""
|
||||
def HandleDeleteSubscription(self, params):
|
||||
"""Handle a request to delete a subscription"""
|
||||
|
||||
if len(params) != 1:
|
||||
raise APIError(0, 'I need 1 parameter!')
|
||||
address, = params
|
||||
address = addBMIfNotPresent(address)
|
||||
sqlExecute("DELETE FROM subscriptions WHERE address=?", address)
|
||||
sqlExecute('''DELETE FROM subscriptions WHERE address=?''', address)
|
||||
shared.reloadBroadcastSendersForWhichImWatching()
|
||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
||||
queues.UISignalQueue.put(('rerenderSubscriptions', ''))
|
||||
return 'Deleted subscription if it existed.'
|
||||
|
||||
@command('listSubscriptions')
|
||||
def ListSubscriptions(self):
|
||||
"""
|
||||
Returns dict with a list of all subscriptions
|
||||
in the *subscriptions* key.
|
||||
"""
|
||||
def ListSubscriptions(self, params):
|
||||
"""Handle a request to list susbcriptions"""
|
||||
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT label, address, enabled FROM subscriptions")
|
||||
data = []
|
||||
for label, address, enabled in queryreturn:
|
||||
data = {'subscriptions': []}
|
||||
for row in queryreturn:
|
||||
label, address, enabled = row
|
||||
label = shared.fixPotentiallyInvalidUTF8Data(label)
|
||||
data.append({
|
||||
data['subscriptions'].append({
|
||||
'label': base64.b64encode(label),
|
||||
'address': address,
|
||||
'enabled': enabled == 1
|
||||
})
|
||||
return {'subscriptions': data}
|
||||
return json.dumps(data, indent=4, separators=(',', ': '))
|
||||
|
||||
@command('disseminatePreEncryptedMsg')
|
||||
def HandleDisseminatePreEncryptedMsg(
|
||||
self, encryptedPayload, requiredAverageProofOfWorkNonceTrialsPerByte,
|
||||
requiredPayloadLengthExtraBytes):
|
||||
def HandleDisseminatePreEncryptedMsg(self, params):
|
||||
"""Handle a request to disseminate an encrypted message"""
|
||||
|
||||
# The device issuing this command to PyBitmessage supplies a msg
|
||||
|
@ -1255,28 +1196,42 @@ class BMRPCDispatcher(object):
|
|||
# to be done. PyBitmessage accepts this msg object and sends it out
|
||||
# to the rest of the Bitmessage network as if it had generated
|
||||
# the message itself. Please do not yet add this to the api doc.
|
||||
if len(params) != 3:
|
||||
raise APIError(0, 'I need 3 parameter!')
|
||||
encryptedPayload, requiredAverageProofOfWorkNonceTrialsPerByte, \
|
||||
requiredPayloadLengthExtraBytes = params
|
||||
encryptedPayload = self._decode(encryptedPayload, "hex")
|
||||
# Let us do the POW and attach it to the front
|
||||
target = 2**64 / ((
|
||||
len(encryptedPayload) + requiredPayloadLengthExtraBytes + 8) *
|
||||
requiredAverageProofOfWorkNonceTrialsPerByte)
|
||||
logger.info(
|
||||
'(For msg message via API) Doing proof of work. Total required'
|
||||
' difficulty: %s\nRequired small message difficulty: %s',
|
||||
float(requiredAverageProofOfWorkNonceTrialsPerByte) /
|
||||
defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
|
||||
float(requiredPayloadLengthExtraBytes) /
|
||||
defaults.networkDefaultPayloadLengthExtraBytes,
|
||||
target = 2**64 / (
|
||||
(
|
||||
len(encryptedPayload) + requiredPayloadLengthExtraBytes + 8
|
||||
) * requiredAverageProofOfWorkNonceTrialsPerByte
|
||||
)
|
||||
with threads.printLock:
|
||||
print(
|
||||
'(For msg message via API) Doing proof of work.'
|
||||
'Total required difficulty:',
|
||||
float(
|
||||
requiredAverageProofOfWorkNonceTrialsPerByte
|
||||
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
|
||||
'Required small message difficulty:',
|
||||
float(
|
||||
requiredPayloadLengthExtraBytes
|
||||
) / defaults.networkDefaultPayloadLengthExtraBytes,
|
||||
)
|
||||
powStartTime = time.time()
|
||||
initialHash = hashlib.sha512(encryptedPayload).digest()
|
||||
trialValue, nonce = proofofwork.run(target, initialHash)
|
||||
logger.info(
|
||||
'(For msg message via API) Found proof of work %s\nNonce: %s\n'
|
||||
'POW took %s seconds. %s nonce trials per second.',
|
||||
trialValue, nonce, int(time.time() - powStartTime),
|
||||
nonce / (time.time() - powStartTime)
|
||||
)
|
||||
with threads.printLock:
|
||||
print '(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce
|
||||
try:
|
||||
print(
|
||||
'POW took', int(time.time() - powStartTime),
|
||||
'seconds.', nonce / (time.time() - powStartTime),
|
||||
'nonce trials per second.',
|
||||
)
|
||||
except BaseException:
|
||||
pass
|
||||
encryptedPayload = pack('>Q', nonce) + encryptedPayload
|
||||
toStreamNumber = decodeVarint(encryptedPayload[16:26])[0]
|
||||
inventoryHash = calculateInventoryHash(encryptedPayload)
|
||||
|
@ -1286,21 +1241,21 @@ class BMRPCDispatcher(object):
|
|||
objectType, toStreamNumber, encryptedPayload,
|
||||
int(time.time()) + TTL, ''
|
||||
)
|
||||
logger.info(
|
||||
'Broadcasting inv for msg(API disseminatePreEncryptedMsg'
|
||||
' command): %s', hexlify(inventoryHash))
|
||||
with threads.printLock:
|
||||
print 'Broadcasting inv for msg(API disseminatePreEncryptedMsg command):', hexlify(inventoryHash)
|
||||
queues.invQueue.put((toStreamNumber, inventoryHash))
|
||||
|
||||
@command('trashSentMessageByAckData')
|
||||
def HandleTrashSentMessageByAckDAta(self, ackdata):
|
||||
"""Trash a sent message by ackdata (hex encoded)"""
|
||||
def HandleTrashSentMessageByAckDAta(self, params):
|
||||
"""Handle a request to trash a sent message by ackdata"""
|
||||
|
||||
# This API method should only be used when msgid is not available
|
||||
ackdata = self._decode(ackdata, "hex")
|
||||
if not params:
|
||||
raise APIError(0, 'I need parameters!')
|
||||
ackdata = self._decode(params[0], "hex")
|
||||
sqlExecute("UPDATE sent SET folder='trash' WHERE ackdata=?", ackdata)
|
||||
return 'Trashed sent message (assuming message existed).'
|
||||
|
||||
@command('disseminatePubkey')
|
||||
def HandleDissimatePubKey(self, payload):
|
||||
def HandleDissimatePubKey(self, params):
|
||||
"""Handle a request to disseminate a public key"""
|
||||
|
||||
# The device issuing this command to PyBitmessage supplies a pubkey
|
||||
|
@ -1308,19 +1263,19 @@ class BMRPCDispatcher(object):
|
|||
# PyBitmessage accepts this pubkey object and sends it out to the rest
|
||||
# of the Bitmessage network as if it had generated the pubkey object
|
||||
# itself. Please do not yet add this to the api doc.
|
||||
if len(params) != 1:
|
||||
raise APIError(0, 'I need 1 parameter!')
|
||||
payload, = params
|
||||
payload = self._decode(payload, "hex")
|
||||
|
||||
# Let us do the POW
|
||||
target = 2 ** 64 / ((
|
||||
len(payload) + defaults.networkDefaultPayloadLengthExtraBytes + 8
|
||||
) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
|
||||
logger.info('(For pubkey message via API) Doing proof of work...')
|
||||
print '(For pubkey message via API) Doing proof of work...'
|
||||
initialHash = hashlib.sha512(payload).digest()
|
||||
trialValue, nonce = proofofwork.run(target, initialHash)
|
||||
logger.info(
|
||||
'(For pubkey message via API) Found proof of work %s Nonce: %s',
|
||||
trialValue, nonce
|
||||
)
|
||||
print '(For pubkey message via API) Found proof of work', trialValue, 'Nonce:', nonce
|
||||
payload = pack('>Q', nonce) + payload
|
||||
|
||||
pubkeyReadPosition = 8 # bypass the nonce
|
||||
|
@ -1329,8 +1284,8 @@ class BMRPCDispatcher(object):
|
|||
pubkeyReadPosition += 8
|
||||
else:
|
||||
pubkeyReadPosition += 4
|
||||
addressVersionLength = decodeVarint(
|
||||
payload[pubkeyReadPosition:pubkeyReadPosition + 10])[1]
|
||||
addressVersion, addressVersionLength = decodeVarint(
|
||||
payload[pubkeyReadPosition:pubkeyReadPosition + 10])
|
||||
pubkeyReadPosition += addressVersionLength
|
||||
pubkeyStreamNumber = decodeVarint(
|
||||
payload[pubkeyReadPosition:pubkeyReadPosition + 10])[0]
|
||||
|
@ -1340,19 +1295,19 @@ class BMRPCDispatcher(object):
|
|||
Inventory()[inventoryHash] = (
|
||||
objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, ''
|
||||
)
|
||||
logger.info(
|
||||
'broadcasting inv within API command disseminatePubkey with'
|
||||
' hash: %s', hexlify(inventoryHash))
|
||||
with threads.printLock:
|
||||
print 'broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash)
|
||||
queues.invQueue.put((pubkeyStreamNumber, inventoryHash))
|
||||
|
||||
@command(
|
||||
'getMessageDataByDestinationHash', 'getMessageDataByDestinationTag')
|
||||
def HandleGetMessageDataByDestinationHash(self, requestedHash):
|
||||
def HandleGetMessageDataByDestinationHash(self, params):
|
||||
"""Handle a request to get message data by destination hash"""
|
||||
|
||||
# Method will eventually be used by a particular Android app to
|
||||
# select relevant messages. Do not yet add this to the api
|
||||
# doc.
|
||||
if len(params) != 1:
|
||||
raise APIError(0, 'I need 1 parameter!')
|
||||
requestedHash, = params
|
||||
if len(requestedHash) != 32:
|
||||
raise APIError(
|
||||
19, 'The length of hash should be 32 bytes (encoded in hex'
|
||||
|
@ -1366,7 +1321,8 @@ class BMRPCDispatcher(object):
|
|||
"SELECT hash, payload FROM inventory WHERE tag = ''"
|
||||
" and objecttype = 2")
|
||||
with SqlBulkExecute() as sql:
|
||||
for hash01, payload in queryreturn:
|
||||
for row in queryreturn:
|
||||
hash01, payload = row
|
||||
readPosition = 16 # Nonce length + time length
|
||||
# Stream Number length
|
||||
readPosition += decodeVarint(
|
||||
|
@ -1376,21 +1332,18 @@ class BMRPCDispatcher(object):
|
|||
|
||||
queryreturn = sqlQuery(
|
||||
"SELECT payload FROM inventory WHERE tag = ?", requestedHash)
|
||||
return {"receivedMessageDatas": [
|
||||
{'data': hexlify(payload)} for payload, in queryreturn
|
||||
]}
|
||||
data = '{"receivedMessageDatas":['
|
||||
for row in queryreturn:
|
||||
payload, = row
|
||||
if len(data) > 25:
|
||||
data += ','
|
||||
data += json.dumps(
|
||||
{'data': hexlify(payload)}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
@command('clientStatus')
|
||||
def HandleClientStatus(self):
|
||||
"""
|
||||
Returns the bitmessage status as dict with keys *networkConnections*,
|
||||
*numberOfMessagesProcessed*, *numberOfBroadcastsProcessed*,
|
||||
*numberOfPubkeysProcessed*, *pendingDownload*, *networkStatus*,
|
||||
*softwareName*, *softwareVersion*. *networkStatus* will be one of
|
||||
these strings: "notConnected",
|
||||
"connectedButHaveNotReceivedIncomingConnections",
|
||||
or "connectedAndReceivingIncomingConnections".
|
||||
"""
|
||||
def HandleClientStatus(self, params):
|
||||
"""Handle a request to get the status of the client"""
|
||||
|
||||
connections_num = len(network.stats.connectedHostsList())
|
||||
if connections_num == 0:
|
||||
|
@ -1399,98 +1352,149 @@ class BMRPCDispatcher(object):
|
|||
networkStatus = 'connectedAndReceivingIncomingConnections'
|
||||
else:
|
||||
networkStatus = 'connectedButHaveNotReceivedIncomingConnections'
|
||||
return {
|
||||
return json.dumps({
|
||||
'networkConnections': connections_num,
|
||||
'numberOfMessagesProcessed': state.numberOfMessagesProcessed,
|
||||
'numberOfBroadcastsProcessed': state.numberOfBroadcastsProcessed,
|
||||
'numberOfPubkeysProcessed': state.numberOfPubkeysProcessed,
|
||||
'pendingDownload': network.stats.pendingDownload(),
|
||||
'networkStatus': networkStatus,
|
||||
'softwareName': 'PyBitmessage',
|
||||
'softwareVersion': softwareVersion
|
||||
}
|
||||
}, indent=4, separators=(',', ': '))
|
||||
|
||||
@command('helloWorld')
|
||||
def HandleHelloWorld(self, a, b):
|
||||
def HandleDecodeAddress(self, params):
|
||||
"""Handle a request to decode an address"""
|
||||
|
||||
# Return a meaningful decoding of an address.
|
||||
if len(params) != 1:
|
||||
raise APIError(0, 'I need 1 parameter!')
|
||||
address, = params
|
||||
status, addressVersion, streamNumber, ripe = decodeAddress(address)
|
||||
return json.dumps({
|
||||
'status': status,
|
||||
'addressVersion': addressVersion,
|
||||
'streamNumber': streamNumber,
|
||||
'ripe': base64.b64encode(ripe)
|
||||
}, indent=4, separators=(',', ': '))
|
||||
|
||||
def HandleHelloWorld(self, params):
|
||||
"""Test two string params"""
|
||||
|
||||
a, b = params
|
||||
return a + '-' + b
|
||||
|
||||
@command('add')
|
||||
def HandleAdd(self, a, b):
|
||||
def HandleAdd(self, params):
|
||||
"""Test two numeric params"""
|
||||
|
||||
a, b = params
|
||||
return a + b
|
||||
|
||||
@command('statusBar')
|
||||
def HandleStatusBar(self, message):
|
||||
"""Update GUI statusbar message"""
|
||||
def HandleStatusBar(self, params):
|
||||
"""Handle a request to update the status bar"""
|
||||
|
||||
message, = params
|
||||
queues.UISignalQueue.put(('updateStatusBar', message))
|
||||
|
||||
@command('deleteAndVacuum')
|
||||
def HandleDeleteAndVacuum(self):
|
||||
"""Cleanup trashes and vacuum messages database"""
|
||||
sqlStoredProcedure('deleteandvacuume')
|
||||
return 'done'
|
||||
def HandleDeleteAndVacuum(self, params):
|
||||
"""Handle a request to run the deleteandvacuum stored procedure"""
|
||||
|
||||
@command('shutdown')
|
||||
def HandleShutdown(self):
|
||||
"""Shutdown the bitmessage. Returns 'done'."""
|
||||
# backward compatible trick because False == 0 is True
|
||||
state.shutdown = False
|
||||
return 'done'
|
||||
if not params:
|
||||
sqlStoredProcedure('deleteandvacuume')
|
||||
return 'done'
|
||||
return None
|
||||
|
||||
def HandleShutdown(self, params):
|
||||
"""Handle a request to shutdown the node"""
|
||||
|
||||
if not params:
|
||||
# backward compatible trick because False == 0 is True
|
||||
state.shutdown = False
|
||||
return 'done'
|
||||
return None
|
||||
|
||||
handlers = {}
|
||||
handlers['helloWorld'] = HandleHelloWorld
|
||||
handlers['add'] = HandleAdd
|
||||
handlers['statusBar'] = HandleStatusBar
|
||||
handlers['listAddresses'] = HandleListAddresses
|
||||
handlers['listAddressBookEntries'] = HandleListAddressBookEntries
|
||||
# the listAddressbook alias should be removed eventually.
|
||||
handlers['listAddressbook'] = HandleListAddressBookEntries
|
||||
handlers['addAddressBookEntry'] = HandleAddAddressBookEntry
|
||||
# the addAddressbook alias should be deleted eventually.
|
||||
handlers['addAddressbook'] = HandleAddAddressBookEntry
|
||||
handlers['deleteAddressBookEntry'] = HandleDeleteAddressBookEntry
|
||||
# The deleteAddressbook alias should be deleted eventually.
|
||||
handlers['deleteAddressbook'] = HandleDeleteAddressBookEntry
|
||||
handlers['createRandomAddress'] = HandleCreateRandomAddress
|
||||
handlers['createDeterministicAddresses'] = \
|
||||
HandleCreateDeterministicAddresses
|
||||
handlers['getDeterministicAddress'] = HandleGetDeterministicAddress
|
||||
handlers['createChan'] = HandleCreateChan
|
||||
handlers['joinChan'] = HandleJoinChan
|
||||
handlers['leaveChan'] = HandleLeaveChan
|
||||
handlers['deleteAddress'] = HandleDeleteAddress
|
||||
handlers['getAllInboxMessages'] = HandleGetAllInboxMessages
|
||||
handlers['getAllInboxMessageIds'] = HandleGetAllInboxMessageIds
|
||||
handlers['getAllInboxMessageIDs'] = HandleGetAllInboxMessageIds
|
||||
handlers['getInboxMessageById'] = HandleGetInboxMessageById
|
||||
handlers['getInboxMessageByID'] = HandleGetInboxMessageById
|
||||
handlers['getAllSentMessages'] = HandleGetAllSentMessages
|
||||
handlers['getAllSentMessageIds'] = HandleGetAllSentMessageIds
|
||||
handlers['getAllSentMessageIDs'] = HandleGetAllSentMessageIds
|
||||
handlers['getInboxMessagesByReceiver'] = HandleInboxMessagesByReceiver
|
||||
# after some time getInboxMessagesByAddress should be removed
|
||||
handlers['getInboxMessagesByAddress'] = HandleInboxMessagesByReceiver
|
||||
handlers['getSentMessageById'] = HandleGetSentMessageById
|
||||
handlers['getSentMessageByID'] = HandleGetSentMessageById
|
||||
handlers['getSentMessagesByAddress'] = HandleGetSentMessagesByAddress
|
||||
handlers['getSentMessagesBySender'] = HandleGetSentMessagesByAddress
|
||||
handlers['getSentMessageByAckData'] = HandleGetSentMessagesByAckData
|
||||
handlers['trashMessage'] = HandleTrashMessage
|
||||
handlers['trashInboxMessage'] = HandleTrashInboxMessage
|
||||
handlers['trashSentMessage'] = HandleTrashSentMessage
|
||||
handlers['trashSentMessageByAckData'] = HandleTrashSentMessageByAckDAta
|
||||
handlers['sendMessage'] = HandleSendMessage
|
||||
handlers['sendBroadcast'] = HandleSendBroadcast
|
||||
handlers['getStatus'] = HandleGetStatus
|
||||
handlers['addSubscription'] = HandleAddSubscription
|
||||
handlers['deleteSubscription'] = HandleDeleteSubscription
|
||||
handlers['listSubscriptions'] = ListSubscriptions
|
||||
handlers['disseminatePreEncryptedMsg'] = HandleDisseminatePreEncryptedMsg
|
||||
handlers['disseminatePubkey'] = HandleDissimatePubKey
|
||||
handlers['getMessageDataByDestinationHash'] = \
|
||||
HandleGetMessageDataByDestinationHash
|
||||
handlers['getMessageDataByDestinationTag'] = \
|
||||
HandleGetMessageDataByDestinationHash
|
||||
handlers['clientStatus'] = HandleClientStatus
|
||||
handlers['decodeAddress'] = HandleDecodeAddress
|
||||
handlers['deleteAndVacuum'] = HandleDeleteAndVacuum
|
||||
handlers['shutdown'] = HandleShutdown
|
||||
|
||||
def _handle_request(self, method, params):
|
||||
try:
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
self._method = method
|
||||
func = self._handlers[method]
|
||||
return func(self, *params)
|
||||
except KeyError:
|
||||
if method not in self.handlers:
|
||||
raise APIError(20, 'Invalid method: %s' % method)
|
||||
except TypeError as e:
|
||||
msg = 'Unexpected API Failure - %s' % e
|
||||
if 'argument' not in str(e):
|
||||
raise APIError(21, msg)
|
||||
argcount = len(params)
|
||||
maxcount = func.func_code.co_argcount
|
||||
if argcount > maxcount:
|
||||
msg = (
|
||||
'Command %s takes at most %s parameters (%s given)'
|
||||
% (method, maxcount, argcount))
|
||||
else:
|
||||
mincount = maxcount - len(func.func_defaults or [])
|
||||
if argcount < mincount:
|
||||
msg = (
|
||||
'Command %s takes at least %s parameters (%s given)'
|
||||
% (method, mincount, argcount))
|
||||
raise APIError(0, msg)
|
||||
finally:
|
||||
state.last_api_response = time.time()
|
||||
result = self.handlers[method](self, params)
|
||||
state.last_api_response = time.time()
|
||||
return result
|
||||
|
||||
def _dispatch(self, method, params):
|
||||
_fault = None
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
self.cookies = []
|
||||
|
||||
validuser = self.APIAuthenticateClient()
|
||||
if not validuser:
|
||||
time.sleep(2)
|
||||
return "RPC Username or password incorrect or HTTP header lacks authentication at all."
|
||||
|
||||
try:
|
||||
return self._handle_request(method, params)
|
||||
except APIError as e:
|
||||
_fault = e
|
||||
return str(e)
|
||||
except varintDecodeError as e:
|
||||
logger.error(e)
|
||||
_fault = APIError(
|
||||
26, 'Data contains a malformed varint. Some details: %s' % e)
|
||||
return "API Error 0026: Data contains a malformed varint. Some details: %s" % e
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
_fault = APIError(21, 'Unexpected API Failure - %s' % e)
|
||||
|
||||
if _fault:
|
||||
if self.config.safeGet(
|
||||
'bitmessagesettings', 'apivariant') == 'legacy':
|
||||
return str(_fault)
|
||||
else:
|
||||
raise _fault # pylint: disable=raising-bad-type
|
||||
|
||||
def _listMethods(self):
|
||||
"""List all API commands"""
|
||||
return self._handlers.keys()
|
||||
|
||||
def _methodHelp(self, method):
|
||||
return self._handlers[method].__doc__
|
||||
return "API Error 0021: Unexpected API Failure - %s" % e
|
||||
|
|
|
@ -19,7 +19,6 @@ from textwrap import fill
|
|||
from threading import Timer
|
||||
|
||||
from dialog import Dialog
|
||||
import helper_sent
|
||||
import l10n
|
||||
import network.stats
|
||||
import queues
|
||||
|
@ -29,9 +28,9 @@ import state
|
|||
|
||||
from addresses import addBMIfNotPresent, decodeAddress
|
||||
from bmconfigparser import BMConfigParser
|
||||
from helper_ackPayload import genAckPayload
|
||||
from helper_sql import sqlExecute, sqlQuery
|
||||
from inventory import Inventory
|
||||
|
||||
# pylint: disable=global-statement
|
||||
|
||||
|
||||
|
@ -919,7 +918,8 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
list(set(recvlist)) # Remove exact duplicates
|
||||
for addr in recvlist:
|
||||
if addr != "":
|
||||
status, version, stream = decodeAddress(addr)[:3]
|
||||
# pylint: disable=redefined-outer-name
|
||||
status, version, stream, ripe = decodeAddress(addr)
|
||||
if status != "success":
|
||||
set_background_title(d, "Recipient address error")
|
||||
err = "Could not decode" + addr + " : " + status + "\n\n"
|
||||
|
@ -964,8 +964,25 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
if not network.stats.connectedHostsList():
|
||||
set_background_title(d, "Not connected warning")
|
||||
scrollbox(d, unicode("Because you are not currently connected to the network, "))
|
||||
helper_sent.insert(
|
||||
toAddress=addr, fromAddress=sender, subject=subject, message=body)
|
||||
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel)
|
||||
sqlExecute(
|
||||
"INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||
"",
|
||||
addr,
|
||||
ripe,
|
||||
sender,
|
||||
subject,
|
||||
body,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this will never change)
|
||||
int(time.time()), # lastActionTime
|
||||
0, # sleepTill time. This will get set when the POW gets done.
|
||||
"msgqueued",
|
||||
0, # retryNumber
|
||||
"sent",
|
||||
2, # encodingType
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl'))
|
||||
queues.workerQueue.put(("sendmessage", addr))
|
||||
else: # Broadcast
|
||||
if recv == "":
|
||||
|
@ -973,9 +990,26 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
scrollbox(d, unicode("You must specify an address to send the message from."))
|
||||
else:
|
||||
# dummy ackdata, no need for stealth
|
||||
helper_sent.insert(
|
||||
fromAddress=sender, subject=subject,
|
||||
message=body, status='broadcastqueued')
|
||||
ackdata = genAckPayload(decodeAddress(addr)[2], 0)
|
||||
recv = BROADCAST_STR
|
||||
ripe = ""
|
||||
sqlExecute(
|
||||
"INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||
"",
|
||||
recv,
|
||||
ripe,
|
||||
sender,
|
||||
subject,
|
||||
body,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this will never change)
|
||||
int(time.time()), # lastActionTime
|
||||
0, # sleepTill time. This will get set when the POW gets done.
|
||||
"broadcastqueued",
|
||||
0, # retryNumber
|
||||
"sent", # folder
|
||||
2, # encodingType
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl'))
|
||||
queues.workerQueue.put(('sendbroadcast', ''))
|
||||
|
||||
|
||||
|
@ -983,7 +1017,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
def loadInbox():
|
||||
"""Load the list of messages"""
|
||||
sys.stdout = sys.__stdout__
|
||||
print("Loading inbox messages...")
|
||||
print "Loading inbox messages..."
|
||||
sys.stdout = printlog
|
||||
|
||||
where = "toaddress || fromaddress || subject || message"
|
||||
|
@ -1035,7 +1069,7 @@ def loadInbox():
|
|||
def loadSent():
|
||||
"""Load the messages that sent"""
|
||||
sys.stdout = sys.__stdout__
|
||||
print("Loading sent messages...")
|
||||
print "Loading sent messages..."
|
||||
sys.stdout = printlog
|
||||
|
||||
where = "toaddress || fromaddress || subject || message"
|
||||
|
@ -1121,7 +1155,7 @@ def loadSent():
|
|||
def loadAddrBook():
|
||||
"""Load address book"""
|
||||
sys.stdout = sys.__stdout__
|
||||
print("Loading address book...")
|
||||
print "Loading address book..."
|
||||
sys.stdout = printlog
|
||||
|
||||
ret = sqlQuery("SELECT label, address FROM addressbook")
|
||||
|
@ -1228,7 +1262,7 @@ def run(stdscr):
|
|||
def doShutdown():
|
||||
"""Shutting the app down"""
|
||||
sys.stdout = sys.__stdout__
|
||||
print("Shutting down...")
|
||||
print "Shutting down..."
|
||||
sys.stdout = printlog
|
||||
shutdown.doCleanShutdown()
|
||||
sys.stdout = sys.__stdout__
|
||||
|
|
0
src/bitmessagekivy/__init__.py
Normal file
45
src/bitmessagekivy/kivy_helper_search.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
from helper_sql import *
|
||||
|
||||
|
||||
def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, what=None, unreadOnly=False):
|
||||
if what is not None and what != "":
|
||||
what = "%" + what + "%"
|
||||
else:
|
||||
what = None
|
||||
|
||||
if folder == "sent":
|
||||
sqlStatementBase = '''
|
||||
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
|
||||
FROM sent '''
|
||||
else:
|
||||
sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
|
||||
FROM inbox '''
|
||||
sqlStatementParts = []
|
||||
sqlArguments = []
|
||||
if account is not None:
|
||||
if xAddress == 'both':
|
||||
sqlStatementParts.append("(fromaddress = ? OR toaddress = ?)")
|
||||
sqlArguments.append(account)
|
||||
sqlArguments.append(account)
|
||||
else:
|
||||
sqlStatementParts.append(xAddress + " = ? ")
|
||||
sqlArguments.append(account)
|
||||
if folder is not None:
|
||||
if folder == "new":
|
||||
folder = "inbox"
|
||||
unreadOnly = True
|
||||
sqlStatementParts.append("folder = ? ")
|
||||
sqlArguments.append(folder)
|
||||
else:
|
||||
sqlStatementParts.append("folder != ?")
|
||||
sqlArguments.append("trash")
|
||||
if what is not None:
|
||||
sqlStatementParts.append("%s LIKE ?" % (where))
|
||||
sqlArguments.append(what)
|
||||
if unreadOnly:
|
||||
sqlStatementParts.append("read = 0")
|
||||
if len(sqlStatementParts) > 0:
|
||||
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
|
||||
if folder == "sent":
|
||||
sqlStatementBase += " ORDER BY lastactiontime"
|
||||
return sqlQuery(sqlStatementBase, sqlArguments)
|
354
src/bitmessagekivy/main.kv
Normal file
|
@ -0,0 +1,354 @@
|
|||
#:import la kivy.adapters.listadapter
|
||||
#:import factory kivy.factory
|
||||
#:import mpybit bitmessagekivy.mpybit
|
||||
#:import C kivy.utils.get_color_from_hex
|
||||
|
||||
<Navigator>:
|
||||
id: nav_drawer
|
||||
NavigationDrawerIconButton:
|
||||
Spinner:
|
||||
pos_hint:{"x":0,"y":.3}
|
||||
id: btn
|
||||
background_color: app.theme_cls.primary_dark
|
||||
text: app.showmeaddresses(name='text')
|
||||
values: app.showmeaddresses(name='values')
|
||||
on_text:app.getCurrentAccountData(self.text)
|
||||
|
||||
NavigationDrawerIconButton:
|
||||
icon: 'email-open'
|
||||
text: "inbox"
|
||||
on_release: app.root.ids.scr_mngr.current = 'inbox'
|
||||
NavigationDrawerIconButton:
|
||||
icon: 'mail-send'
|
||||
text: "sent"
|
||||
on_release: app.root.ids.scr_mngr.current = 'sent'
|
||||
NavigationDrawerIconButton:
|
||||
icon: 'dropbox'
|
||||
text: "trash"
|
||||
on_release: app.root.ids.scr_mngr.current = 'trash'
|
||||
NavigationDrawerIconButton:
|
||||
icon: 'email'
|
||||
text: "drafts"
|
||||
on_release: app.root.ids.scr_mngr.current = 'dialog'
|
||||
NavigationDrawerIconButton:
|
||||
icon: 'markunread-mailbox'
|
||||
text: "test"
|
||||
on_release: app.root.ids.scr_mngr.current = 'test'
|
||||
NavigationDrawerIconButton:
|
||||
text: "new identity"
|
||||
icon:'accounts-add'
|
||||
on_release: app.root.ids.scr_mngr.current = 'newidentity'
|
||||
|
||||
BoxLayout:
|
||||
orientation: 'vertical'
|
||||
Toolbar:
|
||||
id: toolbar
|
||||
title: app.getCurrentAccount()
|
||||
background_color: app.theme_cls.primary_dark
|
||||
left_action_items: [['menu', lambda x: app.nav_drawer.toggle()]]
|
||||
Button:
|
||||
text:"EXIT"
|
||||
color: 0,0,0,1
|
||||
background_color: (0,0,0,0)
|
||||
size_hint_y: 0.4
|
||||
size_hint_x: 0.1
|
||||
pos_hint: {'x': 0.8, 'y':0.4}
|
||||
on_press: app.say_exit()
|
||||
|
||||
|
||||
ScreenManager:
|
||||
id: scr_mngr
|
||||
Inbox:
|
||||
id:sc1
|
||||
Sent:
|
||||
id:sc2
|
||||
Trash:
|
||||
id:sc3
|
||||
Dialog:
|
||||
id:sc4
|
||||
Test:
|
||||
id:sc5
|
||||
Create:
|
||||
id:sc6
|
||||
NewIdentity:
|
||||
id:sc7
|
||||
Page:
|
||||
id:sc8
|
||||
AddressSuccessful:
|
||||
id:sc9
|
||||
|
||||
Button:
|
||||
id:create
|
||||
height:100
|
||||
size_hint_y: 0.13
|
||||
size_hint_x: 0.1
|
||||
pos_hint: {'x': 0.85, 'y': 0.5}
|
||||
background_color: (0,0,0,0)
|
||||
on_press: scr_mngr.current = 'create'
|
||||
Image:
|
||||
source: 'images/plus.png'
|
||||
y: self.parent.y - 7.5
|
||||
x: self.parent.x + self.parent.width - 50
|
||||
size: 70, 70
|
||||
|
||||
<SwipeButton@Carousel>:
|
||||
text: ''
|
||||
size_hint_y: None
|
||||
height: 48
|
||||
ignore_perpendicular_swipes: True
|
||||
data_index: 0
|
||||
min_move: 20 / self.width
|
||||
|
||||
on__offset: app.update_index(root.data_index, self.index)
|
||||
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: C('FFFFFF33')
|
||||
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
Line:
|
||||
rectangle: self.pos + self.size
|
||||
|
||||
Button:
|
||||
text: 'delete ({}:{})'.format(root.text, root.data_index)
|
||||
on_press: app.delete(root.data_index)
|
||||
|
||||
Button:
|
||||
text: root.text
|
||||
on_press: app.getInboxMessageDetail(self.text)
|
||||
|
||||
Button:
|
||||
text: 'archive'
|
||||
on_press: app.archive(root.data_index)
|
||||
|
||||
<Inbox>:
|
||||
name: 'inbox'
|
||||
RecycleView:
|
||||
data: root.data
|
||||
viewclass: 'SwipeButton'
|
||||
do_scroll_x: False
|
||||
scroll_timeout: 100
|
||||
|
||||
RecycleBoxLayout:
|
||||
id:rc
|
||||
orientation: 'vertical'
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
default_size_hint: 1, None
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: 0,0,0, 1
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<Sent>:
|
||||
name: 'sent'
|
||||
RecycleView:
|
||||
data: root.data
|
||||
viewclass: 'SwipeButton'
|
||||
do_scroll_x: False
|
||||
scroll_timeout: 100
|
||||
|
||||
RecycleBoxLayout:
|
||||
id:rc
|
||||
orientation: 'vertical'
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
default_size_hint: 1, None
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: 0,0,0, 1
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<Trash>:
|
||||
name: 'trash'
|
||||
RecycleView:
|
||||
data: root.data
|
||||
viewclass: 'SwipeButton'
|
||||
do_scroll_x: False
|
||||
scroll_timeout: 100
|
||||
|
||||
RecycleBoxLayout:
|
||||
id:rc
|
||||
orientation: 'vertical'
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
default_size_hint: 1, None
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: 0,0,0, 1
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<Dialog>:
|
||||
name: 'dialog'
|
||||
Label:
|
||||
text:"I have a good dialox box"
|
||||
color: 0,0,0,1
|
||||
<Test>:
|
||||
name: 'test'
|
||||
Label:
|
||||
text:"I am in test"
|
||||
color: 0,0,0,1
|
||||
|
||||
<Create>:
|
||||
name: 'create'
|
||||
GridLayout:
|
||||
rows: 5
|
||||
cols: 1
|
||||
padding: 60,60,60,60
|
||||
spacing: 50
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
Label:
|
||||
text: 'FROM'
|
||||
color: 0,0,0,1
|
||||
Spinner:
|
||||
size_hint: 1,1
|
||||
pos_hint: {"x":0,"top":1.}
|
||||
pos: 10,10
|
||||
id: spinner_id
|
||||
text: app.showmeaddresses(name='text')
|
||||
values: app.showmeaddresses(name='values')
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
Label:
|
||||
text: 'TO'
|
||||
color: 0,0,0,1
|
||||
TextInput:
|
||||
id: recipent
|
||||
hint_text: 'To'
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
Label:
|
||||
text: 'SUBJECT'
|
||||
color: 0,0,0,1
|
||||
TextInput:
|
||||
id: subject
|
||||
hint_text: 'SUBJECT'
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
Label:
|
||||
text: 'BODY'
|
||||
color: 0,0,0,1
|
||||
TextInput:
|
||||
id: message
|
||||
multiline:True
|
||||
size_hint: 1,2
|
||||
|
||||
Button:
|
||||
text: 'send'
|
||||
size_hint_y: 0.1
|
||||
size_hint_x: 0.2
|
||||
height: '32dp'
|
||||
pos_hint: {'x': .5, 'y': 0.1}
|
||||
on_press: root.send()
|
||||
Button:
|
||||
text: 'cancel'
|
||||
size_hint_y: 0.1
|
||||
size_hint_x: 0.2
|
||||
height: '32dp'
|
||||
pos_hint: {'x': .72, 'y': 0.1}
|
||||
on_press: root.cancel()
|
||||
|
||||
<NewIdentity>:
|
||||
name: 'newidentity'
|
||||
GridLayout:
|
||||
padding: '120dp'
|
||||
cols: 1
|
||||
Label:
|
||||
text:"""Here you may generate as many addresses as you like. Indeed, creating and abandoning addresses is encouraged."""
|
||||
line_height:1.5
|
||||
text_size:(700,None)
|
||||
color: 0,0,0,1
|
||||
BoxLayout:
|
||||
CheckBox:
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: 1,0,0
|
||||
Ellipse:
|
||||
pos:self.center_x-8, self.center_y-8
|
||||
size:[16,16]
|
||||
group: "money"
|
||||
id:chk
|
||||
text:"use a random number generator to make an address"
|
||||
on_active:
|
||||
root.checked = self.text
|
||||
active:root.is_active
|
||||
|
||||
Label:
|
||||
text: "use a random number generator to make an address"
|
||||
color: 0,0,0,1
|
||||
BoxLayout:
|
||||
CheckBox:
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: 1,0,0
|
||||
Ellipse:
|
||||
pos:self.center_x-8, self.center_y-8
|
||||
size:[16,16]
|
||||
group: "money"
|
||||
id:chk
|
||||
text:"use a pseudo number generator to make an address"
|
||||
on_active:
|
||||
root.checked = self.text
|
||||
active:not root.is_active
|
||||
Label:
|
||||
text: "use a pseudo number generator to make an address"
|
||||
color: 0,0,0,1
|
||||
Label:
|
||||
color: 0,0,0,1
|
||||
size_hint_x: .35
|
||||
markup: True
|
||||
text: "[b]{}[/b]".format("Randomly generated addresses")
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
Label:
|
||||
text: "Label (not shown to anyone except you)"
|
||||
color: 0,0,0,1
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
TextInput:
|
||||
id: label
|
||||
|
||||
Button:
|
||||
text: 'Cancel'
|
||||
size_hint_y: 0.1
|
||||
size_hint_x: 0.3
|
||||
height: '32dp'
|
||||
pos_hint: {'x': .1, 'y': 0.1}
|
||||
Button:
|
||||
text: 'Ok'
|
||||
size_hint_y: 0.1
|
||||
size_hint_x: 0.3
|
||||
height: '32dp'
|
||||
pos_hint: {'x': .5, 'y': 0.1}
|
||||
on_press: root.generateaddress()
|
||||
|
||||
<Page>:
|
||||
name: 'page'
|
||||
Label:
|
||||
text: 'I am on description of my email yooooo'
|
||||
color: 0,0,0,1
|
||||
|
||||
<AddressSuccessful>:
|
||||
name: 'add_sucess'
|
||||
Label:
|
||||
text: 'Successfully created a new bit address'
|
||||
color: 0,0,0,1
|
393
src/bitmessagekivy/mpybit.py
Normal file
|
@ -0,0 +1,393 @@
|
|||
import kivy_helper_search
|
||||
import os
|
||||
import queues
|
||||
import shutdown
|
||||
import state
|
||||
import time
|
||||
|
||||
from kivy.app import App
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import BooleanProperty
|
||||
from kivy.clock import Clock
|
||||
from navigationdrawer import NavigationDrawer
|
||||
from kivy.properties import ObjectProperty, StringProperty, ListProperty
|
||||
from kivy.uix.screenmanager import Screen
|
||||
from kivy.uix.textinput import TextInput
|
||||
from kivymd.theming import ThemeManager
|
||||
from kivymd.toolbar import Toolbar
|
||||
from bmconfigparser import BMConfigParser
|
||||
from helper_ackPayload import genAckPayload
|
||||
from addresses import decodeAddress, addBMIfNotPresent
|
||||
from helper_sql import sqlExecute
|
||||
|
||||
statusIconColor = 'red'
|
||||
|
||||
|
||||
class NavigateApp(App, TextInput):
|
||||
"""Application uses kivy in which base Class of Navigate App inherits from the App class."""
|
||||
|
||||
theme_cls = ThemeManager()
|
||||
nav_drawer = ObjectProperty()
|
||||
|
||||
def build(self):
|
||||
"""Return a main_widget as a root widget.
|
||||
|
||||
An application can be built if you return a widget on build(), or if you set
|
||||
self.root.
|
||||
"""
|
||||
main_widget = Builder.load_file(
|
||||
os.path.join(os.path.dirname(__file__), 'main.kv'))
|
||||
self.nav_drawer = Navigator()
|
||||
return main_widget
|
||||
|
||||
def getCurrentAccountData(self, text):
|
||||
"""Get Current Address Account Data."""
|
||||
state.association = text
|
||||
self.root.ids.sc1.clear_widgets()
|
||||
self.root.ids.sc2.clear_widgets()
|
||||
self.root.ids.sc3.clear_widgets()
|
||||
self.root.ids.sc1.add_widget(Inbox())
|
||||
self.root.ids.sc2.add_widget(Sent())
|
||||
self.root.ids.sc3.add_widget(Trash())
|
||||
self.root.ids.toolbar.title = BMConfigParser().get(
|
||||
state.association, 'label') + '({})'.format(state.association)
|
||||
Inbox()
|
||||
Sent()
|
||||
Trash()
|
||||
|
||||
def say_exit(self):
|
||||
"""Exit the application as uses shutdown PyBitmessage."""
|
||||
print("**************************EXITING FROM APPLICATION*****************************")
|
||||
App.get_running_app().stop()
|
||||
shutdown.doCleanShutdown()
|
||||
|
||||
@staticmethod
|
||||
def showmeaddresses(name="text"):
|
||||
"""Show the addresses in spinner to make as dropdown."""
|
||||
if name == "text":
|
||||
return BMConfigParser().addresses()[0]
|
||||
elif name == "values":
|
||||
return BMConfigParser().addresses()
|
||||
|
||||
def update_index(self, data_index, index):
|
||||
"""Update index after archieve message to trash."""
|
||||
if self.root.ids.scr_mngr.current == 'inbox':
|
||||
self.root.ids.sc1.data[data_index]['index'] = index
|
||||
elif self.root.ids.scr_mngr.current == 'sent':
|
||||
self.root.ids.sc2.data[data_index]['index'] = index
|
||||
elif self.root.ids.scr_mngr.current == 'trash':
|
||||
self.root.ids.sc3.data[data_index]['index'] = index
|
||||
|
||||
def delete(self, data_index):
|
||||
"""It will make delete using remove function."""
|
||||
print("delete {}".format(data_index))
|
||||
self._remove(data_index)
|
||||
|
||||
def archive(self, data_index):
|
||||
"""It will make archieve using remove function."""
|
||||
print("archive {}".format(data_index))
|
||||
self._remove(data_index)
|
||||
|
||||
def _remove(self, data_index):
|
||||
"""It will remove message by resetting the values in recycleview data."""
|
||||
if self.root.ids.scr_mngr.current == 'inbox':
|
||||
self.root.ids.sc1.data.pop(data_index)
|
||||
self.root.ids.sc1.data = [{
|
||||
'data_index': i,
|
||||
'index': d['index'],
|
||||
'height': d['height'],
|
||||
'text': d['text']}
|
||||
for i, d in enumerate(self.root.ids.sc1.data)
|
||||
]
|
||||
elif self.root.ids.scr_mngr.current == 'sent':
|
||||
self.root.ids.sc2.data.pop(data_index)
|
||||
self.root.ids.sc2.data = [{
|
||||
'data_index': i,
|
||||
'index': d['index'],
|
||||
'height': d['height'],
|
||||
'text': d['text']}
|
||||
for i, d in enumerate(self.root.ids.sc2.data)
|
||||
]
|
||||
elif self.root.ids.scr_mngr.current == 'trash':
|
||||
self.root.ids.sc3.data.pop(data_index)
|
||||
self.root.ids.sc3.data = [{
|
||||
'data_index': i,
|
||||
'index': d['index'],
|
||||
'height': d['height'],
|
||||
'text': d['text']}
|
||||
for i, d in enumerate(self.root.ids.sc3.data)
|
||||
]
|
||||
|
||||
def getInboxMessageDetail(self, instance):
|
||||
"""It will get message detail after make selected message description."""
|
||||
try:
|
||||
self.root.ids.scr_mngr.current = 'page'
|
||||
except AttributeError:
|
||||
self.parent.manager.current = 'page'
|
||||
print('Message Clicked {}'.format(instance))
|
||||
|
||||
@staticmethod
|
||||
def getCurrentAccount():
|
||||
"""It uses to get current account label."""
|
||||
return BMConfigParser().get(state.association, 'label') + '({})'.format(state.association)
|
||||
|
||||
|
||||
class Navigator(NavigationDrawer):
|
||||
"""Navigator class uses NavigationDrawer.
|
||||
|
||||
It is an UI panel that shows our app's main navigation menu
|
||||
It is hidden when not in use, but appears when the user swipes
|
||||
a finger from the left edge of the screen or, when at the top
|
||||
level of the app, the user touches the drawer icon in the app bar
|
||||
"""
|
||||
|
||||
image_source = StringProperty('images/qidenticon_two.png')
|
||||
title = StringProperty('Navigation')
|
||||
|
||||
|
||||
class Inbox(Screen):
|
||||
"""Inbox Screen uses screen to show widgets of screens."""
|
||||
|
||||
data = ListProperty()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Inbox, self).__init__(*args, **kwargs)
|
||||
if state.association == '':
|
||||
state.association = Navigator().ids.btn.text
|
||||
Clock.schedule_once(self.init_ui, 0)
|
||||
|
||||
def init_ui(self, dt=0):
|
||||
"""Clock Schdule for method inbox accounts."""
|
||||
self.inboxaccounts()
|
||||
print(dt)
|
||||
|
||||
def inboxaccounts(self):
|
||||
"""Load inbox accounts."""
|
||||
account = state.association
|
||||
self.loadMessagelist(account, 'All', '')
|
||||
|
||||
def loadMessagelist(self, account, where="", what=""):
|
||||
"""Load Inbox list for inbox messages."""
|
||||
xAddress = "toaddress"
|
||||
queryreturn = kivy_helper_search.search_sql(
|
||||
xAddress, account, 'inbox', where, what, False)
|
||||
if queryreturn:
|
||||
self.data = [{
|
||||
'data_index': i,
|
||||
'index': 1,
|
||||
'height': 48,
|
||||
'text': row[4]}
|
||||
for i, row in enumerate(queryreturn)
|
||||
]
|
||||
else:
|
||||
self.data = [{
|
||||
'data_index': 1,
|
||||
'index': 1,
|
||||
'height': 48,
|
||||
'text': "yet no message for this account!!!!!!!!!!!!!"}
|
||||
]
|
||||
|
||||
|
||||
class Page(Screen):
|
||||
pass
|
||||
|
||||
|
||||
class AddressSuccessful(Screen):
|
||||
pass
|
||||
|
||||
|
||||
class Sent(Screen):
|
||||
"""Sent Screen uses screen to show widgets of screens."""
|
||||
|
||||
data = ListProperty()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Sent, self).__init__(*args, **kwargs)
|
||||
if state.association == '':
|
||||
state.association = Navigator().ids.btn.text
|
||||
Clock.schedule_once(self.init_ui, 0)
|
||||
|
||||
def init_ui(self, dt=0):
|
||||
"""Clock Schdule for method sent accounts."""
|
||||
self.sentaccounts()
|
||||
print(dt)
|
||||
|
||||
def sentaccounts(self):
|
||||
"""Load sent accounts."""
|
||||
account = state.association
|
||||
self.loadSent(account, 'All', '')
|
||||
|
||||
def loadSent(self, account, where="", what=""):
|
||||
"""Load Sent list for Sent messages."""
|
||||
xAddress = 'fromaddress'
|
||||
queryreturn = kivy_helper_search.search_sql(
|
||||
xAddress, account, "sent", where, what, False)
|
||||
if queryreturn:
|
||||
self.data = [{
|
||||
'data_index': i,
|
||||
'index': 1,
|
||||
'height': 48,
|
||||
'text': row[2]}
|
||||
for i, row in enumerate(queryreturn)
|
||||
]
|
||||
else:
|
||||
self.data = [{
|
||||
'data_index': 1,
|
||||
'index': 1,
|
||||
'height': 48,
|
||||
'text': "yet no message for this account!!!!!!!!!!!!!"}
|
||||
]
|
||||
|
||||
|
||||
class Trash(Screen):
|
||||
"""Trash Screen uses screen to show widgets of screens."""
|
||||
|
||||
data = ListProperty()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Trash, self).__init__(*args, **kwargs)
|
||||
if state.association == '':
|
||||
state.association = Navigator().ids.btn.text
|
||||
Clock.schedule_once(self.init_ui, 0)
|
||||
|
||||
def init_ui(self, dt=0):
|
||||
"""Clock Schdule for method inbox accounts."""
|
||||
self.inboxaccounts()
|
||||
print(dt)
|
||||
|
||||
def inboxaccounts(self):
|
||||
"""Load inbox accounts."""
|
||||
account = state.association
|
||||
self.loadTrashlist(account, 'All', '')
|
||||
|
||||
def loadTrashlist(self, account, where="", what=""):
|
||||
"""Load Trash list for trashed messages."""
|
||||
xAddress = "toaddress"
|
||||
queryreturn = kivy_helper_search.search_sql(
|
||||
xAddress, account, 'trash', where, what, False)
|
||||
if queryreturn:
|
||||
self.data = [{
|
||||
'data_index': i,
|
||||
'index': 1,
|
||||
'height': 48,
|
||||
'text': row[4]}
|
||||
for i, row in enumerate(queryreturn)
|
||||
]
|
||||
else:
|
||||
self.data = [{
|
||||
'data_index': 1,
|
||||
'index': 1,
|
||||
'height': 48,
|
||||
'text': "yet no message for this account!!!!!!!!!!!!!"}
|
||||
]
|
||||
|
||||
|
||||
class Dialog(Screen):
|
||||
"""Dialog Screen uses screen to show widgets of screens."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class Test(Screen):
|
||||
"""Test Screen uses screen to show widgets of screens."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class Create(Screen):
|
||||
"""Create Screen uses screen to show widgets of screens."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Create, self).__init__(*args, **kwargs)
|
||||
|
||||
def send(self):
|
||||
"""Send message from one address to another."""
|
||||
fromAddress = self.ids.spinner_id.text
|
||||
# For now we are using static address i.e we are not using recipent field value.
|
||||
toAddress = "BM-2cWyUfBdY2FbgyuCb7abFZ49JYxSzUhNFe"
|
||||
message = self.ids.message.text
|
||||
subject = self.ids.subject.text
|
||||
encoding = 3
|
||||
print("message: ", self.ids.message.text)
|
||||
sendMessageToPeople = True
|
||||
if sendMessageToPeople:
|
||||
if toAddress != '':
|
||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
|
||||
toAddress)
|
||||
if status == 'success':
|
||||
toAddress = addBMIfNotPresent(toAddress)
|
||||
|
||||
if addressVersionNumber > 4 or addressVersionNumber <= 1:
|
||||
print("addressVersionNumber > 4 or addressVersionNumber <= 1")
|
||||
if streamNumber > 1 or streamNumber == 0:
|
||||
print("streamNumber > 1 or streamNumber == 0")
|
||||
if statusIconColor == 'red':
|
||||
print("shared.statusIconColor == 'red'")
|
||||
stealthLevel = BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
t = ()
|
||||
sqlExecute(
|
||||
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
|
||||
'',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()),
|
||||
int(time.time()),
|
||||
0,
|
||||
'msgqueued',
|
||||
0,
|
||||
'sent',
|
||||
encoding,
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl'))
|
||||
toLabel = ''
|
||||
queues.workerQueue.put(('sendmessage', toAddress))
|
||||
print("sqlExecute successfully ##### ##################")
|
||||
self.ids.message.text = ''
|
||||
self.ids.spinner_id.text = '<select>'
|
||||
self.ids.subject.text = ''
|
||||
self.ids.recipent.text = ''
|
||||
return None
|
||||
|
||||
def cancel(self):
|
||||
"""Reset values for send message."""
|
||||
self.ids.message.text = ''
|
||||
self.ids.spinner_id.text = '<select>'
|
||||
self.ids.subject.text = ''
|
||||
self.ids.recipent.text = ''
|
||||
return None
|
||||
|
||||
|
||||
class NewIdentity(Screen):
|
||||
"""Create new address for PyBitmessage."""
|
||||
|
||||
is_active = BooleanProperty(False)
|
||||
checked = StringProperty("")
|
||||
# self.manager.parent.ids.create.children[0].source = 'images/plus-4-xxl.png'
|
||||
|
||||
def generateaddress(self):
|
||||
"""Generate new address."""
|
||||
if self.checked == 'use a random number generator to make an address':
|
||||
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
||||
streamNumberForAddress = 1
|
||||
label = self.ids.label.text
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = 1000
|
||||
payloadLengthExtraBytes = 1000
|
||||
|
||||
queues.addressGeneratorQueue.put((
|
||||
'createRandomAddress',
|
||||
4, streamNumberForAddress,
|
||||
label, 1, "", eighteenByteRipe,
|
||||
nonceTrialsPerByte,
|
||||
payloadLengthExtraBytes)
|
||||
)
|
||||
self.manager.current = 'add_sucess'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
NavigateApp().run()
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/python2.7
|
||||
"""
|
||||
The PyBitmessage startup script
|
||||
"""
|
||||
|
@ -12,11 +12,10 @@ The PyBitmessage startup script
|
|||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import pathmagic
|
||||
except ImportError:
|
||||
from pybitmessage import pathmagic
|
||||
app_dir = pathmagic.setup()
|
||||
app_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
os.chdir(app_dir)
|
||||
sys.path.insert(0, app_dir)
|
||||
|
||||
|
||||
import depends
|
||||
depends.check_dependencies()
|
||||
|
@ -189,8 +188,6 @@ class Main(object):
|
|||
'bitmessagesettings', 'apiusername', 'username')
|
||||
config.set(
|
||||
'bitmessagesettings', 'apipassword', 'password')
|
||||
config.set(
|
||||
'bitmessagesettings', 'apivariant', 'legacy')
|
||||
config.set(
|
||||
'bitmessagesettings', 'apinotifypath',
|
||||
os.path.join(app_dir, 'tests', 'apinotify_handler.py')
|
||||
|
@ -321,10 +318,9 @@ class Main(object):
|
|||
receiveQueueThread = ReceiveQueueThread(i)
|
||||
receiveQueueThread.daemon = True
|
||||
receiveQueueThread.start()
|
||||
if config.safeGetBoolean('bitmessagesettings', 'udp'):
|
||||
state.announceThread = AnnounceThread()
|
||||
state.announceThread.daemon = True
|
||||
state.announceThread.start()
|
||||
announceThread = AnnounceThread()
|
||||
announceThread.daemon = True
|
||||
announceThread.start()
|
||||
state.invThread = InvThread()
|
||||
state.invThread.daemon = True
|
||||
state.invThread.start()
|
||||
|
@ -353,6 +349,10 @@ class Main(object):
|
|||
print('Running with curses')
|
||||
import bitmessagecurses
|
||||
bitmessagecurses.runwrapper()
|
||||
elif state.kivy:
|
||||
config.remove_option('bitmessagesettings', 'dontconnect')
|
||||
from bitmessagekivy.mpybit import NavigateApp
|
||||
NavigateApp().run()
|
||||
else:
|
||||
import bitmessageqt
|
||||
bitmessageqt.run()
|
||||
|
@ -369,17 +369,17 @@ class Main(object):
|
|||
self.stop()
|
||||
elif not state.enableGUI:
|
||||
state.enableGUI = True
|
||||
try:
|
||||
# pylint: disable=relative-import
|
||||
from tests import core as test_core
|
||||
except ImportError:
|
||||
self.stop()
|
||||
return
|
||||
|
||||
# pylint: disable=relative-import
|
||||
from tests import core as test_core
|
||||
test_core_result = test_core.run()
|
||||
state.enableGUI = True
|
||||
self.stop()
|
||||
test_core.cleanup()
|
||||
sys.exit(not test_core_result.wasSuccessful())
|
||||
sys.exit(
|
||||
'Core tests failed!'
|
||||
if test_core_result.errors or test_core_result.failures
|
||||
else 0
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def daemonize():
|
||||
|
|
|
@ -35,8 +35,8 @@ from foldertree import (
|
|||
MessageList_TimeWidget)
|
||||
import settingsmixin
|
||||
import support
|
||||
from helper_ackPayload import genAckPayload
|
||||
from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure
|
||||
import helper_addressbook
|
||||
import helper_search
|
||||
import l10n
|
||||
from utils import str_broadcast_subscribers, avatarize
|
||||
|
@ -54,7 +54,6 @@ from statusbar import BMStatusBar
|
|||
import sound
|
||||
# This is needed for tray icon
|
||||
import bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import
|
||||
import helper_sent
|
||||
|
||||
try:
|
||||
from plugins.plugin import get_plugin, get_plugins
|
||||
|
@ -640,6 +639,8 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
BMConfigParser().remove_section(addressInKeysFile)
|
||||
BMConfigParser().save()
|
||||
|
||||
self.updateStartOnLogon()
|
||||
|
||||
self.change_translation()
|
||||
|
||||
# e.g. for editing labels
|
||||
|
@ -824,7 +825,6 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self.sqlInit()
|
||||
self.indicatorInit()
|
||||
self.notifierInit()
|
||||
self.updateStartOnLogon()
|
||||
|
||||
self.ui.updateNetworkSwitchMenuLabel()
|
||||
|
||||
|
@ -843,28 +843,26 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self._contact_selected = None
|
||||
|
||||
def updateStartOnLogon(self):
|
||||
"""
|
||||
Configure Bitmessage to start on startup (or remove the
|
||||
configuration) based on the setting in the keys.dat file
|
||||
"""
|
||||
startonlogon = BMConfigParser().safeGetBoolean(
|
||||
'bitmessagesettings', 'startonlogon')
|
||||
if sys.platform.startswith('win'): # Auto-startup for Windows
|
||||
# Configure Bitmessage to start on startup (or remove the
|
||||
# configuration) based on the setting in the keys.dat file
|
||||
if 'win32' in sys.platform or 'win64' in sys.platform:
|
||||
# Auto-startup for Windows
|
||||
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
|
||||
settings = QtCore.QSettings(
|
||||
self.settings = QtCore.QSettings(
|
||||
RUN_PATH, QtCore.QSettings.NativeFormat)
|
||||
# In case the user moves the program and the registry entry is
|
||||
# no longer valid, this will delete the old registry entry.
|
||||
if startonlogon:
|
||||
settings.setValue("PyBitmessage", sys.argv[0])
|
||||
else:
|
||||
settings.remove("PyBitmessage")
|
||||
else:
|
||||
try: # get desktop plugin if any
|
||||
self.desktop = get_plugin('desktop')()
|
||||
self.desktop.adjust_startonlogon(startonlogon)
|
||||
except (NameError, TypeError):
|
||||
self.desktop = False
|
||||
self.settings.remove("PyBitmessage")
|
||||
if BMConfigParser().getboolean(
|
||||
'bitmessagesettings', 'startonlogon'
|
||||
):
|
||||
self.settings.setValue("PyBitmessage", sys.argv[0])
|
||||
elif 'darwin' in sys.platform:
|
||||
# startup for mac
|
||||
pass
|
||||
elif 'linux' in sys.platform:
|
||||
# startup for linux
|
||||
pass
|
||||
|
||||
def updateTTL(self, sliderPosition):
|
||||
TTL = int(sliderPosition ** 3.199 + 3600)
|
||||
|
@ -1424,11 +1422,9 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
def sqlInit(self):
|
||||
register_adapter(QtCore.QByteArray, str)
|
||||
|
||||
# Try init the distro specific appindicator,
|
||||
# for example the Ubuntu MessagingMenu
|
||||
def indicatorInit(self):
|
||||
"""
|
||||
Try init the distro specific appindicator,
|
||||
for example the Ubuntu MessagingMenu
|
||||
"""
|
||||
def _noop_update(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
@ -1644,7 +1640,6 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
dialog = dialogs.ConnectDialog(self)
|
||||
if dialog.exec_():
|
||||
if dialog.radioButtonConnectNow.isChecked():
|
||||
self.ui.updateNetworkSwitchMenuLabel(False)
|
||||
BMConfigParser().remove_option(
|
||||
'bitmessagesettings', 'dontconnect')
|
||||
BMConfigParser().save()
|
||||
|
@ -2075,7 +2070,8 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
).arg(email)
|
||||
)
|
||||
return
|
||||
status, addressVersionNumber, streamNumber = decodeAddress(toAddress)[:3]
|
||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
|
||||
toAddress)
|
||||
if status != 'success':
|
||||
try:
|
||||
toAddress = unicode(toAddress, 'utf-8', 'ignore')
|
||||
|
@ -2166,9 +2162,29 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
" send the message but it won\'t send until"
|
||||
" you connect.")
|
||||
)
|
||||
ackdata = helper_sent.insert(
|
||||
toAddress=toAddress, fromAddress=fromAddress,
|
||||
subject=subject, message=message, encoding=encoding)
|
||||
stealthLevel = BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
t = ()
|
||||
sqlExecute(
|
||||
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
|
||||
'',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this will never change)
|
||||
int(time.time()), # lastActionTime
|
||||
0, # sleepTill time. This will get set when the POW gets done.
|
||||
'msgqueued',
|
||||
0, # retryNumber
|
||||
'sent', # folder
|
||||
encoding, # encodingtype
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl')
|
||||
)
|
||||
|
||||
toLabel = ''
|
||||
queryreturn = sqlQuery('''select label from addressbook where address=?''',
|
||||
toAddress)
|
||||
|
@ -2202,13 +2218,28 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
# We don't actually need the ackdata for acknowledgement since
|
||||
# this is a broadcast message, but we can use it to update the
|
||||
# user interface when the POW is done generating.
|
||||
streamNumber = decodeAddress(fromAddress)[2]
|
||||
ackdata = genAckPayload(streamNumber, 0)
|
||||
toAddress = str_broadcast_subscribers
|
||||
|
||||
# msgid. We don't know what this will be until the POW is done.
|
||||
ackdata = helper_sent.insert(
|
||||
fromAddress=fromAddress,
|
||||
subject=subject, message=message,
|
||||
status='broadcastqueued', encoding=encoding)
|
||||
ripe = ''
|
||||
t = ('', # msgid. We don't know what this will be until the POW is done.
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this will never change)
|
||||
int(time.time()), # lastActionTime
|
||||
0, # sleepTill time. This will get set when the POW gets done.
|
||||
'broadcastqueued',
|
||||
0, # retryNumber
|
||||
'sent', # folder
|
||||
encoding, # encoding type
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl')
|
||||
)
|
||||
sqlExecute(
|
||||
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||
|
||||
toLabel = str_broadcast_subscribers
|
||||
|
||||
|
@ -2439,15 +2470,15 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
))
|
||||
return
|
||||
|
||||
if helper_addressbook.insert(label=label, address=address):
|
||||
self.rerenderMessagelistFromLabels()
|
||||
self.rerenderMessagelistToLabels()
|
||||
self.rerenderAddressBook()
|
||||
else:
|
||||
self.updateStatusBar(_translate(
|
||||
"MainWindow",
|
||||
"Error: You cannot add your own address in the address book."
|
||||
))
|
||||
self.addEntryToAddressBook(address, label)
|
||||
|
||||
def addEntryToAddressBook(self, address, label):
|
||||
if shared.isAddressInMyAddressBook(address):
|
||||
return
|
||||
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address)
|
||||
self.rerenderMessagelistFromLabels()
|
||||
self.rerenderMessagelistToLabels()
|
||||
self.rerenderAddressBook()
|
||||
|
||||
def addSubscription(self, address, label):
|
||||
# This should be handled outside of this function, for error displaying
|
||||
|
@ -3120,7 +3151,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
idCount = len(inventoryHashesToTrash)
|
||||
sqlExecuteChunked(
|
||||
("DELETE FROM inbox" if folder == "trash" or shifted else
|
||||
"UPDATE inbox SET folder='trash', read=1") +
|
||||
"UPDATE inbox SET folder='trash'") +
|
||||
" WHERE msgid IN ({0})", idCount, *inventoryHashesToTrash)
|
||||
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
|
||||
tableWidget.setUpdatesEnabled(True)
|
||||
|
@ -4068,7 +4099,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
|
||||
def updateStatusBar(self, data):
|
||||
try:
|
||||
message, option = data
|
||||
option, message = data
|
||||
except ValueError:
|
||||
option = 0
|
||||
message = data
|
||||
|
|
354
src/bitmessageqt/newaddresswizard.py
Normal file
|
@ -0,0 +1,354 @@
|
|||
#!/usr/bin/env python2.7
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
class NewAddressWizardIntroPage(QtGui.QWizardPage):
|
||||
def __init__(self):
|
||||
super(QtGui.QWizardPage, self).__init__()
|
||||
self.setTitle("Creating a new address")
|
||||
|
||||
label = QtGui.QLabel("This wizard will help you create as many addresses as you like. Indeed, creating and abandoning addresses is encouraged.\n\n"
|
||||
"What type of address would you like? Would you like to send emails or not?\n"
|
||||
"You can still change your mind later, and register/unregister with an email service provider.\n\n")
|
||||
label.setWordWrap(True)
|
||||
|
||||
self.emailAsWell = QtGui.QRadioButton("Combined email and bitmessage address")
|
||||
self.onlyBM = QtGui.QRadioButton("Bitmessage-only address (no email)")
|
||||
self.emailAsWell.setChecked(True)
|
||||
self.registerField("emailAsWell", self.emailAsWell)
|
||||
self.registerField("onlyBM", self.onlyBM)
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(label)
|
||||
layout.addWidget(self.emailAsWell)
|
||||
layout.addWidget(self.onlyBM)
|
||||
self.setLayout(layout)
|
||||
|
||||
def nextId(self):
|
||||
if self.emailAsWell.isChecked():
|
||||
return 4
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
class NewAddressWizardRngPassphrasePage(QtGui.QWizardPage):
|
||||
def __init__(self):
|
||||
super(QtGui.QWizardPage, self).__init__()
|
||||
self.setTitle("Random or Passphrase")
|
||||
|
||||
label = QtGui.QLabel("<html><head/><body><p>You may generate addresses by using either random numbers or by using a passphrase. "
|
||||
"If you use a passphrase, the address is called a "deterministic" address. "
|
||||
"The \'Random Number\' option is selected by default but deterministic addresses have several pros and cons:</p>"
|
||||
"<table border=0><tr><td><span style=\" font-weight:600;\">Pros:</span></td><td><span style=\" font-weight:600;\">Cons:</span></td></tr>"
|
||||
"<tr><td>You can recreate your addresses on any computer from memory. "
|
||||
"You need-not worry about backing up your keys.dat file as long as you can remember your passphrase.</td>"
|
||||
"<td>You must remember (or write down) your passphrase if you expect to be able "
|
||||
"to recreate your keys if they are lost. "
|
||||
# "You must remember the address version number and the stream number along with your passphrase. "
|
||||
"If you choose a weak passphrase and someone on the Internet can brute-force it, they can read your messages and send messages as you."
|
||||
"</p></body></html>")
|
||||
label.setWordWrap(True)
|
||||
|
||||
self.randomAddress = QtGui.QRadioButton("Use a random number generator to make an address")
|
||||
self.deterministicAddress = QtGui.QRadioButton("Use a passphrase to make an address")
|
||||
self.randomAddress.setChecked(True)
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(label)
|
||||
layout.addWidget(self.randomAddress)
|
||||
layout.addWidget(self.deterministicAddress)
|
||||
self.setLayout(layout)
|
||||
|
||||
def nextId(self):
|
||||
if self.randomAddress.isChecked():
|
||||
return 2
|
||||
else:
|
||||
return 3
|
||||
|
||||
class NewAddressWizardRandomPage(QtGui.QWizardPage):
|
||||
def __init__(self, addresses):
|
||||
super(QtGui.QWizardPage, self).__init__()
|
||||
self.setTitle("Random")
|
||||
|
||||
label = QtGui.QLabel("Random address.")
|
||||
label.setWordWrap(True)
|
||||
|
||||
labelLabel = QtGui.QLabel("Label (not shown to anyone except you):")
|
||||
self.labelLineEdit = QtGui.QLineEdit()
|
||||
|
||||
self.radioButtonMostAvailable = QtGui.QRadioButton("Use the most available stream\n"
|
||||
"(best if this is the first of many addresses you will create)")
|
||||
self.radioButtonExisting = QtGui.QRadioButton("Use the same stream as an existing address\n"
|
||||
"(saves you some bandwidth and processing power)")
|
||||
self.radioButtonMostAvailable.setChecked(True)
|
||||
self.comboBoxExisting = QtGui.QComboBox()
|
||||
self.comboBoxExisting.setEnabled(False)
|
||||
self.comboBoxExisting.setEditable(True)
|
||||
|
||||
for address in addresses:
|
||||
self.comboBoxExisting.addItem(address)
|
||||
|
||||
# self.comboBoxExisting.setObjectName(_fromUtf8("comboBoxExisting"))
|
||||
self.checkBoxEighteenByteRipe = QtGui.QCheckBox("Spend several minutes of extra computing time to make the address(es) 1 or 2 characters shorter")
|
||||
|
||||
layout = QtGui.QGridLayout()
|
||||
layout.addWidget(label, 0, 0)
|
||||
layout.addWidget(labelLabel, 1, 0)
|
||||
layout.addWidget(self.labelLineEdit, 2, 0)
|
||||
layout.addWidget(self.radioButtonMostAvailable, 3, 0)
|
||||
layout.addWidget(self.radioButtonExisting, 4, 0)
|
||||
layout.addWidget(self.comboBoxExisting, 5, 0)
|
||||
layout.addWidget(self.checkBoxEighteenByteRipe, 6, 0)
|
||||
self.setLayout(layout)
|
||||
|
||||
QtCore.QObject.connect(self.radioButtonExisting, QtCore.SIGNAL("toggled(bool)"), self.comboBoxExisting.setEnabled)
|
||||
|
||||
self.registerField("label", self.labelLineEdit)
|
||||
self.registerField("radioButtonMostAvailable", self.radioButtonMostAvailable)
|
||||
self.registerField("radioButtonExisting", self.radioButtonExisting)
|
||||
self.registerField("comboBoxExisting", self.comboBoxExisting)
|
||||
|
||||
# self.emailAsWell = QtGui.QRadioButton("Combined email and bitmessage account")
|
||||
# self.onlyBM = QtGui.QRadioButton("Bitmessage-only account (no email)")
|
||||
# self.emailAsWell.setChecked(True)
|
||||
|
||||
def nextId(self):
|
||||
return 6
|
||||
|
||||
|
||||
class NewAddressWizardPassphrasePage(QtGui.QWizardPage):
|
||||
def __init__(self):
|
||||
super(QtGui.QWizardPage, self).__init__()
|
||||
self.setTitle("Passphrase")
|
||||
|
||||
label = QtGui.QLabel("Deterministric address.")
|
||||
label.setWordWrap(True)
|
||||
|
||||
passphraseLabel = QtGui.QLabel("Passphrase")
|
||||
self.lineEditPassphrase = QtGui.QLineEdit()
|
||||
self.lineEditPassphrase.setEchoMode(QtGui.QLineEdit.Password)
|
||||
self.lineEditPassphrase.setInputMethodHints(QtCore.Qt.ImhHiddenText|QtCore.Qt.ImhNoAutoUppercase|QtCore.Qt.ImhNoPredictiveText)
|
||||
retypePassphraseLabel = QtGui.QLabel("Retype passphrase")
|
||||
self.lineEditPassphraseAgain = QtGui.QLineEdit()
|
||||
self.lineEditPassphraseAgain.setEchoMode(QtGui.QLineEdit.Password)
|
||||
|
||||
numberLabel = QtGui.QLabel("Number of addresses to make based on your passphrase:")
|
||||
self.spinBoxNumberOfAddressesToMake = QtGui.QSpinBox()
|
||||
self.spinBoxNumberOfAddressesToMake.setMinimum(1)
|
||||
self.spinBoxNumberOfAddressesToMake.setProperty("value", 8)
|
||||
# self.spinBoxNumberOfAddressesToMake.setObjectName(_fromUtf8("spinBoxNumberOfAddressesToMake"))
|
||||
label2 = QtGui.QLabel("In addition to your passphrase, you must remember these numbers:")
|
||||
label3 = QtGui.QLabel("Address version number: 4")
|
||||
label4 = QtGui.QLabel("Stream number: 1")
|
||||
|
||||
layout = QtGui.QGridLayout()
|
||||
layout.addWidget(label, 0, 0, 1, 4)
|
||||
layout.addWidget(passphraseLabel, 1, 0, 1, 4)
|
||||
layout.addWidget(self.lineEditPassphrase, 2, 0, 1, 4)
|
||||
layout.addWidget(retypePassphraseLabel, 3, 0, 1, 4)
|
||||
layout.addWidget(self.lineEditPassphraseAgain, 4, 0, 1, 4)
|
||||
layout.addWidget(numberLabel, 5, 0, 1, 3)
|
||||
layout.addWidget(self.spinBoxNumberOfAddressesToMake, 5, 3)
|
||||
layout.setColumnMinimumWidth(3, 1)
|
||||
layout.addWidget(label2, 6, 0, 1, 4)
|
||||
layout.addWidget(label3, 7, 0, 1, 2)
|
||||
layout.addWidget(label4, 7, 2, 1, 2)
|
||||
self.setLayout(layout)
|
||||
|
||||
def nextId(self):
|
||||
return 6
|
||||
|
||||
|
||||
class NewAddressWizardEmailProviderPage(QtGui.QWizardPage):
|
||||
def __init__(self):
|
||||
super(QtGui.QWizardPage, self).__init__()
|
||||
self.setTitle("Choose email provider")
|
||||
|
||||
label = QtGui.QLabel("Currently only Mailchuck email gateway is available "
|
||||
"(@mailchuck.com email address). In the future, maybe other gateways will be available. "
|
||||
"Press Next.")
|
||||
label.setWordWrap(True)
|
||||
|
||||
# self.mailchuck = QtGui.QRadioButton("Mailchuck email gateway (@mailchuck.com)")
|
||||
# self.mailchuck.setChecked(True)
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(label)
|
||||
# layout.addWidget(self.mailchuck)
|
||||
self.setLayout(layout)
|
||||
|
||||
def nextId(self):
|
||||
return 5
|
||||
|
||||
|
||||
class NewAddressWizardEmailAddressPage(QtGui.QWizardPage):
|
||||
def __init__(self):
|
||||
super(QtGui.QWizardPage, self).__init__()
|
||||
self.setTitle("Email address")
|
||||
|
||||
label = QtGui.QLabel("Choosing an email address. Address must end with @mailchuck.com")
|
||||
label.setWordWrap(True)
|
||||
|
||||
self.specificEmail = QtGui.QRadioButton("Pick your own email address:")
|
||||
self.specificEmail.setChecked(True)
|
||||
self.emailLineEdit = QtGui.QLineEdit()
|
||||
self.randomEmail = QtGui.QRadioButton("Generate a random email address")
|
||||
|
||||
QtCore.QObject.connect(self.specificEmail, QtCore.SIGNAL("toggled(bool)"), self.emailLineEdit.setEnabled)
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(label)
|
||||
layout.addWidget(self.specificEmail)
|
||||
layout.addWidget(self.emailLineEdit)
|
||||
layout.addWidget(self.randomEmail)
|
||||
self.setLayout(layout)
|
||||
|
||||
def nextId(self):
|
||||
return 6
|
||||
|
||||
|
||||
class NewAddressWizardWaitPage(QtGui.QWizardPage):
|
||||
def __init__(self):
|
||||
super(QtGui.QWizardPage, self).__init__()
|
||||
self.setTitle("Wait")
|
||||
|
||||
self.label = QtGui.QLabel("Wait!")
|
||||
self.label.setWordWrap(True)
|
||||
self.progressBar = QtGui.QProgressBar()
|
||||
self.progressBar.setMinimum(0)
|
||||
self.progressBar.setMaximum(100)
|
||||
self.progressBar.setValue(0)
|
||||
|
||||
# self.emailAsWell = QtGui.QRadioButton("Combined email and bitmessage account")
|
||||
# self.onlyBM = QtGui.QRadioButton("Bitmessage-only account (no email)")
|
||||
# self.emailAsWell.setChecked(True)
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(self.label)
|
||||
layout.addWidget(self.progressBar)
|
||||
# layout.addWidget(self.emailAsWell)
|
||||
# layout.addWidget(self.onlyBM)
|
||||
self.setLayout(layout)
|
||||
|
||||
def update(self, i):
|
||||
if i == 101 and self.wizard().currentId() == 6:
|
||||
self.wizard().button(QtGui.QWizard.NextButton).click()
|
||||
return
|
||||
elif i == 101:
|
||||
print "haha"
|
||||
return
|
||||
self.progressBar.setValue(i)
|
||||
if i == 50:
|
||||
self.emit(QtCore.SIGNAL('completeChanged()'))
|
||||
|
||||
def isComplete(self):
|
||||
# print "val = " + str(self.progressBar.value())
|
||||
if self.progressBar.value() >= 50:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def initializePage(self):
|
||||
if self.field("emailAsWell").toBool():
|
||||
val = "yes/"
|
||||
else:
|
||||
val = "no/"
|
||||
if self.field("onlyBM").toBool():
|
||||
val += "yes"
|
||||
else:
|
||||
val += "no"
|
||||
|
||||
self.label.setText("Wait! " + val)
|
||||
# self.wizard().button(QtGui.QWizard.NextButton).setEnabled(False)
|
||||
self.progressBar.setValue(0)
|
||||
self.thread = NewAddressThread()
|
||||
self.connect(self.thread, self.thread.signal, self.update)
|
||||
self.thread.start()
|
||||
|
||||
def nextId(self):
|
||||
return 10
|
||||
|
||||
|
||||
class NewAddressWizardConclusionPage(QtGui.QWizardPage):
|
||||
def __init__(self):
|
||||
super(QtGui.QWizardPage, self).__init__()
|
||||
self.setTitle("All done!")
|
||||
|
||||
label = QtGui.QLabel("You successfully created a new address.")
|
||||
label.setWordWrap(True)
|
||||
|
||||
layout = QtGui.QVBoxLayout()
|
||||
layout.addWidget(label)
|
||||
self.setLayout(layout)
|
||||
|
||||
class Ui_NewAddressWizard(QtGui.QWizard):
|
||||
def __init__(self, addresses):
|
||||
super(QtGui.QWizard, self).__init__()
|
||||
|
||||
self.pages = {}
|
||||
|
||||
page = NewAddressWizardIntroPage()
|
||||
self.setPage(0, page)
|
||||
self.setStartId(0)
|
||||
page = NewAddressWizardRngPassphrasePage()
|
||||
self.setPage(1, page)
|
||||
page = NewAddressWizardRandomPage(addresses)
|
||||
self.setPage(2, page)
|
||||
page = NewAddressWizardPassphrasePage()
|
||||
self.setPage(3, page)
|
||||
page = NewAddressWizardEmailProviderPage()
|
||||
self.setPage(4, page)
|
||||
page = NewAddressWizardEmailAddressPage()
|
||||
self.setPage(5, page)
|
||||
page = NewAddressWizardWaitPage()
|
||||
self.setPage(6, page)
|
||||
page = NewAddressWizardConclusionPage()
|
||||
self.setPage(10, page)
|
||||
|
||||
self.setWindowTitle("New address wizard")
|
||||
self.adjustSize()
|
||||
self.show()
|
||||
|
||||
class NewAddressThread(QtCore.QThread):
|
||||
def __init__(self):
|
||||
QtCore.QThread.__init__(self)
|
||||
self.signal = QtCore.SIGNAL("signal")
|
||||
|
||||
def __del__(self):
|
||||
self.wait()
|
||||
|
||||
def createDeterministic(self):
|
||||
pass
|
||||
|
||||
def createPassphrase(self):
|
||||
pass
|
||||
|
||||
def broadcastAddress(self):
|
||||
pass
|
||||
|
||||
def registerMailchuck(self):
|
||||
pass
|
||||
|
||||
def waitRegistration(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
import time
|
||||
for i in range(1, 101):
|
||||
time.sleep(0.1) # artificial time delay
|
||||
self.emit(self.signal, i)
|
||||
self.emit(self.signal, 101)
|
||||
# self.terminate()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
import sys
|
||||
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
|
||||
wizard = Ui_NewAddressWizard(["a", "b", "c", "d"])
|
||||
if (wizard.exec_()):
|
||||
print "Email: " + ("yes" if wizard.field("emailAsWell").toBool() else "no")
|
||||
print "BM: " + ("yes" if wizard.field("onlyBM").toBool() else "no")
|
||||
else:
|
||||
print "Wizard cancelled"
|
||||
sys.exit()
|
|
@ -65,8 +65,6 @@ class SafeHTMLParser(HTMLParser):
|
|||
HTMLParser.__init__(self, *args, **kwargs)
|
||||
self.reset()
|
||||
self.reset_safe()
|
||||
self.has_html = None
|
||||
self.allow_picture = None
|
||||
|
||||
def reset_safe(self):
|
||||
"""Reset runtime variables specific to this class"""
|
||||
|
@ -94,7 +92,7 @@ class SafeHTMLParser(HTMLParser):
|
|||
if url.scheme not in self.src_schemes:
|
||||
val = ""
|
||||
self.sanitised += " " + quote_plus(attr)
|
||||
if val is not None:
|
||||
if not (val is None):
|
||||
self.sanitised += "=\"" + val + "\""
|
||||
if inspect.stack()[1][3] == "handle_startendtag":
|
||||
self.sanitised += "/"
|
||||
|
|
|
@ -19,7 +19,7 @@ import widgets
|
|||
from bmconfigparser import BMConfigParser
|
||||
from helper_sql import sqlExecute, sqlStoredProcedure
|
||||
from helper_startup import start_proxyconfig
|
||||
from network import knownnodes, AnnounceThread
|
||||
from network import knownnodes
|
||||
from network.asyncore_pollchoose import set_rates
|
||||
from tr import _translate
|
||||
|
||||
|
@ -49,8 +49,6 @@ class SettingsDialog(QtGui.QDialog):
|
|||
self.net_restart_needed = False
|
||||
self.timer = QtCore.QTimer()
|
||||
|
||||
if self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'):
|
||||
self.firstrun = False
|
||||
try:
|
||||
import pkg_resources
|
||||
except ImportError:
|
||||
|
@ -119,6 +117,9 @@ class SettingsDialog(QtGui.QDialog):
|
|||
self.checkBoxPortableMode.setDisabled(True)
|
||||
|
||||
if 'darwin' in sys.platform:
|
||||
self.checkBoxStartOnLogon.setDisabled(True)
|
||||
self.checkBoxStartOnLogon.setText(_translate(
|
||||
"MainWindow", "Start-on-login not yet supported on your OS."))
|
||||
self.checkBoxMinimizeToTray.setDisabled(True)
|
||||
self.checkBoxMinimizeToTray.setText(_translate(
|
||||
"MainWindow",
|
||||
|
@ -127,19 +128,15 @@ class SettingsDialog(QtGui.QDialog):
|
|||
self.checkBoxShowTrayNotifications.setText(_translate(
|
||||
"MainWindow",
|
||||
"Tray notifications not yet supported on your OS."))
|
||||
|
||||
if 'win' not in sys.platform and not self.parent.desktop:
|
||||
elif 'linux' in sys.platform:
|
||||
self.checkBoxStartOnLogon.setDisabled(True)
|
||||
self.checkBoxStartOnLogon.setText(_translate(
|
||||
"MainWindow", "Start-on-login not yet supported on your OS."))
|
||||
|
||||
# On the Network settings tab:
|
||||
self.lineEditTCPPort.setText(str(
|
||||
config.get('bitmessagesettings', 'port')))
|
||||
self.checkBoxUPnP.setChecked(
|
||||
config.safeGetBoolean('bitmessagesettings', 'upnp'))
|
||||
self.checkBoxUDP.setChecked(
|
||||
config.safeGetBoolean('bitmessagesettings', 'udp'))
|
||||
self.checkBoxAuthentication.setChecked(
|
||||
config.getboolean('bitmessagesettings', 'socksauthentication'))
|
||||
self.checkBoxSocksListen.setChecked(
|
||||
|
@ -328,8 +325,7 @@ class SettingsDialog(QtGui.QDialog):
|
|||
self.lineEditTCPPort.text()):
|
||||
self.config.set(
|
||||
'bitmessagesettings', 'port', str(self.lineEditTCPPort.text()))
|
||||
if not self.config.safeGetBoolean(
|
||||
'bitmessagesettings', 'dontconnect'):
|
||||
if not self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'):
|
||||
self.net_restart_needed = True
|
||||
|
||||
if self.checkBoxUPnP.isChecked() != self.config.safeGetBoolean(
|
||||
|
@ -342,27 +338,10 @@ class SettingsDialog(QtGui.QDialog):
|
|||
upnpThread = upnp.uPnPThread()
|
||||
upnpThread.start()
|
||||
|
||||
udp_enabled = self.checkBoxUDP.isChecked()
|
||||
if udp_enabled != self.config.safeGetBoolean(
|
||||
'bitmessagesettings', 'udp'):
|
||||
self.config.set('bitmessagesettings', 'udp', str(udp_enabled))
|
||||
if udp_enabled:
|
||||
announceThread = AnnounceThread()
|
||||
announceThread.daemon = True
|
||||
announceThread.start()
|
||||
else:
|
||||
try:
|
||||
state.announceThread.stopThread()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
proxytype_index = self.comboBoxProxyType.currentIndex()
|
||||
if proxytype_index == 0:
|
||||
if self._proxy_type and state.statusIconColor != 'red':
|
||||
self.net_restart_needed = True
|
||||
elif state.statusIconColor == 'red' and self.config.safeGetBoolean(
|
||||
'bitmessagesettings', 'dontconnect'):
|
||||
self.net_restart_needed = False
|
||||
elif self.comboBoxProxyType.currentText() != self._proxy_type:
|
||||
self.net_restart_needed = True
|
||||
self.parent.statusbar.clearMessage()
|
||||
|
@ -387,11 +366,8 @@ class SettingsDialog(QtGui.QDialog):
|
|||
self.lineEditSocksPassword.text()))
|
||||
self.config.set('bitmessagesettings', 'sockslisten', str(
|
||||
self.checkBoxSocksListen.isChecked()))
|
||||
if (
|
||||
self.checkBoxOnionOnly.isChecked()
|
||||
and not self.config.safeGetBoolean(
|
||||
'bitmessagesettings', 'onionservicesonly')
|
||||
):
|
||||
if self.checkBoxOnionOnly.isChecked() \
|
||||
and not self.config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'):
|
||||
self.net_restart_needed = True
|
||||
self.config.set('bitmessagesettings', 'onionservicesonly', str(
|
||||
self.checkBoxOnionOnly.isChecked()))
|
||||
|
@ -453,8 +429,8 @@ class SettingsDialog(QtGui.QDialog):
|
|||
acceptableDifficultyChanged = False
|
||||
|
||||
if (
|
||||
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1
|
||||
or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
|
||||
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1
|
||||
or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
|
||||
):
|
||||
if self.config.get(
|
||||
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte'
|
||||
|
@ -470,8 +446,8 @@ class SettingsDialog(QtGui.QDialog):
|
|||
* defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
|
||||
)
|
||||
if (
|
||||
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1
|
||||
or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
|
||||
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1
|
||||
or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
|
||||
):
|
||||
if self.config.get(
|
||||
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
|
||||
|
@ -562,8 +538,8 @@ class SettingsDialog(QtGui.QDialog):
|
|||
self.parent.updateStartOnLogon()
|
||||
|
||||
if (
|
||||
state.appdata != paths.lookupExeFolder()
|
||||
and self.checkBoxPortableMode.isChecked()
|
||||
state.appdata != paths.lookupExeFolder()
|
||||
and self.checkBoxPortableMode.isChecked()
|
||||
):
|
||||
# If we are NOT using portable mode now but the user selected
|
||||
# that we should...
|
||||
|
@ -585,8 +561,8 @@ class SettingsDialog(QtGui.QDialog):
|
|||
pass
|
||||
|
||||
if (
|
||||
state.appdata == paths.lookupExeFolder()
|
||||
and not self.checkBoxPortableMode.isChecked()
|
||||
state.appdata == paths.lookupExeFolder()
|
||||
and not self.checkBoxPortableMode.isChecked()
|
||||
):
|
||||
# If we ARE using portable mode now but the user selected
|
||||
# that we shouldn't...
|
||||
|
|
|
@ -231,7 +231,7 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Bandwidth limit</string>
|
||||
|
@ -322,7 +322,7 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Proxy server / Tor</string>
|
||||
|
@ -432,14 +432,7 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="checkBoxUDP">
|
||||
<property name="text">
|
||||
<string>Announce self by UDP</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
# pylint: disable=unused-argument
|
||||
"""Status bar Module"""
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from Queue import Queue
|
||||
from time import time
|
||||
from PyQt4 import QtGui
|
||||
|
||||
|
||||
class BMStatusBar(QtGui.QStatusBar):
|
||||
"""Status bar with queue and priorities"""
|
||||
duration = 10000
|
||||
deleteAfter = 60
|
||||
|
||||
|
@ -17,9 +13,6 @@ class BMStatusBar(QtGui.QStatusBar):
|
|||
self.iterator = 0
|
||||
|
||||
def timerEvent(self, event):
|
||||
"""an event handler which allows to queue and prioritise messages to
|
||||
show in the status bar, for example if many messages come very quickly
|
||||
after one another, it adds delays and so on"""
|
||||
while len(self.important) > 0:
|
||||
self.iterator += 1
|
||||
try:
|
||||
|
@ -37,3 +30,9 @@ class BMStatusBar(QtGui.QStatusBar):
|
|||
self.important.append([message, time()])
|
||||
self.iterator = len(self.important) - 2
|
||||
self.timerEvent(None)
|
||||
|
||||
def showMessage(self, message, timeout=0):
|
||||
super(BMStatusBar, self).showMessage(message, timeout)
|
||||
|
||||
def clearMessage(self):
|
||||
super(BMStatusBar, self).clearMessage()
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
"""bitmessageqt tests"""
|
||||
|
||||
from addressbook import TestAddressbook
|
||||
from main import TestMain, TestUISignaler
|
||||
from settings import TestSettings
|
||||
from main import TestMain
|
||||
from support import TestSupport
|
||||
|
||||
__all__ = [
|
||||
"TestAddressbook", "TestMain", "TestSettings", "TestSupport",
|
||||
"TestUISignaler"
|
||||
]
|
||||
__all__ = ["TestMain", "TestSupport"]
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
import helper_addressbook
|
||||
from bitmessageqt.support import createAddressIfNeeded
|
||||
|
||||
from main import TestBase
|
||||
|
||||
|
||||
class TestAddressbook(TestBase):
|
||||
"""Test case for addressbook"""
|
||||
|
||||
def test_add_own_address_to_addressbook(self):
|
||||
"""Checking own address adding in addressbook"""
|
||||
try:
|
||||
address = createAddressIfNeeded(self.window)
|
||||
self.assertFalse(
|
||||
helper_addressbook.insert(label='test', address=address))
|
||||
except IndexError:
|
||||
self.fail("Can't generate addresses")
|
|
@ -1,13 +1,10 @@
|
|||
"""Common definitions for bitmessageqt tests"""
|
||||
|
||||
import Queue
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
import bitmessageqt
|
||||
import queues
|
||||
from tr import _translate
|
||||
|
||||
|
||||
|
@ -15,23 +12,11 @@ class TestBase(unittest.TestCase):
|
|||
"""Base class for bitmessageqt test case"""
|
||||
|
||||
def setUp(self):
|
||||
self.app = (
|
||||
QtGui.QApplication.instance()
|
||||
or bitmessageqt.BitmessageQtApplication(sys.argv))
|
||||
self.window = self.app.activeWindow()
|
||||
if not self.window:
|
||||
self.window = bitmessageqt.MyForm()
|
||||
self.window.appIndicatorInit(self.app)
|
||||
self.app = QtGui.QApplication([])
|
||||
self.window = bitmessageqt.MyForm()
|
||||
|
||||
def tearDown(self):
|
||||
# self.app.deleteLater()
|
||||
while True:
|
||||
try:
|
||||
thread, exc = queues.excQueue.get(block=False)
|
||||
except Queue.Empty:
|
||||
return
|
||||
if thread == 'tests':
|
||||
self.fail('Exception in the main thread: %s' % exc)
|
||||
self.app.deleteLater()
|
||||
|
||||
|
||||
class TestMain(unittest.TestCase):
|
||||
|
@ -43,18 +28,3 @@ class TestMain(unittest.TestCase):
|
|||
_translate("MainWindow", "Test"),
|
||||
QtCore.QString
|
||||
)
|
||||
|
||||
|
||||
class TestUISignaler(TestBase):
|
||||
"""Test case for UISignalQueue"""
|
||||
|
||||
def test_updateStatusBar(self):
|
||||
"""Check arguments order of updateStatusBar command"""
|
||||
queues.UISignalQueue.put((
|
||||
'updateStatusBar', (
|
||||
_translate("test", "Testing updateStatusBar..."), 1)
|
||||
))
|
||||
|
||||
QtCore.QTimer.singleShot(60, self.app.quit)
|
||||
self.app.exec_()
|
||||
# self.app.processEvents(QtCore.QEventLoop.AllEvents, 60)
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
import threading
|
||||
import time
|
||||
|
||||
from main import TestBase
|
||||
from bmconfigparser import BMConfigParser
|
||||
from bitmessageqt import settings
|
||||
|
||||
|
||||
class TestSettings(TestBase):
|
||||
"""A test case for the "Settings" dialog"""
|
||||
def setUp(self):
|
||||
super(TestSettings, self).setUp()
|
||||
self.dialog = settings.SettingsDialog(self.window)
|
||||
|
||||
def test_udp(self):
|
||||
"""Test the effect of checkBoxUDP"""
|
||||
udp_setting = BMConfigParser().safeGetBoolean(
|
||||
'bitmessagesettings', 'udp')
|
||||
self.assertEqual(udp_setting, self.dialog.checkBoxUDP.isChecked())
|
||||
self.dialog.checkBoxUDP.setChecked(not udp_setting)
|
||||
self.dialog.accept()
|
||||
self.assertEqual(
|
||||
not udp_setting,
|
||||
BMConfigParser().safeGetBoolean('bitmessagesettings', 'udp'))
|
||||
time.sleep(5)
|
||||
for thread in threading.enumerate():
|
||||
if thread.name == 'Announcer': # find Announcer thread
|
||||
if udp_setting:
|
||||
self.fail(
|
||||
'Announcer thread is running while udp set to False')
|
||||
break
|
||||
else:
|
||||
if not udp_setting:
|
||||
self.fail('No Announcer thread found while udp set to True')
|
|
@ -2,22 +2,13 @@
|
|||
BMConfigParser class definition and default configuration settings
|
||||
"""
|
||||
|
||||
import sys
|
||||
if sys.version_info[0] == 3:
|
||||
# python 3
|
||||
import configparser as ConfigParser
|
||||
SafeConfigParser = ConfigParser.ConfigParser
|
||||
else:
|
||||
# python 2
|
||||
import ConfigParser
|
||||
SafeConfigParser = ConfigParser.SafeConfigParser
|
||||
|
||||
import state
|
||||
from singleton import Singleton
|
||||
import ConfigParser
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
|
||||
import state
|
||||
from singleton import Singleton
|
||||
|
||||
BMConfigDefaults = {
|
||||
"bitmessagesettings": {
|
||||
|
@ -28,32 +19,30 @@ BMConfigDefaults = {
|
|||
"maxtotalconnections": 200,
|
||||
"maxuploadrate": 0,
|
||||
"apiinterface": "127.0.0.1",
|
||||
"apiport": 8442,
|
||||
"udp": "True"
|
||||
"apiport": 8442
|
||||
},
|
||||
"threads": {
|
||||
"receive": 3,
|
||||
},
|
||||
"network": {
|
||||
"bind": "",
|
||||
"bind": '',
|
||||
"dandelion": 90,
|
||||
},
|
||||
"inventory": {
|
||||
"storage": "sqlite",
|
||||
"acceptmismatch": "False",
|
||||
"acceptmismatch": False,
|
||||
},
|
||||
"knownnodes": {
|
||||
"maxnodes": 20000,
|
||||
},
|
||||
"zlib": {
|
||||
"maxsize": 1048576
|
||||
'maxsize': 1048576
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Singleton
|
||||
class BMConfigParser(SafeConfigParser):
|
||||
|
||||
class BMConfigParser(ConfigParser.SafeConfigParser):
|
||||
"""
|
||||
Singleton class inherited from :class:`ConfigParser.SafeConfigParser`
|
||||
with additional methods specific to bitmessage config.
|
||||
|
@ -70,47 +59,26 @@ class BMConfigParser(SafeConfigParser):
|
|||
raise ValueError("Invalid value %s" % value)
|
||||
return ConfigParser.ConfigParser.set(self, section, option, value)
|
||||
|
||||
def get(self, section, option, raw=False, vars=None):
|
||||
if sys.version_info[0] == 3:
|
||||
# pylint: disable=arguments-differ
|
||||
try:
|
||||
if section == "bitmessagesettings" and option == "timeformat":
|
||||
return ConfigParser.ConfigParser.get(
|
||||
self, section, option)
|
||||
try:
|
||||
return self._temp[section][option]
|
||||
except KeyError:
|
||||
pass
|
||||
def get(self, section, option, raw=False, variables=None):
|
||||
# pylint: disable=arguments-differ
|
||||
try:
|
||||
if section == "bitmessagesettings" and option == "timeformat":
|
||||
return ConfigParser.ConfigParser.get(
|
||||
self, section, option)
|
||||
except ConfigParser.InterpolationError:
|
||||
return ConfigParser.ConfigParser.get(
|
||||
self, section, option)
|
||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
|
||||
try:
|
||||
return BMConfigDefaults[section][option]
|
||||
except (KeyError, ValueError, AttributeError):
|
||||
raise e
|
||||
else:
|
||||
# pylint: disable=arguments-differ
|
||||
self, section, option, raw, variables)
|
||||
try:
|
||||
if section == "bitmessagesettings" and option == "timeformat":
|
||||
return ConfigParser.ConfigParser.get(
|
||||
self, section, option, raw, vars)
|
||||
try:
|
||||
return self._temp[section][option]
|
||||
except KeyError:
|
||||
pass
|
||||
return ConfigParser.ConfigParser.get(
|
||||
self, section, option, True, vars)
|
||||
except ConfigParser.InterpolationError:
|
||||
return ConfigParser.ConfigParser.get(
|
||||
self, section, option, True, vars)
|
||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
|
||||
try:
|
||||
return BMConfigDefaults[section][option]
|
||||
except (KeyError, ValueError, AttributeError):
|
||||
raise e
|
||||
return self._temp[section][option]
|
||||
except KeyError:
|
||||
pass
|
||||
return ConfigParser.ConfigParser.get(
|
||||
self, section, option, True, variables)
|
||||
except ConfigParser.InterpolationError:
|
||||
return ConfigParser.ConfigParser.get(
|
||||
self, section, option, True, variables)
|
||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
|
||||
try:
|
||||
return BMConfigDefaults[section][option]
|
||||
except (KeyError, ValueError, AttributeError):
|
||||
raise e
|
||||
|
||||
def setTemp(self, section, option, value=None):
|
||||
"""Temporary set option to value, not saving."""
|
||||
|
@ -156,16 +124,7 @@ class BMConfigParser(SafeConfigParser):
|
|||
return [
|
||||
x for x in BMConfigParser().sections() if x.startswith('BM-')]
|
||||
|
||||
def _reset(self):
|
||||
"""Reset current config. There doesn't appear to be a built in
|
||||
method for this"""
|
||||
sections = self.sections()
|
||||
for x in sections:
|
||||
self.remove_section(x)
|
||||
|
||||
def read(self, filenames):
|
||||
"""Read config and populate defaults"""
|
||||
self._reset()
|
||||
ConfigParser.ConfigParser.read(self, filenames)
|
||||
for section in self.sections():
|
||||
for option in self.options(section):
|
||||
|
@ -222,4 +181,3 @@ class BMConfigParser(SafeConfigParser):
|
|||
if value < 0 or value > 8:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
275
src/buildozer.spec
Normal file
|
@ -0,0 +1,275 @@
|
|||
[app]
|
||||
|
||||
# (str) Title of your application
|
||||
title = PyBitmessage
|
||||
|
||||
# (str) Package name
|
||||
package.name = PyBitmessage
|
||||
|
||||
# (str) Package domain (needed for android/ios packaging)
|
||||
package.domain = org.test
|
||||
|
||||
# (str) Source code where the main.py live
|
||||
source.dir = .
|
||||
|
||||
# (list) Source files to include (let empty to include all the files)
|
||||
source.include_exts = py,png,jpg,kv,atlas
|
||||
|
||||
# (list) List of inclusions using pattern matching
|
||||
#source.include_patterns = assets/*,images/*.png
|
||||
|
||||
# (list) Source files to exclude (let empty to not exclude anything)
|
||||
#source.exclude_exts = spec
|
||||
|
||||
# (list) List of directory to exclude (let empty to not exclude anything)
|
||||
#source.exclude_dirs = tests, bin
|
||||
|
||||
# (list) List of exclusions using pattern matching
|
||||
#source.exclude_patterns = license,images/*/*.jpg
|
||||
|
||||
# (str) Application versioning (method 1)
|
||||
version = 0.1
|
||||
|
||||
# (str) Application versioning (method 2)
|
||||
# version.regex = __version__ = ['"](.*)['"]
|
||||
# version.filename = %(source.dir)s/main.py
|
||||
|
||||
# (list) Application requirements
|
||||
# comma seperated e.g. requirements = sqlite3,kivy
|
||||
requirements = python2, sqlite3, kivy, openssl
|
||||
|
||||
# (str) Custom source folders for requirements
|
||||
# Sets custom source for any requirements with recipes
|
||||
# requirements.source.kivy = ../../kivy
|
||||
#requirements.source.sqlite3 =
|
||||
|
||||
# (list) Garden requirements
|
||||
#garden_requirements =
|
||||
|
||||
# (str) Presplash of the application
|
||||
#presplash.filename = %(source.dir)s/data/presplash.png
|
||||
|
||||
# (str) Icon of the application
|
||||
#icon.filename = %(source.dir)s/data/icon.png
|
||||
|
||||
# (str) Supported orientation (one of landscape, portrait or all)
|
||||
orientation = portrait
|
||||
|
||||
# (list) List of service to declare
|
||||
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY
|
||||
|
||||
#
|
||||
# OSX Specific
|
||||
#
|
||||
|
||||
#
|
||||
# author = © Copyright Info
|
||||
|
||||
# change the major version of python used by the app
|
||||
#osx.python_version = 2
|
||||
|
||||
|
||||
# Kivy version to use
|
||||
osx.kivy_version = 1.9.1
|
||||
|
||||
#
|
||||
# Android specific
|
||||
#
|
||||
|
||||
# (bool) Indicate if the application should be fullscreen or not
|
||||
fullscreen = 0
|
||||
|
||||
# (string) Presplash background color (for new android toolchain)
|
||||
# Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
|
||||
# red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray,
|
||||
# darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy,
|
||||
# olive, purple, silver, teal.
|
||||
#android.presplash_color = #FFFFFF
|
||||
|
||||
# (list) Permissions
|
||||
android.permissions = INTERNET
|
||||
|
||||
# (int) Android API to use
|
||||
#android.api = 19
|
||||
|
||||
# (int) Minimum API required
|
||||
#android.minapi = 9
|
||||
|
||||
# (int) Android SDK version to use
|
||||
#android.sdk = 20
|
||||
|
||||
# (str) Android NDK version to use
|
||||
#android.ndk = 9c
|
||||
|
||||
# (bool) Use --private data storage (True) or --dir public storage (False)
|
||||
#android.private_storage = True
|
||||
|
||||
# (str) Android NDK directory (if empty, it will be automatically downloaded.)
|
||||
#android.ndk_path =
|
||||
|
||||
# (str) Android SDK directory (if empty, it will be automatically downloaded.)
|
||||
#android.sdk_path =
|
||||
|
||||
# (str) ANT directory (if empty, it will be automatically downloaded.)
|
||||
#android.ant_path =
|
||||
|
||||
# (bool) If True, then skip trying to update the Android sdk
|
||||
# This can be useful to avoid excess Internet downloads or save time
|
||||
# when an update is due and you just want to test/build your package
|
||||
# android.skip_update = False
|
||||
|
||||
# (str) Android entry point, default is ok for Kivy-based app
|
||||
#android.entrypoint = org.renpy.android.PythonActivity
|
||||
|
||||
# (list) Pattern to whitelist for the whole project
|
||||
#android.whitelist =
|
||||
|
||||
android.whitelist = /usr/lib/komodo-edit/python/lib/python2.7/lib-dynload/_sqlite3.so
|
||||
|
||||
|
||||
# (str) Path to a custom whitelist file
|
||||
#android.whitelist_src =
|
||||
|
||||
# (str) Path to a custom blacklist file
|
||||
#android.blacklist_src =
|
||||
|
||||
# (list) List of Java .jar files to add to the libs so that pyjnius can access
|
||||
# their classes. Don't add jars that you do not need, since extra jars can slow
|
||||
# down the build process. Allows wildcards matching, for example:
|
||||
# OUYA-ODK/libs/*.jar
|
||||
#android.add_jars = foo.jar,bar.jar,path/to/more/*.jar
|
||||
|
||||
# (list) List of Java files to add to the android project (can be java or a
|
||||
# directory containing the files)
|
||||
#android.add_src =
|
||||
|
||||
# (list) Android AAR archives to add (currently works only with sdl2_gradle
|
||||
# bootstrap)
|
||||
#android.add_aars =
|
||||
|
||||
# (list) Gradle dependencies to add (currently works only with sdl2_gradle
|
||||
# bootstrap)
|
||||
#android.gradle_dependencies =
|
||||
, /home/cis/Downloads/libssl1.0.2_1.0.2l-2+deb9u2_amd64
|
||||
# (str) python-for-android branch to use, defaults to stable
|
||||
#p4a.branch = stable
|
||||
|
||||
# (str) OUYA Console category. Should be one of GAME or APP
|
||||
# If you leave this blank, OUYA support will not be enabled
|
||||
#android.ouya.category = GAME
|
||||
|
||||
# (str) Filename of OUYA Console icon. It must be a 732x412 png image.
|
||||
#android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png
|
||||
|
||||
# (str) XML file to include as an intent filters in <activity> tag
|
||||
#android.manifest.intent_filters =
|
||||
|
||||
# (list) Android additionnal libraries to copy into libs/armeabi
|
||||
#android.add_libs_armeabi = libs/android/*.so
|
||||
#android.add_libs_armeabi_v7a = libs/android-v7/*.so
|
||||
#android.add_libs_x86 = libs/android-x86/*.so
|
||||
#android.add_libs_mips = libs/android-mips/*.so
|
||||
|
||||
# (bool) Indicate whether the screen should stay on
|
||||
# Don't forget to add the WAKE_LOCK permission if you set this to True
|
||||
#android.wakelock = False
|
||||
|
||||
# (list) Android application meta-data to set (key=value format)
|
||||
#android.meta_data =
|
||||
|
||||
# (list) Android library project to add (will be added in the
|
||||
# project.properties automatically.)
|
||||
#android.library_references =
|
||||
|
||||
# (str) Android logcat filters to use
|
||||
#android.logcat_filters = *:S python:D
|
||||
|
||||
# (bool) Copy library instead of making a libpymodules.so
|
||||
#android.copy_libs = 1
|
||||
|
||||
# (str) The Android arch to build for, choices: armeabi-v7a, arm64-v8a, x86
|
||||
android.arch = armeabi-v7a
|
||||
|
||||
#
|
||||
# Python for android (p4a) specific
|
||||
#
|
||||
|
||||
# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
|
||||
#p4a.source_dir =
|
||||
|
||||
# (str) The directory in which python-for-android should look for your own build recipes (if any)
|
||||
#p4a.local_recipes =
|
||||
|
||||
# (str) Filename to the hook for p4a
|
||||
#p4a.hook =
|
||||
|
||||
# (str) Bootstrap to use for android builds
|
||||
# p4a.bootstrap = sdl2
|
||||
|
||||
|
||||
#
|
||||
# iOS specific
|
||||
#
|
||||
|
||||
# (str) Path to a custom kivy-ios folder
|
||||
#ios.kivy_ios_dir = ../kivy-ios
|
||||
|
||||
# (str) Name of the certificate to use for signing the debug version
|
||||
# Get a list of available identities: buildozer ios list_identities
|
||||
#ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)"
|
||||
|
||||
# (str) Name of the certificate to use for signing the release version
|
||||
#ios.codesign.release = %(ios.codesign.debug)s
|
||||
|
||||
|
||||
[buildozer]
|
||||
|
||||
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
|
||||
log_level = 2
|
||||
|
||||
# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
|
||||
warn_on_root = 1
|
||||
|
||||
# (str) Path to build artifact storage, absolute or relative to spec file
|
||||
# build_dir = ./.buildozer
|
||||
|
||||
# (str) Path to build output (i.e. .apk, .ipa) storage
|
||||
# bin_dir = ./bin
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# List as sections
|
||||
#
|
||||
# You can define all the "list" as [section:key].
|
||||
# Each line will be considered as a option to the list.
|
||||
# Let's take [app] / source.exclude_patterns.
|
||||
# Instead of doing:
|
||||
#
|
||||
#[app]
|
||||
#source.exclude_patterns = license,data/audio/*.wav,data/images/original/*
|
||||
#
|
||||
# This can be translated into:
|
||||
#
|
||||
#[app:source.exclude_patterns]
|
||||
#license
|
||||
#data/audio/*.wav
|
||||
#data/images/original/*
|
||||
#
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Profiles
|
||||
#
|
||||
# You can extend section / key with a profile
|
||||
# For example, you want to deploy a demo version of your application without
|
||||
# HD content. You could first change the title to add "(demo)" in the name
|
||||
# and extend the excluded directories to remove the HD content.
|
||||
#
|
||||
#[app@demo]
|
||||
#title = My Application (demo)
|
||||
#
|
||||
#[app:source.exclude_patterns@demo]
|
||||
#images/hd/*
|
||||
#
|
||||
# Then, invoke the command line with the "demo" profile:
|
||||
#
|
||||
#buildozer --profile demo android debug
|
|
@ -29,7 +29,8 @@ from addresses import (
|
|||
)
|
||||
from bmconfigparser import BMConfigParser
|
||||
from fallback import RIPEMD160Hash
|
||||
from helper_sql import sql_ready, SqlBulkExecute, sqlExecute, sqlQuery
|
||||
from helper_ackPayload import genAckPayload
|
||||
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
|
||||
from network import bmproto, knownnodes
|
||||
from network.node import Peer
|
||||
# pylint: disable=too-many-locals, too-many-return-statements, too-many-branches, too-many-statements
|
||||
|
@ -50,7 +51,6 @@ class objectProcessor(threading.Thread):
|
|||
# objectProcessorQueue. Assuming that Bitmessage wasn't closed
|
||||
# forcefully, it should have saved the data in the queue into the
|
||||
# objectprocessorqueue table. Let's pull it out.
|
||||
sql_ready.wait()
|
||||
queryreturn = sqlQuery(
|
||||
'''SELECT objecttype, data FROM objectprocessorqueue''')
|
||||
for row in queryreturn:
|
||||
|
@ -576,6 +576,7 @@ class objectProcessor(threading.Thread):
|
|||
decryptedData[readPosition:readPosition + 10])
|
||||
readPosition += messageLengthLength
|
||||
message = decryptedData[readPosition:readPosition + messageLength]
|
||||
# print 'First 150 characters of message:', repr(message[:150])
|
||||
readPosition += messageLength
|
||||
ackLength, ackLengthLength = decodeVarint(
|
||||
decryptedData[readPosition:readPosition + 10])
|
||||
|
@ -744,14 +745,32 @@ class objectProcessor(threading.Thread):
|
|||
# We don't actually need the ackdata for acknowledgement
|
||||
# since this is a broadcast message but we can use it to
|
||||
# update the user interface when the POW is done generating.
|
||||
toAddress = '[Broadcast subscribers]'
|
||||
streamNumber = decodeAddress(fromAddress)[2]
|
||||
|
||||
ackdata = helper_sent.insert(
|
||||
fromAddress=fromAddress,
|
||||
status='broadcastqueued',
|
||||
subject=subject,
|
||||
message=message,
|
||||
encoding=messageEncodingType)
|
||||
ackdata = genAckPayload(streamNumber, 0)
|
||||
toAddress = '[Broadcast subscribers]'
|
||||
ripe = ''
|
||||
|
||||
# We really should have a discussion about how to
|
||||
# set the TTL for mailing list broadcasts. This is obviously
|
||||
# hard-coded.
|
||||
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks
|
||||
t = ('',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this doesn't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'broadcastqueued',
|
||||
0,
|
||||
'sent',
|
||||
messageEncodingType,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
|
||||
queues.UISignalQueue.put((
|
||||
'displayNewSentMessage', (
|
||||
|
|
|
@ -179,7 +179,7 @@ class singleCleaner(StoppableThread):
|
|||
'Doing work necessary to again attempt to request a public key...'
|
||||
))
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET status='msgqueued' WHERE toaddress=? AND folder='sent' ''',
|
||||
'''UPDATE sent SET status='msgqueued' WHERE toaddress=?''',
|
||||
address)
|
||||
queues.workerQueue.put(('sendmessage', ''))
|
||||
|
||||
|
@ -190,7 +190,7 @@ class singleCleaner(StoppableThread):
|
|||
' to our msg. Sending again.'
|
||||
)
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET status='msgqueued' WHERE ackdata=? AND folder='sent' ''',
|
||||
'''UPDATE sent SET status='msgqueued' WHERE ackdata=?''',
|
||||
ackdata)
|
||||
queues.workerQueue.put(('sendmessage', ''))
|
||||
queues.UISignalQueue.put((
|
||||
|
|
|
@ -16,7 +16,6 @@ import defaults
|
|||
import helper_inbox
|
||||
import helper_msgcoding
|
||||
import helper_random
|
||||
import helper_sql
|
||||
import highlevelcrypto
|
||||
import l10n
|
||||
import proofofwork
|
||||
|
@ -63,8 +62,8 @@ class singleWorker(StoppableThread):
|
|||
def run(self):
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
|
||||
while not helper_sql.sql_ready.wait(1.0) and state.shutdown == 0:
|
||||
self.stop.wait(1.0)
|
||||
while not state.sqlReady and state.shutdown == 0:
|
||||
self.stop.wait(2)
|
||||
if state.shutdown > 0:
|
||||
return
|
||||
|
||||
|
@ -97,7 +96,7 @@ class singleWorker(StoppableThread):
|
|||
|
||||
# Initialize the state.ackdataForWhichImWatching data structure
|
||||
queryreturn = sqlQuery(
|
||||
'''SELECT ackdata FROM sent WHERE status = 'msgsent' AND folder = 'sent' ''')
|
||||
'''SELECT ackdata FROM sent WHERE status = 'msgsent' ''')
|
||||
for row in queryreturn:
|
||||
ackdata, = row
|
||||
self.logger.info('Watching for ackdata %s', hexlify(ackdata))
|
||||
|
@ -110,7 +109,7 @@ class singleWorker(StoppableThread):
|
|||
newack = '\x00\x00\x00\x02\x01\x01' + oldack
|
||||
state.ackdataForWhichImWatching[newack] = 0
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET ackdata=? WHERE ackdata=? AND folder = 'sent' ''',
|
||||
'UPDATE sent SET ackdata=? WHERE ackdata=?',
|
||||
newack, oldack
|
||||
)
|
||||
del state.ackdataForWhichImWatching[oldack]
|
||||
|
@ -523,7 +522,7 @@ class singleWorker(StoppableThread):
|
|||
sqlExecute(
|
||||
'''UPDATE sent SET status='broadcastqueued' '''
|
||||
|
||||
'''WHERE status = 'doingbroadcastpow' AND folder = 'sent' ''')
|
||||
'''WHERE status = 'doingbroadcastpow' ''')
|
||||
queryreturn = sqlQuery(
|
||||
'''SELECT fromaddress, subject, message, '''
|
||||
''' ackdata, ttl, encodingtype FROM sent '''
|
||||
|
@ -557,12 +556,10 @@ class singleWorker(StoppableThread):
|
|||
))
|
||||
continue
|
||||
|
||||
if not sqlExecute(
|
||||
'''UPDATE sent SET status='doingbroadcastpow' '''
|
||||
''' WHERE ackdata=? AND status='broadcastqueued' '''
|
||||
''' AND folder='sent' ''',
|
||||
ackdata):
|
||||
continue
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET status='doingbroadcastpow' '''
|
||||
''' WHERE ackdata=? AND status='broadcastqueued' ''',
|
||||
ackdata)
|
||||
|
||||
# At this time these pubkeys are 65 bytes long
|
||||
# because they include the encoding byte which we won't
|
||||
|
@ -683,8 +680,8 @@ class singleWorker(StoppableThread):
|
|||
# Update the status of the message in the 'sent' table to have
|
||||
# a 'broadcastsent' status
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET msgid=?, status=?, lastactiontime=? '''
|
||||
''' WHERE ackdata=? AND folder='sent' ''',
|
||||
'UPDATE sent SET msgid=?, status=?, lastactiontime=?'
|
||||
' WHERE ackdata=?',
|
||||
inventoryHash, 'broadcastsent', int(time.time()), ackdata
|
||||
)
|
||||
|
||||
|
@ -694,8 +691,7 @@ class singleWorker(StoppableThread):
|
|||
# Reset just in case
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET status='msgqueued' '''
|
||||
''' WHERE status IN ('doingpubkeypow', 'doingmsgpow') '''
|
||||
''' AND folder='sent' ''')
|
||||
''' WHERE status IN ('doingpubkeypow', 'doingmsgpow')''')
|
||||
queryreturn = sqlQuery(
|
||||
'''SELECT toaddress, fromaddress, subject, message, '''
|
||||
''' ackdata, status, ttl, retrynumber, encodingtype FROM '''
|
||||
|
@ -731,12 +727,11 @@ class singleWorker(StoppableThread):
|
|||
# we can calculate the needed pubkey using the private keys
|
||||
# in our keys.dat file.
|
||||
elif BMConfigParser().has_section(toaddress):
|
||||
if not sqlExecute(
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET status='doingmsgpow' '''
|
||||
''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''',
|
||||
''' WHERE toaddress=? AND status='msgqueued' ''',
|
||||
toaddress
|
||||
):
|
||||
continue
|
||||
)
|
||||
status = 'doingmsgpow'
|
||||
elif status == 'msgqueued':
|
||||
# Let's see if we already have the pubkey in our pubkeys table
|
||||
|
@ -747,12 +742,11 @@ class singleWorker(StoppableThread):
|
|||
# If we have the needed pubkey in the pubkey table already,
|
||||
if queryreturn != []:
|
||||
# set the status of this msg to doingmsgpow
|
||||
if not sqlExecute(
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET status='doingmsgpow' '''
|
||||
''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''',
|
||||
''' WHERE toaddress=? AND status='msgqueued' ''',
|
||||
toaddress
|
||||
):
|
||||
continue
|
||||
)
|
||||
status = 'doingmsgpow'
|
||||
# mark the pubkey as 'usedpersonally' so that
|
||||
# we don't delete it later. If the pubkey version
|
||||
|
@ -835,8 +829,7 @@ class singleWorker(StoppableThread):
|
|||
''' toaddress=? AND '''
|
||||
''' (status='msgqueued' or '''
|
||||
''' status='awaitingpubkey' or '''
|
||||
''' status='doingpubkeypow') AND '''
|
||||
''' folder='sent' ''',
|
||||
''' status='doingpubkeypow')''',
|
||||
toaddress)
|
||||
del state.neededPubkeys[tag]
|
||||
break
|
||||
|
@ -853,7 +846,7 @@ class singleWorker(StoppableThread):
|
|||
sqlExecute(
|
||||
'''UPDATE sent SET '''
|
||||
''' status='doingpubkeypow' WHERE '''
|
||||
''' toaddress=? AND status='msgqueued' AND folder='sent' ''',
|
||||
''' toaddress=? AND status='msgqueued' ''',
|
||||
toaddress
|
||||
)
|
||||
queues.UISignalQueue.put((
|
||||
|
@ -1046,7 +1039,7 @@ class singleWorker(StoppableThread):
|
|||
# we are willing to do.
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET status='toodifficult' '''
|
||||
''' WHERE ackdata=? AND folder='sent' ''',
|
||||
''' WHERE ackdata=? ''',
|
||||
ackdata)
|
||||
queues.UISignalQueue.put((
|
||||
'updateSentItemStatusByAckdata', (
|
||||
|
@ -1194,7 +1187,7 @@ class singleWorker(StoppableThread):
|
|||
)
|
||||
except:
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET status='badkey' WHERE ackdata=? AND folder='sent' ''',
|
||||
'''UPDATE sent SET status='badkey' WHERE ackdata=?''',
|
||||
ackdata
|
||||
)
|
||||
queues.UISignalQueue.put((
|
||||
|
@ -1301,7 +1294,7 @@ class singleWorker(StoppableThread):
|
|||
sleepTill = int(time.time() + TTL * 1.1)
|
||||
sqlExecute(
|
||||
'''UPDATE sent SET msgid=?, status=?, retrynumber=?, '''
|
||||
''' sleeptill=?, lastactiontime=? WHERE ackdata=? AND folder='sent' ''',
|
||||
''' sleeptill=?, lastactiontime=? WHERE ackdata=?''',
|
||||
inventoryHash, newStatus, retryNumber + 1,
|
||||
sleepTill, int(time.time()), ackdata
|
||||
)
|
||||
|
@ -1347,7 +1340,7 @@ class singleWorker(StoppableThread):
|
|||
queryReturn = sqlQuery(
|
||||
'''SELECT retrynumber FROM sent WHERE toaddress=? '''
|
||||
''' AND (status='doingpubkeypow' OR status='awaitingpubkey') '''
|
||||
''' AND folder='sent' LIMIT 1''',
|
||||
''' LIMIT 1''',
|
||||
toAddress
|
||||
)
|
||||
if not queryReturn:
|
||||
|
@ -1406,6 +1399,7 @@ class singleWorker(StoppableThread):
|
|||
self.logger.info(
|
||||
'making request for v4 pubkey with tag: %s', hexlify(tag))
|
||||
|
||||
# print 'trial value', trialValue
|
||||
statusbar = 'Doing the computations necessary to request' +\
|
||||
' the recipient\'s public key.'
|
||||
queues.UISignalQueue.put(('updateStatusBar', statusbar))
|
||||
|
@ -1432,7 +1426,7 @@ class singleWorker(StoppableThread):
|
|||
'''UPDATE sent SET lastactiontime=?, '''
|
||||
''' status='awaitingpubkey', retrynumber=?, sleeptill=? '''
|
||||
''' WHERE toaddress=? AND (status='doingpubkeypow' OR '''
|
||||
''' status='awaitingpubkey') AND folder='sent' ''',
|
||||
''' status='awaitingpubkey') ''',
|
||||
int(time.time()), retryNumber + 1, sleeptill, toAddress)
|
||||
|
||||
queues.UISignalQueue.put((
|
||||
|
|
|
@ -73,6 +73,7 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
|
|||
pair = self.accept()
|
||||
if pair is not None:
|
||||
conn, addr = pair
|
||||
# print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
|
||||
self.channel = smtpServerChannel(self, conn, addr)
|
||||
|
||||
def send(self, fromAddress, toAddress, subject, message):
|
||||
|
@ -117,6 +118,7 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
|
|||
def process_message(self, peer, mailfrom, rcpttos, data):
|
||||
"""Process an email"""
|
||||
# pylint: disable=too-many-locals, too-many-branches
|
||||
# print 'Receiving message from:', peer
|
||||
p = re.compile(".*<([^>]+)>")
|
||||
if not hasattr(self.channel, "auth") or not self.channel.auth:
|
||||
logger.error('Missing or invalid auth')
|
||||
|
|
|
@ -28,7 +28,6 @@ class sqlThread(threading.Thread):
|
|||
|
||||
def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
|
||||
"""Process SQL queries from `.helper_sql.sqlSubmitQueue`"""
|
||||
helper_sql.sql_available = True
|
||||
self.conn = sqlite3.connect(state.appdata + 'messages.dat')
|
||||
self.conn.text_factory = str
|
||||
self.cur = self.conn.cursor()
|
||||
|
@ -47,7 +46,7 @@ class sqlThread(threading.Thread):
|
|||
self.cur.execute(
|
||||
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
|
||||
self.cur.execute(
|
||||
'''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
|
||||
'''CREATE TABLE addressbook (label text, address text)''')
|
||||
self.cur.execute(
|
||||
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
|
||||
self.cur.execute(
|
||||
|
@ -63,7 +62,7 @@ class sqlThread(threading.Thread):
|
|||
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
|
||||
self.cur.execute(
|
||||
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
|
||||
self.cur.execute('''INSERT INTO settings VALUES('version','11')''')
|
||||
self.cur.execute('''INSERT INTO settings VALUES('version','10')''')
|
||||
self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
|
||||
int(time.time()),))
|
||||
self.cur.execute(
|
||||
|
@ -390,25 +389,6 @@ class sqlThread(threading.Thread):
|
|||
' and removing the hash field.')
|
||||
self.cur.execute('''update settings set value=10 WHERE key='version';''')
|
||||
|
||||
# Update the address colunm to unique in addressbook table
|
||||
item = '''SELECT value FROM settings WHERE key='version';'''
|
||||
parameters = ''
|
||||
self.cur.execute(item, parameters)
|
||||
currentVersion = int(self.cur.fetchall()[0][0])
|
||||
if currentVersion == 10:
|
||||
logger.debug(
|
||||
'In messages.dat database, updating address column to UNIQUE'
|
||||
' in the addressbook table.')
|
||||
self.cur.execute(
|
||||
'''ALTER TABLE addressbook RENAME TO old_addressbook''')
|
||||
self.cur.execute(
|
||||
'''CREATE TABLE addressbook'''
|
||||
''' (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
|
||||
self.cur.execute(
|
||||
'''INSERT INTO addressbook SELECT label, address FROM old_addressbook;''')
|
||||
self.cur.execute('''DROP TABLE old_addressbook''')
|
||||
self.cur.execute('''update settings set value=11 WHERE key='version';''')
|
||||
|
||||
# Are you hoping to add a new option to the keys.dat file of existing
|
||||
# Bitmessage users or modify the SQLite database? Add it right
|
||||
# above this line!
|
||||
|
@ -484,7 +464,7 @@ class sqlThread(threading.Thread):
|
|||
parameters = (int(time.time()),)
|
||||
self.cur.execute(item, parameters)
|
||||
|
||||
helper_sql.sql_ready.set()
|
||||
state.sqlReady = True
|
||||
|
||||
while True:
|
||||
item = helper_sql.sqlSubmitQueue.get()
|
||||
|
@ -587,6 +567,8 @@ class sqlThread(threading.Thread):
|
|||
else:
|
||||
parameters = helper_sql.sqlSubmitQueue.get()
|
||||
rowcount = 0
|
||||
# print 'item', item
|
||||
# print 'parameters', parameters
|
||||
try:
|
||||
self.cur.execute(item, parameters)
|
||||
rowcount = self.cur.rowcount
|
||||
|
|
|
@ -421,8 +421,8 @@ def check_dependencies(verbose=False, optional=False):
|
|||
if sys.hexversion >= 0x3000000:
|
||||
logger.error(
|
||||
'PyBitmessage does not support Python 3+. Python 2.7.4'
|
||||
' or greater is required. Python 2.7.18 is recommended.')
|
||||
sys.exit()
|
||||
' or greater is required.')
|
||||
has_all_dependencies = False
|
||||
|
||||
check_functions = [check_ripemd160, check_sqlite, check_openssl]
|
||||
if optional:
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
"""
|
||||
Insert value into addressbook
|
||||
"""
|
||||
|
||||
from bmconfigparser import BMConfigParser
|
||||
from helper_sql import sqlExecute
|
||||
|
||||
|
||||
def insert(address, label):
|
||||
"""perform insert into addressbook"""
|
||||
|
||||
if address not in BMConfigParser().addresses():
|
||||
return sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address) == 1
|
||||
return False
|
|
@ -2,47 +2,9 @@
|
|||
Insert values into sent table
|
||||
"""
|
||||
|
||||
import time
|
||||
import uuid
|
||||
from addresses import decodeAddress
|
||||
from bmconfigparser import BMConfigParser
|
||||
from helper_ackPayload import genAckPayload
|
||||
from helper_sql import sqlExecute
|
||||
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def insert(msgid=None, toAddress='[Broadcast subscribers]', fromAddress=None, subject=None,
|
||||
message=None, status='msgqueued', ripe=None, ackdata=None, sentTime=None,
|
||||
lastActionTime=None, sleeptill=0, retryNumber=0, encoding=2, ttl=None, folder='sent'):
|
||||
def insert(t):
|
||||
"""Perform an insert into the `sent` table"""
|
||||
# pylint: disable=unused-variable
|
||||
# pylint: disable-msg=too-many-locals
|
||||
|
||||
valid_addr = True
|
||||
if not ripe or not ackdata:
|
||||
addr = fromAddress if toAddress == '[Broadcast subscribers]' else toAddress
|
||||
new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(addr)
|
||||
valid_addr = True if new_status == 'success' else False
|
||||
if not ripe:
|
||||
ripe = new_ripe
|
||||
|
||||
if not ackdata:
|
||||
stealthLevel = BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'ackstealthlevel')
|
||||
new_ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
ackdata = new_ackdata
|
||||
if valid_addr:
|
||||
msgid = msgid if msgid else uuid.uuid4().bytes
|
||||
sentTime = sentTime if sentTime else int(time.time()) # sentTime (this doesn't change)
|
||||
lastActionTime = lastActionTime if lastActionTime else int(time.time())
|
||||
|
||||
ttl = ttl if ttl else BMConfigParser().getint('bitmessagesettings', 'ttl')
|
||||
|
||||
t = (msgid, toAddress, ripe, fromAddress, subject, message, ackdata,
|
||||
sentTime, lastActionTime, sleeptill, status, retryNumber, folder,
|
||||
encoding, ttl)
|
||||
|
||||
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||
return ackdata
|
||||
else:
|
||||
return None
|
||||
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||
|
|
|
@ -23,27 +23,19 @@ sqlSubmitQueue = Queue.Queue()
|
|||
"""the queue for SQL"""
|
||||
sqlReturnQueue = Queue.Queue()
|
||||
"""the queue for results"""
|
||||
sql_lock = threading.Lock()
|
||||
""" lock to prevent queueing a new request until the previous response
|
||||
is available """
|
||||
sql_available = False
|
||||
"""set to True by `.threads.sqlThread` immediately upon start"""
|
||||
sql_ready = threading.Event()
|
||||
"""set by `.threads.sqlThread` when ready for processing (after
|
||||
initialization is done)"""
|
||||
sqlLock = threading.Lock()
|
||||
|
||||
|
||||
def sqlQuery(sql_statement, *args):
|
||||
def sqlQuery(sqlStatement, *args):
|
||||
"""
|
||||
Query sqlite and return results
|
||||
|
||||
:param str sql_statement: SQL statement string
|
||||
:param str sqlStatement: SQL statement string
|
||||
:param list args: SQL query parameters
|
||||
:rtype: list
|
||||
"""
|
||||
assert sql_available
|
||||
sql_lock.acquire()
|
||||
sqlSubmitQueue.put(sql_statement)
|
||||
sqlLock.acquire()
|
||||
sqlSubmitQueue.put(sqlStatement)
|
||||
|
||||
if args == ():
|
||||
sqlSubmitQueue.put('')
|
||||
|
@ -52,48 +44,46 @@ def sqlQuery(sql_statement, *args):
|
|||
else:
|
||||
sqlSubmitQueue.put(args)
|
||||
queryreturn, _ = sqlReturnQueue.get()
|
||||
sql_lock.release()
|
||||
sqlLock.release()
|
||||
|
||||
return queryreturn
|
||||
|
||||
|
||||
def sqlExecuteChunked(sql_statement, idCount, *args):
|
||||
def sqlExecuteChunked(sqlStatement, idCount, *args):
|
||||
"""Execute chunked SQL statement to avoid argument limit"""
|
||||
# SQLITE_MAX_VARIABLE_NUMBER,
|
||||
# unfortunately getting/setting isn't exposed to python
|
||||
assert sql_available
|
||||
sqlExecuteChunked.chunkSize = 999
|
||||
|
||||
if idCount == 0 or idCount > len(args):
|
||||
return 0
|
||||
|
||||
total_row_count = 0
|
||||
with sql_lock:
|
||||
totalRowCount = 0
|
||||
with sqlLock:
|
||||
for i in range(
|
||||
len(args) - idCount, len(args),
|
||||
sqlExecuteChunked.chunkSize - (len(args) - idCount)
|
||||
len(args) - idCount, len(args),
|
||||
sqlExecuteChunked.chunkSize - (len(args) - idCount)
|
||||
):
|
||||
chunk_slice = args[
|
||||
i:i + sqlExecuteChunked.chunkSize - (len(args) - idCount)
|
||||
]
|
||||
sqlSubmitQueue.put(
|
||||
sql_statement.format(','.join('?' * len(chunk_slice)))
|
||||
sqlStatement.format(','.join('?' * len(chunk_slice)))
|
||||
)
|
||||
# first static args, and then iterative chunk
|
||||
sqlSubmitQueue.put(
|
||||
args[0:len(args) - idCount] + chunk_slice
|
||||
)
|
||||
ret_val = sqlReturnQueue.get()
|
||||
total_row_count += ret_val[1]
|
||||
retVal = sqlReturnQueue.get()
|
||||
totalRowCount += retVal[1]
|
||||
sqlSubmitQueue.put('commit')
|
||||
return total_row_count
|
||||
return totalRowCount
|
||||
|
||||
|
||||
def sqlExecute(sql_statement, *args):
|
||||
def sqlExecute(sqlStatement, *args):
|
||||
"""Execute SQL statement (optionally with arguments)"""
|
||||
assert sql_available
|
||||
sql_lock.acquire()
|
||||
sqlSubmitQueue.put(sql_statement)
|
||||
sqlLock.acquire()
|
||||
sqlSubmitQueue.put(sqlStatement)
|
||||
|
||||
if args == ():
|
||||
sqlSubmitQueue.put('')
|
||||
|
@ -101,34 +91,32 @@ def sqlExecute(sql_statement, *args):
|
|||
sqlSubmitQueue.put(args)
|
||||
_, rowcount = sqlReturnQueue.get()
|
||||
sqlSubmitQueue.put('commit')
|
||||
sql_lock.release()
|
||||
sqlLock.release()
|
||||
return rowcount
|
||||
|
||||
|
||||
def sqlStoredProcedure(procName):
|
||||
"""Schedule procName to be run"""
|
||||
assert sql_available
|
||||
sql_lock.acquire()
|
||||
sqlLock.acquire()
|
||||
sqlSubmitQueue.put(procName)
|
||||
sql_lock.release()
|
||||
sqlLock.release()
|
||||
|
||||
|
||||
class SqlBulkExecute(object):
|
||||
"""This is used when you have to execute the same statement in a cycle."""
|
||||
|
||||
def __enter__(self):
|
||||
sql_lock.acquire()
|
||||
sqlLock.acquire()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, value, traceback):
|
||||
sqlSubmitQueue.put('commit')
|
||||
sql_lock.release()
|
||||
sqlLock.release()
|
||||
|
||||
@staticmethod
|
||||
def execute(sql_statement, *args):
|
||||
def execute(sqlStatement, *args):
|
||||
"""Used for statements that do not return results."""
|
||||
assert sql_available
|
||||
sqlSubmitQueue.put(sql_statement)
|
||||
sqlSubmitQueue.put(sqlStatement)
|
||||
|
||||
if args == ():
|
||||
sqlSubmitQueue.put('')
|
||||
|
|
21
src/kivymd/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Andrés Rodríguez and KivyMD contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
6
src/kivymd/__init__.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
|
||||
path = os.path.dirname(__file__)
|
||||
fonts_path = os.path.join(path, "fonts/")
|
||||
images_path = os.path.join(path, 'images/')
|
254
src/kivymd/accordion.py
Normal file
|
@ -0,0 +1,254 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import StringProperty, ListProperty, OptionProperty
|
||||
from kivy.utils import get_color_from_hex
|
||||
from kivymd.color_definitions import colors
|
||||
from kivymd.theming import ThemableBehavior
|
||||
from kivy.uix.accordion import Accordion, AccordionItem
|
||||
from kivymd.backgroundcolorbehavior import BackgroundColorBehavior
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
|
||||
|
||||
class MDAccordionItemTitleLayout(ThemableBehavior, BackgroundColorBehavior, BoxLayout):
|
||||
pass
|
||||
|
||||
|
||||
class MDAccordion(ThemableBehavior, BackgroundColorBehavior, Accordion):
|
||||
pass
|
||||
|
||||
|
||||
class MDAccordionItem(ThemableBehavior, AccordionItem):
|
||||
title_theme_color = OptionProperty(None, allownone=True,
|
||||
options=['Primary', 'Secondary', 'Hint',
|
||||
'Error', 'Custom'])
|
||||
''' Color theme for title text and icon '''
|
||||
|
||||
title_color = ListProperty(None, allownone=True)
|
||||
''' Color for title text and icon if `title_theme_color` is Custom '''
|
||||
|
||||
background_color = ListProperty(None, allownone=True)
|
||||
''' Color for the background of the accordian item title in rgba format.
|
||||
'''
|
||||
|
||||
divider_color = ListProperty(None, allownone=True)
|
||||
''' Color for dividers between different titles in rgba format
|
||||
To remove the divider set a color with an alpha of 0.
|
||||
'''
|
||||
|
||||
indicator_color = ListProperty(None, allownone=True)
|
||||
''' Color for the indicator on the side of the active item in rgba format
|
||||
To remove the indicator set a color with an alpha of 0.
|
||||
'''
|
||||
|
||||
font_style = OptionProperty(
|
||||
'Subhead', options=['Body1', 'Body2', 'Caption', 'Subhead', 'Title',
|
||||
'Headline', 'Display1', 'Display2', 'Display3',
|
||||
'Display4', 'Button', 'Icon'])
|
||||
''' Font style to use for the title text '''
|
||||
|
||||
title_template = StringProperty('MDAccordionItemTitle')
|
||||
''' Template to use for the title '''
|
||||
|
||||
icon = StringProperty(None,allownone=True)
|
||||
''' Icon name to use when this item is expanded '''
|
||||
|
||||
icon_expanded = StringProperty('chevron-up')
|
||||
''' Icon name to use when this item is expanded '''
|
||||
|
||||
icon_collapsed = StringProperty('chevron-down')
|
||||
''' Icon name to use when this item is collapsed '''
|
||||
|
||||
|
||||
Builder.load_string('''
|
||||
#:import MDLabel kivymd.label.MDLabel
|
||||
#:import md_icons kivymd.icon_definitions.md_icons
|
||||
|
||||
|
||||
<MDAccordionItem>:
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: self.background_color or self.theme_cls.primary_color
|
||||
Rectangle:
|
||||
size:self.size
|
||||
pos:self.pos
|
||||
|
||||
PushMatrix
|
||||
Translate:
|
||||
xy: (dp(2),0) if self.orientation == 'vertical' else (0,dp(2))
|
||||
canvas.after:
|
||||
PopMatrix
|
||||
Color:
|
||||
rgba: self.divider_color or self.theme_cls.divider_color
|
||||
Rectangle:
|
||||
size:(dp(1),self.height) if self.orientation == 'horizontal' else (self.width,dp(1))
|
||||
pos:self.pos
|
||||
Color:
|
||||
rgba: [0,0,0,0] if self.collapse else (self.indicator_color or self.theme_cls.accent_color)
|
||||
Rectangle:
|
||||
size:(dp(2),self.height) if self.orientation == 'vertical' else (self.width,dp(2))
|
||||
pos:self.pos
|
||||
|
||||
[MDAccordionItemTitle@MDAccordionItemTitleLayout]:
|
||||
padding: '12dp'
|
||||
spacing: '12dp'
|
||||
orientation: 'horizontal' if ctx.item.orientation=='vertical' else 'vertical'
|
||||
canvas:
|
||||
PushMatrix
|
||||
Translate:
|
||||
xy: (-dp(2),0) if ctx.item.orientation == 'vertical' else (0,-dp(2))
|
||||
|
||||
Color:
|
||||
rgba: self.background_color or self.theme_cls.primary_color
|
||||
Rectangle:
|
||||
size:self.size
|
||||
pos:self.pos
|
||||
|
||||
canvas.after:
|
||||
Color:
|
||||
rgba: [0,0,0,0] if ctx.item.collapse else (ctx.item.indicator_color or self.theme_cls.accent_color)
|
||||
Rectangle:
|
||||
size:(dp(2),self.height) if ctx.item.orientation == 'vertical' else (self.width,dp(2))
|
||||
pos:self.pos
|
||||
PopMatrix
|
||||
MDLabel:
|
||||
id:_icon
|
||||
theme_text_color:ctx.item.title_theme_color if ctx.item.icon else 'Custom'
|
||||
text_color:ctx.item.title_color if ctx.item.icon else [0,0,0,0]
|
||||
text: md_icons[ctx.item.icon if ctx.item.icon else 'menu']
|
||||
font_style:'Icon'
|
||||
size_hint: (None,1) if ctx.item.orientation == 'vertical' else (1,None)
|
||||
size: ((self.texture_size[0],1) if ctx.item.orientation == 'vertical' else (1,self.texture_size[1])) \
|
||||
if ctx.item.icon else (0,0)
|
||||
text_size: (self.width, None) if ctx.item.orientation=='vertical' else (None,self.width)
|
||||
canvas.before:
|
||||
PushMatrix
|
||||
Rotate:
|
||||
angle: 90 if ctx.item.orientation == 'horizontal' else 0
|
||||
origin: self.center
|
||||
canvas.after:
|
||||
PopMatrix
|
||||
MDLabel:
|
||||
id:_label
|
||||
theme_text_color:ctx.item.title_theme_color
|
||||
text_color:ctx.item.title_color
|
||||
text: ctx.item.title
|
||||
font_style:ctx.item.font_style
|
||||
text_size: (self.width, None) if ctx.item.orientation=='vertical' else (None,self.width)
|
||||
canvas.before:
|
||||
PushMatrix
|
||||
Rotate:
|
||||
angle: 90 if ctx.item.orientation == 'horizontal' else 0
|
||||
origin: self.center
|
||||
canvas.after:
|
||||
PopMatrix
|
||||
|
||||
MDLabel:
|
||||
id:_expand_icon
|
||||
theme_text_color:ctx.item.title_theme_color
|
||||
text_color:ctx.item.title_color
|
||||
font_style:'Icon'
|
||||
size_hint: (None,1) if ctx.item.orientation == 'vertical' else (1,None)
|
||||
size: (self.texture_size[0],1) if ctx.item.orientation == 'vertical' else (1,self.texture_size[1])
|
||||
text:md_icons[ctx.item.icon_collapsed if ctx.item.collapse else ctx.item.icon_expanded]
|
||||
halign: 'right' if ctx.item.orientation=='vertical' else 'center'
|
||||
#valign: 'middle' if ctx.item.orientation=='vertical' else 'bottom'
|
||||
canvas.before:
|
||||
PushMatrix
|
||||
Rotate:
|
||||
angle: 90 if ctx.item.orientation == 'horizontal' else 0
|
||||
origin:self.center
|
||||
canvas.after:
|
||||
PopMatrix
|
||||
|
||||
''')
|
||||
|
||||
if __name__ == '__main__':
|
||||
from kivy.app import App
|
||||
from kivymd.theming import ThemeManager
|
||||
|
||||
class AccordionApp(App):
|
||||
theme_cls = ThemeManager()
|
||||
|
||||
def build(self):
|
||||
# self.theme_cls.primary_palette = 'Indigo'
|
||||
return Builder.load_string("""
|
||||
#:import MDLabel kivymd.label.MDLabel
|
||||
#:import MDList kivymd.list.MDList
|
||||
#:import OneLineListItem kivymd.list.OneLineListItem
|
||||
BoxLayout:
|
||||
spacing: '64dp'
|
||||
MDAccordion:
|
||||
orientation:'vertical'
|
||||
MDAccordionItem:
|
||||
title:'Item 1'
|
||||
icon: 'home'
|
||||
ScrollView:
|
||||
MDList:
|
||||
OneLineListItem:
|
||||
text: "Subitem 1"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
OneLineListItem:
|
||||
text: "Subitem 2"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
OneLineListItem:
|
||||
text: "Subitem 3"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
MDAccordionItem:
|
||||
title:'Item 2'
|
||||
icon: 'globe'
|
||||
ScrollView:
|
||||
MDList:
|
||||
OneLineListItem:
|
||||
text: "Subitem 4"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
OneLineListItem:
|
||||
text: "Subitem 5"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
OneLineListItem:
|
||||
text: "Subitem 6"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
MDAccordionItem:
|
||||
title:'Item 3'
|
||||
ScrollView:
|
||||
MDList:
|
||||
OneLineListItem:
|
||||
text: "Subitem 7"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
OneLineListItem:
|
||||
text: "Subitem 8"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
OneLineListItem:
|
||||
text: "Subitem 9"
|
||||
theme_text_color: 'Custom'
|
||||
text_color: [1,1,1,1]
|
||||
MDAccordion:
|
||||
orientation:'horizontal'
|
||||
MDAccordionItem:
|
||||
title:'Item 1'
|
||||
icon: 'home'
|
||||
MDLabel:
|
||||
text:'Content 1'
|
||||
theme_text_color:'Primary'
|
||||
MDAccordionItem:
|
||||
title:'Item 2'
|
||||
MDLabel:
|
||||
text:'Content 2'
|
||||
theme_text_color:'Primary'
|
||||
MDAccordionItem:
|
||||
title:'Item 3'
|
||||
MDLabel:
|
||||
text:'Content 3'
|
||||
theme_text_color:'Primary'
|
||||
""")
|
||||
|
||||
|
||||
AccordionApp().run()
|
23
src/kivymd/backgroundcolorbehavior.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import BoundedNumericProperty, ReferenceListProperty
|
||||
from kivy.uix.widget import Widget
|
||||
|
||||
Builder.load_string('''
|
||||
<BackgroundColorBehavior>
|
||||
canvas:
|
||||
Color:
|
||||
rgba: self.background_color
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
''')
|
||||
|
||||
|
||||
class BackgroundColorBehavior(Widget):
|
||||
r = BoundedNumericProperty(1., min=0., max=1.)
|
||||
g = BoundedNumericProperty(1., min=0., max=1.)
|
||||
b = BoundedNumericProperty(1., min=0., max=1.)
|
||||
a = BoundedNumericProperty(0., min=0., max=1.)
|
||||
|
||||
background_color = ReferenceListProperty(r, g, b, a)
|
211
src/kivymd/bottomsheet.py
Normal file
|
@ -0,0 +1,211 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Bottom Sheets
|
||||
=============
|
||||
|
||||
`Material Design spec Bottom Sheets page <http://www.google.com/design/spec/components/bottom-sheets.html>`_
|
||||
|
||||
In this module there's the :class:`MDBottomSheet` class which will let you implement your own Material Design Bottom Sheets, and there are two classes called :class:`MDListBottomSheet` and :class:`MDGridBottomSheet` implementing the ones mentioned in the spec.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
.. note::
|
||||
|
||||
These widgets are designed to be called from Python code only.
|
||||
|
||||
For :class:`MDListBottomSheet`:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
bs = MDListBottomSheet()
|
||||
bs.add_item("Here's an item with text only", lambda x: x)
|
||||
bs.add_item("Here's an item with an icon", lambda x: x, icon='md-cast')
|
||||
bs.add_item("Here's another!", lambda x: x, icon='md-nfc')
|
||||
bs.open()
|
||||
|
||||
For :class:`MDListBottomSheet`:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
bs = MDGridBottomSheet()
|
||||
bs.add_item("Facebook", lambda x: x, icon_src='./assets/facebook-box.png')
|
||||
bs.add_item("YouTube", lambda x: x, icon_src='./assets/youtube-play.png')
|
||||
bs.add_item("Twitter", lambda x: x, icon_src='./assets/twitter.png')
|
||||
bs.add_item("Da Cloud", lambda x: x, icon_src='./assets/cloud-upload.png')
|
||||
bs.add_item("Camera", lambda x: x, icon_src='./assets/camera.png')
|
||||
bs.open()
|
||||
|
||||
API
|
||||
---
|
||||
'''
|
||||
from kivy.clock import Clock
|
||||
from kivy.lang import Builder
|
||||
from kivy.metrics import dp
|
||||
from kivy.properties import ObjectProperty, StringProperty
|
||||
from kivy.uix.behaviors import ButtonBehavior
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.modalview import ModalView
|
||||
from kivy.uix.scrollview import ScrollView
|
||||
from kivymd.backgroundcolorbehavior import BackgroundColorBehavior
|
||||
from kivymd.label import MDLabel
|
||||
from kivymd.list import MDList, OneLineListItem, ILeftBody, \
|
||||
OneLineIconListItem
|
||||
from kivymd.theming import ThemableBehavior
|
||||
|
||||
Builder.load_string('''
|
||||
<MDBottomSheet>
|
||||
background: 'atlas://data/images/defaulttheme/action_group_disabled'
|
||||
background_color: 0,0,0,.8
|
||||
sv: sv
|
||||
upper_padding: upper_padding
|
||||
gl_content: gl_content
|
||||
ScrollView:
|
||||
id: sv
|
||||
do_scroll_x: False
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
orientation: 'vertical'
|
||||
padding: 0,1,0,0
|
||||
height: upper_padding.height + gl_content.height + 1 # +1 to allow overscroll
|
||||
BsPadding:
|
||||
id: upper_padding
|
||||
size_hint_y: None
|
||||
height: root.height - min(root.width * 9 / 16, gl_content.height)
|
||||
on_release: root.dismiss()
|
||||
BottomSheetContent:
|
||||
id: gl_content
|
||||
size_hint_y: None
|
||||
background_color: root.theme_cls.bg_normal
|
||||
cols: 1
|
||||
''')
|
||||
|
||||
|
||||
class BsPadding(ButtonBehavior, FloatLayout):
|
||||
pass
|
||||
|
||||
|
||||
class BottomSheetContent(BackgroundColorBehavior, GridLayout):
|
||||
pass
|
||||
|
||||
|
||||
class MDBottomSheet(ThemableBehavior, ModalView):
|
||||
sv = ObjectProperty()
|
||||
upper_padding = ObjectProperty()
|
||||
gl_content = ObjectProperty()
|
||||
dismiss_zone_scroll = 1000 # Arbitrary high number
|
||||
|
||||
def open(self, *largs):
|
||||
super(MDBottomSheet, self).open(*largs)
|
||||
Clock.schedule_once(self.set_dismiss_zone, 0)
|
||||
|
||||
def set_dismiss_zone(self, *largs):
|
||||
# Scroll to right below overscroll threshold:
|
||||
self.sv.scroll_y = 1 - self.sv.convert_distance_to_scroll(0, 1)[1]
|
||||
|
||||
# This is a line where m (slope) is 1/6 and b (y-intercept) is 80:
|
||||
self.dismiss_zone_scroll = self.sv.convert_distance_to_scroll(
|
||||
0, (self.height - self.upper_padding.height) * (1 / 6.0) + 80)[
|
||||
1]
|
||||
# Uncomment next line if the limit should just be half of
|
||||
# visible content on open (capped by specs to 16 units to width/9:
|
||||
# self.dismiss_zone_scroll = (self.sv.convert_distance_to_scroll(
|
||||
# 0, self.height - self.upper_padding.height)[1] * 0.50)
|
||||
|
||||
# Check if user has overscrolled enough to dismiss bottom sheet:
|
||||
self.sv.bind(on_scroll_stop=self.check_if_scrolled_to_death)
|
||||
|
||||
def check_if_scrolled_to_death(self, *largs):
|
||||
if self.sv.scroll_y >= 1 + self.dismiss_zone_scroll:
|
||||
self.dismiss()
|
||||
|
||||
def add_widget(self, widget, index=0):
|
||||
if type(widget) == ScrollView:
|
||||
super(MDBottomSheet, self).add_widget(widget, index)
|
||||
else:
|
||||
self.gl_content.add_widget(widget,index)
|
||||
|
||||
|
||||
Builder.load_string('''
|
||||
#:import md_icons kivymd.icon_definitions.md_icons
|
||||
<ListBSIconLeft>
|
||||
font_style: 'Icon'
|
||||
text: u"{}".format(md_icons[root.icon])
|
||||
halign: 'center'
|
||||
theme_text_color: 'Primary'
|
||||
valign: 'middle'
|
||||
''')
|
||||
|
||||
|
||||
class ListBSIconLeft(ILeftBody, MDLabel):
|
||||
icon = StringProperty()
|
||||
|
||||
|
||||
class MDListBottomSheet(MDBottomSheet):
|
||||
mlist = ObjectProperty()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(MDListBottomSheet, self).__init__(**kwargs)
|
||||
self.mlist = MDList()
|
||||
self.gl_content.add_widget(self.mlist)
|
||||
Clock.schedule_once(self.resize_content_layout, 0)
|
||||
|
||||
def resize_content_layout(self, *largs):
|
||||
self.gl_content.height = self.mlist.height
|
||||
|
||||
def add_item(self, text, callback, icon=None):
|
||||
if icon:
|
||||
item = OneLineIconListItem(text=text, on_release=callback)
|
||||
item.add_widget(ListBSIconLeft(icon=icon))
|
||||
else:
|
||||
item = OneLineListItem(text=text, on_release=callback)
|
||||
|
||||
item.bind(on_release=lambda x: self.dismiss())
|
||||
self.mlist.add_widget(item)
|
||||
|
||||
|
||||
Builder.load_string('''
|
||||
<GridBSItem>
|
||||
orientation: 'vertical'
|
||||
padding: 0, dp(24), 0, 0
|
||||
size_hint_y: None
|
||||
size: dp(64), dp(96)
|
||||
BoxLayout:
|
||||
padding: dp(8), 0, dp(8), dp(8)
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
Image:
|
||||
source: root.source
|
||||
MDLabel:
|
||||
font_style: 'Caption'
|
||||
theme_text_color: 'Secondary'
|
||||
text: root.caption
|
||||
halign: 'center'
|
||||
''')
|
||||
|
||||
|
||||
class GridBSItem(ButtonBehavior, BoxLayout):
|
||||
source = StringProperty()
|
||||
|
||||
caption = StringProperty()
|
||||
|
||||
|
||||
class MDGridBottomSheet(MDBottomSheet):
|
||||
def __init__(self, **kwargs):
|
||||
super(MDGridBottomSheet, self).__init__(**kwargs)
|
||||
self.gl_content.padding = (dp(16), 0, dp(16), dp(24))
|
||||
self.gl_content.height = dp(24)
|
||||
self.gl_content.cols = 3
|
||||
|
||||
def add_item(self, text, callback, icon_src):
|
||||
item = GridBSItem(
|
||||
caption=text,
|
||||
on_release=callback,
|
||||
source=icon_src
|
||||
)
|
||||
item.bind(on_release=lambda x: self.dismiss())
|
||||
if len(self.gl_content.children) % 3 == 0:
|
||||
self.gl_content.height += dp(96)
|
||||
self.gl_content.add_widget(item)
|
453
src/kivymd/button.py
Normal file
|
@ -0,0 +1,453 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Buttons
|
||||
=======
|
||||
|
||||
`Material Design spec, Buttons page <https://www.google.com/design/spec/components/buttons.html>`_
|
||||
|
||||
`Material Design spec, Buttons: Floating Action Button page <https://www.google.com/design/spec/components/buttons-floating-action-button.html>`_
|
||||
|
||||
TO-DO: DOCUMENT MODULE
|
||||
'''
|
||||
from kivy.clock import Clock
|
||||
from kivy.lang import Builder
|
||||
from kivy.metrics import dp
|
||||
from kivy.utils import get_color_from_hex
|
||||
from kivy.properties import StringProperty, BoundedNumericProperty, \
|
||||
ListProperty, AliasProperty, BooleanProperty, NumericProperty, \
|
||||
OptionProperty
|
||||
from kivy.uix.anchorlayout import AnchorLayout
|
||||
from kivy.uix.behaviors import ButtonBehavior
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.animation import Animation
|
||||
from kivymd.backgroundcolorbehavior import BackgroundColorBehavior
|
||||
from kivymd.ripplebehavior import CircularRippleBehavior, \
|
||||
RectangularRippleBehavior
|
||||
from kivymd.elevationbehavior import ElevationBehavior, \
|
||||
RoundElevationBehavior
|
||||
from kivymd.theming import ThemableBehavior
|
||||
from kivymd.color_definitions import colors
|
||||
|
||||
Builder.load_string('''
|
||||
#:import md_icons kivymd.icon_definitions.md_icons
|
||||
#:import colors kivymd.color_definitions.colors
|
||||
#:import MDLabel kivymd.label.MDLabel
|
||||
<MDIconButton>
|
||||
size_hint: (None, None)
|
||||
size: (dp(48), dp(48))
|
||||
padding: dp(12)
|
||||
theme_text_color: 'Primary'
|
||||
MDLabel:
|
||||
id: _label
|
||||
font_style: 'Icon'
|
||||
text: u"{}".format(md_icons[root.icon])
|
||||
halign: 'center'
|
||||
theme_text_color: root.theme_text_color
|
||||
text_color: root.text_color
|
||||
opposite_colors: root.opposite_colors
|
||||
valign: 'middle'
|
||||
|
||||
<MDFlatButton>
|
||||
canvas:
|
||||
Color:
|
||||
#rgba: self.background_color if self.state == 'normal' else self._bg_color_down
|
||||
rgba: self._current_button_color
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
size_hint: (None, None)
|
||||
height: dp(36)
|
||||
width: _label.texture_size[0] + dp(16)
|
||||
padding: (dp(8), 0)
|
||||
theme_text_color: 'Custom'
|
||||
text_color: root.theme_cls.primary_color
|
||||
MDLabel:
|
||||
id: _label
|
||||
text: root._text
|
||||
font_style: 'Button'
|
||||
size_hint_x: None
|
||||
text_size: (None, root.height)
|
||||
height: self.texture_size[1]
|
||||
theme_text_color: root.theme_text_color
|
||||
text_color: root.text_color
|
||||
valign: 'middle'
|
||||
halign: 'center'
|
||||
opposite_colors: root.opposite_colors
|
||||
|
||||
<MDRaisedButton>:
|
||||
canvas:
|
||||
Clear
|
||||
Color:
|
||||
rgba: self.background_color_disabled if self.disabled else \
|
||||
(self.background_color if self.state == 'normal' else self.background_color_down)
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
||||
anchor_x: 'center'
|
||||
anchor_y: 'center'
|
||||
background_color: root.theme_cls.primary_color
|
||||
background_color_down: root.theme_cls.primary_dark
|
||||
background_color_disabled: root.theme_cls.divider_color
|
||||
theme_text_color: 'Primary'
|
||||
MDLabel:
|
||||
id: label
|
||||
font_style: 'Button'
|
||||
text: root._text
|
||||
size_hint: None, None
|
||||
width: root.width
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
theme_text_color: root.theme_text_color
|
||||
text_color: root.text_color
|
||||
opposite_colors: root.opposite_colors
|
||||
disabled: root.disabled
|
||||
halign: 'center'
|
||||
valign: 'middle'
|
||||
|
||||
<MDFloatingActionButton>:
|
||||
canvas:
|
||||
Clear
|
||||
Color:
|
||||
rgba: self.background_color_disabled if self.disabled else \
|
||||
(self.background_color if self.state == 'normal' else self.background_color_down)
|
||||
Ellipse:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
||||
anchor_x: 'center'
|
||||
anchor_y: 'center'
|
||||
background_color: root.theme_cls.accent_color
|
||||
background_color_down: root.theme_cls.accent_dark
|
||||
background_color_disabled: root.theme_cls.divider_color
|
||||
theme_text_color: 'Primary'
|
||||
MDLabel:
|
||||
id: label
|
||||
font_style: 'Icon'
|
||||
text: u"{}".format(md_icons[root.icon])
|
||||
size_hint: None, None
|
||||
size: dp(24), dp(24)
|
||||
text_size: self.size
|
||||
theme_text_color: root.theme_text_color
|
||||
text_color: root.text_color
|
||||
opposite_colors: root.opposite_colors
|
||||
disabled: root.disabled
|
||||
halign: 'center'
|
||||
valign: 'middle'
|
||||
''')
|
||||
|
||||
|
||||
class MDIconButton(CircularRippleBehavior, ButtonBehavior, BoxLayout):
|
||||
icon = StringProperty('circle')
|
||||
theme_text_color = OptionProperty(None, allownone=True,
|
||||
options=['Primary', 'Secondary', 'Hint',
|
||||
'Error', 'Custom'])
|
||||
text_color = ListProperty(None, allownone=True)
|
||||
opposite_colors = BooleanProperty(False)
|
||||
|
||||
|
||||
class MDFlatButton(ThemableBehavior, RectangularRippleBehavior,
|
||||
ButtonBehavior, BackgroundColorBehavior, AnchorLayout):
|
||||
width = BoundedNumericProperty(dp(64), min=dp(64), max=None,
|
||||
errorhandler=lambda x: dp(64))
|
||||
|
||||
text_color = ListProperty()
|
||||
|
||||
text = StringProperty('')
|
||||
theme_text_color = OptionProperty(None, allownone=True,
|
||||
options=['Primary', 'Secondary', 'Hint',
|
||||
'Error', 'Custom'])
|
||||
text_color = ListProperty(None, allownone=True)
|
||||
|
||||
_text = StringProperty('')
|
||||
_bg_color_down = ListProperty([0, 0, 0, 0])
|
||||
_current_button_color = ListProperty([0, 0, 0, 0])
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(MDFlatButton, self).__init__(**kwargs)
|
||||
self._current_button_color = self.background_color
|
||||
self._bg_color_down = get_color_from_hex(
|
||||
colors[self.theme_cls.theme_style]['FlatButtonDown'])
|
||||
|
||||
Clock.schedule_once(lambda x: self.ids._label.bind(
|
||||
texture_size=self.update_width_on_label_texture))
|
||||
|
||||
def update_width_on_label_texture(self, instance, value):
|
||||
self.ids._label.width = value[0]
|
||||
|
||||
def on_text(self, instance, value):
|
||||
self._text = value.upper()
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
if touch.is_mouse_scrolling:
|
||||
return False
|
||||
elif not self.collide_point(touch.x, touch.y):
|
||||
return False
|
||||
elif self in touch.ud:
|
||||
return False
|
||||
elif self.disabled:
|
||||
return False
|
||||
else:
|
||||
self.fade_bg = Animation(duration=.2, _current_button_color=get_color_from_hex(
|
||||
colors[self.theme_cls.theme_style]['FlatButtonDown']))
|
||||
self.fade_bg.start(self)
|
||||
return super(MDFlatButton, self).on_touch_down(touch)
|
||||
|
||||
def on_touch_up(self, touch):
|
||||
if touch.grab_current is self:
|
||||
self.fade_bg.stop_property(self, '_current_button_color')
|
||||
Animation(duration=.05, _current_button_color=self.background_color).start(self)
|
||||
return super(MDFlatButton, self).on_touch_up(touch)
|
||||
|
||||
|
||||
class MDRaisedButton(ThemableBehavior, RectangularRippleBehavior,
|
||||
ElevationBehavior, ButtonBehavior,
|
||||
AnchorLayout):
|
||||
_bg_color_down = ListProperty([])
|
||||
background_color = ListProperty()
|
||||
background_color_down = ListProperty()
|
||||
background_color_disabled = ListProperty()
|
||||
theme_text_color = OptionProperty(None, allownone=True,
|
||||
options=['Primary', 'Secondary', 'Hint',
|
||||
'Error', 'Custom'])
|
||||
text_color = ListProperty(None, allownone=True)
|
||||
|
||||
def _get_bg_color_down(self):
|
||||
return self._bg_color_down
|
||||
|
||||
def _set_bg_color_down(self, color, alpha=None):
|
||||
if len(color) == 2:
|
||||
self._bg_color_down = get_color_from_hex(
|
||||
colors[color[0]][color[1]])
|
||||
if alpha:
|
||||
self._bg_color_down[3] = alpha
|
||||
elif len(color) == 4:
|
||||
self._bg_color_down = color
|
||||
|
||||
background_color_down = AliasProperty(_get_bg_color_down,
|
||||
_set_bg_color_down,
|
||||
bind=('_bg_color_down',))
|
||||
|
||||
_bg_color_disabled = ListProperty([])
|
||||
|
||||
def _get_bg_color_disabled(self):
|
||||
return self._bg_color_disabled
|
||||
|
||||
def _set_bg_color_disabled(self, color, alpha=None):
|
||||
if len(color) == 2:
|
||||
self._bg_color_disabled = get_color_from_hex(
|
||||
colors[color[0]][color[1]])
|
||||
if alpha:
|
||||
self._bg_color_disabled[3] = alpha
|
||||
elif len(color) == 4:
|
||||
self._bg_color_disabled = color
|
||||
|
||||
background_color_disabled = AliasProperty(_get_bg_color_disabled,
|
||||
_set_bg_color_disabled,
|
||||
bind=('_bg_color_disabled',))
|
||||
|
||||
_elev_norm = NumericProperty(2)
|
||||
|
||||
def _get_elev_norm(self):
|
||||
return self._elev_norm
|
||||
|
||||
def _set_elev_norm(self, value):
|
||||
self._elev_norm = value if value <= 12 else 12
|
||||
self._elev_raised = (value + 6) if value + 6 <= 12 else 12
|
||||
self.elevation = self._elev_norm
|
||||
|
||||
elevation_normal = AliasProperty(_get_elev_norm, _set_elev_norm,
|
||||
bind=('_elev_norm',))
|
||||
|
||||
_elev_raised = NumericProperty(8)
|
||||
|
||||
def _get_elev_raised(self):
|
||||
return self._elev_raised
|
||||
|
||||
def _set_elev_raised(self, value):
|
||||
self._elev_raised = value if value + self._elev_norm <= 12 else 12
|
||||
|
||||
elevation_raised = AliasProperty(_get_elev_raised, _set_elev_raised,
|
||||
bind=('_elev_raised',))
|
||||
|
||||
text = StringProperty()
|
||||
|
||||
_text = StringProperty()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(MDRaisedButton, self).__init__(**kwargs)
|
||||
self.elevation_press_anim = Animation(elevation=self.elevation_raised,
|
||||
duration=.2, t='out_quad')
|
||||
self.elevation_release_anim = Animation(
|
||||
elevation=self.elevation_normal, duration=.2, t='out_quad')
|
||||
|
||||
def on_disabled(self, instance, value):
|
||||
if value:
|
||||
self.elevation = 0
|
||||
else:
|
||||
self.elevation = self.elevation_normal
|
||||
super(MDRaisedButton, self).on_disabled(instance, value)
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
if not self.disabled:
|
||||
if touch.is_mouse_scrolling:
|
||||
return False
|
||||
if not self.collide_point(touch.x, touch.y):
|
||||
return False
|
||||
if self in touch.ud:
|
||||
return False
|
||||
Animation.cancel_all(self, 'elevation')
|
||||
self.elevation_press_anim.start(self)
|
||||
return super(MDRaisedButton, self).on_touch_down(touch)
|
||||
|
||||
def on_touch_up(self, touch):
|
||||
if not self.disabled:
|
||||
if touch.grab_current is not self:
|
||||
return super(ButtonBehavior, self).on_touch_up(touch)
|
||||
Animation.cancel_all(self, 'elevation')
|
||||
self.elevation_release_anim.start(self)
|
||||
else:
|
||||
Animation.cancel_all(self, 'elevation')
|
||||
self.elevation = 0
|
||||
return super(MDRaisedButton, self).on_touch_up(touch)
|
||||
|
||||
def on_text(self, instance, text):
|
||||
self._text = text.upper()
|
||||
|
||||
def on__elev_norm(self, instance, value):
|
||||
self.elevation_release_anim = Animation(elevation=value,
|
||||
duration=.2, t='out_quad')
|
||||
|
||||
def on__elev_raised(self, instance, value):
|
||||
self.elevation_press_anim = Animation(elevation=value,
|
||||
duration=.2, t='out_quad')
|
||||
|
||||
|
||||
class MDFloatingActionButton(ThemableBehavior, CircularRippleBehavior,
|
||||
RoundElevationBehavior, ButtonBehavior,
|
||||
AnchorLayout):
|
||||
_bg_color_down = ListProperty([])
|
||||
background_color = ListProperty()
|
||||
background_color_down = ListProperty()
|
||||
background_color_disabled = ListProperty()
|
||||
theme_text_color = OptionProperty(None, allownone=True,
|
||||
options=['Primary', 'Secondary', 'Hint',
|
||||
'Error', 'Custom'])
|
||||
text_color = ListProperty(None, allownone=True)
|
||||
|
||||
def _get_bg_color_down(self):
|
||||
return self._bg_color_down
|
||||
|
||||
def _set_bg_color_down(self, color, alpha=None):
|
||||
if len(color) == 2:
|
||||
self._bg_color_down = get_color_from_hex(
|
||||
colors[color[0]][color[1]])
|
||||
if alpha:
|
||||
self._bg_color_down[3] = alpha
|
||||
elif len(color) == 4:
|
||||
self._bg_color_down = color
|
||||
|
||||
background_color_down = AliasProperty(_get_bg_color_down,
|
||||
_set_bg_color_down,
|
||||
bind=('_bg_color_down',))
|
||||
|
||||
_bg_color_disabled = ListProperty([])
|
||||
|
||||
def _get_bg_color_disabled(self):
|
||||
return self._bg_color_disabled
|
||||
|
||||
def _set_bg_color_disabled(self, color, alpha=None):
|
||||
if len(color) == 2:
|
||||
self._bg_color_disabled = get_color_from_hex(
|
||||
colors[color[0]][color[1]])
|
||||
if alpha:
|
||||
self._bg_color_disabled[3] = alpha
|
||||
elif len(color) == 4:
|
||||
self._bg_color_disabled = color
|
||||
|
||||
background_color_disabled = AliasProperty(_get_bg_color_disabled,
|
||||
_set_bg_color_disabled,
|
||||
bind=('_bg_color_disabled',))
|
||||
icon = StringProperty('android')
|
||||
|
||||
_elev_norm = NumericProperty(6)
|
||||
|
||||
def _get_elev_norm(self):
|
||||
return self._elev_norm
|
||||
|
||||
def _set_elev_norm(self, value):
|
||||
self._elev_norm = value if value <= 12 else 12
|
||||
self._elev_raised = (value + 6) if value + 6 <= 12 else 12
|
||||
self.elevation = self._elev_norm
|
||||
|
||||
elevation_normal = AliasProperty(_get_elev_norm, _set_elev_norm,
|
||||
bind=('_elev_norm',))
|
||||
|
||||
# _elev_raised = NumericProperty(12)
|
||||
_elev_raised = NumericProperty(6)
|
||||
|
||||
def _get_elev_raised(self):
|
||||
return self._elev_raised
|
||||
|
||||
def _set_elev_raised(self, value):
|
||||
self._elev_raised = value if value + self._elev_norm <= 12 else 12
|
||||
|
||||
elevation_raised = AliasProperty(_get_elev_raised, _set_elev_raised,
|
||||
bind=('_elev_raised',))
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
if self.elevation_raised == 0 and self.elevation_normal + 6 <= 12:
|
||||
self.elevation_raised = self.elevation_normal + 6
|
||||
elif self.elevation_raised == 0:
|
||||
self.elevation_raised = 12
|
||||
|
||||
super(MDFloatingActionButton, self).__init__(**kwargs)
|
||||
|
||||
self.elevation_press_anim = Animation(elevation=self.elevation_raised,
|
||||
duration=.2, t='out_quad')
|
||||
self.elevation_release_anim = Animation(
|
||||
elevation=self.elevation_normal, duration=.2, t='out_quad')
|
||||
|
||||
def _set_ellipse(self, instance, value):
|
||||
ellipse = self.ellipse
|
||||
ripple_rad = self.ripple_rad
|
||||
|
||||
ellipse.size = (ripple_rad, ripple_rad)
|
||||
ellipse.pos = (self.center_x - ripple_rad / 2.,
|
||||
self.center_y - ripple_rad / 2.)
|
||||
|
||||
def on_disabled(self, instance, value):
|
||||
super(MDFloatingActionButton, self).on_disabled(instance, value)
|
||||
if self.disabled:
|
||||
self.elevation = 0
|
||||
else:
|
||||
self.elevation = self.elevation_normal
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
if not self.disabled:
|
||||
if touch.is_mouse_scrolling:
|
||||
return False
|
||||
if not self.collide_point(touch.x, touch.y):
|
||||
return False
|
||||
if self in touch.ud:
|
||||
return False
|
||||
self.elevation_press_anim.stop(self)
|
||||
self.elevation_press_anim.start(self)
|
||||
return super(MDFloatingActionButton, self).on_touch_down(touch)
|
||||
|
||||
def on_touch_up(self, touch):
|
||||
if not self.disabled:
|
||||
if touch.grab_current is not self:
|
||||
return super(ButtonBehavior, self).on_touch_up(touch)
|
||||
self.elevation_release_anim.stop(self)
|
||||
self.elevation_release_anim.start(self)
|
||||
return super(MDFloatingActionButton, self).on_touch_up(touch)
|
||||
|
||||
def on_elevation_normal(self, instance, value):
|
||||
self.elevation = value
|
||||
|
||||
def on_elevation_raised(self, instance, value):
|
||||
if self.elevation_raised == 0 and self.elevation_normal + 6 <= 12:
|
||||
self.elevation_raised = self.elevation_normal + 6
|
||||
elif self.elevation_raised == 0:
|
||||
self.elevation_raised = 12
|
58
src/kivymd/card.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import BoundedNumericProperty, ReferenceListProperty, ListProperty,BooleanProperty
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivymd.elevationbehavior import ElevationBehavior
|
||||
from kivymd.theming import ThemableBehavior
|
||||
from kivy.metrics import dp
|
||||
from kivy.uix.widget import Widget
|
||||
|
||||
Builder.load_string('''
|
||||
<MDCard>
|
||||
canvas:
|
||||
Color:
|
||||
rgba: self.background_color
|
||||
RoundedRectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
radius: [self.border_radius]
|
||||
Color:
|
||||
rgba: self.theme_cls.divider_color
|
||||
a: self.border_color_a
|
||||
Line:
|
||||
rounded_rectangle: (self.pos[0],self.pos[1],self.size[0],self.size[1],self.border_radius)
|
||||
background_color: self.theme_cls.bg_light
|
||||
|
||||
<MDSeparator>
|
||||
canvas:
|
||||
Color:
|
||||
rgba: self.theme_cls.divider_color
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
''')
|
||||
|
||||
|
||||
class MDSeparator(ThemableBehavior, BoxLayout):
|
||||
""" A separator line """
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MDSeparator, self).__init__(*args, **kwargs)
|
||||
self.on_orientation()
|
||||
|
||||
def on_orientation(self,*args):
|
||||
self.size_hint = (1, None) if self.orientation == 'horizontal' else (None, 1)
|
||||
if self.orientation == 'horizontal':
|
||||
self.height = dp(1)
|
||||
else:
|
||||
self.width = dp(1)
|
||||
|
||||
|
||||
class MDCard(ThemableBehavior, ElevationBehavior, BoxLayout):
|
||||
r = BoundedNumericProperty(1., min=0., max=1.)
|
||||
g = BoundedNumericProperty(1., min=0., max=1.)
|
||||
b = BoundedNumericProperty(1., min=0., max=1.)
|
||||
a = BoundedNumericProperty(0., min=0., max=1.)
|
||||
|
||||
border_radius = BoundedNumericProperty(dp(3),min=0)
|
||||
border_color_a = BoundedNumericProperty(0, min=0., max=1.)
|
||||
background_color = ReferenceListProperty(r, g, b, a)
|
360
src/kivymd/color_definitions.py
Normal file
|
@ -0,0 +1,360 @@
|
|||
colors = {
|
||||
'Pink': {
|
||||
'50': 'fce4ec',
|
||||
'100': 'f8bbd0',
|
||||
'200': 'f48fb1',
|
||||
'300': 'f06292',
|
||||
'400': 'ec407a',
|
||||
'500': 'e91e63',
|
||||
'600': 'd81b60',
|
||||
'700': 'C2185B',
|
||||
'800': 'ad1457',
|
||||
'900': '88e4ff',
|
||||
'A100': 'ff80ab',
|
||||
'A400': 'F50057',
|
||||
'A700': 'c51162',
|
||||
'A200': 'ff4081'
|
||||
},
|
||||
|
||||
'Blue': {
|
||||
'200': '90caf9',
|
||||
'900': '0D47A1',
|
||||
'600': '1e88e5',
|
||||
'A100': '82b1ff',
|
||||
'300': '64b5f6',
|
||||
'A400': '2979ff',
|
||||
'700': '1976d2',
|
||||
'50': 'e3f2fd',
|
||||
'A700': '2962ff',
|
||||
'400': '42a5f5',
|
||||
'100': 'bbdefb',
|
||||
'800': '1565c0',
|
||||
'A200': '448aff',
|
||||
'500': '2196f3'
|
||||
},
|
||||
|
||||
'Indigo': {
|
||||
'200': '9fa8da',
|
||||
'900': '1a237e',
|
||||
'600': '3949ab',
|
||||
'A100': '8c9eff',
|
||||
'300': '7986cb',
|
||||
'A400': '3d5afe',
|
||||
'700': '303f9f',
|
||||
'50': 'e8eaf6',
|
||||
'A700': '304ffe',
|
||||
'400': '5c6bc0',
|
||||
'100': 'c5cae9',
|
||||
'800': '283593',
|
||||
'A200': '536dfe',
|
||||
'500': '3f51b5'
|
||||
},
|
||||
|
||||
'BlueGrey': {
|
||||
'200': 'b0bec5',
|
||||
'900': '263238',
|
||||
'600': '546e7a',
|
||||
'300': '90a4ae',
|
||||
'700': '455a64',
|
||||
'50': 'eceff1',
|
||||
'400': '78909c',
|
||||
'100': 'cfd8dc',
|
||||
'800': '37474f',
|
||||
'500': '607d8b'
|
||||
},
|
||||
|
||||
'Brown': {
|
||||
'200': 'bcaaa4',
|
||||
'900': '3e2723',
|
||||
'600': '6d4c41',
|
||||
'300': 'a1887f',
|
||||
'700': '5d4037',
|
||||
'50': 'efebe9',
|
||||
'400': '8d6e63',
|
||||
'100': 'd7ccc8',
|
||||
'800': '4e342e',
|
||||
'500': '795548'
|
||||
},
|
||||
|
||||
'LightBlue': {
|
||||
'200': '81d4fa',
|
||||
'900': '01579B',
|
||||
'600': '039BE5',
|
||||
'A100': '80d8ff',
|
||||
'300': '4fc3f7',
|
||||
'A400': '00B0FF',
|
||||
'700': '0288D1',
|
||||
'50': 'e1f5fe',
|
||||
'A700': '0091EA',
|
||||
'400': '29b6f6',
|
||||
'100': 'b3e5fc',
|
||||
'800': '0277BD',
|
||||
'A200': '40c4ff',
|
||||
'500': '03A9F4'
|
||||
},
|
||||
|
||||
'Purple': {
|
||||
'200': 'ce93d8',
|
||||
'900': '4a148c',
|
||||
'600': '8e24aa',
|
||||
'A100': 'ea80fc',
|
||||
'300': 'ba68c8',
|
||||
'A400': 'D500F9',
|
||||
'700': '7b1fa2',
|
||||
'50': 'f3e5f5',
|
||||
'A700': 'AA00FF',
|
||||
'400': 'ab47bc',
|
||||
'100': 'e1bee7',
|
||||
'800': '6a1b9a',
|
||||
'A200': 'e040fb',
|
||||
'500': '9c27b0'
|
||||
},
|
||||
|
||||
'Grey': {
|
||||
'200': 'eeeeee',
|
||||
'900': '212121',
|
||||
'600': '757575',
|
||||
'300': 'e0e0e0',
|
||||
'700': '616161',
|
||||
'50': 'fafafa',
|
||||
'400': 'bdbdbd',
|
||||
'100': 'f5f5f5',
|
||||
'800': '424242',
|
||||
'500': '9e9e9e'
|
||||
},
|
||||
|
||||
'Yellow': {
|
||||
'200': 'fff59d',
|
||||
'900': 'f57f17',
|
||||
'600': 'fdd835',
|
||||
'A100': 'ffff8d',
|
||||
'300': 'fff176',
|
||||
'A400': 'FFEA00',
|
||||
'700': 'fbc02d',
|
||||
'50': 'fffde7',
|
||||
'A700': 'FFD600',
|
||||
'400': 'ffee58',
|
||||
'100': 'fff9c4',
|
||||
'800': 'f9a825',
|
||||
'A200': 'FFFF00',
|
||||
'500': 'ffeb3b'
|
||||
},
|
||||
|
||||
'LightGreen': {
|
||||
'200': 'c5e1a5',
|
||||
'900': '33691e',
|
||||
'600': '7cb342',
|
||||
'A100': 'ccff90',
|
||||
'300': 'aed581',
|
||||
'A400': '76FF03',
|
||||
'700': '689f38',
|
||||
'50': 'f1f8e9',
|
||||
'A700': '64dd17',
|
||||
'400': '9ccc65',
|
||||
'100': 'dcedc8',
|
||||
'800': '558b2f',
|
||||
'A200': 'b2ff59',
|
||||
'500': '8bc34a'
|
||||
},
|
||||
|
||||
'DeepOrange': {
|
||||
'200': 'ffab91',
|
||||
'900': 'bf36c',
|
||||
'600': 'f4511e',
|
||||
'A100': 'ff9e80',
|
||||
'300': 'ff8a65',
|
||||
'A400': 'FF3D00',
|
||||
'700': 'e64a19',
|
||||
'50': 'fbe9e7',
|
||||
'A700': 'DD2C00',
|
||||
'400': 'ff7043',
|
||||
'100': 'ffccbc',
|
||||
'800': 'd84315',
|
||||
'A200': 'ff6e40',
|
||||
'500': 'ff5722'
|
||||
},
|
||||
|
||||
'Green': {
|
||||
'200': 'a5d6a7',
|
||||
'900': '1b5e20',
|
||||
'600': '43a047',
|
||||
'A100': 'b9f6ca',
|
||||
'300': '81c784',
|
||||
'A400': '00E676',
|
||||
'700': '388e3c',
|
||||
'50': 'e8f5e9',
|
||||
'A700': '00C853',
|
||||
'400': '66bb6a',
|
||||
'100': 'c8e6c9',
|
||||
'800': '2e7d32',
|
||||
'A200': '69f0ae',
|
||||
'500': '4caf50'
|
||||
},
|
||||
|
||||
'Red': {
|
||||
'200': 'ef9a9a',
|
||||
'900': 'b71c1c',
|
||||
'600': 'e53935',
|
||||
'A100': 'ff8a80',
|
||||
'300': 'e57373',
|
||||
'A400': 'ff1744',
|
||||
'700': 'd32f2f',
|
||||
'50': 'ffebee',
|
||||
'A700': 'd50000',
|
||||
'400': 'ef5350',
|
||||
'100': 'ffcdd2',
|
||||
'800': 'c62828',
|
||||
'A200': 'ff5252',
|
||||
'500': 'f44336'
|
||||
},
|
||||
|
||||
'Teal': {
|
||||
'200': '80cbc4',
|
||||
'900': '004D40',
|
||||
'600': '00897B',
|
||||
'A100': 'a7ffeb',
|
||||
'300': '4db6ac',
|
||||
'A400': '1de9b6',
|
||||
'700': '00796B',
|
||||
'50': 'e0f2f1',
|
||||
'A700': '00BFA5',
|
||||
'400': '26a69a',
|
||||
'100': 'b2dfdb',
|
||||
'800': '00695C',
|
||||
'A200': '64ffda',
|
||||
'500': '009688'
|
||||
},
|
||||
|
||||
'Orange': {
|
||||
'200': 'ffcc80',
|
||||
'900': 'E65100',
|
||||
'600': 'FB8C00',
|
||||
'A100': 'ffd180',
|
||||
'300': 'ffb74d',
|
||||
'A400': 'FF9100',
|
||||
'700': 'F57C00',
|
||||
'50': 'fff3e0',
|
||||
'A700': 'FF6D00',
|
||||
'400': 'ffa726',
|
||||
'100': 'ffe0b2',
|
||||
'800': 'EF6C00',
|
||||
'A200': 'ffab40',
|
||||
'500': 'FF9800'
|
||||
},
|
||||
|
||||
'Cyan': {
|
||||
'200': '80deea',
|
||||
'900': '006064',
|
||||
'600': '00ACC1',
|
||||
'A100': '84ffff',
|
||||
'300': '4dd0e1',
|
||||
'A400': '00E5FF',
|
||||
'700': '0097A7',
|
||||
'50': 'e0f7fa',
|
||||
'A700': '00B8D4',
|
||||
'400': '26c6da',
|
||||
'100': 'b2ebf2',
|
||||
'800': '00838F',
|
||||
'A200': '18ffff',
|
||||
'500': '00BCD4'
|
||||
},
|
||||
|
||||
'Amber': {
|
||||
'200': 'ffe082',
|
||||
'900': 'FF6F00',
|
||||
'600': 'FFB300',
|
||||
'A100': 'ffe57f',
|
||||
'300': 'ffd54f',
|
||||
'A400': 'FFC400',
|
||||
'700': 'FFA000',
|
||||
'50': 'fff8e1',
|
||||
'A700': 'FFAB00',
|
||||
'400': 'ffca28',
|
||||
'100': 'ffecb3',
|
||||
'800': 'FF8F00',
|
||||
'A200': 'ffd740',
|
||||
'500': 'FFC107'
|
||||
},
|
||||
|
||||
'DeepPurple': {
|
||||
'200': 'b39ddb',
|
||||
'900': '311b92',
|
||||
'600': '5e35b1',
|
||||
'A100': 'b388ff',
|
||||
'300': '9575cd',
|
||||
'A400': '651fff',
|
||||
'700': '512da8',
|
||||
'50': 'ede7f6',
|
||||
'A700': '6200EA',
|
||||
'400': '7e57c2',
|
||||
'100': 'd1c4e9',
|
||||
'800': '4527a0',
|
||||
'A200': '7c4dff',
|
||||
'500': '673ab7'
|
||||
},
|
||||
|
||||
'Lime': {
|
||||
'200': 'e6ee9c',
|
||||
'900': '827717',
|
||||
'600': 'c0ca33',
|
||||
'A100': 'f4ff81',
|
||||
'300': 'dce775',
|
||||
'A400': 'C6FF00',
|
||||
'700': 'afb42b',
|
||||
'50': 'f9fbe7',
|
||||
'A700': 'AEEA00',
|
||||
'400': 'd4e157',
|
||||
'100': 'f0f4c3',
|
||||
'800': '9e9d24',
|
||||
'A200': 'eeff41',
|
||||
'500': 'cddc39'
|
||||
},
|
||||
|
||||
'Light': {
|
||||
'StatusBar': 'E0E0E0',
|
||||
'AppBar': 'F5F5F5',
|
||||
'Background': 'FAFAFA',
|
||||
'CardsDialogs': 'FFFFFF',
|
||||
'FlatButtonDown': 'cccccc'
|
||||
},
|
||||
|
||||
'Dark': {
|
||||
'StatusBar': '000000',
|
||||
'AppBar': '212121',
|
||||
'Background': '303030',
|
||||
'CardsDialogs': '424242',
|
||||
'FlatButtonDown': '999999'
|
||||
}
|
||||
}
|
||||
|
||||
light_colors = {
|
||||
'Pink': ['50' '100', '200', 'A100'],
|
||||
'Blue': ['50' '100', '200', '300', '400', 'A100'],
|
||||
'Indigo': ['50' '100', '200', 'A100'],
|
||||
'BlueGrey': ['50' '100', '200', '300'],
|
||||
'Brown': ['50' '100', '200'],
|
||||
'LightBlue': ['50' '100', '200', '300', '400', '500', 'A100', 'A200',
|
||||
'A400'],
|
||||
'Purple': ['50' '100', '200', 'A100'],
|
||||
'Grey': ['50' '100', '200', '300', '400', '500'],
|
||||
'Yellow': ['50' '100', '200', '300', '400', '500', '600', '700', '800',
|
||||
'900', 'A100', 'A200', 'A400', 'A700'],
|
||||
'LightGreen': ['50' '100', '200', '300', '400', '500', '600', 'A100',
|
||||
'A200', 'A400', 'A700'],
|
||||
'DeepOrange': ['50' '100', '200', '300', '400', 'A100', 'A200'],
|
||||
'Green': ['50' '100', '200', '300', '400', '500', 'A100', 'A200', 'A400',
|
||||
'A700'],
|
||||
'Red': ['50' '100', '200', '300', 'A100'],
|
||||
'Teal': ['50' '100', '200', '300', '400', 'A100', 'A200', 'A400', 'A700'],
|
||||
'Orange': ['50' '100', '200', '300', '400', '500', '600', '700', 'A100',
|
||||
'A200', 'A400', 'A700'],
|
||||
'Cyan': ['50' '100', '200', '300', '400', '500', '600', 'A100', 'A200',
|
||||
'A400', 'A700'],
|
||||
'Amber': ['50' '100', '200', '300', '400', '500', '600', '700', '800',
|
||||
'900', 'A100', 'A200', 'A400', 'A700'],
|
||||
'DeepPurple': ['50' '100', '200', 'A100'],
|
||||
'Lime': ['50' '100', '200', '300', '400', '500', '600', '700', '800',
|
||||
'A100', 'A200', 'A400', 'A700'],
|
||||
'Dark': [],
|
||||
'Light': ['White', 'MainBackground', 'DialogBackground']
|
||||
}
|
325
src/kivymd/date_picker.py
Normal file
|
@ -0,0 +1,325 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from kivy.lang import Builder
|
||||
from kivy.uix.modalview import ModalView
|
||||
from kivymd.label import MDLabel
|
||||
from kivymd.theming import ThemableBehavior
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivymd.elevationbehavior import ElevationBehavior
|
||||
import calendar
|
||||
from datetime import date
|
||||
import datetime
|
||||
from kivy.properties import StringProperty, NumericProperty, ObjectProperty, \
|
||||
BooleanProperty
|
||||
from kivy.uix.anchorlayout import AnchorLayout
|
||||
from kivy.uix.behaviors import ButtonBehavior
|
||||
from kivymd.ripplebehavior import CircularRippleBehavior
|
||||
from kivy.clock import Clock
|
||||
from kivy.core.window import Window
|
||||
|
||||
Builder.load_string("""
|
||||
#:import calendar calendar
|
||||
<MDDatePicker>
|
||||
cal_layout: cal_layout
|
||||
|
||||
size_hint: (None, None)
|
||||
size: [dp(328), dp(484)] if self.theme_cls.device_orientation == 'portrait'\
|
||||
else [dp(512), dp(304)]
|
||||
pos_hint: {'center_x': .5, 'center_y': .5}
|
||||
canvas:
|
||||
Color:
|
||||
rgb: app.theme_cls.primary_color
|
||||
Rectangle:
|
||||
size: [dp(328), dp(96)] if self.theme_cls.device_orientation == 'portrait'\
|
||||
else [dp(168), dp(304)]
|
||||
pos: [root.pos[0], root.pos[1] + root.height-dp(96)] if self.theme_cls.device_orientation == 'portrait'\
|
||||
else [root.pos[0], root.pos[1] + root.height-dp(304)]
|
||||
Color:
|
||||
rgb: app.theme_cls.bg_normal
|
||||
Rectangle:
|
||||
size: [dp(328), dp(484)-dp(96)] if self.theme_cls.device_orientation == 'portrait'\
|
||||
else [dp(344), dp(304)]
|
||||
pos: [root.pos[0], root.pos[1] + root.height-dp(96)-(dp(484)-dp(96))]\
|
||||
if self.theme_cls.device_orientation == 'portrait' else [root.pos[0]+dp(168), root.pos[1]] #+dp(334)
|
||||
MDLabel:
|
||||
id: label_full_date
|
||||
font_style: 'Display1'
|
||||
text_color: 1, 1, 1, 1
|
||||
theme_text_color: 'Custom'
|
||||
size_hint: (None, None)
|
||||
size: [root.width, dp(30)] if root.theme_cls.device_orientation == 'portrait'\
|
||||
else [dp(168), dp(30)]
|
||||
pos: [root.pos[0]+dp(23), root.pos[1] + root.height - dp(74)] \
|
||||
if root.theme_cls.device_orientation == 'portrait' \
|
||||
else [root.pos[0]+dp(3), root.pos[1] + dp(214)]
|
||||
line_height: 0.84
|
||||
valign: 'middle'
|
||||
text_size: [root.width, None] if root.theme_cls.device_orientation == 'portrait'\
|
||||
else [dp(149), None]
|
||||
bold: True
|
||||
text: root.fmt_lbl_date(root.sel_year, root.sel_month, root.sel_day, root.theme_cls.device_orientation)
|
||||
MDLabel:
|
||||
id: label_year
|
||||
font_style: 'Subhead'
|
||||
text_color: 1, 1, 1, 1
|
||||
theme_text_color: 'Custom'
|
||||
size_hint: (None, None)
|
||||
size: root.width, dp(30)
|
||||
pos: (root.pos[0]+dp(23), root.pos[1]+root.height-dp(40)) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (root.pos[0]+dp(16), root.pos[1]+root.height-dp(41))
|
||||
valign: 'middle'
|
||||
text: str(root.sel_year)
|
||||
GridLayout:
|
||||
id: cal_layout
|
||||
cols: 7
|
||||
size: (dp(44*7), dp(40*7)) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (dp(46*7), dp(32*7))
|
||||
col_default_width: dp(42) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else dp(39)
|
||||
size_hint: (None, None)
|
||||
padding: (dp(2), 0) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (dp(7), 0)
|
||||
spacing: (dp(2), 0) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (dp(7), 0)
|
||||
pos: (root.pos[0]+dp(10), root.pos[1]+dp(60)) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (root.pos[0]+dp(168)+dp(8), root.pos[1]+dp(48))
|
||||
MDLabel:
|
||||
id: label_month_selector
|
||||
font_style: 'Body2'
|
||||
text: calendar.month_name[root.month].capitalize() + ' ' + str(root.year)
|
||||
size_hint: (None, None)
|
||||
size: root.width, dp(30)
|
||||
pos: root.pos
|
||||
theme_text_color: 'Primary'
|
||||
pos_hint: {'center_x': 0.5, 'center_y': 0.75} if self.theme_cls.device_orientation == 'portrait'\
|
||||
else {'center_x': 0.67, 'center_y': 0.915}
|
||||
valign: "middle"
|
||||
halign: "center"
|
||||
MDIconButton:
|
||||
icon: 'chevron-left'
|
||||
theme_text_color: 'Secondary'
|
||||
pos_hint: {'center_x': 0.09, 'center_y': 0.745} if root.theme_cls.device_orientation == 'portrait'\
|
||||
else {'center_x': 0.39, 'center_y': 0.925}
|
||||
on_release: root.change_month('prev')
|
||||
MDIconButton:
|
||||
icon: 'chevron-right'
|
||||
theme_text_color: 'Secondary'
|
||||
pos_hint: {'center_x': 0.92, 'center_y': 0.745} if root.theme_cls.device_orientation == 'portrait'\
|
||||
else {'center_x': 0.94, 'center_y': 0.925}
|
||||
on_release: root.change_month('next')
|
||||
MDFlatButton:
|
||||
pos: root.pos[0]+root.size[0]-dp(72)*2, root.pos[1] + dp(7)
|
||||
text: "Cancel"
|
||||
on_release: root.dismiss()
|
||||
MDFlatButton:
|
||||
pos: root.pos[0]+root.size[0]-dp(72), root.pos[1] + dp(7)
|
||||
text: "OK"
|
||||
on_release: root.ok_click()
|
||||
|
||||
<DayButton>
|
||||
size_hint: None, None
|
||||
size: (dp(40), dp(40)) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (dp(32), dp(32))
|
||||
MDLabel:
|
||||
font_style: 'Caption'
|
||||
theme_text_color: 'Custom' if root.is_today and not root.is_selected else 'Primary'
|
||||
text_color: root.theme_cls.primary_color
|
||||
opposite_colors: root.is_selected if root.owner.sel_month == root.owner.month \
|
||||
and root.owner.sel_year == root.owner.year and str(self.text) == str(root.owner.sel_day) else False
|
||||
size_hint_x: None
|
||||
valign: 'middle'
|
||||
halign: 'center'
|
||||
text: root.text
|
||||
|
||||
<WeekdayLabel>
|
||||
font_style: 'Caption'
|
||||
theme_text_color: 'Secondary'
|
||||
size: (dp(40), dp(40)) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (dp(32), dp(32))
|
||||
size_hint: None, None
|
||||
text_size: self.size
|
||||
valign: 'middle' if root.theme_cls.device_orientation == 'portrait' else 'bottom'
|
||||
halign: 'center'
|
||||
|
||||
<DaySelector>
|
||||
size: (dp(40), dp(40)) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (dp(32), dp(32))
|
||||
size_hint: (None, None)
|
||||
canvas:
|
||||
Color:
|
||||
rgba: self.theme_cls.primary_color if self.shown else [0, 0, 0, 0]
|
||||
Ellipse:
|
||||
size: (dp(40), dp(40)) if root.theme_cls.device_orientation == 'portrait'\
|
||||
else (dp(32), dp(32))
|
||||
pos: self.pos if root.theme_cls.device_orientation == 'portrait'\
|
||||
else [self.pos[0] + dp(3), self.pos[1]]
|
||||
""")
|
||||
|
||||
|
||||
class DaySelector(ThemableBehavior, AnchorLayout):
|
||||
shown = BooleanProperty(False)
|
||||
|
||||
def __init__(self, parent):
|
||||
super(DaySelector, self).__init__()
|
||||
self.parent_class = parent
|
||||
self.parent_class.add_widget(self, index=7)
|
||||
self.selected_widget = None
|
||||
Window.bind(on_resize=self.move_resize)
|
||||
|
||||
def update(self):
|
||||
parent = self.parent_class
|
||||
if parent.sel_month == parent.month and parent.sel_year == parent.year:
|
||||
self.shown = True
|
||||
else:
|
||||
self.shown = False
|
||||
|
||||
def set_widget(self, widget):
|
||||
self.selected_widget = widget
|
||||
self.pos = widget.pos
|
||||
self.move_resize(do_again=True)
|
||||
self.update()
|
||||
|
||||
def move_resize(self, window=None, width=None, height=None, do_again=True):
|
||||
self.pos = self.selected_widget.pos
|
||||
if do_again:
|
||||
Clock.schedule_once(lambda x: self.move_resize(do_again=False), 0.01)
|
||||
|
||||
|
||||
class DayButton(ThemableBehavior, CircularRippleBehavior, ButtonBehavior,
|
||||
AnchorLayout):
|
||||
text = StringProperty()
|
||||
owner = ObjectProperty()
|
||||
is_today = BooleanProperty(False)
|
||||
is_selected = BooleanProperty(False)
|
||||
|
||||
def on_release(self):
|
||||
self.owner.set_selected_widget(self)
|
||||
|
||||
|
||||
class WeekdayLabel(MDLabel):
|
||||
pass
|
||||
|
||||
|
||||
class MDDatePicker(FloatLayout, ThemableBehavior, ElevationBehavior,
|
||||
ModalView):
|
||||
_sel_day_widget = ObjectProperty()
|
||||
cal_list = None
|
||||
cal_layout = ObjectProperty()
|
||||
sel_year = NumericProperty()
|
||||
sel_month = NumericProperty()
|
||||
sel_day = NumericProperty()
|
||||
day = NumericProperty()
|
||||
month = NumericProperty()
|
||||
year = NumericProperty()
|
||||
today = date.today()
|
||||
callback = ObjectProperty()
|
||||
|
||||
class SetDateError(Exception):
|
||||
pass
|
||||
|
||||
def __init__(self, callback, year=None, month=None, day=None,
|
||||
firstweekday=0,
|
||||
**kwargs):
|
||||
self.callback = callback
|
||||
self.cal = calendar.Calendar(firstweekday)
|
||||
self.sel_year = year if year else self.today.year
|
||||
self.sel_month = month if month else self.today.month
|
||||
self.sel_day = day if day else self.today.day
|
||||
self.month = self.sel_month
|
||||
self.year = self.sel_year
|
||||
self.day = self.sel_day
|
||||
super(MDDatePicker, self).__init__(**kwargs)
|
||||
self.selector = DaySelector(parent=self)
|
||||
self.generate_cal_widgets()
|
||||
self.update_cal_matrix(self.sel_year, self.sel_month)
|
||||
self.set_month_day(self.sel_day)
|
||||
self.selector.update()
|
||||
|
||||
def ok_click(self):
|
||||
self.callback(date(self.sel_year, self.sel_month, self.sel_day))
|
||||
self.dismiss()
|
||||
|
||||
def fmt_lbl_date(self, year, month, day, orientation):
|
||||
d = datetime.date(int(year), int(month), int(day))
|
||||
separator = '\n' if orientation == 'landscape' else ' '
|
||||
return d.strftime('%a,').capitalize() + separator + d.strftime(
|
||||
'%b').capitalize() + ' ' + str(day).lstrip('0')
|
||||
|
||||
def set_date(self, year, month, day):
|
||||
try:
|
||||
date(year, month, day)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
if str(e) == "day is out of range for month":
|
||||
raise self.SetDateError(" Day %s day is out of range for month %s" % (day, month))
|
||||
elif str(e) == "month must be in 1..12":
|
||||
raise self.SetDateError("Month must be between 1 and 12, got %s" % month)
|
||||
elif str(e) == "year is out of range":
|
||||
raise self.SetDateError("Year must be between %s and %s, got %s" %
|
||||
(datetime.MINYEAR, datetime.MAXYEAR, year))
|
||||
else:
|
||||
self.sel_year = year
|
||||
self.sel_month = month
|
||||
self.sel_day = day
|
||||
self.month = self.sel_month
|
||||
self.year = self.sel_year
|
||||
self.day = self.sel_day
|
||||
self.update_cal_matrix(self.sel_year, self.sel_month)
|
||||
self.set_month_day(self.sel_day)
|
||||
self.selector.update()
|
||||
|
||||
def set_selected_widget(self, widget):
|
||||
if self._sel_day_widget:
|
||||
self._sel_day_widget.is_selected = False
|
||||
widget.is_selected = True
|
||||
self.sel_month = int(self.month)
|
||||
self.sel_year = int(self.year)
|
||||
self.sel_day = int(widget.text)
|
||||
self._sel_day_widget = widget
|
||||
self.selector.set_widget(widget)
|
||||
|
||||
def set_month_day(self, day):
|
||||
for idx in range(len(self.cal_list)):
|
||||
if str(day) == str(self.cal_list[idx].text):
|
||||
self._sel_day_widget = self.cal_list[idx]
|
||||
self.sel_day = int(self.cal_list[idx].text)
|
||||
if self._sel_day_widget:
|
||||
self._sel_day_widget.is_selected = False
|
||||
self._sel_day_widget = self.cal_list[idx]
|
||||
self.cal_list[idx].is_selected = True
|
||||
self.selector.set_widget(self.cal_list[idx])
|
||||
|
||||
def update_cal_matrix(self, year, month):
|
||||
try:
|
||||
dates = [x for x in self.cal.itermonthdates(year, month)]
|
||||
except ValueError as e:
|
||||
if str(e) == "year is out of range":
|
||||
pass
|
||||
else:
|
||||
self.year = year
|
||||
self.month = month
|
||||
for idx in range(len(self.cal_list)):
|
||||
if idx >= len(dates) or dates[idx].month != month:
|
||||
self.cal_list[idx].disabled = True
|
||||
self.cal_list[idx].text = ''
|
||||
else:
|
||||
self.cal_list[idx].disabled = False
|
||||
self.cal_list[idx].text = str(dates[idx].day)
|
||||
self.cal_list[idx].is_today = dates[idx] == self.today
|
||||
self.selector.update()
|
||||
|
||||
def generate_cal_widgets(self):
|
||||
cal_list = []
|
||||
for i in calendar.day_abbr:
|
||||
self.cal_layout.add_widget(WeekdayLabel(text=i[0].upper()))
|
||||
for i in range(6 * 7): # 6 weeks, 7 days a week
|
||||
db = DayButton(owner=self)
|
||||
cal_list.append(db)
|
||||
self.cal_layout.add_widget(db)
|
||||
self.cal_list = cal_list
|
||||
|
||||
def change_month(self, operation):
|
||||
op = 1 if operation is 'next' else -1
|
||||
sl, sy = self.month, self.year
|
||||
m = 12 if sl + op == 0 else 1 if sl + op == 13 else sl + op
|
||||
y = sy - 1 if sl + op == 0 else sy + 1 if sl + op == 13 else sy
|
||||
self.update_cal_matrix(y, m)
|
176
src/kivymd/dialog.py
Normal file
|
@ -0,0 +1,176 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import StringProperty, ObjectProperty, ListProperty
|
||||
from kivy.metrics import dp
|
||||
from kivy.uix.modalview import ModalView
|
||||
from kivy.animation import Animation
|
||||
from kivymd.theming import ThemableBehavior
|
||||
from kivymd.elevationbehavior import ElevationBehavior
|
||||
from kivymd.button import MDFlatButton
|
||||
|
||||
Builder.load_string('''
|
||||
<MDDialog>:
|
||||
canvas:
|
||||
Color:
|
||||
rgba: self.theme_cls.bg_light
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
||||
_container: container
|
||||
_action_area: action_area
|
||||
elevation: 12
|
||||
GridLayout:
|
||||
cols: 1
|
||||
|
||||
GridLayout:
|
||||
cols: 1
|
||||
padding: dp(24), dp(24), dp(24), 0
|
||||
spacing: dp(20)
|
||||
MDLabel:
|
||||
text: root.title
|
||||
font_style: 'Title'
|
||||
theme_text_color: 'Primary'
|
||||
halign: 'left'
|
||||
valign: 'middle'
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
BoxLayout:
|
||||
id: container
|
||||
|
||||
AnchorLayout:
|
||||
anchor_x: 'right'
|
||||
anchor_y: 'center'
|
||||
size_hint: 1, None
|
||||
height: dp(48)
|
||||
padding: dp(8), dp(8)
|
||||
spacing: dp(4)
|
||||
|
||||
GridLayout:
|
||||
id: action_area
|
||||
rows: 1
|
||||
size_hint: None, None if len(root._action_buttons) > 0 else 1
|
||||
height: dp(36) if len(root._action_buttons) > 0 else 0
|
||||
width: self.minimum_width
|
||||
''')
|
||||
|
||||
|
||||
class MDDialog(ThemableBehavior, ElevationBehavior, ModalView):
|
||||
title = StringProperty('')
|
||||
|
||||
content = ObjectProperty(None)
|
||||
|
||||
background_color = ListProperty([0, 0, 0, .2])
|
||||
|
||||
_container = ObjectProperty()
|
||||
_action_buttons = ListProperty([])
|
||||
_action_area = ObjectProperty()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(MDDialog, self).__init__(**kwargs)
|
||||
self.bind(_action_buttons=self._update_action_buttons,
|
||||
auto_dismiss=lambda *x: setattr(self.shadow, 'on_release',
|
||||
self.shadow.dismiss if self.auto_dismiss else None))
|
||||
|
||||
def add_action_button(self, text, action=None):
|
||||
"""Add an :class:`FlatButton` to the right of the action area.
|
||||
|
||||
:param icon: Unicode character for the icon
|
||||
:type icon: str or None
|
||||
:param action: Function set to trigger when on_release fires
|
||||
:type action: function or None
|
||||
"""
|
||||
button = MDFlatButton(text=text,
|
||||
size_hint=(None, None),
|
||||
height=dp(36))
|
||||
if action:
|
||||
button.bind(on_release=action)
|
||||
button.text_color = self.theme_cls.primary_color
|
||||
button.background_color = self.theme_cls.bg_light
|
||||
self._action_buttons.append(button)
|
||||
|
||||
def add_widget(self, widget):
|
||||
if self._container:
|
||||
if self.content:
|
||||
raise PopupException(
|
||||
'Popup can have only one widget as content')
|
||||
self.content = widget
|
||||
else:
|
||||
super(MDDialog, self).add_widget(widget)
|
||||
|
||||
def open(self, *largs):
|
||||
'''Show the view window from the :attr:`attach_to` widget. If set, it
|
||||
will attach to the nearest window. If the widget is not attached to any
|
||||
window, the view will attach to the global
|
||||
:class:`~kivy.core.window.Window`.
|
||||
'''
|
||||
if self._window is not None:
|
||||
Logger.warning('ModalView: you can only open once.')
|
||||
return self
|
||||
# search window
|
||||
self._window = self._search_window()
|
||||
if not self._window:
|
||||
Logger.warning('ModalView: cannot open view, no window found.')
|
||||
return self
|
||||
self._window.add_widget(self)
|
||||
self._window.bind(on_resize=self._align_center,
|
||||
on_keyboard=self._handle_keyboard)
|
||||
self.center = self._window.center
|
||||
self.bind(size=self._align_center)
|
||||
a = Animation(_anim_alpha=1., d=self._anim_duration)
|
||||
a.bind(on_complete=lambda *x: self.dispatch('on_open'))
|
||||
a.start(self)
|
||||
return self
|
||||
|
||||
def dismiss(self, *largs, **kwargs):
|
||||
'''Close the view if it is open. If you really want to close the
|
||||
view, whatever the on_dismiss event returns, you can use the *force*
|
||||
argument:
|
||||
::
|
||||
|
||||
view = ModalView(...)
|
||||
view.dismiss(force=True)
|
||||
|
||||
When the view is dismissed, it will be faded out before being
|
||||
removed from the parent. If you don't want animation, use::
|
||||
|
||||
view.dismiss(animation=False)
|
||||
|
||||
'''
|
||||
if self._window is None:
|
||||
return self
|
||||
if self.dispatch('on_dismiss') is True:
|
||||
if kwargs.get('force', False) is not True:
|
||||
return self
|
||||
if kwargs.get('animation', True):
|
||||
Animation(_anim_alpha=0., d=self._anim_duration).start(self)
|
||||
else:
|
||||
self._anim_alpha = 0
|
||||
self._real_remove_widget()
|
||||
return self
|
||||
|
||||
def on_content(self, instance, value):
|
||||
if self._container:
|
||||
self._container.clear_widgets()
|
||||
self._container.add_widget(value)
|
||||
|
||||
def on__container(self, instance, value):
|
||||
if value is None or self.content is None:
|
||||
return
|
||||
self._container.clear_widgets()
|
||||
self._container.add_widget(self.content)
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
if self.disabled and self.collide_point(*touch.pos):
|
||||
return True
|
||||
return super(MDDialog, self).on_touch_down(touch)
|
||||
|
||||
def _update_action_buttons(self, *args):
|
||||
self._action_area.clear_widgets()
|
||||
for btn in self._action_buttons:
|
||||
btn.ids._label.texture_update()
|
||||
btn.width = btn.ids._label.texture_size[0] + dp(16)
|
||||
self._action_area.add_widget(btn)
|
187
src/kivymd/elevationbehavior.py
Normal file
|
@ -0,0 +1,187 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from kivy.app import App
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import (ListProperty, ObjectProperty, NumericProperty)
|
||||
from kivy.properties import AliasProperty
|
||||
from kivy.metrics import dp
|
||||
|
||||
Builder.load_string('''
|
||||
<ElevationBehavior>
|
||||
canvas.before:
|
||||
Color:
|
||||
a: self._soft_shadow_a
|
||||
Rectangle:
|
||||
texture: self._soft_shadow_texture
|
||||
size: self._soft_shadow_size
|
||||
pos: self._soft_shadow_pos
|
||||
Color:
|
||||
a: self._hard_shadow_a
|
||||
Rectangle:
|
||||
texture: self._hard_shadow_texture
|
||||
size: self._hard_shadow_size
|
||||
pos: self._hard_shadow_pos
|
||||
Color:
|
||||
a: 1
|
||||
|
||||
<RoundElevationBehavior>
|
||||
canvas.before:
|
||||
Color:
|
||||
a: self._soft_shadow_a
|
||||
Rectangle:
|
||||
texture: self._soft_shadow_texture
|
||||
size: self._soft_shadow_size
|
||||
pos: self._soft_shadow_pos
|
||||
Color:
|
||||
a: self._hard_shadow_a
|
||||
Rectangle:
|
||||
texture: self._hard_shadow_texture
|
||||
size: self._hard_shadow_size
|
||||
pos: self._hard_shadow_pos
|
||||
Color:
|
||||
a: 1
|
||||
''')
|
||||
|
||||
|
||||
class ElevationBehavior(object):
|
||||
_elevation = NumericProperty(1)
|
||||
|
||||
def _get_elevation(self):
|
||||
return self._elevation
|
||||
|
||||
def _set_elevation(self, elevation):
|
||||
try:
|
||||
self._elevation = elevation
|
||||
except:
|
||||
self._elevation = 1
|
||||
|
||||
elevation = AliasProperty(_get_elevation, _set_elevation,
|
||||
bind=('_elevation',))
|
||||
|
||||
_soft_shadow_texture = ObjectProperty()
|
||||
_soft_shadow_size = ListProperty([0, 0])
|
||||
_soft_shadow_pos = ListProperty([0, 0])
|
||||
_soft_shadow_a = NumericProperty(0)
|
||||
_hard_shadow_texture = ObjectProperty()
|
||||
_hard_shadow_size = ListProperty([0, 0])
|
||||
_hard_shadow_pos = ListProperty([0, 0])
|
||||
_hard_shadow_a = NumericProperty(0)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(ElevationBehavior, self).__init__(**kwargs)
|
||||
self.bind(elevation=self._update_shadow,
|
||||
pos=self._update_shadow,
|
||||
size=self._update_shadow)
|
||||
|
||||
def _update_shadow(self, *args):
|
||||
if self.elevation > 0:
|
||||
ratio = self.width / (self.height if self.height != 0 else 1)
|
||||
if ratio > -2 and ratio < 2:
|
||||
self._shadow = App.get_running_app().theme_cls.quad_shadow
|
||||
width = soft_width = self.width * 1.9
|
||||
height = soft_height = self.height * 1.9
|
||||
elif ratio <= -2:
|
||||
self._shadow = App.get_running_app().theme_cls.rec_st_shadow
|
||||
ratio = abs(ratio)
|
||||
if ratio > 5:
|
||||
ratio = ratio * 22
|
||||
else:
|
||||
ratio = ratio * 11.5
|
||||
|
||||
width = soft_width = self.width * 1.9
|
||||
height = self.height + dp(ratio)
|
||||
soft_height = self.height + dp(ratio) + dp(self.elevation) * .5
|
||||
else:
|
||||
self._shadow = App.get_running_app().theme_cls.quad_shadow
|
||||
width = soft_width = self.width * 1.8
|
||||
height = soft_height = self.height * 1.8
|
||||
# self._shadow = App.get_running_app().theme_cls.rec_shadow
|
||||
# ratio = abs(ratio)
|
||||
# if ratio > 5:
|
||||
# ratio = ratio * 22
|
||||
# else:
|
||||
# ratio = ratio * 11.5
|
||||
#
|
||||
# width = self.width + dp(ratio)
|
||||
# soft_width = self.width + dp(ratio) + dp(self.elevation) * .9
|
||||
# height = soft_height = self.height * 1.9
|
||||
|
||||
x = self.center_x - width / 2
|
||||
soft_x = self.center_x - soft_width / 2
|
||||
self._soft_shadow_size = (soft_width, soft_height)
|
||||
self._hard_shadow_size = (width, height)
|
||||
|
||||
y = self.center_y - soft_height / 2 - dp(
|
||||
.1 * 1.5 ** self.elevation)
|
||||
self._soft_shadow_pos = (soft_x, y)
|
||||
self._soft_shadow_a = 0.1 * 1.1 ** self.elevation
|
||||
self._soft_shadow_texture = self._shadow.textures[
|
||||
str(int(round(self.elevation - 1)))]
|
||||
|
||||
y = self.center_y - height / 2 - dp(.5 * 1.18 ** self.elevation)
|
||||
self._hard_shadow_pos = (x, y)
|
||||
self._hard_shadow_a = .4 * .9 ** self.elevation
|
||||
self._hard_shadow_texture = self._shadow.textures[
|
||||
str(int(round(self.elevation)))]
|
||||
|
||||
else:
|
||||
self._soft_shadow_a = 0
|
||||
self._hard_shadow_a = 0
|
||||
|
||||
|
||||
class RoundElevationBehavior(object):
|
||||
_elevation = NumericProperty(1)
|
||||
|
||||
def _get_elevation(self):
|
||||
return self._elevation
|
||||
|
||||
def _set_elevation(self, elevation):
|
||||
try:
|
||||
self._elevation = elevation
|
||||
except:
|
||||
self._elevation = 1
|
||||
|
||||
elevation = AliasProperty(_get_elevation, _set_elevation,
|
||||
bind=('_elevation',))
|
||||
|
||||
_soft_shadow_texture = ObjectProperty()
|
||||
_soft_shadow_size = ListProperty([0, 0])
|
||||
_soft_shadow_pos = ListProperty([0, 0])
|
||||
_soft_shadow_a = NumericProperty(0)
|
||||
_hard_shadow_texture = ObjectProperty()
|
||||
_hard_shadow_size = ListProperty([0, 0])
|
||||
_hard_shadow_pos = ListProperty([0, 0])
|
||||
_hard_shadow_a = NumericProperty(0)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(RoundElevationBehavior, self).__init__(**kwargs)
|
||||
self._shadow = App.get_running_app().theme_cls.round_shadow
|
||||
self.bind(elevation=self._update_shadow,
|
||||
pos=self._update_shadow,
|
||||
size=self._update_shadow)
|
||||
|
||||
def _update_shadow(self, *args):
|
||||
if self.elevation > 0:
|
||||
width = self.width * 2
|
||||
height = self.height * 2
|
||||
|
||||
x = self.center_x - width / 2
|
||||
self._soft_shadow_size = (width, height)
|
||||
|
||||
self._hard_shadow_size = (width, height)
|
||||
|
||||
y = self.center_y - height / 2 - dp(.1 * 1.5 ** self.elevation)
|
||||
self._soft_shadow_pos = (x, y)
|
||||
self._soft_shadow_a = 0.1 * 1.1 ** self.elevation
|
||||
self._soft_shadow_texture = self._shadow.textures[
|
||||
str(int(round(self.elevation)))]
|
||||
|
||||
y = self.center_y - height / 2 - dp(.5 * 1.18 ** self.elevation)
|
||||
self._hard_shadow_pos = (x, y)
|
||||
self._hard_shadow_a = .4 * .9 ** self.elevation
|
||||
self._hard_shadow_texture = self._shadow.textures[
|
||||
str(int(round(self.elevation - 1)))]
|
||||
|
||||
else:
|
||||
self._soft_shadow_a = 0
|
||||
self._hard_shadow_a = 0
|
BIN
src/kivymd/fonts/Material-Design-Iconic-Font.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-Bold.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-Italic.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-Light.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-LightItalic.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-Medium.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-MediumItalic.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-Regular.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-Thin.ttf
Normal file
BIN
src/kivymd/fonts/Roboto-ThinItalic.ttf
Normal file
168
src/kivymd/grid.py
Normal file
|
@ -0,0 +1,168 @@
|
|||
# coding=utf-8
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import StringProperty, BooleanProperty, ObjectProperty, \
|
||||
NumericProperty, ListProperty, OptionProperty
|
||||
from kivy.uix.behaviors import ButtonBehavior
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivymd.ripplebehavior import RectangularRippleBehavior
|
||||
from kivymd.theming import ThemableBehavior
|
||||
|
||||
Builder.load_string("""
|
||||
<SmartTile>
|
||||
_img_widget: img
|
||||
_img_overlay: img_overlay
|
||||
_box_overlay: box
|
||||
AsyncImage:
|
||||
id: img
|
||||
allow_stretch: root.allow_stretch
|
||||
anim_delay: root.anim_delay
|
||||
anim_loop: root.anim_loop
|
||||
color: root.img_color
|
||||
keep_ratio: root.keep_ratio
|
||||
mipmap: root.mipmap
|
||||
source: root.source
|
||||
size_hint_y: 1 if root.overlap else None
|
||||
x: root.x
|
||||
y: root.y if root.overlap or root.box_position == 'header' else box.top
|
||||
BoxLayout:
|
||||
id: img_overlay
|
||||
size_hint: img.size_hint
|
||||
size: img.size
|
||||
pos: img.pos
|
||||
BoxLayout:
|
||||
canvas:
|
||||
Color:
|
||||
rgba: root.box_color
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
id: box
|
||||
size_hint_y: None
|
||||
height: dp(68) if root.lines == 2 else dp(48)
|
||||
x: root.x
|
||||
y: root.y if root.box_position == 'footer' else root.y + root.height - self.height
|
||||
|
||||
<SmartTileWithLabel>
|
||||
_img_widget: img
|
||||
_img_overlay: img_overlay
|
||||
_box_overlay: box
|
||||
_box_label: boxlabel
|
||||
AsyncImage:
|
||||
id: img
|
||||
allow_stretch: root.allow_stretch
|
||||
anim_delay: root.anim_delay
|
||||
anim_loop: root.anim_loop
|
||||
color: root.img_color
|
||||
keep_ratio: root.keep_ratio
|
||||
mipmap: root.mipmap
|
||||
source: root.source
|
||||
size_hint_y: 1 if root.overlap else None
|
||||
x: root.x
|
||||
y: root.y if root.overlap or root.box_position == 'header' else box.top
|
||||
BoxLayout:
|
||||
id: img_overlay
|
||||
size_hint: img.size_hint
|
||||
size: img.size
|
||||
pos: img.pos
|
||||
BoxLayout:
|
||||
canvas:
|
||||
Color:
|
||||
rgba: root.box_color
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
id: box
|
||||
size_hint_y: None
|
||||
height: dp(68) if root.lines == 2 else dp(48)
|
||||
x: root.x
|
||||
y: root.y if root.box_position == 'footer' else root.y + root.height - self.height
|
||||
MDLabel:
|
||||
id: boxlabel
|
||||
font_style: "Caption"
|
||||
halign: "center"
|
||||
text: root.text
|
||||
""")
|
||||
|
||||
|
||||
class Tile(ThemableBehavior, RectangularRippleBehavior, ButtonBehavior,
|
||||
BoxLayout):
|
||||
"""A simple tile. It does nothing special, just inherits the right behaviors
|
||||
to work as a building block.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class SmartTile(ThemableBehavior, RectangularRippleBehavior, ButtonBehavior,
|
||||
FloatLayout):
|
||||
"""A tile for more complex needs.
|
||||
|
||||
Includes an image, a container to place overlays and a box that can act
|
||||
as a header or a footer, as described in the Material Design specs.
|
||||
"""
|
||||
|
||||
box_color = ListProperty([0, 0, 0, 0.5])
|
||||
"""Sets the color and opacity for the information box."""
|
||||
|
||||
box_position = OptionProperty('footer', options=['footer', 'header'])
|
||||
"""Determines wether the information box acts as a header or footer to the
|
||||
image.
|
||||
"""
|
||||
|
||||
lines = OptionProperty(1, options=[1, 2])
|
||||
"""Number of lines in the header/footer.
|
||||
|
||||
As per Material Design specs, only 1 and 2 are valid values.
|
||||
"""
|
||||
|
||||
overlap = BooleanProperty(True)
|
||||
"""Determines if the header/footer overlaps on top of the image or not"""
|
||||
|
||||
# Img properties
|
||||
allow_stretch = BooleanProperty(True)
|
||||
anim_delay = NumericProperty(0.25)
|
||||
anim_loop = NumericProperty(0)
|
||||
img_color = ListProperty([1, 1, 1, 1])
|
||||
keep_ratio = BooleanProperty(False)
|
||||
mipmap = BooleanProperty(False)
|
||||
source = StringProperty()
|
||||
|
||||
_img_widget = ObjectProperty()
|
||||
_img_overlay = ObjectProperty()
|
||||
_box_overlay = ObjectProperty()
|
||||
_box_label = ObjectProperty()
|
||||
|
||||
def reload(self):
|
||||
self._img_widget.reload()
|
||||
|
||||
def add_widget(self, widget, index=0):
|
||||
if issubclass(widget.__class__, IOverlay):
|
||||
self._img_overlay.add_widget(widget, index)
|
||||
elif issubclass(widget.__class__, IBoxOverlay):
|
||||
self._box_overlay.add_widget(widget, index)
|
||||
else:
|
||||
super(SmartTile, self).add_widget(widget, index)
|
||||
|
||||
|
||||
class SmartTileWithLabel(SmartTile):
|
||||
_box_label = ObjectProperty()
|
||||
|
||||
# MDLabel properties
|
||||
font_style = StringProperty("Caption")
|
||||
theme_text_color = StringProperty("")
|
||||
text = StringProperty("")
|
||||
"""Determines the text for the box footer/header"""
|
||||
|
||||
|
||||
class IBoxOverlay():
|
||||
"""An interface to specify widgets that belong to to the image overlay
|
||||
in the :class:`SmartTile` widget when added as a child.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class IOverlay():
|
||||
"""An interface to specify widgets that belong to to the image overlay
|
||||
in the :class:`SmartTile` widget when added as a child.
|
||||
"""
|
||||
pass
|
1569
src/kivymd/icon_definitions.py
Normal file
|
@ -0,0 +1,1569 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Thanks to Sergey Kupletsky (github.com/zavoloklom) for its Material Design
|
||||
# Iconic Font, which provides KivyMD's icons.
|
||||
|
||||
# GALLERY HERE:
|
||||
# https://zavoloklom.github.io/material-design-iconic-font/icons.html
|
||||
|
||||
# LAST UPDATED: version 2.2.0 of Material Design Iconic Font
|
||||
|
||||
md_icons = {
|
||||
'3d-rotation': u'',
|
||||
|
||||
'airplane-off': u'',
|
||||
|
||||
'address': u'',
|
||||
|
||||
'airplane': u'',
|
||||
|
||||
'album': u'',
|
||||
|
||||
'archive': u'',
|
||||
|
||||
'assignment-account': u'',
|
||||
|
||||
'assignment-alert': u'',
|
||||
|
||||
'assignment-check': u'',
|
||||
|
||||
'assignment-o': u'',
|
||||
|
||||
'assignment-return': u'',
|
||||
|
||||
'assignment-returned': u'',
|
||||
|
||||
'assignment': u'',
|
||||
|
||||
'attachment-alt': u'',
|
||||
|
||||
'attachment': u'',
|
||||
|
||||
'audio': u'',
|
||||
|
||||
'badge-check': u'',
|
||||
|
||||
'balance-wallet': u'',
|
||||
|
||||
'balance': u'',
|
||||
|
||||
'battery-alert': u'',
|
||||
|
||||
'battery-flash': u'',
|
||||
|
||||
'battery-unknown': u'',
|
||||
|
||||
'battery': u'',
|
||||
|
||||
'bike': u'',
|
||||
|
||||
'block-alt': u'',
|
||||
|
||||
'block': u'',
|
||||
|
||||
'boat': u'',
|
||||
|
||||
'book-image': u'',
|
||||
|
||||
'book': u'',
|
||||
|
||||
'bookmark-outline': u'',
|
||||
|
||||
'bookmark': u'',
|
||||
|
||||
'brush': u'',
|
||||
|
||||
'bug': u'',
|
||||
|
||||
'bus': u'',
|
||||
|
||||
'cake': u'',
|
||||
|
||||
'car-taxi': u'',
|
||||
|
||||
'car-wash': u'',
|
||||
|
||||
'car': u'',
|
||||
|
||||
'card-giftcard': u'',
|
||||
|
||||
'card-membership': u'',
|
||||
|
||||
'card-travel': u'',
|
||||
|
||||
'card': u'',
|
||||
|
||||
'case-check': u'',
|
||||
|
||||
'case-download': u'',
|
||||
|
||||
'case-play': u'',
|
||||
|
||||
'case': u'',
|
||||
|
||||
'cast-connected': u'',
|
||||
|
||||
'cast': u'',
|
||||
|
||||
'chart-donut': u'',
|
||||
|
||||
'chart': u'',
|
||||
|
||||
'city-alt': u'',
|
||||
|
||||
'city': u'',
|
||||
|
||||
'close-circle-o': u'',
|
||||
|
||||
'close-circle': u'',
|
||||
|
||||
'close': u'',
|
||||
|
||||
'cocktail': u'',
|
||||
|
||||
'code-setting': u'',
|
||||
|
||||
'code-smartphone': u'',
|
||||
|
||||
'code': u'',
|
||||
|
||||
'coffee': u'',
|
||||
|
||||
'collection-bookmark': u'',
|
||||
|
||||
'collection-case-play': u'',
|
||||
|
||||
'collection-folder-image': u'',
|
||||
|
||||
'collection-image-o': u'',
|
||||
|
||||
'collection-image': u'',
|
||||
|
||||
'collection-item-1': u'',
|
||||
|
||||
'collection-item-2': u'',
|
||||
|
||||
'collection-item-3': u'',
|
||||
|
||||
'collection-item-4': u'',
|
||||
|
||||
'collection-item-5': u'',
|
||||
|
||||
'collection-item-6': u'',
|
||||
|
||||
'collection-item-7': u'',
|
||||
|
||||
'collection-item-8': u'',
|
||||
|
||||
'collection-item-9-plus': u'',
|
||||
|
||||
'collection-item-9': u'',
|
||||
|
||||
'collection-item': u'',
|
||||
|
||||
'collection-music': u'',
|
||||
|
||||
'collection-pdf': u'',
|
||||
|
||||
'collection-plus': u'',
|
||||
|
||||
'collection-speaker': u'',
|
||||
|
||||
'collection-text': u'',
|
||||
|
||||
'collection-video': u'',
|
||||
|
||||
'compass': u'',
|
||||
|
||||
'cutlery': u'',
|
||||
|
||||
'delete': u'',
|
||||
|
||||
'dialpad': u'',
|
||||
|
||||
'dns': u'',
|
||||
|
||||
'drink': u'',
|
||||
|
||||
'edit': u'',
|
||||
|
||||
'email-open': u'',
|
||||
|
||||
'email': u'',
|
||||
|
||||
'eye-off': u'',
|
||||
|
||||
'eye': u'',
|
||||
|
||||
'eyedropper': u'',
|
||||
|
||||
'favorite-outline': u'',
|
||||
|
||||
'favorite': u'',
|
||||
|
||||
'filter-list': u'',
|
||||
|
||||
'fire': u'',
|
||||
|
||||
'flag': u'',
|
||||
|
||||
'flare': u'',
|
||||
|
||||
'flash-auto': u'',
|
||||
|
||||
'flash-off': u'',
|
||||
|
||||
'flash': u'',
|
||||
|
||||
'flip': u'',
|
||||
|
||||
'flower-alt': u'',
|
||||
|
||||
'flower': u'',
|
||||
|
||||
'font': u'',
|
||||
|
||||
'fullscreen-alt': u'',
|
||||
|
||||
'fullscreen-exit': u'',
|
||||
|
||||
'fullscreen': u'',
|
||||
|
||||
'functions': u'',
|
||||
|
||||
'gas-station': u'',
|
||||
|
||||
'gesture': u'',
|
||||
|
||||
'globe-alt': u'',
|
||||
|
||||
'globe-lock': u'',
|
||||
|
||||
'globe': u'',
|
||||
|
||||
'graduation-cap': u'',
|
||||
|
||||
'group': u'',
|
||||
|
||||
'home': u'',
|
||||
|
||||
'hospital-alt': u'',
|
||||
|
||||
'hospital': u'',
|
||||
|
||||
'hotel': u'',
|
||||
|
||||
'hourglass-alt': u'',
|
||||
|
||||
'hourglass-outline': u'',
|
||||
|
||||
'hourglass': u'',
|
||||
|
||||
'http': u'',
|
||||
|
||||
'image-alt': u'',
|
||||
|
||||
'image-o': u'',
|
||||
|
||||
'image': u'',
|
||||
|
||||
'inbox': u'',
|
||||
|
||||
'invert-colors-off': u'',
|
||||
|
||||
'invert-colors': u'',
|
||||
|
||||
'key': u'',
|
||||
|
||||
'label-alt-outline': u'',
|
||||
|
||||
'label-alt': u'',
|
||||
|
||||
'label-heart': u'',
|
||||
|
||||
'label': u'',
|
||||
|
||||
'labels': u'',
|
||||
|
||||
'lamp': u'',
|
||||
|
||||
'landscape': u'',
|
||||
|
||||
'layers-off': u'',
|
||||
|
||||
'layers': u'',
|
||||
|
||||
'library': u'',
|
||||
|
||||
'link': u'',
|
||||
|
||||
'lock-open': u'',
|
||||
|
||||
'lock-outline': u'',
|
||||
|
||||
'lock': u'',
|
||||
|
||||
'mail-reply-all': u'',
|
||||
|
||||
'mail-reply': u'',
|
||||
|
||||
'mail-send': u'',
|
||||
|
||||
'mall': u'',
|
||||
|
||||
'map': u'',
|
||||
|
||||
'menu': u'',
|
||||
|
||||
'money-box': u'',
|
||||
|
||||
'money-off': u'',
|
||||
|
||||
'money': u'',
|
||||
|
||||
'more-vert': u'',
|
||||
|
||||
'more': u'',
|
||||
|
||||
'movie-alt': u'',
|
||||
|
||||
'movie': u'',
|
||||
|
||||
'nature-people': u'',
|
||||
|
||||
'nature': u'',
|
||||
|
||||
'navigation': u'',
|
||||
|
||||
'open-in-browser': u'',
|
||||
|
||||
'open-in-new': u'',
|
||||
|
||||
'palette': u'',
|
||||
|
||||
'parking': u'',
|
||||
|
||||
'pin-account': u'',
|
||||
|
||||
'pin-assistant': u'',
|
||||
|
||||
'pin-drop': u'',
|
||||
|
||||
'pin-help': u'',
|
||||
|
||||
'pin-off': u'',
|
||||
|
||||
'pin': u'',
|
||||
|
||||
'pizza': u'',
|
||||
|
||||
'plaster': u'',
|
||||
|
||||
'power-setting': u'',
|
||||
|
||||
'power': u'',
|
||||
|
||||
'print': u'',
|
||||
|
||||
'puzzle-piece': u'',
|
||||
|
||||
'quote': u'',
|
||||
|
||||
'railway': u'',
|
||||
|
||||
'receipt': u'',
|
||||
|
||||
'refresh-alt': u'',
|
||||
|
||||
'refresh-sync-alert': u'',
|
||||
|
||||
'refresh-sync-off': u'',
|
||||
|
||||
'refresh-sync': u'',
|
||||
|
||||
'refresh': u'',
|
||||
|
||||
'roller': u'',
|
||||
|
||||
'ruler': u'',
|
||||
|
||||
'scissors': u'',
|
||||
|
||||
'screen-rotation-lock': u'',
|
||||
|
||||
'screen-rotation': u'',
|
||||
|
||||
'search-for': u'',
|
||||
|
||||
'search-in-file': u'',
|
||||
|
||||
'search-in-page': u'',
|
||||
|
||||
'search-replace': u'',
|
||||
|
||||
'search': u'',
|
||||
|
||||
'seat': u'',
|
||||
|
||||
'settings-square': u'',
|
||||
|
||||
'settings': u'',
|
||||
|
||||
'shape': u'',
|
||||
|
||||
'shield-check': u'',
|
||||
|
||||
'shield-security': u'',
|
||||
|
||||
'shopping-basket': u'',
|
||||
|
||||
'shopping-cart-plus': u'',
|
||||
|
||||
'shopping-cart': u'',
|
||||
|
||||
'sign-in': u'',
|
||||
|
||||
'sort-amount-asc': u'',
|
||||
|
||||
'sort-amount-desc': u'',
|
||||
|
||||
'sort-asc': u'',
|
||||
|
||||
'sort-desc': u'',
|
||||
|
||||
'spellcheck': u'',
|
||||
|
||||
'spinner': u'',
|
||||
|
||||
'storage': u'',
|
||||
|
||||
'store-24': u'',
|
||||
|
||||
'store': u'',
|
||||
|
||||
'subway': u'',
|
||||
|
||||
'sun': u'',
|
||||
|
||||
'tab-unselected': u'',
|
||||
|
||||
'tab': u'',
|
||||
|
||||
'tag-close': u'',
|
||||
|
||||
'tag-more': u'',
|
||||
|
||||
'tag': u'',
|
||||
|
||||
'thumb-down': u'',
|
||||
|
||||
'thumb-up-down': u'',
|
||||
|
||||
'thumb-up': u'',
|
||||
|
||||
'ticket-star': u'',
|
||||
|
||||
'toll': u'',
|
||||
|
||||
'toys': u'',
|
||||
|
||||
'traffic': u'',
|
||||
|
||||
'translate': u'',
|
||||
|
||||
'triangle-down': u'',
|
||||
|
||||
'triangle-up': u'',
|
||||
|
||||
'truck': u'',
|
||||
|
||||
'turning-sign': u'',
|
||||
|
||||
' ungroup': u'',
|
||||
|
||||
'wallpaper': u'',
|
||||
|
||||
'washing-machine': u'',
|
||||
|
||||
'window-maximize': u'',
|
||||
|
||||
'window-minimize': u'',
|
||||
|
||||
'window-restore': u'',
|
||||
|
||||
'wrench': u'',
|
||||
|
||||
'zoom-in': u'',
|
||||
|
||||
'zoom-out': u'',
|
||||
|
||||
'alert-circle-o': u'',
|
||||
|
||||
'alert-circle': u'',
|
||||
|
||||
'alert-octagon': u'',
|
||||
|
||||
'alert-polygon': u'',
|
||||
|
||||
'alert-triangle': u'',
|
||||
|
||||
'help-outline': u'',
|
||||
|
||||
'help': u'',
|
||||
|
||||
'info-outline': u'',
|
||||
|
||||
'info': u'',
|
||||
|
||||
'notifications-active': u'',
|
||||
|
||||
'notifications-add': u'',
|
||||
|
||||
'notifications-none': u'',
|
||||
|
||||
'notifications-off': u'',
|
||||
|
||||
'notifications-paused': u'',
|
||||
|
||||
'notifications': u'',
|
||||
|
||||
'account-add': u'',
|
||||
|
||||
'account-box-mail': u'',
|
||||
|
||||
'account-box-o': u'',
|
||||
|
||||
'account-box-phone': u'',
|
||||
|
||||
'account-box': u'',
|
||||
|
||||
'account-calendar': u'',
|
||||
|
||||
'account-circle': u'',
|
||||
|
||||
'account-o': u'',
|
||||
|
||||
'account': u'',
|
||||
|
||||
'accounts-add': u'',
|
||||
|
||||
'accounts-alt': u'',
|
||||
|
||||
'accounts-list-alt': u'',
|
||||
|
||||
'accounts-list': u'',
|
||||
|
||||
'accounts-outline': u'',
|
||||
|
||||
'accounts': u'',
|
||||
|
||||
'face': u'',
|
||||
|
||||
'female': u'',
|
||||
|
||||
'male-alt': u'',
|
||||
|
||||
'male-female': u'',
|
||||
|
||||
'male': u'',
|
||||
|
||||
'mood-bad': u'',
|
||||
|
||||
'mood': u'',
|
||||
|
||||
'run': u'',
|
||||
|
||||
'walk': u'',
|
||||
|
||||
'cloud-box': u'',
|
||||
|
||||
'cloud-circle': u'',
|
||||
|
||||
'cloud-done': u'',
|
||||
|
||||
'cloud-download': u'',
|
||||
|
||||
'cloud-off': u'',
|
||||
|
||||
'cloud-outline-alt': u'',
|
||||
|
||||
'cloud-outline': u'',
|
||||
|
||||
'cloud-upload': u'',
|
||||
|
||||
'cloud': u'',
|
||||
|
||||
'download': u'',
|
||||
|
||||
'file-plus': u'',
|
||||
|
||||
'file-text': u'',
|
||||
|
||||
'file': u'',
|
||||
|
||||
'folder-outline': u'',
|
||||
|
||||
'folder-person': u'',
|
||||
|
||||
'folder-star-alt': u'',
|
||||
|
||||
'folder-star': u'',
|
||||
|
||||
'folder': u'',
|
||||
|
||||
'gif': u'',
|
||||
|
||||
'upload': u'',
|
||||
|
||||
'border-all': u'',
|
||||
|
||||
'border-bottom': u'',
|
||||
|
||||
'border-clear': u'',
|
||||
|
||||
'border-color': u'',
|
||||
|
||||
'border-horizontal': u'',
|
||||
|
||||
'border-inner': u'',
|
||||
|
||||
'border-left': u'',
|
||||
|
||||
'border-outer': u'',
|
||||
|
||||
'border-right': u'',
|
||||
|
||||
'border-style': u'',
|
||||
|
||||
'border-top': u'',
|
||||
|
||||
'border-vertical': u'',
|
||||
|
||||
'copy': u'',
|
||||
|
||||
'crop': u'',
|
||||
|
||||
'format-align-center': u'',
|
||||
|
||||
'format-align-justify': u'',
|
||||
|
||||
'format-align-left': u'',
|
||||
|
||||
'format-align-right': u'',
|
||||
|
||||
'format-bold': u'',
|
||||
|
||||
'format-clear-all': u'',
|
||||
|
||||
'format-clear': u'',
|
||||
|
||||
'format-color-fill': u'',
|
||||
|
||||
'format-color-reset': u'',
|
||||
|
||||
'format-color-text': u'',
|
||||
|
||||
'format-indent-decrease': u'',
|
||||
|
||||
'format-indent-increase': u'',
|
||||
|
||||
'format-italic': u'',
|
||||
|
||||
'format-line-spacing': u'',
|
||||
|
||||
'format-list-bulleted': u'',
|
||||
|
||||
'format-list-numbered': u'',
|
||||
|
||||
'format-ltr': u'',
|
||||
|
||||
'format-rtl': u'',
|
||||
|
||||
'format-size': u'',
|
||||
|
||||
'format-strikethrough-s': u'',
|
||||
|
||||
'format-strikethrough': u'',
|
||||
|
||||
'format-subject': u'',
|
||||
|
||||
'format-underlined': u'',
|
||||
|
||||
'format-valign-bottom': u'',
|
||||
|
||||
'format-valign-center': u'',
|
||||
|
||||
'format-valign-top': u'',
|
||||
|
||||
'redo': u'',
|
||||
|
||||
'select-all': u'',
|
||||
|
||||
'space-bar': u'',
|
||||
|
||||
'text-format': u'',
|
||||
|
||||
'transform': u'',
|
||||
|
||||
'undo': u'',
|
||||
|
||||
'wrap-text': u'',
|
||||
|
||||
'comment-alert': u'',
|
||||
|
||||
'comment-alt-text': u'',
|
||||
|
||||
'comment-alt': u'',
|
||||
|
||||
'comment-edit': u'',
|
||||
|
||||
'comment-image': u'',
|
||||
|
||||
'comment-list': u'',
|
||||
|
||||
'comment-more': u'',
|
||||
|
||||
'comment-outline': u'',
|
||||
|
||||
'comment-text-alt': u'',
|
||||
|
||||
'comment-text': u'',
|
||||
|
||||
'comment-video': u'',
|
||||
|
||||
'comment': u'',
|
||||
|
||||
'comments': u'',
|
||||
|
||||
'rm': u'F',
|
||||
|
||||
'check-all': u'',
|
||||
|
||||
'check-circle-u': u'',
|
||||
|
||||
'check-circle': u'',
|
||||
|
||||
'check-square': u'',
|
||||
|
||||
'check': u'',
|
||||
|
||||
'circle-o': u'',
|
||||
|
||||
'circle': u'',
|
||||
|
||||
'dot-circle-alt': u'',
|
||||
|
||||
'dot-circle': u'',
|
||||
|
||||
'minus-circle-outline': u'',
|
||||
|
||||
'minus-circle': u'',
|
||||
|
||||
'minus-square': u'',
|
||||
|
||||
'minus': u'',
|
||||
|
||||
'plus-circle-o-duplicate': u'',
|
||||
|
||||
'plus-circle-o': u'',
|
||||
|
||||
'plus-circle': u'',
|
||||
|
||||
'plus-square': u'',
|
||||
|
||||
'plus': u'',
|
||||
|
||||
'square-o': u'',
|
||||
|
||||
'star-circle': u'',
|
||||
|
||||
'star-half': u'',
|
||||
|
||||
'star-outline': u'',
|
||||
|
||||
'star': u'',
|
||||
|
||||
'bluetooth-connected': u'',
|
||||
|
||||
'bluetooth-off': u'',
|
||||
|
||||
'bluetooth-search': u'',
|
||||
|
||||
'bluetooth-setting': u'',
|
||||
|
||||
'bluetooth': u'',
|
||||
|
||||
'camera-add': u'',
|
||||
|
||||
'camera-alt': u'',
|
||||
|
||||
'camera-bw': u'',
|
||||
|
||||
'camera-front': u'',
|
||||
|
||||
'camera-mic': u'',
|
||||
|
||||
'camera-party-mode': u'',
|
||||
|
||||
'camera-rear': u'',
|
||||
|
||||
'camera-roll': u'',
|
||||
|
||||
'camera-switch': u'',
|
||||
|
||||
'camera': u'',
|
||||
|
||||
'card-alert': u'',
|
||||
|
||||
'card-off': u'',
|
||||
|
||||
'card-sd': u'',
|
||||
|
||||
'card-sim': u'',
|
||||
|
||||
'desktop-mac': u'',
|
||||
|
||||
'desktop-windows': u'',
|
||||
|
||||
'device-hub': u'',
|
||||
|
||||
'devices-off': u'',
|
||||
|
||||
'devices': u'',
|
||||
|
||||
'dock': u'',
|
||||
|
||||
'floppy': u'',
|
||||
|
||||
'gamepad': u'',
|
||||
|
||||
'gps-dot': u'',
|
||||
|
||||
'gps-off': u'',
|
||||
|
||||
'gps': u'',
|
||||
|
||||
'headset-mic': u'',
|
||||
|
||||
'headset': u'',
|
||||
|
||||
'input-antenna': u'',
|
||||
|
||||
'input-composite': u'',
|
||||
|
||||
'input-hdmi': u'',
|
||||
|
||||
'input-power': u'',
|
||||
|
||||
'input-svideo': u'',
|
||||
|
||||
'keyboard-hide': u'',
|
||||
|
||||
'keyboard': u'',
|
||||
|
||||
'laptop-chromebook': u'',
|
||||
|
||||
'laptop-mac': u'',
|
||||
|
||||
'laptop': u'',
|
||||
|
||||
'mic-off': u'',
|
||||
|
||||
'mic-outline': u'',
|
||||
|
||||
'mic-setting': u'',
|
||||
|
||||
'mic': u'',
|
||||
|
||||
'mouse': u'',
|
||||
|
||||
'network-alert': u'',
|
||||
|
||||
'network-locked': u'',
|
||||
|
||||
'network-off': u'',
|
||||
|
||||
'network-outline': u'',
|
||||
|
||||
'network-setting': u'',
|
||||
|
||||
'network': u'',
|
||||
|
||||
'phone-bluetooth': u'',
|
||||
|
||||
'phone-end': u'',
|
||||
|
||||
'phone-forwarded': u'',
|
||||
|
||||
'phone-in-talk': u'',
|
||||
|
||||
'phone-locked': u'',
|
||||
|
||||
'phone-missed': u'',
|
||||
|
||||
'phone-msg': u'',
|
||||
|
||||
'phone-paused': u'',
|
||||
|
||||
'phone-ring': u'',
|
||||
|
||||
'phone-setting': u'',
|
||||
|
||||
'phone-sip': u'',
|
||||
|
||||
'phone': u'',
|
||||
|
||||
'portable-wifi-changes': u'',
|
||||
|
||||
'portable-wifi-off': u'',
|
||||
|
||||
'portable-wifi': u'',
|
||||
|
||||
'radio': u'',
|
||||
|
||||
'reader': u'',
|
||||
|
||||
'remote-control-alt': u'',
|
||||
|
||||
'remote-control': u'',
|
||||
|
||||
'router': u'',
|
||||
|
||||
'scanner': u'',
|
||||
|
||||
'smartphone-android': u'',
|
||||
|
||||
'smartphone-download': u'',
|
||||
|
||||
'smartphone-erase': u'',
|
||||
|
||||
'smartphone-info': u'',
|
||||
|
||||
'smartphone-iphone': u'',
|
||||
|
||||
'smartphone-landscape-lock': u'',
|
||||
|
||||
'smartphone-landscape': u'',
|
||||
|
||||
'smartphone-lock': u'',
|
||||
|
||||
'smartphone-portrait-lock': u'',
|
||||
|
||||
'smartphone-ring': u'',
|
||||
|
||||
'smartphone-setting': u'',
|
||||
|
||||
'smartphone-setup': u'',
|
||||
|
||||
'smartphone': u'',
|
||||
|
||||
'speaker': u'',
|
||||
|
||||
'tablet-android': u'',
|
||||
|
||||
'tablet-mac': u'',
|
||||
|
||||
'tablet': u'',
|
||||
|
||||
'tv-alt-play': u'',
|
||||
|
||||
'tv-list': u'',
|
||||
|
||||
'tv-play': u'',
|
||||
|
||||
'tv': u'',
|
||||
|
||||
'usb': u'',
|
||||
|
||||
'videocam-off': u'',
|
||||
|
||||
'videocam-switch': u'',
|
||||
|
||||
'videocam': u'',
|
||||
|
||||
'watch': u'',
|
||||
|
||||
'wifi-alt-2': u'',
|
||||
|
||||
'wifi-alt': u'',
|
||||
|
||||
'wifi-info': u'',
|
||||
|
||||
'wifi-lock': u'',
|
||||
|
||||
'wifi-off': u'',
|
||||
|
||||
'wifi-outline': u'',
|
||||
|
||||
'wifi': u'',
|
||||
|
||||
'arrow-left-bottom': u'',
|
||||
|
||||
'arrow-left': u'',
|
||||
|
||||
'arrow-merge': u'',
|
||||
|
||||
'arrow-missed': u'',
|
||||
|
||||
'arrow-right-top': u'',
|
||||
|
||||
'arrow-right': u'',
|
||||
|
||||
'arrow-split': u'',
|
||||
|
||||
'arrows': u'',
|
||||
|
||||
'caret-down-circle': u'',
|
||||
|
||||
'caret-down': u'',
|
||||
|
||||
'caret-left-circle': u'',
|
||||
|
||||
'caret-left': u'',
|
||||
|
||||
'caret-right-circle': u'',
|
||||
|
||||
'caret-right': u'',
|
||||
|
||||
'caret-up-circle': u'',
|
||||
|
||||
'caret-up': u'',
|
||||
|
||||
'chevron-down': u'',
|
||||
|
||||
'chevron-left': u'',
|
||||
|
||||
'chevron-right': u'',
|
||||
|
||||
'chevron-up': u'',
|
||||
|
||||
'forward': u'',
|
||||
|
||||
'long-arrow-down': u'',
|
||||
|
||||
'long-arrow-left': u'',
|
||||
|
||||
'long-arrow-return': u'',
|
||||
|
||||
'long-arrow-right': u'',
|
||||
|
||||
'long-arrow-tab': u'',
|
||||
|
||||
'long-arrow-up': u'',
|
||||
|
||||
'rotate-ccw': u'',
|
||||
|
||||
'rotate-cw': u'',
|
||||
|
||||
'rotate-left': u'',
|
||||
|
||||
'rotate-right': u'',
|
||||
|
||||
'square-down': u'',
|
||||
|
||||
'square-right': u'',
|
||||
|
||||
'swap-alt': u'',
|
||||
|
||||
'swap-vertical-circle': u'',
|
||||
|
||||
'swap-vertical': u'',
|
||||
|
||||
'swap': u'',
|
||||
|
||||
'trending-down': u'',
|
||||
|
||||
'trending-flat': u'',
|
||||
|
||||
'trending-up': u'',
|
||||
|
||||
'unfold-less': u'',
|
||||
|
||||
'unfold-more': u'',
|
||||
|
||||
'apps': u'',
|
||||
|
||||
'grid-off': u'',
|
||||
|
||||
'grid': u'',
|
||||
|
||||
'view-agenda': u'',
|
||||
|
||||
'view-array': u'',
|
||||
|
||||
'view-carousel': u'',
|
||||
|
||||
'view-column': u'',
|
||||
|
||||
'view-comfy': u'',
|
||||
|
||||
'view-compact': u'',
|
||||
|
||||
'view-dashboard': u'',
|
||||
|
||||
'view-day': u'',
|
||||
|
||||
'view-headline': u'',
|
||||
|
||||
'view-list-alt': u'',
|
||||
|
||||
'view-list': u'',
|
||||
|
||||
'view-module': u'',
|
||||
|
||||
'view-quilt': u'',
|
||||
|
||||
'view-stream': u'',
|
||||
|
||||
'view-subtitles': u'',
|
||||
|
||||
'view-toc': u'',
|
||||
|
||||
'view-web': u'',
|
||||
|
||||
'view-week': u'',
|
||||
|
||||
'widgets': u'',
|
||||
|
||||
'alarm-check': u'',
|
||||
|
||||
'alarm-off': u'',
|
||||
|
||||
'alarm-plus': u'',
|
||||
|
||||
'alarm-snooze': u'',
|
||||
|
||||
'alarm': u'',
|
||||
|
||||
'calendar-alt': u'',
|
||||
|
||||
'calendar-check': u'',
|
||||
|
||||
'calendar-close': u'',
|
||||
|
||||
'calendar-note': u'',
|
||||
|
||||
'calendar': u'',
|
||||
|
||||
'time-countdown': u'',
|
||||
|
||||
'time-interval': u'',
|
||||
|
||||
'time-restore-setting': u'',
|
||||
|
||||
'time-restore': u'',
|
||||
|
||||
'time': u'',
|
||||
|
||||
'timer-off': u'',
|
||||
|
||||
'timer': u'',
|
||||
|
||||
'android-alt': u'',
|
||||
|
||||
'android': u'',
|
||||
|
||||
'apple': u'',
|
||||
|
||||
'behance': u'',
|
||||
|
||||
'codepen': u'',
|
||||
|
||||
'dribbble': u'',
|
||||
|
||||
'dropbox': u'',
|
||||
|
||||
'evernote': u'',
|
||||
|
||||
'facebook-box': u'',
|
||||
|
||||
'facebook': u'',
|
||||
|
||||
'github-box': u'',
|
||||
|
||||
'github': u'',
|
||||
|
||||
'google-drive': u'',
|
||||
|
||||
'google-earth': u'',
|
||||
|
||||
'google-glass': u'',
|
||||
|
||||
'google-maps': u'',
|
||||
|
||||
'google-pages': u'',
|
||||
|
||||
'google-play': u'',
|
||||
|
||||
'google-plus-box': u'',
|
||||
|
||||
'google-plus': u'',
|
||||
|
||||
'google': u'',
|
||||
|
||||
'instagram': u'',
|
||||
|
||||
'language-css3': u'',
|
||||
|
||||
'language-html5': u'',
|
||||
|
||||
'language-javascript': u'',
|
||||
|
||||
'language-python-alt': u'',
|
||||
|
||||
'language-python': u'',
|
||||
|
||||
'lastfm': u'',
|
||||
|
||||
'linkedin-box': u'',
|
||||
|
||||
'paypal': u'',
|
||||
|
||||
'pinterest-box': u'',
|
||||
|
||||
'pocket': u'',
|
||||
|
||||
'polymer': u'',
|
||||
|
||||
'rss': u'',
|
||||
|
||||
'share': u'',
|
||||
|
||||
'stackoverflow': u'',
|
||||
|
||||
'steam-square': u'',
|
||||
|
||||
'steam': u'',
|
||||
|
||||
'twitter-box': u'',
|
||||
|
||||
'twitter': u'',
|
||||
|
||||
'vk': u'',
|
||||
|
||||
'wikipedia': u'',
|
||||
|
||||
'windows': u'',
|
||||
|
||||
'500px': u'',
|
||||
|
||||
'8tracks': u'',
|
||||
|
||||
'amazon': u'',
|
||||
|
||||
'blogger': u'',
|
||||
|
||||
'delicious': u'',
|
||||
|
||||
'disqus': u'',
|
||||
|
||||
'flattr': u'',
|
||||
|
||||
'flickr': u'',
|
||||
|
||||
'github-alt': u'',
|
||||
|
||||
'google-old': u'',
|
||||
|
||||
'linkedin': u'',
|
||||
|
||||
'odnoklassniki': u'',
|
||||
|
||||
'outlook': u'',
|
||||
|
||||
'paypal-alt': u'',
|
||||
|
||||
'pinterest': u'',
|
||||
|
||||
'playstation': u'',
|
||||
|
||||
'reddit': u'',
|
||||
|
||||
'skype': u'',
|
||||
|
||||
'slideshare': u'',
|
||||
|
||||
'soundcloud': u'',
|
||||
|
||||
'tumblr': u'',
|
||||
|
||||
'twitch': u'',
|
||||
|
||||
'vimeo': u'',
|
||||
|
||||
'whatsapp': u'',
|
||||
|
||||
'xbox': u'',
|
||||
|
||||
'yahoo': u'',
|
||||
|
||||
'youtube-play': u'',
|
||||
|
||||
'youtube': u'',
|
||||
|
||||
'aspect-ratio-alt': u'',
|
||||
|
||||
'aspect-ratio': u'',
|
||||
|
||||
'blur-circular': u'',
|
||||
|
||||
'blur-linear': u'',
|
||||
|
||||
'blur-off': u'',
|
||||
|
||||
'blur': u'',
|
||||
|
||||
'brightness-2': u'',
|
||||
|
||||
'brightness-3': u'',
|
||||
|
||||
'brightness-4': u'',
|
||||
|
||||
'brightness-5': u'',
|
||||
|
||||
'brightness-6': u'',
|
||||
|
||||
'brightness-7': u'',
|
||||
|
||||
'brightness-auto': u'',
|
||||
|
||||
'brightness-setting': u'',
|
||||
|
||||
'broken-image': u'',
|
||||
|
||||
'center-focus-strong': u'',
|
||||
|
||||
'center-focus-weak': u'',
|
||||
|
||||
'compare': u'',
|
||||
|
||||
'crop-16-9': u'',
|
||||
|
||||
'crop-3-2': u'',
|
||||
|
||||
'crop-5-4': u'',
|
||||
|
||||
'crop-7-5': u'',
|
||||
|
||||
'crop-din': u'',
|
||||
|
||||
'crop-free': u'',
|
||||
|
||||
'crop-landscape': u'',
|
||||
|
||||
'crop-portrait': u'',
|
||||
|
||||
'crop-square': u'',
|
||||
|
||||
'exposure-alt': u'',
|
||||
|
||||
'exposure': u'',
|
||||
|
||||
'filter-b-and-w': u'',
|
||||
|
||||
'filter-center-focus': u'',
|
||||
|
||||
'filter-frames': u'',
|
||||
|
||||
'filter-tilt-shift': u'',
|
||||
|
||||
'gradient': u'',
|
||||
|
||||
'grain': u'',
|
||||
|
||||
'graphic-eq': u'',
|
||||
|
||||
'hdr-off': u'',
|
||||
|
||||
'hdr-strong': u'',
|
||||
|
||||
'hdr-weak': u'',
|
||||
|
||||
'hdr': u'',
|
||||
|
||||
'iridescent': u'',
|
||||
|
||||
'leak-off': u'',
|
||||
|
||||
'leak': u'',
|
||||
|
||||
'looks': u'',
|
||||
|
||||
'loupe': u'',
|
||||
|
||||
'panorama-horizontal': u'',
|
||||
|
||||
'panorama-vertical': u'',
|
||||
|
||||
'panorama-wide-angle': u'',
|
||||
|
||||
'photo-size-select-large': u'',
|
||||
|
||||
'photo-size-select-small': u'',
|
||||
|
||||
'picture-in-picture': u'',
|
||||
|
||||
'slideshow': u'',
|
||||
|
||||
'texture': u'',
|
||||
|
||||
'tonality': u'',
|
||||
|
||||
'vignette': u'',
|
||||
|
||||
'wb-auto': u'',
|
||||
|
||||
'eject-alt': u'',
|
||||
|
||||
'eject': u'',
|
||||
|
||||
'equalizer': u'',
|
||||
|
||||
'fast-forward': u'',
|
||||
|
||||
'fast-rewind': u'',
|
||||
|
||||
'forward-10': u'',
|
||||
|
||||
'forward-30': u'',
|
||||
|
||||
'forward-5': u'',
|
||||
|
||||
'hearing': u'',
|
||||
|
||||
'pause-circle-outline': u'',
|
||||
|
||||
'pause-circle': u'',
|
||||
|
||||
'pause': u'',
|
||||
|
||||
'play-circle-outline': u'',
|
||||
|
||||
'play-circle': u'',
|
||||
|
||||
'play': u'',
|
||||
|
||||
'playlist-audio': u'',
|
||||
|
||||
'playlist-plus': u'',
|
||||
|
||||
'repeat-one': u'',
|
||||
|
||||
'repeat': u'',
|
||||
|
||||
'replay-10': u'',
|
||||
|
||||
'replay-30': u'',
|
||||
|
||||
'replay-5': u'',
|
||||
|
||||
'replay': u'',
|
||||
|
||||
'shuffle': u'',
|
||||
|
||||
'skip-next': u'',
|
||||
|
||||
'skip-previous': u'',
|
||||
|
||||
'stop': u'',
|
||||
|
||||
'surround-sound': u'',
|
||||
|
||||
'tune': u'',
|
||||
|
||||
'volume-down': u'',
|
||||
|
||||
'volume-mute': u'',
|
||||
|
||||
'volume-off': u'',
|
||||
|
||||
'volume-up': u'',
|
||||
|
||||
'n-1-square': u'',
|
||||
|
||||
'n-2-square': u'',
|
||||
|
||||
'n-3-square': u'',
|
||||
|
||||
'n-4-square': u'',
|
||||
|
||||
'n-5-square': u'',
|
||||
|
||||
'n-6-square': u'',
|
||||
|
||||
'neg-1': u'',
|
||||
|
||||
'neg-2': u'',
|
||||
|
||||
'plus-1': u'',
|
||||
|
||||
'plus-2': u'',
|
||||
|
||||
'sec-10': u'',
|
||||
|
||||
'sec-3': u'',
|
||||
|
||||
'zero': u'',
|
||||
|
||||
'airline-seat-flat-angled': u'',
|
||||
|
||||
'airline-seat-flat': u'',
|
||||
|
||||
'airline-seat-individual-suite': u'',
|
||||
|
||||
'airline-seat-legroom-extra': u'',
|
||||
|
||||
'airline-seat-legroom-normal': u'',
|
||||
|
||||
'airline-seat-legroom-reduced': u'',
|
||||
|
||||
'airline-seat-recline-extra': u'',
|
||||
|
||||
'airline-seat-recline-normal': u'',
|
||||
|
||||
'airplay': u'',
|
||||
|
||||
'closed-caption': u'',
|
||||
|
||||
'confirmation-number': u'',
|
||||
|
||||
'developer-board': u'',
|
||||
|
||||
'disc-full': u'',
|
||||
|
||||
'explicit': u'',
|
||||
|
||||
'flight-land': u'',
|
||||
|
||||
'flight-takeoff': u'',
|
||||
|
||||
'flip-to-back': u'',
|
||||
|
||||
'flip-to-front': u'',
|
||||
|
||||
'group-work': u'',
|
||||
|
||||
'hd': u'',
|
||||
|
||||
'hq': u'',
|
||||
|
||||
'markunread-mailbox': u'',
|
||||
|
||||
'memory': u'',
|
||||
|
||||
'nfc': u'',
|
||||
|
||||
'play-for-work': u'',
|
||||
|
||||
'power-input': u'',
|
||||
|
||||
'present-to-all': u'',
|
||||
|
||||
'satellite': u'',
|
||||
|
||||
'tap-and-play': u'',
|
||||
|
||||
'vibration': u'',
|
||||
|
||||
'voicemail': u'',
|
||||
}
|
BIN
src/kivymd/images/kivymd_512.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
src/kivymd/images/kivymd_logo.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
src/kivymd/images/quad_shadow-0.png
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
src/kivymd/images/quad_shadow-1.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
src/kivymd/images/quad_shadow-2.png
Normal file
After Width: | Height: | Size: 19 KiB |
1
src/kivymd/images/quad_shadow.atlas
Normal file
|
@ -0,0 +1 @@
|
|||
{"quad_shadow-1.png": {"20": [2, 136, 128, 128], "21": [132, 136, 128, 128], "22": [262, 136, 128, 128], "23": [2, 6, 128, 128], "19": [132, 266, 128, 128], "18": [2, 266, 128, 128], "1": [262, 266, 128, 128], "3": [262, 6, 128, 128], "2": [132, 6, 128, 128]}, "quad_shadow-0.png": {"11": [262, 266, 128, 128], "10": [132, 266, 128, 128], "13": [132, 136, 128, 128], "12": [2, 136, 128, 128], "15": [2, 6, 128, 128], "14": [262, 136, 128, 128], "17": [262, 6, 128, 128], "16": [132, 6, 128, 128], "0": [2, 266, 128, 128]}, "quad_shadow-2.png": {"5": [132, 266, 128, 128], "4": [2, 266, 128, 128], "7": [2, 136, 128, 128], "6": [262, 266, 128, 128], "9": [262, 136, 128, 128], "8": [132, 136, 128, 128]}}
|
BIN
src/kivymd/images/rec_shadow-0.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
src/kivymd/images/rec_shadow-1.png
Normal file
After Width: | Height: | Size: 43 KiB |
1
src/kivymd/images/rec_shadow.atlas
Normal file
|
@ -0,0 +1 @@
|
|||
{"rec_shadow-1.png": {"20": [2, 266, 256, 128], "21": [260, 266, 256, 128], "22": [518, 266, 256, 128], "23": [776, 266, 256, 128], "3": [260, 136, 256, 128], "2": [2, 136, 256, 128], "5": [776, 136, 256, 128], "4": [518, 136, 256, 128], "7": [260, 6, 256, 128], "6": [2, 6, 256, 128], "9": [776, 6, 256, 128], "8": [518, 6, 256, 128]}, "rec_shadow-0.png": {"11": [518, 266, 256, 128], "10": [260, 266, 256, 128], "13": [2, 136, 256, 128], "12": [776, 266, 256, 128], "15": [518, 136, 256, 128], "14": [260, 136, 256, 128], "17": [2, 6, 256, 128], "16": [776, 136, 256, 128], "19": [518, 6, 256, 128], "18": [260, 6, 256, 128], "1": [776, 6, 256, 128], "0": [2, 266, 256, 128]}}
|
BIN
src/kivymd/images/rec_st_shadow-0.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
src/kivymd/images/rec_st_shadow-1.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
src/kivymd/images/rec_st_shadow-2.png
Normal file
After Width: | Height: | Size: 28 KiB |
1
src/kivymd/images/rec_st_shadow.atlas
Normal file
|
@ -0,0 +1 @@
|
|||
{"rec_st_shadow-0.png": {"11": [262, 138, 128, 256], "10": [132, 138, 128, 256], "13": [522, 138, 128, 256], "12": [392, 138, 128, 256], "15": [782, 138, 128, 256], "14": [652, 138, 128, 256], "16": [912, 138, 128, 256], "0": [2, 138, 128, 256]}, "rec_st_shadow-1.png": {"20": [522, 138, 128, 256], "21": [652, 138, 128, 256], "17": [2, 138, 128, 256], "23": [912, 138, 128, 256], "19": [262, 138, 128, 256], "18": [132, 138, 128, 256], "22": [782, 138, 128, 256], "1": [392, 138, 128, 256]}, "rec_st_shadow-2.png": {"3": [132, 138, 128, 256], "2": [2, 138, 128, 256], "5": [392, 138, 128, 256], "4": [262, 138, 128, 256], "7": [652, 138, 128, 256], "6": [522, 138, 128, 256], "9": [912, 138, 128, 256], "8": [782, 138, 128, 256]}}
|
BIN
src/kivymd/images/round_shadow-0.png
Normal file
After Width: | Height: | Size: 39 KiB |
BIN
src/kivymd/images/round_shadow-1.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
src/kivymd/images/round_shadow-2.png
Normal file
After Width: | Height: | Size: 26 KiB |
1
src/kivymd/images/round_shadow.atlas
Normal file
|
@ -0,0 +1 @@
|
|||
{"round_shadow-1.png": {"20": [2, 136, 128, 128], "21": [132, 136, 128, 128], "22": [262, 136, 128, 128], "23": [2, 6, 128, 128], "19": [132, 266, 128, 128], "18": [2, 266, 128, 128], "1": [262, 266, 128, 128], "3": [262, 6, 128, 128], "2": [132, 6, 128, 128]}, "round_shadow-0.png": {"11": [262, 266, 128, 128], "10": [132, 266, 128, 128], "13": [132, 136, 128, 128], "12": [2, 136, 128, 128], "15": [2, 6, 128, 128], "14": [262, 136, 128, 128], "17": [262, 6, 128, 128], "16": [132, 6, 128, 128], "0": [2, 266, 128, 128]}, "round_shadow-2.png": {"5": [132, 266, 128, 128], "4": [2, 266, 128, 128], "7": [2, 136, 128, 128], "6": [262, 266, 128, 128], "9": [262, 136, 128, 128], "8": [132, 136, 128, 128]}}
|
94
src/kivymd/label.py
Normal file
|
@ -0,0 +1,94 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from kivy.lang import Builder
|
||||
from kivy.metrics import sp
|
||||
from kivy.properties import OptionProperty, DictProperty, ListProperty
|
||||
from kivy.uix.label import Label
|
||||
from kivymd.material_resources import DEVICE_TYPE
|
||||
from kivymd.theming import ThemableBehavior
|
||||
|
||||
Builder.load_string('''
|
||||
<MDLabel>
|
||||
disabled_color: self.theme_cls.disabled_hint_text_color
|
||||
text_size: (self.width, None)
|
||||
''')
|
||||
|
||||
|
||||
class MDLabel(ThemableBehavior, Label):
|
||||
font_style = OptionProperty(
|
||||
'Body1', options=['Body1', 'Body2', 'Caption', 'Subhead', 'Title',
|
||||
'Headline', 'Display1', 'Display2', 'Display3',
|
||||
'Display4', 'Button', 'Icon'])
|
||||
|
||||
# Font, Bold, Mobile size, Desktop size (None if same as Mobile)
|
||||
_font_styles = DictProperty({'Body1': ['Roboto', False, 14, 13],
|
||||
'Body2': ['Roboto', True, 14, 13],
|
||||
'Caption': ['Roboto', False, 12, None],
|
||||
'Subhead': ['Roboto', False, 16, 15],
|
||||
'Title': ['Roboto', True, 20, None],
|
||||
'Headline': ['Roboto', False, 24, None],
|
||||
'Display1': ['Roboto', False, 34, None],
|
||||
'Display2': ['Roboto', False, 45, None],
|
||||
'Display3': ['Roboto', False, 56, None],
|
||||
'Display4': ['RobotoLight', False, 112, None],
|
||||
'Button': ['Roboto', True, 14, None],
|
||||
'Icon': ['Icons', False, 24, None]})
|
||||
|
||||
theme_text_color = OptionProperty(None, allownone=True,
|
||||
options=['Primary', 'Secondary', 'Hint',
|
||||
'Error', 'Custom'])
|
||||
|
||||
text_color = ListProperty(None, allownone=True)
|
||||
|
||||
_currently_bound_property = {}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(MDLabel, self).__init__(**kwargs)
|
||||
self.on_theme_text_color(None, self.theme_text_color)
|
||||
self.on_font_style(None, self.font_style)
|
||||
self.on_opposite_colors(None, self.opposite_colors)
|
||||
|
||||
def on_font_style(self, instance, style):
|
||||
info = self._font_styles[style]
|
||||
self.font_name = info[0]
|
||||
self.bold = info[1]
|
||||
if DEVICE_TYPE == 'desktop' and info[3] is not None:
|
||||
self.font_size = sp(info[3])
|
||||
else:
|
||||
self.font_size = sp(info[2])
|
||||
|
||||
def on_theme_text_color(self, instance, value):
|
||||
t = self.theme_cls
|
||||
op = self.opposite_colors
|
||||
setter = self.setter('color')
|
||||
t.unbind(**self._currently_bound_property)
|
||||
c = {}
|
||||
if value == 'Primary':
|
||||
c = {'text_color' if not op else 'opposite_text_color': setter}
|
||||
t.bind(**c)
|
||||
self.color = t.text_color if not op else t.opposite_text_color
|
||||
elif value == 'Secondary':
|
||||
c = {'secondary_text_color' if not op else
|
||||
'opposite_secondary_text_color': setter}
|
||||
t.bind(**c)
|
||||
self.color = t.secondary_text_color if not op else \
|
||||
t.opposite_secondary_text_color
|
||||
elif value == 'Hint':
|
||||
c = {'disabled_hint_text_color' if not op else
|
||||
'opposite_disabled_hint_text_color': setter}
|
||||
t.bind(**c)
|
||||
self.color = t.disabled_hint_text_color if not op else \
|
||||
t.opposite_disabled_hint_text_color
|
||||
elif value == 'Error':
|
||||
c = {'error_color': setter}
|
||||
t.bind(**c)
|
||||
self.color = t.error_color
|
||||
elif value == 'Custom':
|
||||
self.color = self.text_color if self.text_color else (0, 0, 0, 1)
|
||||
self._currently_bound_property = c
|
||||
|
||||
def on_text_color(self, *args):
|
||||
if self.theme_text_color == 'Custom':
|
||||
self.color = self.text_color
|
||||
|
||||
def on_opposite_colors(self, instance, value):
|
||||
self.on_theme_text_color(self, self.theme_text_color)
|
531
src/kivymd/list.py
Normal file
|
@ -0,0 +1,531 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Lists
|
||||
=====
|
||||
|
||||
`Material Design spec, Lists page <https://www.google.com/design/spec/components/lists.html>`_
|
||||
|
||||
`Material Design spec, Lists: Controls page <https://www.google.com/design/spec/components/lists-controls.html>`_
|
||||
|
||||
The class :class:`MDList` in combination with a ListItem like
|
||||
:class:`OneLineListItem` will create a list that expands as items are added to
|
||||
it, working nicely with Kivy's :class:`~kivy.uix.scrollview.ScrollView`.
|
||||
|
||||
|
||||
Simple examples
|
||||
---------------
|
||||
|
||||
Kv Lang:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
ScrollView:
|
||||
do_scroll_x: False # Important for MD compliance
|
||||
MDList:
|
||||
OneLineListItem:
|
||||
text: "Single-line item"
|
||||
TwoLineListItem:
|
||||
text: "Two-line item"
|
||||
secondary_text: "Secondary text here"
|
||||
ThreeLineListItem:
|
||||
text: "Three-line item"
|
||||
secondary_text: "This is a multi-line label where you can fit more text than usual"
|
||||
|
||||
|
||||
Python:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Sets up ScrollView with MDList, as normally used in Android:
|
||||
sv = ScrollView()
|
||||
ml = MDList()
|
||||
sv.add_widget(ml)
|
||||
|
||||
contacts = ["Paula", "John", "Kate", "Vlad"]
|
||||
for c in contacts:
|
||||
ml.add_widget(
|
||||
OneLineListItem(
|
||||
text=c
|
||||
)
|
||||
)
|
||||
|
||||
Advanced usage
|
||||
--------------
|
||||
|
||||
Due to the variety in sizes and controls in the MD spec, this module suffers
|
||||
from a certain level of complexity to keep the widgets compliant, flexible
|
||||
and performant.
|
||||
|
||||
For this KivyMD provides ListItems that try to cover the most common usecases,
|
||||
when those are insufficient, there's a base class called :class:`ListItem`
|
||||
which you can use to create your own ListItems. This documentation will only
|
||||
cover the provided ones, for custom implementations please refer to this
|
||||
module's source code.
|
||||
|
||||
Text only ListItems
|
||||
-------------------
|
||||
|
||||
- :class:`~OneLineListItem`
|
||||
- :class:`~TwoLineListItem`
|
||||
- :class:`~ThreeLineListItem`
|
||||
|
||||
These are the simplest ones. The :attr:`~ListItem.text` attribute changes the
|
||||
text in the most prominent line, while :attr:`~ListItem.secondary_text`
|
||||
changes the second and third line.
|
||||
|
||||
If there are only two lines, :attr:`~ListItem.secondary_text` will shorten
|
||||
the text to fit in case it is too long; if a third line is available, it will
|
||||
instead wrap the text to make use of it.
|
||||
|
||||
ListItems with widget containers
|
||||
--------------------------------
|
||||
|
||||
- :class:`~OneLineAvatarListItem`
|
||||
- :class:`~TwoLineAvatarListItem`
|
||||
- :class:`~ThreeLineAvatarListItem`
|
||||
- :class:`~OneLineIconListItem`
|
||||
- :class:`~TwoLineIconListItem`
|
||||
- :class:`~ThreeLineIconListItem`
|
||||
- :class:`~OneLineAvatarIconListItem`
|
||||
- :class:`~TwoLineAvatarIconListItem`
|
||||
- :class:`~ThreeLineAvatarIconListItem`
|
||||
|
||||
These widgets will take other widgets that inherit from :class:`~ILeftBody`,
|
||||
:class:`ILeftBodyTouch`, :class:`~IRightBody` or :class:`~IRightBodyTouch` and
|
||||
put them in their corresponding container.
|
||||
|
||||
As the name implies, :class:`~ILeftBody` and :class:`~IRightBody` will signal
|
||||
that the widget goes into the left or right container, respectively.
|
||||
|
||||
:class:`~ILeftBodyTouch` and :class:`~IRightBodyTouch` do the same thing,
|
||||
except these widgets will also receive touch events that occur within their
|
||||
surfaces.
|
||||
|
||||
Python example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class ContactPhoto(ILeftBody, AsyncImage):
|
||||
pass
|
||||
|
||||
class MessageButton(IRightBodyTouch, MDIconButton):
|
||||
phone_number = StringProperty()
|
||||
|
||||
def on_release(self):
|
||||
# sample code:
|
||||
Dialer.send_sms(phone_number, "Hey! What's up?")
|
||||
pass
|
||||
|
||||
# Sets up ScrollView with MDList, as normally used in Android:
|
||||
sv = ScrollView()
|
||||
ml = MDList()
|
||||
sv.add_widget(ml)
|
||||
|
||||
contacts = [
|
||||
["Annie", "555-24235", "http://myphotos.com/annie.png"],
|
||||
["Bob", "555-15423", "http://myphotos.com/bob.png"],
|
||||
["Claire", "555-66098", "http://myphotos.com/claire.png"]
|
||||
]
|
||||
|
||||
for c in contacts:
|
||||
item = TwoLineAvatarIconListItem(
|
||||
text=c[0],
|
||||
secondary_text=c[1]
|
||||
)
|
||||
item.add_widget(ContactPhoto(source=c[2]))
|
||||
item.add_widget(MessageButton(phone_number=c[1])
|
||||
ml.add_widget(item)
|
||||
|
||||
API
|
||||
---
|
||||
'''
|
||||
|
||||
from kivy.lang import Builder
|
||||
from kivy.metrics import dp
|
||||
from kivy.properties import ObjectProperty, StringProperty, NumericProperty, \
|
||||
ListProperty, OptionProperty
|
||||
from kivy.uix.behaviors import ButtonBehavior
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
import kivymd.material_resources as m_res
|
||||
from kivymd.ripplebehavior import RectangularRippleBehavior
|
||||
from kivymd.theming import ThemableBehavior
|
||||
|
||||
Builder.load_string('''
|
||||
#:import m_res kivymd.material_resources
|
||||
<MDList>
|
||||
cols: 1
|
||||
size_hint_y: None
|
||||
height: self._min_list_height
|
||||
padding: 0, self._list_vertical_padding
|
||||
|
||||
<BaseListItem>
|
||||
size_hint_y: None
|
||||
canvas:
|
||||
Color:
|
||||
rgba: self.theme_cls.divider_color
|
||||
Line:
|
||||
points: root.x,root.y, root.x+self.width,root.y
|
||||
BoxLayout:
|
||||
id: _text_container
|
||||
orientation: 'vertical'
|
||||
pos: root.pos
|
||||
padding: root._txt_left_pad, root._txt_top_pad, root._txt_right_pad, root._txt_bot_pad
|
||||
MDLabel:
|
||||
id: _lbl_primary
|
||||
text: root.text
|
||||
font_style: root.font_style
|
||||
theme_text_color: root.theme_text_color
|
||||
text_color: root.text_color
|
||||
size_hint_y: None
|
||||
height: self.texture_size[1]
|
||||
MDLabel:
|
||||
id: _lbl_secondary
|
||||
text: '' if root._num_lines == 1 else root.secondary_text
|
||||
font_style: root.secondary_font_style
|
||||
theme_text_color: root.secondary_theme_text_color
|
||||
text_color: root.secondary_text_color
|
||||
size_hint_y: None
|
||||
height: 0 if root._num_lines == 1 else self.texture_size[1]
|
||||
shorten: True if root._num_lines == 2 else False
|
||||
|
||||
<OneLineAvatarListItem>
|
||||
BoxLayout:
|
||||
id: _left_container
|
||||
size_hint: None, None
|
||||
x: root.x + dp(16)
|
||||
y: root.y + root.height/2 - self.height/2
|
||||
size: dp(40), dp(40)
|
||||
|
||||
<ThreeLineAvatarListItem>
|
||||
BoxLayout:
|
||||
id: _left_container
|
||||
size_hint: None, None
|
||||
x: root.x + dp(16)
|
||||
y: root.y + root.height - root._txt_top_pad - self.height - dp(5)
|
||||
size: dp(40), dp(40)
|
||||
|
||||
<OneLineIconListItem>
|
||||
BoxLayout:
|
||||
id: _left_container
|
||||
size_hint: None, None
|
||||
x: root.x + dp(16)
|
||||
y: root.y + root.height/2 - self.height/2
|
||||
size: dp(48), dp(48)
|
||||
|
||||
<ThreeLineIconListItem>
|
||||
BoxLayout:
|
||||
id: _left_container
|
||||
size_hint: None, None
|
||||
x: root.x + dp(16)
|
||||
y: root.y + root.height - root._txt_top_pad - self.height - dp(5)
|
||||
size: dp(48), dp(48)
|
||||
|
||||
<OneLineRightIconListItem>
|
||||
BoxLayout:
|
||||
id: _right_container
|
||||
size_hint: None, None
|
||||
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
|
||||
y: root.y + root.height/2 - self.height/2
|
||||
size: dp(48), dp(48)
|
||||
|
||||
<ThreeLineRightIconListItem>
|
||||
BoxLayout:
|
||||
id: _right_container
|
||||
size_hint: None, None
|
||||
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
|
||||
y: root.y + root.height/2 - self.height/2
|
||||
size: dp(48), dp(48)
|
||||
|
||||
<OneLineAvatarIconListItem>
|
||||
BoxLayout:
|
||||
id: _right_container
|
||||
size_hint: None, None
|
||||
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
|
||||
y: root.y + root.height/2 - self.height/2
|
||||
size: dp(48), dp(48)
|
||||
|
||||
<TwoLineAvatarIconListItem>
|
||||
BoxLayout:
|
||||
id: _right_container
|
||||
size_hint: None, None
|
||||
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
|
||||
y: root.y + root.height/2 - self.height/2
|
||||
size: dp(48), dp(48)
|
||||
|
||||
<ThreeLineAvatarIconListItem>
|
||||
BoxLayout:
|
||||
id: _right_container
|
||||
size_hint: None, None
|
||||
x: root.x + root.width - m_res.HORIZ_MARGINS - self.width
|
||||
y: root.y + root.height - root._txt_top_pad - self.height - dp(5)
|
||||
size: dp(48), dp(48)
|
||||
''')
|
||||
|
||||
|
||||
class MDList(GridLayout):
|
||||
'''ListItem container. Best used in conjunction with a
|
||||
:class:`kivy.uix.ScrollView`.
|
||||
|
||||
When adding (or removing) a widget, it will resize itself to fit its
|
||||
children, plus top and bottom paddings as described by the MD spec.
|
||||
'''
|
||||
selected = ObjectProperty()
|
||||
_min_list_height = dp(16)
|
||||
_list_vertical_padding = dp(8)
|
||||
|
||||
icon = StringProperty()
|
||||
|
||||
def add_widget(self, widget, index=0):
|
||||
super(MDList, self).add_widget(widget, index)
|
||||
self.height += widget.height
|
||||
|
||||
def remove_widget(self, widget):
|
||||
super(MDList, self).remove_widget(widget)
|
||||
self.height -= widget.height
|
||||
|
||||
|
||||
class BaseListItem(ThemableBehavior, RectangularRippleBehavior,
|
||||
ButtonBehavior, FloatLayout):
|
||||
'''Base class to all ListItems. Not supposed to be instantiated on its own.
|
||||
'''
|
||||
|
||||
text = StringProperty()
|
||||
'''Text shown in the first line.
|
||||
|
||||
:attr:`text` is a :class:`~kivy.properties.StringProperty` and defaults
|
||||
to "".
|
||||
'''
|
||||
|
||||
text_color = ListProperty(None)
|
||||
''' Text color used if theme_text_color is set to 'Custom' '''
|
||||
|
||||
font_style = OptionProperty(
|
||||
'Subhead', options=['Body1', 'Body2', 'Caption', 'Subhead', 'Title',
|
||||
'Headline', 'Display1', 'Display2', 'Display3',
|
||||
'Display4', 'Button', 'Icon'])
|
||||
|
||||
theme_text_color = StringProperty('Primary',allownone=True)
|
||||
''' Theme text color for primary text '''
|
||||
|
||||
secondary_text = StringProperty()
|
||||
'''Text shown in the second and potentially third line.
|
||||
|
||||
The text will wrap into the third line if the ListItem's type is set to
|
||||
\'one-line\'. It can be forced into the third line by adding a \\n
|
||||
escape sequence.
|
||||
|
||||
:attr:`secondary_text` is a :class:`~kivy.properties.StringProperty` and
|
||||
defaults to "".
|
||||
'''
|
||||
|
||||
secondary_text_color = ListProperty(None)
|
||||
''' Text color used for secondary text if secondary_theme_text_color
|
||||
is set to 'Custom' '''
|
||||
|
||||
secondary_theme_text_color = StringProperty('Secondary',allownone=True)
|
||||
''' Theme text color for secondary primary text '''
|
||||
|
||||
secondary_font_style = OptionProperty(
|
||||
'Body1', options=['Body1', 'Body2', 'Caption', 'Subhead', 'Title',
|
||||
'Headline', 'Display1', 'Display2', 'Display3',
|
||||
'Display4', 'Button', 'Icon'])
|
||||
|
||||
_txt_left_pad = NumericProperty(dp(16))
|
||||
_txt_top_pad = NumericProperty()
|
||||
_txt_bot_pad = NumericProperty()
|
||||
_txt_right_pad = NumericProperty(m_res.HORIZ_MARGINS)
|
||||
_num_lines = 2
|
||||
|
||||
|
||||
class ILeftBody:
|
||||
'''Pseudo-interface for widgets that go in the left container for
|
||||
ListItems that support it.
|
||||
|
||||
Implements nothing and requires no implementation, for annotation only.
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class ILeftBodyTouch:
|
||||
'''Same as :class:`~ILeftBody`, but allows the widget to receive touch
|
||||
events instead of triggering the ListItem's ripple effect
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class IRightBody:
|
||||
'''Pseudo-interface for widgets that go in the right container for
|
||||
ListItems that support it.
|
||||
|
||||
Implements nothing and requires no implementation, for annotation only.
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class IRightBodyTouch:
|
||||
'''Same as :class:`~IRightBody`, but allows the widget to receive touch
|
||||
events instead of triggering the ListItem's ripple effect
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class ContainerSupport:
|
||||
'''Overrides add_widget in a ListItem to include support for I*Body
|
||||
widgets when the appropiate containers are present.
|
||||
'''
|
||||
_touchable_widgets = ListProperty()
|
||||
|
||||
def add_widget(self, widget, index=0):
|
||||
if issubclass(widget.__class__, ILeftBody):
|
||||
self.ids['_left_container'].add_widget(widget)
|
||||
elif issubclass(widget.__class__, ILeftBodyTouch):
|
||||
self.ids['_left_container'].add_widget(widget)
|
||||
self._touchable_widgets.append(widget)
|
||||
elif issubclass(widget.__class__, IRightBody):
|
||||
self.ids['_right_container'].add_widget(widget)
|
||||
elif issubclass(widget.__class__, IRightBodyTouch):
|
||||
self.ids['_right_container'].add_widget(widget)
|
||||
self._touchable_widgets.append(widget)
|
||||
else:
|
||||
return super(BaseListItem, self).add_widget(widget,index)
|
||||
|
||||
def remove_widget(self, widget):
|
||||
super(BaseListItem, self).remove_widget(widget)
|
||||
if widget in self._touchable_widgets:
|
||||
self._touchable_widgets.remove(widget)
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
if self.propagate_touch_to_touchable_widgets(touch, 'down'):
|
||||
return
|
||||
super(BaseListItem, self).on_touch_down(touch)
|
||||
|
||||
def on_touch_move(self, touch, *args):
|
||||
if self.propagate_touch_to_touchable_widgets(touch, 'move', *args):
|
||||
return
|
||||
super(BaseListItem, self).on_touch_move(touch, *args)
|
||||
|
||||
def on_touch_up(self, touch):
|
||||
if self.propagate_touch_to_touchable_widgets(touch, 'up'):
|
||||
return
|
||||
super(BaseListItem, self).on_touch_up(touch)
|
||||
|
||||
def propagate_touch_to_touchable_widgets(self, touch, touch_event, *args):
|
||||
triggered = False
|
||||
for i in self._touchable_widgets:
|
||||
if i.collide_point(touch.x, touch.y):
|
||||
triggered = True
|
||||
if touch_event == 'down':
|
||||
i.on_touch_down(touch)
|
||||
elif touch_event == 'move':
|
||||
i.on_touch_move(touch, *args)
|
||||
elif touch_event == 'up':
|
||||
i.on_touch_up(touch)
|
||||
return triggered
|
||||
|
||||
|
||||
class OneLineListItem(BaseListItem):
|
||||
_txt_top_pad = NumericProperty(dp(16))
|
||||
_txt_bot_pad = NumericProperty(dp(15)) # dp(20) - dp(5)
|
||||
_num_lines = 1
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(OneLineListItem, self).__init__(**kwargs)
|
||||
self.height = dp(48)
|
||||
|
||||
|
||||
class TwoLineListItem(BaseListItem):
|
||||
_txt_top_pad = NumericProperty(dp(20))
|
||||
_txt_bot_pad = NumericProperty(dp(15)) # dp(20) - dp(5)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(TwoLineListItem, self).__init__(**kwargs)
|
||||
self.height = dp(72)
|
||||
|
||||
|
||||
class ThreeLineListItem(BaseListItem):
|
||||
_txt_top_pad = NumericProperty(dp(16))
|
||||
_txt_bot_pad = NumericProperty(dp(15)) # dp(20) - dp(5)
|
||||
_num_lines = 3
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(ThreeLineListItem, self).__init__(**kwargs)
|
||||
self.height = dp(88)
|
||||
|
||||
|
||||
class OneLineAvatarListItem(ContainerSupport, BaseListItem):
|
||||
_txt_left_pad = NumericProperty(dp(72))
|
||||
_txt_top_pad = NumericProperty(dp(20))
|
||||
_txt_bot_pad = NumericProperty(dp(19)) # dp(24) - dp(5)
|
||||
_num_lines = 1
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(OneLineAvatarListItem, self).__init__(**kwargs)
|
||||
self.height = dp(56)
|
||||
|
||||
|
||||
class TwoLineAvatarListItem(OneLineAvatarListItem):
|
||||
_txt_top_pad = NumericProperty(dp(20))
|
||||
_txt_bot_pad = NumericProperty(dp(15)) # dp(20) - dp(5)
|
||||
_num_lines = 2
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(BaseListItem, self).__init__(**kwargs)
|
||||
self.height = dp(72)
|
||||
|
||||
|
||||
class ThreeLineAvatarListItem(ContainerSupport, ThreeLineListItem):
|
||||
_txt_left_pad = NumericProperty(dp(72))
|
||||
|
||||
|
||||
class OneLineIconListItem(ContainerSupport, OneLineListItem):
|
||||
_txt_left_pad = NumericProperty(dp(72))
|
||||
|
||||
|
||||
class TwoLineIconListItem(OneLineIconListItem):
|
||||
_txt_top_pad = NumericProperty(dp(20))
|
||||
_txt_bot_pad = NumericProperty(dp(15)) # dp(20) - dp(5)
|
||||
_num_lines = 2
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(BaseListItem, self).__init__(**kwargs)
|
||||
self.height = dp(72)
|
||||
|
||||
|
||||
class ThreeLineIconListItem(ContainerSupport, ThreeLineListItem):
|
||||
_txt_left_pad = NumericProperty(dp(72))
|
||||
|
||||
|
||||
class OneLineRightIconListItem(ContainerSupport, OneLineListItem):
|
||||
# dp(40) = dp(16) + dp(24):
|
||||
_txt_right_pad = NumericProperty(dp(40) + m_res.HORIZ_MARGINS)
|
||||
|
||||
|
||||
class TwoLineRightIconListItem(OneLineRightIconListItem):
|
||||
_txt_top_pad = NumericProperty(dp(20))
|
||||
_txt_bot_pad = NumericProperty(dp(15)) # dp(20) - dp(5)
|
||||
_num_lines = 2
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(BaseListItem, self).__init__(**kwargs)
|
||||
self.height = dp(72)
|
||||
|
||||
|
||||
class ThreeLineRightIconListitem(ContainerSupport, ThreeLineListItem):
|
||||
# dp(40) = dp(16) + dp(24):
|
||||
_txt_right_pad = NumericProperty(dp(40) + m_res.HORIZ_MARGINS)
|
||||
|
||||
|
||||
class OneLineAvatarIconListItem(OneLineAvatarListItem):
|
||||
# dp(40) = dp(16) + dp(24):
|
||||
_txt_right_pad = NumericProperty(dp(40) + m_res.HORIZ_MARGINS)
|
||||
|
||||
|
||||
class TwoLineAvatarIconListItem(TwoLineAvatarListItem):
|
||||
# dp(40) = dp(16) + dp(24):
|
||||
_txt_right_pad = NumericProperty(dp(40) + m_res.HORIZ_MARGINS)
|
||||
|
||||
|
||||
class ThreeLineAvatarIconListItem(ThreeLineAvatarListItem):
|
||||
# dp(40) = dp(16) + dp(24):
|
||||
_txt_right_pad = NumericProperty(dp(40) + m_res.HORIZ_MARGINS)
|