Compare commits
475 Commits
Author | SHA1 | Date | |
---|---|---|---|
7e978593d2 | |||
0466115a6d | |||
5168b9e7d8 | |||
329c84a65f | |||
7c5fa5dea7 | |||
3ed262bd61 | |||
f159889f5d | |||
e1f517595d | |||
6fbe6be74e | |||
d443b99f27 | |||
b977e2b2af | |||
3dda56688c | |||
4b62576a0a | |||
5c48f3ed70 | |||
8ebf5dedd2 | |||
1d181b61a3 | |||
c5b9f668b2 | |||
cc1be262d1 | |||
ae2288a982 | |||
7e1765c26b | |||
4955986c3e | |||
aacaa528fb | |||
dc4f9a30bd | |||
a2ea4dad11 | |||
725097392a | |||
f267161c29 | |||
794cc4f3dc | |||
9373b3db93 | |||
9dfb6dc916 | |||
98c35f6f9d | |||
2f488a5daf | |||
1622f864fc | |||
08d3201cee | |||
bc996df3d8 | |||
3f5c79dd05 | |||
296b4164a7 | |||
ed260b6b37 | |||
5f1604aece | |||
7ddca4aec7 | |||
d286674cee | |||
1d96a4807b | |||
02bedad2ed | |||
1876907bac | |||
07398456c1 | |||
58414affe8 | |||
1a89871aa9 | |||
10fcedf537 | |||
c4d89faa33 | |||
a912b4aeef | |||
0b5ca8ddb3 | |||
2932427ab0 | |||
3b4625961f | |||
46d5608dfe | |||
1b44f35967 | |||
ecd758220a | |||
28e03cbf8e | |||
e51601a8bd | |||
6667b9e4cb | |||
93fe11728a | |||
c83f7c8d94 | |||
1ef8c99c43 | |||
f4bb812fd4 | |||
81963979d1 | |||
da6d73d9bf | |||
d91c4f4cf2 | |||
f3aeb9f61b | |||
20dcb4a475 | |||
0bf0fd9f27 | |||
17bfa4b260 | |||
73f1a9c31f | |||
c74c6f6f5d | |||
28e2d3df08 | |||
62914b2dfd | |||
46c1beed88 | |||
9f499b8e8f | |||
33c15d2444 | |||
7116d5c805 | |||
c4ccb4f072 | |||
fe1ac8e324 | |||
6049531de5 | |||
ed52202017 | |||
b90eb1fc8f | |||
f9a1183993 | |||
63585661ae | |||
711ec58419 | |||
bbeb80600b | |||
15d4124d89 | |||
87acd01273 | |||
8d83e51947 | |||
b19032da9b | |||
b4b977ffc5 | |||
d82d07bf2c | |||
3a87d2957a | |||
8aa7f34fd2 | |||
79f3177a60 | |||
c468147db0 | |||
c19fbf40a0 | |||
55193a958d | |||
bb92a8a8d4 | |||
e0a3b6db70 | |||
c860834f17 | |||
8544fe806e | |||
a14f648cb3 | |||
56171f94cf | |||
2e08fa5745 | |||
0afcdcc1f6 | |||
e7d71e3607 | |||
2d068cfd79 | |||
ee0c22e37c | |||
925e82e5c5 | |||
0cdfc253d2 | |||
9e6e72c0a1 | |||
63def5530f | |||
c206a40e62 | |||
2889923940 | |||
3deabdbf36 | |||
89c8e6a194 | |||
19a5216373 | |||
f274ba9caa | |||
5a36db2366 | |||
9003d3c738 | |||
d06a32311e | |||
63fb0e0ff9 | |||
4e14801db6 | |||
926db6007a | |||
cf0e001cfc | |||
ee6370bb0b | |||
33ba50a7b4 | |||
29e8b00656 | |||
ff175c0c8f | |||
a015593971 | |||
fdbf42ad1a | |||
61583447b6 | |||
33ab63c1bc | |||
5b3a013766 | |||
69f8b79fc4 | |||
60d283f931 | |||
f41dd51dc7 | |||
a7173adc22 | |||
bbef34d125 | |||
277b10b155 | |||
6a69d4eaac | |||
4d3c1cacc9 | |||
2ed26bc8d9 | |||
52e55a24fa | |||
98b85435ac | |||
3903c5630f | |||
ac7ef77a8d | |||
c80ca295c6 | |||
19a9c305ce | |||
dca7b4a694 | |||
357d18fbe0 | |||
251623acf0 | |||
4caa5a6ab0 | |||
d1b11c0630 | |||
36b25e1c9f | |||
6a2407a07c | |||
cd623065e7 | |||
2b462bfecb | |||
9353ea93c1 | |||
853cce4a66 | |||
2d944b276c | |||
b4299ef066 | |||
64799d2e14 | |||
ead54fce3f | |||
ae93efb17a | |||
d95dfb18fd | |||
4e3c397ce5 | |||
4e6126405f | |||
8cdec543e1 | |||
4810cbe138 | |||
8ec7fbb49e | |||
7d52ed8802 | |||
9d44d063eb | |||
d5eb9ed478 | |||
40afb6cdc2 | |||
74234476ab | |||
82c71a3bd8 | |||
5161e1c045 | |||
40052dbf3f | |||
e73d92754e | |||
6df1b80941 | |||
a9e5963b74 | |||
95671966cd | |||
a8ce7216e1 | |||
5c6829165b | |||
91eebfd895 | |||
72cc04342f | |||
75267294f9 | |||
f81d302c9a | |||
c3ab0406e4 | |||
fdcaf4e596 | |||
ca7b3eff29 | |||
f1eb640564 | |||
194ca2d380 | |||
976e90f0a0 | |||
2c836f473d | |||
f834b6046e | |||
e6087f3818 | |||
20c3df6be2 | |||
b914e4b548 | |||
f336489609 | |||
4ce2e88568 | |||
a917a6a9cd | |||
a01eabea91 | |||
605f0da751 | |||
6bd0c10ef2 | |||
a9032602bf | |||
8c03601bd2 | |||
afc4c0ca1f | |||
e0ee8a7040 | |||
e32336aff8 | |||
0edbba5625 | |||
eec5350926 | |||
20f0b3f782 | |||
5cf4128c49 | |||
47768acf5c | |||
f88d2177c3 | |||
9373f10d68 | |||
4f3bb6ac93 | |||
5f224a077c | |||
14cdeb0b5a | |||
b02137c216 | |||
7c90103af4 | |||
903af03d15 | |||
b57ca4d207 | |||
2fe58941ea | |||
04f734bebe | |||
a0d43ebe0e | |||
6d80dce66d | |||
3d765dd701 | |||
2b42c64160 | |||
7928131112 | |||
9cb1f9647c | |||
6d6daa60b6 | |||
81a454c29c | |||
6f245d9b7f | |||
05c001067e | |||
fea57a4034 | |||
00eebf9260 | |||
cde18c8d35 | |||
0b2c3fa96e | |||
8f631cfe4b | |||
f10b25c07f | |||
77a959fe29 | |||
d8db111d30 | |||
c2811f2818 | |||
b258a3ff9c | |||
02029d22b0 | |||
1f7f1c170d | |||
a13a4a5695 | |||
0b9dcaa8f1 | |||
9c7030f80e | |||
d8112550f5 | |||
4eb662d314 | |||
8e06ffc3b1 | |||
98c5c052de | |||
95fe0c9516 | |||
2908b1449c | |||
454b461e89 | |||
0a8d2ad233 | |||
35e34e44ee | |||
b6ce1f62e0 | |||
55eaa85979 | |||
b3f5c532dd | |||
0821565a75 | |||
d187ad43f3 | |||
b5aff6a8eb | |||
a6291b3ee2 | |||
f1f86e04e6 | |||
06898ca0af | |||
305f8317fe | |||
d7d13dd523 | |||
84dd9dbcea | |||
a345fa8874 | |||
5780d3ca21 | |||
4c220cbb36 | |||
942f9296a0 | |||
fb50f2783f | |||
a50ddd25b2 | |||
4b6d5a86b2 | |||
fbada0c4be | |||
6a8459cc4e | |||
fce9e9a73f | |||
8ab3c937b6 | |||
f8e431cc2e | |||
3f7c069ce0 | |||
21895d307b | |||
38b0eec741 | |||
2496f19bee | |||
21932dc329 | |||
35fc287d55 | |||
3a3623859b | |||
f623e78bdc | |||
2bcc14888c | |||
7bee6cf1ea | |||
eea264a099 | |||
b99d872c53 | |||
f09d1b5da1 | |||
9e3ff74b98 | |||
2e64e31a8f | |||
150f9d6c08 | |||
a6565aae53 | |||
ac268c0672 | |||
94902c661f | |||
0a90e1fe4a | |||
9f1a09689f | |||
af68d9b0cf | |||
d75b7de20b | |||
f968e618ac | |||
fb9717a00f | |||
0acdf41fa3 | |||
f5fddd0369 | |||
660f801afd | |||
da66118d20 | |||
93d1de941c | |||
94106a11c0 | |||
76f0ee3ef0 | |||
712792ac9f | |||
56424cf0d1 | |||
9230bd8115 | |||
ab0d34599f | |||
0c4ee6a033 | |||
f5b80b6e63 | |||
63f4a8310e | |||
53176a9a26 | |||
8422243465 | |||
91317b7a41 | |||
cbcc6f812a | |||
a53a3d595c | |||
d741035707 | |||
bab02110b0 | |||
1db4e10dc8 | |||
d6a87bc426 | |||
d8096a3695 | |||
0927695261 | |||
97380e9833 | |||
2c64581a2c | |||
05a00e8ce0 | |||
d056bd0bd2 | |||
fa187be88a | |||
357ccca819 | |||
993f49c0a0 | |||
3b180cda83 | |||
1a877bbfa1 | |||
c3bbd75c65 | |||
03a6e537b8 | |||
401a1480d6 | |||
5c75b2cb38 | |||
2137043c8c | |||
a919f51fc0 | |||
16d85a5a41 | |||
0ccf46456a | |||
2f20961395 | |||
f3318e0dd0 | |||
7843090907 | |||
29ceca055e | |||
076f64788a | |||
b9dca52e52 | |||
2ac306ec15 | |||
999bfae344 | |||
0994743fd8 | |||
8b0070efd4 | |||
82ed352c1d | |||
2a975123fc | |||
5d6a66dcac | |||
8c1197e8e1 | |||
6db4ba7082 | |||
609bccefe1 | |||
ff35e480f2 | |||
b32ccb48be | |||
db6c6de8e9 | |||
6f69fe2545 | |||
05a4491bb2 | |||
27334858c9 | |||
a8bdfef271 | |||
b59d64682e | |||
d3d4add5a2 | |||
fa4dd48955 | |||
dce50b226f | |||
a0aa04e036 | |||
2670bb8f6d | |||
b0642aafb7 | |||
3901a2a281 | |||
2403881a7c | |||
758907a660 | |||
70a511a141 | |||
86aa453093 | |||
be6fb7bd75 | |||
0ab5b873f1 | |||
06dbc71a1d | |||
a51b25208f | |||
cb00ff7c5d | |||
43b762dd2a | |||
ba40b74230 | |||
da9425228e | |||
2ba4233ac7 | |||
1545bf39ee | |||
ff4496be24 | |||
bf7e602e4a | |||
a66430c255 | |||
689d7bf0a9 | |||
6d1417ab73 | |||
a60edfdd37 | |||
a28c088c06 | |||
acb57bffb4 | |||
35c2e07261 | |||
14a2313e5f | |||
1f75ba41cf | |||
77109fd3cc | |||
21570ea5ec | |||
2b8ed2192b | |||
1e5cf55521 | |||
87db7ddd98 | |||
09d7bd4fae | |||
38e56254ff | |||
c5246e73ca | |||
120da86904 | |||
02f1ab0e4a | |||
9465cf03ac | |||
7168b874aa | |||
67f2eec4eb | |||
50a23afe7a | |||
d57c07affd | |||
d5c975d0b6 | |||
febf9f2c3e | |||
cfadede201 | |||
9988c4daf6 | |||
6b4feb3b91 | |||
b4625335b6 | |||
0d7bae5be8 | |||
11b4aaad6e | |||
589a7da53b | |||
71ce8597e5 | |||
7ef1ba10a9 | |||
b8df7e9603 | |||
73d2d4a95d | |||
0f68d2d0fc | |||
9083fc65d4 | |||
9604869639 | |||
0c0238ee20 | |||
0763168367 | |||
9490952d6c | |||
9a576d70e4 | |||
0530b450ce | |||
17e90c4761 | |||
200d476462 | |||
e7d1044716 | |||
44df84e286 | |||
f8738c64b7 | |||
fdfeb2a90b | |||
2804400910 | |||
9d2fc5bc6e | |||
536aea6c48 | |||
c64ca0c814 | |||
86c9ac93d5 | |||
e1f25475b1 | |||
6cd4b6c549 | |||
81f7a5f25b | |||
a10064c205 | |||
f1b9be44f4 | |||
14ca2b6687 | |||
e78dacd029 | |||
87b420e21e | |||
da3374a484 | |||
b151eed4b6 | |||
f0513c19b8 | |||
ee0219b39a | |||
a93d334b1f | |||
59803d547c | |||
8dcee29952 | |||
53d5a09fb4 | |||
acdfae1608 | |||
4442931dd4 | |||
1aeab0aef5 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*.py.bak
|
||||
*.pyc
|
||||
*~
|
||||
src/config/
|
||||
|
105
.gitlab-ci.yml
105
.gitlab-ci.yml
@@ -1,52 +1,99 @@
|
||||
# Jobs to build the two channels in Socializer.
|
||||
alpha:
|
||||
# Currently using python 3.7.7
|
||||
variables:
|
||||
PYTHON3_32: "C:\\python37-32\\python.exe"
|
||||
PYTHON3_64: "C:\\python37-64\\python.exe"
|
||||
NSIS: "C:\\nsis\\makensis.exe"
|
||||
|
||||
.configure_environment: &configure_environment
|
||||
tags:
|
||||
- windows10
|
||||
before_script:
|
||||
- '&$env:PYTHON3_32 -V'
|
||||
- '&$env:PYTHON3_32 -m pip install --upgrade pip'
|
||||
- '&$env:PYTHON3_32 -m pip install --upgrade -r requirements.txt'
|
||||
- '&$env:PYTHON3_32 -m pip uninstall enum34 -y'
|
||||
|
||||
# Create documentation in all available languages so we'll have it at http://socializer.su/documentation
|
||||
# this job is triggered on every commit to master, so we always will display the latest available version of the documentation in the website.
|
||||
documentation:
|
||||
type: deploy
|
||||
tags:
|
||||
- windows
|
||||
- windows10
|
||||
script:
|
||||
- pip install --upgrade pip
|
||||
- pip install --upgrade -r requirements.txt
|
||||
### Dependencies.
|
||||
- '&$env:PYTHON3_32 -m pip install --upgrade babel markdown'
|
||||
# generate all html documents first.
|
||||
- copy changelog.md doc\changelog.md
|
||||
- cd doc
|
||||
- python documentation_importer.py
|
||||
- '&$env:PYTHON3_32 documentation_importer.py'
|
||||
- cd ..\src
|
||||
- python ..\doc\generator.py
|
||||
- python write_version_data.py
|
||||
- python setup.py py2exe
|
||||
- cd ..
|
||||
- cd scripts
|
||||
- python prepare_zipversion.py
|
||||
- cd ..
|
||||
- move src\socializer.zip socializer.zip
|
||||
- '&$env:PYTHON3_32 ..\doc\generator.py'
|
||||
- 'move documentation ..\'
|
||||
# Update interface and documentation translation catalogs.
|
||||
- '&$env:PYTHON3_32 setup.py extract_messages -F babel.cfg --input-dirs . --output-file socializer.pot'
|
||||
- '&$env:PYTHON3_32 setup.py update_catalog --no-fuzzy-matching --domain socializer --output-dir locales --input-file socializer.pot'
|
||||
- cd ..\doc
|
||||
- '&$env:PYTHON3_32 translate.py'
|
||||
- cd ..\src
|
||||
- 'move locales ..\'
|
||||
only:
|
||||
- master
|
||||
artifacts:
|
||||
paths:
|
||||
- socializer.zip
|
||||
name: socializer
|
||||
expire_in: 1 week
|
||||
- documentation
|
||||
- locales
|
||||
name: socializer_documentation
|
||||
expire_in: 30 days
|
||||
|
||||
stable:
|
||||
alpha32:
|
||||
<<: *configure_environment
|
||||
type: deploy
|
||||
tags:
|
||||
- windows
|
||||
script:
|
||||
- pip install --upgrade pip
|
||||
- pip install --upgrade -r requirements.txt
|
||||
- copy changelog.md doc\changelog.md
|
||||
- cd doc
|
||||
- python documentation_importer.py
|
||||
- '&$env:PYTHON3_32 documentation_importer.py'
|
||||
- cd ..\src
|
||||
- python ..\doc\generator.py
|
||||
- python setup.py py2exe
|
||||
- '&$env:PYTHON3_32 ..\doc\generator.py'
|
||||
- '&$env:PYTHON3_32 write_version_data.py'
|
||||
- '&$env:PYTHON3_32 setup.py build'
|
||||
- '&$env:NSIS installer_alpha.nsi'
|
||||
- cd ..
|
||||
- move src\socializer* .
|
||||
- cd scripts
|
||||
- python prepare_zipversion.py
|
||||
- '&$env:PYTHON3_32 prepare_zipversion.py'
|
||||
- cd ..
|
||||
- move src\socializer.zip socializer.zip
|
||||
- move src\socializer.zip socializer_x86_alpha.zip
|
||||
- '&$env:PYTHON3_32 scripts/generate_update_file.py'
|
||||
- '&$env:PYTHON3_32 scripts/upload.py'
|
||||
- move socializer_x86_alpha.zip socializer_x86.zip
|
||||
only:
|
||||
- tags
|
||||
- schedules
|
||||
artifacts:
|
||||
paths:
|
||||
- socializer.zip
|
||||
name: socializer
|
||||
- socializer_x86.zip
|
||||
name: socializer_alpha
|
||||
expire_in: 1 day
|
||||
|
||||
# Generates a new stable version of the application every tag.
|
||||
stable:
|
||||
<<: *configure_environment
|
||||
type: deploy
|
||||
script:
|
||||
- copy changelog.md doc\changelog.md
|
||||
- cd doc
|
||||
- '&$env:PYTHON3_32 documentation_importer.py'
|
||||
- cd ..\src
|
||||
- '&$env:PYTHON3_32 ..\doc\generator.py'
|
||||
- '&$env:PYTHON3_32 write_version_data.py'
|
||||
- '&$env:PYTHON3_32 setup.py build'
|
||||
- '&$env:NSIS installer.nsi'
|
||||
- cd ..
|
||||
- move src\socializer* .
|
||||
- cd scripts
|
||||
- '&$env:PYTHON3_32 prepare_zipversion.py'
|
||||
- cd ..
|
||||
- move src\socializer.zip socializer_x86.zip
|
||||
- '&$env:PYTHON3_32 scripts/upload.py'
|
||||
only:
|
||||
- tags
|
15
README.md
15
README.md
@@ -6,24 +6,13 @@
|
||||
|
||||
A desktop application for handling [vk.com](http://vk.com) in an easy way.
|
||||
|
||||
## download the current build
|
||||
|
||||
Socializer's functionality is far to be perfect, in fact there are lots of methods of the VK API that this application doesn't support right now, but if you are curious enough, and you want to help by giving me your impressions and making tests for fixing bugs, you can download the last source code, compiled as an application. This is the snapshot build of socializer. This version is only for testing purposes, never think that it can be used for everyday use. This version does not include any documentation, Only the changelog, because it's build with an authomatic process.
|
||||
|
||||
Before downloading, take in to account the following: This source code is completely experimental. The current functionality in this application is not very useful. If you decide to use nightly build versions, take into account that this doesn't work as an application for everyday use yet.
|
||||
|
||||
Version: 0.16
|
||||
Build date: Dec 14 2018
|
||||
[Download socializer](https://code.manuelcortez.net/manuelcortez/socializer/-/jobs/artifacts/master/raw/socializer.zip?job=alpha)
|
||||
|
||||
I have started this effort as an open source project on Feb 13, 2016. Pull requests and bug reports are welcome.
|
||||
[See Socializer's website](http://socializer.su)
|
||||
|
||||
## dependencies not installed by PIP
|
||||
|
||||
For other dependencies, do pip install --upgrade -r requirements.txt
|
||||
|
||||
* [Python,](http://python.org) version 2.7.15
|
||||
* [PyEnchant,](http://pythonhosted.org/pyenchant/) version 1.6.6.
|
||||
* [Python,](http://python.org) version 3.7.2
|
||||
|
||||
## Documentation
|
||||
|
||||
|
185
changelog.md
185
changelog.md
@@ -1,6 +1,189 @@
|
||||
# Changelog
|
||||
|
||||
## changes in this version
|
||||
## News in this version
|
||||
|
||||
### New additions
|
||||
|
||||
* Socializer will ask for confirmation before closing the application.
|
||||
* In all audio buffers, there is a new item in the context menu that allows downloading of the audio directly from the buffer. If there are multiple audios selected, socializer will ask for a folder where all audios should be placed. When downloading multiple audios, socializer will name those automatically by following the template "song title - artist".
|
||||
* In all audio buffers, there are two new menu items for selecting and deselecting all items in the buffer.
|
||||
* Added displaying of articles as attachments in wall posts. When opened, Socializer will open the article in the web browser.
|
||||
* Starting from Version 0.24, there will be an installer for the Alpha version of socializer, always available from our downloads page.
|
||||
|
||||
### bugfixes
|
||||
|
||||
* Fixed an error that was making socializer unable to render correctly certain Links containing uppercase letters (such as yandex.disk shared links). Before, those links were giving 404 errors when pressed, now they should work normally. This error was present in wall posts, comments, topics and chat messages.
|
||||
* Fixed an error related to chat notifications in Socializer. Before, the "online now" notification could break the Socializer interface, making it unable to load the chat in real time.
|
||||
* Fixed a small inconsistency when marking a conversation as read. Before, if two messages were sent by the recipient, only the last message was marked as read and the previous was making the unread sound all the time. Now that issue should be handled properly.
|
||||
|
||||
### Changes
|
||||
|
||||
* Socializer will not be marked as Virus by most antivirus softwares due to a new build tool which is cleaner and less prone to be flagged by antivirus.
|
||||
* Socializer is distributed with the Microsoft C++ redistributable package, so everyone will be able to use the software without needing to install any extra package.
|
||||
* Replaced the underlying library we were using for spelling correction as is no longer in development. Instead, we started to use a new approach in socializer, which, in theory, should allow us to switch language for spelling correction and other benefits a bit later. For now, available languages are Russian, Ukranian, English, Polish and Spanish, but more languages can be added by request.
|
||||
* When downloading a file (such as an audio file or document), the download process should be relatively faster due to some optimizations made in the function.
|
||||
* Socializer now uses just the first name of users in typing notifications.
|
||||
* socializer should be able to inform users about common errors when sending chat messages (such as sending messages to people in the current user's blacklist or banned from VK). Later, more errors related to posts will be added.
|
||||
* The application will load up to 100 audio albums instead of the default 10.
|
||||
|
||||
## Changes in Version 0.23 (11.11.2019)
|
||||
|
||||
### New additions
|
||||
|
||||
* Socializer is now more tolerant to internet issues. When attempting to create a wall post, comment, topic or send a chat message, if the data is unable to be posted to VK, socializer will allow you to try to post it again, giving you the opportunity to edit or copy the text of the post in case you want to save it for later.
|
||||
* Switching accounts is now supported in socializer. In the application menu, there is an option called "manage accounts" which allows you to add or remove an account. Socializer will take changes after a restart of the application. In case of having multiple accounts, every time Socializer starts, you will see a dialog from where is possible to choose the account for logging in.
|
||||
* when selecting multiple audio files in audio buffers, multiple actions can be performed in all items, these actions are present in the contextual menu of the buffer (namely play, add/remove from the library and move to a different playlist). This means you can select all the audios you want and Socializer will perform the selected options in all items, making it a bit easier to operate with multiple songs.
|
||||
* Now it is possible to like and see who liked a comment when displaying it individually. This applies to comments in wall posts and topics.
|
||||
* Now it is possible to choose how many items Socializer will load in conversation buffers, from the General tab in the preferences dialog. The default value is 50 items, and the maximum value is 200.
|
||||
* There is a new tab called buffer settings, in the preferences dialog. Settings related to how many items should be loaded in certain buffer types have been moved to this tab, so it will separate better the configuration options in the application.
|
||||
* Added management of the Blacklist on VK. Users can be blocked from people buffers (friends, online, or any buffer inside friend requests). You can access the blacklist from the application menu, located in the menu bar. From there, you can unblock any previously blocked user.
|
||||
* In the new timeline dialog, it is possible to create video buffers by selecting the "video" radio button as buffer type.
|
||||
|
||||
### bugfixes
|
||||
|
||||
* Fixed an error that was causing socializer to not update the "Online friends" buffer if chat notifications were disabled.
|
||||
* Fixed an error that was making Socializer unable to attach audio files from the computer, if the file does not include correct ID3 TAGS.
|
||||
* Fixed a traceback that was being logged when attempting to load an image but cancel the dialog for attaching it.
|
||||
* Fixed an error that was making Socializer to fail when loading the newsfeed buffer, thus not loading any other buffers. This error was caused due to VK sending a new object type representing push subscriptions. The item is ignored by Socializer so it will not break the newsfeed buffer anymore.
|
||||
* Fixed an error that was making the status bar to not fit the full size of the Window. This was cutting the messages placed on it, now, all messages are displayed properly again.
|
||||
* fixed an unhandled condition when playing a song and voice message at the same time, that was potentially making Socializer to stop loading certain buffers.
|
||||
* fixed an error that was making socializer unable to parse video data, thus video buffers were impossible to be loaded.
|
||||
|
||||
### Changes
|
||||
|
||||
* Less confidential user data will be send to the logs, so it will be much safer to pass logs publicly.
|
||||
* automatic update checks will be disabled if using socializer from the source code.
|
||||
* it is possible to post in an user's wall by using the post button located next to the user, in people buffers. This applies only to online users and list of friends.
|
||||
* When displaying a profile, information about mobile and home phone is displayed in the basic information tab.
|
||||
* In wall posts, all comments, including replies, will be displayed in the same list. Before, you had to open a comment to read its replies. When a new comment is posted by the current user, the list of comments will be reloaded and new additions will be fetched and sorted properly.
|
||||
|
||||
## changes in Versions 0.21 and 0.22 (14.07.2019)
|
||||
|
||||
### New additions
|
||||
|
||||
* Added "post in groups" feature. In order to do so, you need to load the posts for the group where you want to send something. Once loaded, go to the post button in the group's wall and select whether you want to post in the group's behalf or as yourself.
|
||||
* In all audio buffers, it is possible to select individual tracks to be played together. In order to do so, you need to press space to start the selection of items. When selected, the item will emit a sound to indicate the change. Press space in all items you want to select/unselect. When you're focusing an already selected item it will play a sound to indicate that it is already selected. Once you're done with your selection, pressing enter in the list of tracks will start the playback of the list of items you have selected. This is a very experimental feature. More actions can be supported based in this selection method if it proves to be useful.
|
||||
* In conversation buffers, it is possible to display and open wall posts sent as attachments in messages.
|
||||
* In people buffers, it is possible to create a new timeline by using the context menu while focusing an user. This method will create the buffer for the selected user, as opposed to creating the buffer from the menu bar, where you have to type the username or find it in a list.
|
||||
|
||||
### bugfixes
|
||||
|
||||
* Fixed an error with two factor authentication in the recent socializer version. Now it works reliably again.
|
||||
* Fixed an error when trying to attach a photo to a wall post. The error was fixed in the [vk_api](https://github.com/python273/vk_api) module and the fix was sent to the developer of the library, so he will be able to merge it in the next version. In the meantime, socializer already includes the fix for this method, so you can upload photos to wall posts normally.
|
||||
* Fixed an error retrieving some group information for the current session.
|
||||
* When posting in a topic, links will be posted properly.
|
||||
|
||||
|
||||
### Changes
|
||||
|
||||
* the audio player module has received some improvements:
|
||||
- When there is something being played, the label of the "play" button, located in all audio buffers, will change automatically to "pause". When pressed, it will pause the song instead of starting the playback again since the beginning.
|
||||
- The last change will work also in the dialog for displaying audio information. Now it's possible to play and pause an audio from such dialog.
|
||||
- When playing a voice message, if a song is playing already socializer will decrease the volume so you can hear the voice message well enough. Some seconds after the message has finished, the song's volume will be restored.
|
||||
* In audio buffers, you will play the focused audio when pressing enter in the item, instead of opening the audio information dialog.
|
||||
* Removed some old keystrokes in socializer buffers due to better alternatives. The reason for this change is that currently you don't need to be focusing an item in a buffer for being able to use the alternative keystrokes, which makes those a better implementation.
|
||||
- Control+Enter and control+Shift+Enter: superseeded by Control+P for playing (and pausing) the currently focused audio.
|
||||
- F5 and F6: superseeded by Alt+down and up arrows for modifying volume.
|
||||
|
||||
## changes in version 0.20 (25.04.2019)
|
||||
|
||||
### New additions
|
||||
|
||||
* For users with multiple soundcards, there is a new tab in the preferences dialogue of Socializer, called sound. From there, you can define which soundcard will be used for input and output. [#25,](https://code.manuelcortez.net/manuelcortez/socializer/issues/25)
|
||||
* the audio player can seek positions in the currently playing track. You can use the menu items (located in the main menu) or use the new available keystrokes dedicated to the actions. Seeking will be made in 5 second intervals.
|
||||
* Alt+Shift+Left arrow: Seek 5 seconds backwards.
|
||||
* Alt+Shift+Right arrow: Seek 5 seconds forwards.
|
||||
* it is possible to select the language used in socializer from the preferences dialog. When changing the language, the application must be restarted for the changes to take effect.
|
||||
* A new option, called open in vk.com, has been added in the context menu for almost all objects (items in home timeline, walls, documents, people, group topics and in buffers for conversations). This option will open the selected item in the VK website.
|
||||
* when opening the list of friends added by an user, you can display the context menu from an item on the list and view the user profile, open it in VK.com, among other actions. [#8,](https://code.manuelcortez.net/manuelcortez/socializer/issues/8)
|
||||
* When displaying a post, if you press enter in the button indicating how many people liked or shared the post, Socializer will display the listt of people who have liked or shared it. You can use the context menu in the list to do certain actions. [#38,](https://code.manuelcortez.net/manuelcortez/socializer/issues/38)
|
||||
* it is possible to retrieve more items for conversation buffers. Due to API limitations, it is possible to load up to the last 600 messages for every conversation. Take into account that the process of loading more items takes some time. You will hear a message when the process is done.
|
||||
* It is possible to delete entire conversations from the buffer's tree, by using the menu key and selecting "delete conversation". The conversation will be removed from VK.
|
||||
* When loading a topic in a group, socializer will display the latest 100 messages. In order to load more messages, you will find a button that will load the previous 100 messages present in the topic, or the amount of messages not loaded yet.
|
||||
|
||||
### bugfixes
|
||||
|
||||
* All spelling dictionaries are included by default for the following languages: Russian, English, German, French, italian, Polish, spanish and Turkish. Before, some dictionaries were missing and the spelling checker was failing.
|
||||
* Fixed an error in the default configuration template used for new sessions in the application. This error was making Socializer to fail when loading any conversation buffer.
|
||||
* Fixed an error in the algorithm to detect friends disconnecting from VK. This problem was interrupting the connection with the chat server every time it was happening, thus chat server's connection should be more reliable now.
|
||||
* The audio player should behave better in situations where a song is interrupted. Before, if you pressed "next song" while the currently playing sound was interrupted due to internet connection issues, two or more songs were played at the same time.
|
||||
* The bug reporting feature works normally again.
|
||||
|
||||
### Changes
|
||||
|
||||
* Updated method for accessing audio files due to the latest changes on VK apps.
|
||||
* When changing volume of the playing audio, it will decrease or increase the volume by 2% instead of 5%.
|
||||
* Read confirmations will be sent to VK as soon as you read the message. Before, read confirmations were being sent every 3 minutes to the social network.
|
||||
|
||||
## Changes in version 0.19 (13.03.2019)
|
||||
|
||||
* Added a new buffer called documents. When loading the buffer, it will contain all documents owned by the current user. The context menu of any item will allow you to download the document to your computer or remove it from VK.
|
||||
* A new buffer, called online, has been added in the friends section. It contains friends currently connected to VK. Items in this buffer will be added as soon as new friends are online in the social network, and will be removed when friends are offline. This buffer needs a lot of testing. Please report any possible inconsistency on this method.
|
||||
* Added new options to open the config and logs folder, these options are located in the help menu and may be useful during error reporting.
|
||||
* Added experimental support to "subscribers" buffer, inside frienship requests. This shows friend requests that have been declined by the current user.
|
||||
* the message when an user is typing in conversation buffers will be announced only if the socializer window is focused.
|
||||
* In "my audios" buffer, there is a button that allows a direct audio upload from your computer. The audio will be placed in your library.
|
||||
* Added experimental support to user and community polls:
|
||||
* If the poll is already closed or the user has send a vote to the poll previously, it will display only the results of the poll.
|
||||
* Otherwise it will display a dialog from where the user can vote in the current poll.
|
||||
* Fixed an error in Socializer that was making it unable to detect unread messages properly.
|
||||
* Socializer should save all tracebacks directly to error.log instead of displaying an error message during exit. ([#27,](https://code.manuelcortez.net/manuelcortez/socializer/issues/27))
|
||||
* When displaying user profiles, fixed an error where a married person without specifing relation partner would cause an error in the program. ([#29,](https://code.manuelcortez.net/manuelcortez/socializer/issues/29))
|
||||
* Socializer will load all conversations during startup, not only conversations with unread messages.
|
||||
* Added new global keystrokes, available in the main window.
|
||||
* Alt + up/down arrows: Increase / decrease volume.
|
||||
* Alt + Left/down arrows: Play previous and next song if playing an audios buffer.
|
||||
* Control + P: Play/pause.
|
||||
* control+Shift+P: Play all.
|
||||
* Fixed an error in the audio player that was skipping the first track if you were in the last song and pressed "play next" in the menu bar or via the keystroke.
|
||||
* Chats with unread messages will be placed at the top of the chats section. When a chat buffer receives a new message, socializer will move the buffer to the first position in the chats list. This should make easier for everyone to determine which chats contain unread items. ([#24,](https://code.manuelcortez.net/manuelcortez/socializer/issues/24))
|
||||
* In dialogs for displaying posts and comments, and also in the two edit boxes present in chat buffers, it is possible to select all by pressing Control+A.
|
||||
* Now it is possible to remove friends directly from the friends buffer. There is a new option for this purpose in the context menu for the focused friend. After being removed, the person will be placed in the subscribers buffer.
|
||||
* Deleted posts will display an error message when trying to view details about those. Before, the dialog was created and left blank.
|
||||
* Improvements in audio features present in Socializer:
|
||||
* The audio search feature has received improvements: Now it is possible to indicate wether the search will be performed by title or artist, and select to sort the results by duration, popularity or date of addition to VK.
|
||||
* Now it is possible to create and delete audio albums again.
|
||||
* Fixed errors when moving songs to albums. Now everything works as expected.
|
||||
* Added documents to the list of supported files when adding attachments to a wall post or private message.
|
||||
* It is possible to enable or disable proxy from the preferences dialog. The application must be restarted for this change to take effect.
|
||||
* Fixed an error that was making Socializer unable to display the changelog properly, when opened from the help menu. ([#21](https://code.manuelcortez.net/manuelcortez/socializer/issues/21))
|
||||
* When receiving chat messages and in some other situations, socializer will display all characters properly. Before, usernames were rendered using the internal code VK uses for them, and some unicode characters were displaying their HTML representation.
|
||||
* It is possible to retrieve previous items for the home buffer and walls (current user's wall and any other timeline):
|
||||
* For the home buffer, only a limited amount of items (around 700) can be loaded, supposedly due to VK API limits.
|
||||
* For walls, all posts should be possible to be loaded, however, testing with walls containing more than 2000 posts are not performed yet.
|
||||
* Added improvements to groups:
|
||||
* It is possible to load topics, audios, videos and documents for a group. In order to do so, you need to go to the group buffer and press the menu key, or right mouse click, in the tree item representing the group. New buffers will be created inside the current group's buffer.
|
||||
* You can create or delete all buffers for groups by pressing the menu key or right mouse click in the "communities" buffer.
|
||||
* There is support for group topics. When opening them, they will be displayed as a list of posts. You can like or reply to such posts, as well as adding new posts in the topic.
|
||||
* Authentication errors should be handled gracefully by the application:
|
||||
* When there is a password change, Socializer must be reauthorized again. An error message will indicate this if the user forgot to do that. After the error, the app will be restarted, prompting the user to introduce the new data for authorizing the application.
|
||||
* If the user introduced incorrect or invalid data, Socializer will display an error and prompt the user again for valid information.
|
||||
* If there is a connection problem when opening Socializer, it will display an error and inform the user about the issue.
|
||||
|
||||
## Changes in version 0.18 (21.01.2019)
|
||||
|
||||
* Changed authentication tokens in Socializer. It is mandatory to download a fresh copy of socializer and start a new configuration for your account.
|
||||
* Stable versions of Socializer are built with Python 3. Previous versions are built with Python 2, however support for Python 2 will be dropped very soon.
|
||||
* There is an installer file for Socializer, available in our downloads page. Installed version of Socializer will be more confortable for some people.
|
||||
* For users from countries where VK is not allowed, Socializer includes a proxy to bypass country restrictions. The first time you start socializer, it will ask you whether you need a proxy or not. It is suggested to use a proxy only if you need it.
|
||||
* Now it is possible to post in someone else's wall. When viewing a timeline of an user, the "post" button will post in his/her wall. To post in your own wall, you'll need to go to the newsfeed or your own wall and press the post button.
|
||||
* If you are not allowed to post in someone's wall, the post button will not be visible.
|
||||
* A new option for deleting wall posts has been added to the context menu in newsfeed and walls (current user's wall and timelines). This option will be visible only if the current user is allowed to delete the focused post.
|
||||
* Socializer will be able to handle all users correctly. Before, if an user that was not present in the local storage system was needed, the program was displaying "no specified user". ([#17,](https://code.manuelcortez.net/manuelcortez/socializer/issues/17))
|
||||
* It is possible to use user domains (short names for users) to create timelines. Just write @username and the program will create the needed timeline, regardless if the user is present in your friend list. ([#18,](https://code.manuelcortez.net/manuelcortez/socializer/issues/18))
|
||||
* When displaying someone's profile, the dialog should be loaded dramatically faster than before. A message will be spoken when all data of the profile is loaded.
|
||||
* When opening a timeline, if the current user is not allowed to do it, an error message should be displayed and the buffer will not be created. Before the buffer was partially created in the main window. ([#22.](https://code.manuelcortez.net/manuelcortez/socializer/issues/22))
|
||||
* Added basic support to handle group chats. At the current moment it is possible to receive and reply to chat messages only. Chat groups will be placed inside the conversations section. ([#23.](https://code.manuelcortez.net/manuelcortez/socializer/issues/23))
|
||||
* It is possible to delete a conversation buffer from the buffer menu. Deleting a conversation will only dismiss the buffer, no data is deleted at VK.
|
||||
* During the first start of Socializer, an invitation will be shown to join the Socializer's group in case the current user is not already a member.
|
||||
* It is possible to see how many people has read a wall post when showing it in the dialog. ([#28.](https://code.manuelcortez.net/manuelcortez/socializer/issues/28))
|
||||
* A new tab has been added to the preferences dialog. From the new section, it is possible to control whether socializer should create buffers for the first 1000 audio albums, video albums and communities when starting.
|
||||
* Added functionality regarding comments in wall posts:
|
||||
* when reading a post, you can press enter in any comment to display a dialog from where it is possible to view attachments, translate, check spelling or reply to the thread. If there are replies made to this comment, these will be visible in a section called replies. Pressing enter in a reply will also open the same dialog.
|
||||
* A new "replies" field has been added to the comments' list.
|
||||
* When writing a comment, it is possible to do the same actions available for a post (translate, spell checking and adding attachments).
|
||||
|
||||
## Changes in version 0.17 (01.01.2019)
|
||||
|
||||
* Added support for Two factor authentication (2FA). ([#13,](https://code.manuelcortez.net/manuelcortez/socializer/issues/13))
|
||||
* Added update channels in socializer. You can subscribe to the "stable" or "alpha" channel from the preferences dialog and you will receive updates published for those:
|
||||
|
@@ -1,2 +0,0 @@
|
||||
Manuel Cortéz
|
||||
Valeria K
|
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from codecs import open
|
||||
""" This script converts the hold documentation (saved in markdown files) in a python file with a list of strings to translate it using gettext."""
|
||||
|
||||
def prepare_documentation_in_file(fileSource, fileDest):
|
||||
@@ -6,16 +7,16 @@ def prepare_documentation_in_file(fileSource, fileDest):
|
||||
@fileSource str: A markdown(.md) file.
|
||||
@fileDest str: A file where this will put the new strings"""
|
||||
|
||||
f1 = open(fileSource, "r")
|
||||
f2 = open(fileDest, "w")
|
||||
f1 = open(fileSource, "r", encoding="utf-8")
|
||||
f2 = open(fileDest, "w", encoding="utf-8")
|
||||
lns = f1.readlines()
|
||||
f2.write("# -*- coding: utf-8 -*-\n")
|
||||
f2.write("documentation = [\n")
|
||||
for i in lns:
|
||||
if "\n" == i:
|
||||
newvar = "\"\","
|
||||
if "\n" == i or i.splitlines()[0] == "":
|
||||
newvar = "\"\",\n"
|
||||
elif "\n" == i[-1]:
|
||||
newvar = "_(u\"\"\"%s\"\"\"),\n" % (i[:-1])
|
||||
newvar = "_(u\"\"\"%s\"\"\"),\n" % (i.splitlines()[0])
|
||||
else:
|
||||
newvar = "_(u\"\"\"%s\"\"\"),\n" % (i)
|
||||
f2.write(newvar)
|
||||
@@ -23,5 +24,6 @@ def prepare_documentation_in_file(fileSource, fileDest):
|
||||
f2.write("]")
|
||||
f2.close()
|
||||
|
||||
|
||||
prepare_documentation_in_file("manual.md", "strings.py")
|
||||
prepare_documentation_in_file("changelog.md", "changelog.py")
|
@@ -1,31 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import markdown
|
||||
import gettext
|
||||
import os
|
||||
import locale
|
||||
import markdown
|
||||
import shutil
|
||||
from codecs import open as _open
|
||||
import languageHandler
|
||||
languageHandler.setLanguage("en")
|
||||
import strings
|
||||
import changelog
|
||||
from importlib import reload
|
||||
|
||||
# the list of supported language codes
|
||||
languages = ["en", "es"]
|
||||
def change_language(name, language):
|
||||
global _
|
||||
os.environ["lang"] = language
|
||||
_ = gettext.install(name, os.path.join(os.getcwd(), "locales"))
|
||||
|
||||
languages = ["en", "ru"]
|
||||
|
||||
def generate_document(language, document_type="documentation"):
|
||||
reload(languageHandler)
|
||||
translation_file = "socializer-documentation"
|
||||
change_language(translation_file, language)
|
||||
if document_type == "documentation":
|
||||
translation_file = "socializer-documentation"
|
||||
languageHandler.setLanguage(language, translation_file)
|
||||
reload(strings)
|
||||
markdown_file = markdown.markdown("\n".join(strings.documentation[1:]), extensions=["markdown.extensions.toc"])
|
||||
title = strings.documentation[0]
|
||||
title = strings.documentation[0][1:]
|
||||
filename = "manual.html"
|
||||
elif document_type == "changelog":
|
||||
translation_file = "socializer-changelog"
|
||||
languageHandler.setLanguage(language, translation_file)
|
||||
reload(changelog)
|
||||
markdown_file = markdown.markdown("\n".join(changelog.documentation[1:]), extensions=["markdown.extensions.toc"])
|
||||
title = changelog.documentation[0]
|
||||
title = changelog.documentation[0][1:]
|
||||
filename = "changelog.html"
|
||||
first_html_block = """<!doctype html>
|
||||
<html lang="%s">
|
||||
@@ -56,4 +56,7 @@ def create_documentation():
|
||||
generate_document(i, "changelog")
|
||||
print("Done")
|
||||
|
||||
change_language("socializer-documentation", "en")
|
||||
import strings
|
||||
import changelog
|
||||
create_documentation()
|
@@ -1,176 +0,0 @@
|
||||
import __builtin__
|
||||
import os
|
||||
import sys
|
||||
import ctypes
|
||||
import locale
|
||||
import gettext
|
||||
#import paths
|
||||
import platform
|
||||
|
||||
# A fix for the mac locales
|
||||
if platform.system() != 'Windows':
|
||||
if locale.getlocale()[0] is None:
|
||||
locale.setlocale(locale.LC_ALL, 'en_US')
|
||||
|
||||
#a few Windows locale constants
|
||||
LOCALE_SLANGUAGE=0x2
|
||||
LOCALE_SLANGDISPLAYNAME=0x6f
|
||||
|
||||
curLang="en"
|
||||
|
||||
def localeNameToWindowsLCID(localeName):
|
||||
"""Retreave the Windows locale identifier (LCID) for the given locale name
|
||||
@param localeName: a string of 2letterLanguage_2letterCountry or or just 2letterLanguage
|
||||
@type localeName: string
|
||||
@returns: a Windows LCID
|
||||
@rtype: integer
|
||||
"""
|
||||
#Windows Vista is able to convert locale names to LCIDs
|
||||
func_LocaleNameToLCID=getattr(ctypes.windll.kernel32,'LocaleNameToLCID',None)
|
||||
if func_LocaleNameToLCID is not None:
|
||||
localeName=localeName.replace('_','-')
|
||||
LCID=func_LocaleNameToLCID(unicode(localeName),0)
|
||||
else: #Windows doesn't have this functionality, manually search Python's windows_locale dictionary for the LCID
|
||||
localeName=locale.normalize(localeName)
|
||||
if '.' in localeName:
|
||||
localeName=localeName.split('.')[0]
|
||||
LCList=[x[0] for x in locale.windows_locale.iteritems() if x[1]==localeName]
|
||||
if len(LCList)>0:
|
||||
LCID=LCList[0]
|
||||
else:
|
||||
LCID=0
|
||||
return LCID
|
||||
|
||||
def getLanguageDescription(language):
|
||||
"""Finds out the description (localized full name) of a given local name"""
|
||||
desc=None
|
||||
if platform.system() == "Windows":
|
||||
LCID=localeNameToWindowsLCID(language)
|
||||
if LCID!=0:
|
||||
buf=ctypes.create_unicode_buffer(1024)
|
||||
if '_' not in language:
|
||||
res=ctypes.windll.kernel32.GetLocaleInfoW(LCID,LOCALE_SLANGDISPLAYNAME,buf,1024)
|
||||
else:
|
||||
res=0
|
||||
if res==0:
|
||||
res=ctypes.windll.kernel32.GetLocaleInfoW(LCID,LOCALE_SLANGUAGE,buf,1024)
|
||||
desc=buf.value
|
||||
elif platform.system() == "Linux" or not desc:
|
||||
desc={
|
||||
"am":pgettext("languageName","Amharic"),
|
||||
"an":pgettext("languageName","Aragonese"),
|
||||
"es":pgettext("languageName","Spanish"),
|
||||
"pt":pgettext("languageName","Portuguese"),
|
||||
"ru":pgettext("languageName","Russian"),
|
||||
"it":pgettext("languageName","italian"),
|
||||
"tr":pgettext("languageName","Turkey"),
|
||||
"gl":pgettext("languageName","Galician"),
|
||||
"ca":pgettext("languageName","Catala"),
|
||||
"eu":pgettext("languageName","Vasque"),
|
||||
"pl":pgettext("languageName","polish"),
|
||||
"ar":pgettext("languageName","Arabic"),
|
||||
"ne":pgettext("languageName","Nepali"),
|
||||
"sr":pgettext("languageName","Serbian (Latin)"),
|
||||
}.get(language,None)
|
||||
return desc
|
||||
|
||||
def getAvailableLanguages():
|
||||
"""generates a list of locale names, plus their full localized language and country names.
|
||||
@rtype: list of tuples
|
||||
"""
|
||||
#Make a list of all the locales found in NVDA's locale dir
|
||||
l=[x for x in os.listdir("locales") if not x.startswith('.')]
|
||||
l=[x for x in l if os.path.isfile('locales/%s/LC_MESSAGES/twblue-documentation.mo' % x)]
|
||||
#Make sure that en (english) is in the list as it may not have any locale files, but is default
|
||||
if 'en' not in l:
|
||||
l.append('en')
|
||||
l.sort()
|
||||
#For each locale, ask Windows for its human readable display name
|
||||
d=[]
|
||||
for i in l:
|
||||
desc=getLanguageDescription(i)
|
||||
label="%s, %s"%(desc,i) if desc else i
|
||||
d.append(label)
|
||||
#include a 'user default, windows' language, which just represents the default language for this user account
|
||||
l.append("system")
|
||||
# Translators: the label for the Windows default NVDA interface language.
|
||||
d.append(_("User default"))
|
||||
#return a zipped up version of both the lists (a list with tuples of locale,label)
|
||||
return zip(l,d)
|
||||
|
||||
def makePgettext(translations):
|
||||
"""Obtaina pgettext function for use with a gettext translations instance.
|
||||
pgettext is used to support message contexts,
|
||||
but Python 2.7's gettext module doesn't support this,
|
||||
so NVDA must provide its own implementation.
|
||||
"""
|
||||
if isinstance(translations, gettext.GNUTranslations):
|
||||
def pgettext(context, message):
|
||||
message = unicode(message)
|
||||
try:
|
||||
# Look up the message with its context.
|
||||
return translations._catalog[u"%s\x04%s" % (context, message)]
|
||||
except KeyError:
|
||||
return message
|
||||
else:
|
||||
def pgettext(context, message):
|
||||
return unicode(message)
|
||||
return pgettext
|
||||
|
||||
def setLanguage(lang, translation_file="socializer-documentation"):
|
||||
system = platform.system()
|
||||
global curLang
|
||||
try:
|
||||
if lang=="system":
|
||||
if system == "Windows":
|
||||
windowsLCID=ctypes.windll.kernel32.GetUserDefaultUILanguage()
|
||||
localeName=locale.windows_locale[windowsLCID]
|
||||
else:
|
||||
localeName=locale.getlocale()[0]
|
||||
trans=gettext.translation(translation_file, localedir="locales", languages=[localeName])
|
||||
curLang=localeName
|
||||
else:
|
||||
trans=gettext.translation(translation_file, localedir="locales", languages=[lang])
|
||||
curLang=lang
|
||||
localeChanged=False
|
||||
#Try setting Python's locale to lang
|
||||
try:
|
||||
locale.setlocale(locale.LC_ALL, lang)
|
||||
localeChanged=True
|
||||
except:
|
||||
pass
|
||||
if not localeChanged and '_' in lang:
|
||||
#Python couldn'tsupport the language_country locale, just try language.
|
||||
try:
|
||||
locale.setlocale(locale.LC_ALL, lang.split('_')[0])
|
||||
except:
|
||||
pass
|
||||
#Set the windows locale for this thread (NVDA core) to this locale.
|
||||
if system == "Windows":
|
||||
LCID=localeNameToWindowsLCID(lang)
|
||||
ctypes.windll.kernel32.SetThreadLocale(LCID)
|
||||
except IOError:
|
||||
trans=gettext.translation(translation_file,fallback=True)
|
||||
curLang="en"
|
||||
trans.install(unicode=True)
|
||||
# Install our pgettext function.
|
||||
__builtin__.__dict__["pgettext"] = makePgettext(trans)
|
||||
|
||||
def getLanguage():
|
||||
return curLang
|
||||
|
||||
def normalizeLanguage(lang):
|
||||
"""
|
||||
Normalizes a language-dialect string in to a standard form we can deal with.
|
||||
Converts any dash to underline, and makes sure that language is lowercase and dialect is upercase.
|
||||
"""
|
||||
lang=lang.replace('-','_')
|
||||
ld=lang.split('_')
|
||||
ld[0]=ld[0].lower()
|
||||
#Filter out meta languages such as x-western
|
||||
if ld[0]=='x':
|
||||
return None
|
||||
if len(ld)>=2:
|
||||
ld[1]=ld[1].upper()
|
||||
return "_".join(ld)
|
||||
|
@@ -1,18 +1,17 @@
|
||||
Socializer's manual
|
||||
# Socializer's manual
|
||||
|
||||
## Introduction
|
||||
|
||||
Socializer is an application to use [VK.com](https://vk.com) in an easy and accessible way with minimal CPU resource usage. Socializer will allow you to interact with the VK social network by giving you access to the most relevant features such as:
|
||||
|
||||
* Basic post creation in your wall (including photos).
|
||||
* (limited) audio support. (*)
|
||||
* Supports two factor authentication (2FA).
|
||||
* Post creation in user and community walls.
|
||||
* audio support.
|
||||
* Post comments.
|
||||
* like, unlike and repost other's posts.
|
||||
* Open other's timelines so you could track their friends, posts or audio files.
|
||||
* Open other's timelines so you could track their friends, posts, audio or video files.
|
||||
* Basic chat features.
|
||||
|
||||
\* Audio support in socializer is limited due to the restrictions VK has decided to apply for third party applications on december 2016.
|
||||
|
||||
## Usage
|
||||
|
||||
In order to use socializer, you must have an account in the [VK](https://vk.com) website. The process for registering an account is very accessible and is not covered in this manual. In the documentation, it is assumed you have a registered account on VK and you are able to sign in in the website by providing your phone number or email address, and a password. You will require this data for signing in the application later.
|
||||
@@ -21,7 +20,11 @@ In order to use socializer, you must have an account in the [VK](https://vk.com)
|
||||
|
||||
First of all, it's necessary to authorise the application so it can access your VK account and act on your behalf. The authorisation process is quite simple, and will be required only once. In order to start the authorisation process, you just need to run the executable file called "socializer.exe" (on some computers it will appear only as socializer, depending if windows explorer is set to display file extensions or not). You may like to place a Windows shortcut in your desktop for an easier access to the application.
|
||||
|
||||
If this is the first time you have launched socializer, you will see a message dialog asking you to proceed with the account authorisation process. It consists in providing the authentication data you normally use to sign in VK. It is very important to know that this data will be stored in a folder called config, located in the same folder where are the socializer files. Your config folder is a very important storage for your authentication data, so you must be sure you never will share it with anyone, mostly because your data is stored as plain text (this will be fixed in a future release and your data will be properly encrypted). Socializer will need your authentication data for acting in your behalf and offering you a better experience that what it could do with a simple access token. You must provide your phone number or email address in the first text box, and your password in the second. When pressing OK, your data will be saved and the application will start to retrieve all the required information for showing your buffers.
|
||||
If this is the first time you have launched socializer, you will see a message asking you whether socializer should connect through a proxy server, already configured in the application, or use the system network settings. This allows people from countries where VK is blocked to use the social network without having to look for a proxy server themselves. It is highly adviced to use the proxy server only if you are in need of it.
|
||||
|
||||
After the proxy message, you will see a new message dialog asking you to proceed with the account authorisation process. It consists in providing the authentication data you normally use to sign in VK. It is very important to know that this data will be stored in a folder called config, located in the same folder where the socializer files are. Your config folder is a very important storage for your authentication data, so you must be sure you never will share it with anyone, mostly because your data is stored as plain text (this will be fixed in a future release and your data will be properly encrypted). Socializer will need your authentication data for acting in your behalf and offering you a better experience that what it could do with a simple access token. You must provide your phone number or email address in the first text box, and your password in the second. When pressing OK, your data will be saved and the application will start to retrieve all the required information for showing your buffers. If you have two factor authentication configured in your account, you will see an additional dialog where you have to type the code provided by VK via SMS.
|
||||
|
||||
It is worth saying that whenever you change your password in the VK website, you will need to authorize Socializer again. When you open socializer after changing your password, you will see a message informing you of the problem and the application will be restarted, allowing you to write your new data and start the authorization again.
|
||||
|
||||
Once started, the application will start loading your data (posts, audio files, conversations, friends). When done, it will show you a notification indicating that the program is ready.
|
||||
|
||||
@@ -31,12 +34,12 @@ Before starting to describe Socializer's usage, we'll explain some concepts that
|
||||
|
||||
### Buffer
|
||||
|
||||
A buffer is a list of items that will manage the data which arrives from VK, after being processed by the application. When you configure your account on Socializer and start it, many buffers are created. Each of them may contain some of the items which this program works with: Newsfeed posts, wall posts, audio and video files, friendship requests and conversations. According to the buffer you are focusing, you will be able to do different actions with these items.
|
||||
A buffer is a list of items that will manage the data which arrives from VK, after being processed by the application. When you configure your account on Socializer and start it, many buffers are created. Each of them may contain some of the items which this program works with: Newsfeed posts, wall posts, audio and video files, documents, friendship requests and conversations. According to the buffer you are focusing, you will be able to do different actions with these items.
|
||||
|
||||
All buffers will be updated in one of the following ways:
|
||||
|
||||
* Periodically: Most buffers containing posts, audio or video files and people, will be updated periodically to reflect the new additions to them. Updates will be every 2 minutes for every buffer, so if you posted something and did not see the post in the buffer, you may need to wait a moment. There is an option, located in the buffer menu on the menu bar, which allows you to trigger a manual update in the current buffer.
|
||||
* Real time: Conversation buffers will be updated every time someone sends a message to you. When an user sends you a message, if there is not a conversation buffer created to receive the message, a new conversation buffer will be opened automatically and the message will be placed on it. If you already have an opened conversation for the user sending the message, the message will be placed at the end of the buffer. A different sound will indicate whether a new conversation has been opened or an existing buffer gets updated.
|
||||
* Real time: Conversation buffers will be updated every time someone sends a message to you. When an user sends you a message, if there is not a conversation buffer created to receive the message, a new conversation buffer will be opened automatically and the message will be placed on it. If you already have an opened conversation for the user sending the message, the message will be placed at the end of the buffer. A different sound will indicate whether a new conversation has been opened or an existing buffer gets updated. Socializer will sort conversation buffers by placing buffers with unread messages at the top of the conversations section. When a buffer gets a new message, it will be moved automatically to the first place in the conversations category.
|
||||
|
||||
### item
|
||||
|
||||
@@ -44,11 +47,11 @@ An item is an element representing some data provided by VK. Items are separated
|
||||
|
||||
The following is a brief description of the kind of items socializer can work with, and what actions are available for those.
|
||||
|
||||
* Newsfeed post: It represents a post displayed in your "home" page on VK. It may contain a variety of information based in what you or your friends do. A newsfeed item may contain information about new audios added to your friend's library, new people added to friends, wall posts, reposts and new photos added. Depending on the kind of data VK has supplied, the item can open a dialog showing information about the post, a list displaying the people added to friends, or a dialog displaying information for every audio added to library. Take into account that it is not possible to play an audio item from the newsfeed buffer due to limits placed by VK, however, you may add it to your library and play it from your "my music" folder. If a wall post contains a long message, the first 140 characters will be displayed only. You can open the post to read the full message in the dialog. Available options for this item are different depending in the information the item contains. You can open or view the profile of the user that generated the item, like, dislike or add a comment to a post.
|
||||
* Wall post: Represent a post in an user's wall. This posts will be similar to wall posts displayed in the newsfeed. If a wall post contains a long message, the first 140 characters will be displayed only. You can open the post to read the full message in the dialog. When opened (by pressing enter or the open option in the associated menu), it will show a dialogue where you can read the message, see and interact with attachment files (by searching the list and pressing enter in the focused attachment to open it), see the photos included in the post, read information related to likes and times the post has been shared, and read all comments. Additionally, you can share the post, indicate you like it, or add a comment. You can cycle through every item in the dialog by pressing tab.
|
||||
* Audio: It represent an audio uploaded to the VK'S platform. Actions available for this item are only opening the audio in a dialog and play it due to limitations in access to audio features. When opened, it will be displayed in a dialog allowing you to read the title of the song, artist name, duration and a few buttons: play and download. You can control playback of audio items from the buffer by using the player menu on the menu bar.
|
||||
* Video: It represent a video uploaded to the VK'S platform. Actions available for this item are opening the video in your default web browser and move it to a video album. When opened, it will open a web browser and play the video automatically due to VK limitations in access to video files.
|
||||
* person: It contains information about a VK user, this item is present in all buffers under the "people" category. Actions available for this item are view user profile, send message and create a timeline, which is a special buffer to track all posts, friends or audios owned by the user. When opened, it will display the profile of this user in a dialog and will provide actions to send a message to the user, or view other sections of her/his profile.
|
||||
* Newsfeed post: It represents a post displayed in your "home" page on VK. It may contain a variety of information based in what you or your friends do. A newsfeed item may contain information about new audios added to your friend's library, new people added to friends, wall posts, reposts and new photos added. Depending on the kind of data VK has supplied, the item can open a dialog showing information about the post, a list displaying the people added to friends, or a dialog displaying information for every audio added to library. If a wall post contains a long message, only the first 140 characters will be displayed. You can open the post to read the full message in the dialog. Available options for this item are different depending in the information the item contains. You can open or view the profile of the user that generated the item, like, dislike or add a comment to a post.
|
||||
* Wall post: Represents a post in an user's wall. This post will be similar to wall posts displayed in the newsfeed. If a wall post contains a long message, only the first 140 characters will be displayed. You can open the post to read the full message in the dialog. When opened (by pressing enter or the open option in the associated menu), it will show a dialogue where you can read the message, see how many times the post has been viewed by other users, interact with attachment files (by searching the list and pressing enter in the focused attachment to open it), see the photos included in the post, read information related to likes and times the post has been shared, read and reply to comments. Additionally, you can share the post, indicate you like it, or add a comment. You can cycle through every item in the dialog by pressing tab.
|
||||
* Audio: It represents an audio uploaded to the VK'S platform. Actions available for this item are opening the audio in a dialog, add or remove it from your library, move the audio to a playlist, and play it. When opened, it will be displayed in a dialog allowing you to read the title of the song, artist name, duration and a few buttons: play, add or remove from your library and download. You can control playback of audio items from the buffer by using the player menu on the menu bar or the corresponding keyboard shortcuts. Additionally, it is possible to select multiple audios in the same buffer to perform specific actions on them, such as play, remove or add the selected audios to a playlist. In order to select multiple audios, press the spacebar in every audio item you want to select. You will hear a sound when an item is selected, and when you focus a selected audio. When you're done, press enter to play all the selected audios or use the context menu to see available actions. All actions will be applied in the selected audios.
|
||||
* Video: It represents a video uploaded to the VK'S platform. Actions available for this item are opening the video in your default web browser and move it to a video album. When opened, it will open a web browser and play the video automatically due to VK limitations in access to video files.
|
||||
* person: It contains information about a VK user, this item is present in all buffers under the "people" category. Actions available for this item are view user profile, send message and create a timeline, which is a special buffer to track all posts, friends, audios or videos owned by the user. When opened, it will display the profile of this user in a dialog and will provide actions to send a message to the user, or view other sections of her/his profile.
|
||||
* Message: A message appears only in conversation buffers and represents a chat message. It may include a list of attached files that will be displayed in a separated list. You can tab to that list (from the history) and press enter in the attached file you want to open. Chat items are marked as read automatically as soon as they are focused.
|
||||
|
||||
## Main interface
|
||||
@@ -56,8 +59,8 @@ The following is a brief description of the kind of items socializer can work wi
|
||||
The graphical user interface of Socializer consists of a window containing:
|
||||
|
||||
* a menu bar accomodating five menus (application, Me, buffer, player and help),
|
||||
* One tree view,
|
||||
* One list of items
|
||||
* One tree view, where you can press the menu key or right mouse click to display a context menu which contains actions you can apply in the selected buffer,
|
||||
* One list of items, which also accepts the menu key to display actions available for the selected item,
|
||||
* Some buttons, depending which is the focused buffer.
|
||||
|
||||
The actions that are available for every item will be described later.
|
||||
@@ -66,21 +69,24 @@ In summary, the GUI contains two core components. These are the controls you wil
|
||||
|
||||
### Buttons in the application
|
||||
|
||||
* Post: this button opens up a dialogue box to write a post in your wall. For the moment, only posting in your own wall is supported. You can upload a picture by pressing the "attach" button and the photo button in the dialog which will appear, check spelling or translate your message by selecting one of the available buttons in the dialogue box. In addition, you can tag a friend in your post by pressing the corresponding button for that purpose. Also it is possible to configure the privacy settings for your post by allowing all users or just your friends to read it. Press the send button to send the post.
|
||||
* Post: this button opens up a dialogue box to write a post in the wall of the focused user. For example, if you are in the "my wall" buffer you will send a post to your own wall, but if you are in an user timeline the post will be sent to the owner of the timeline. You can upload an attachment by pressing the "attach" button and choosing between uploading a photo, audio file or document in the dialog which will appear, check spelling or translate your message by selecting one of the available buttons in the dialogue box. In addition, you can tag a friend in your post by pressing the corresponding button for that purpose. Also it is possible to configure the privacy settings for your post by allowing all users or just your friends to read it. Press the send button to send the post.
|
||||
* Load buffer: Some buffers are created but not loaded in VK. These special buffers need to be loaded manually by pressing the load button. Once loaded, this kind of buffers will behave in the same way other buffers do. Examples of these buffers are audio and video albums, community walls, and the current user's documents
|
||||
* Play: In audio buffers, plays the focused song. In video buffers, this button will open a web browser for playing the focused video, due to a limitation VK placed to third party developers with videos.
|
||||
* Play all: In audio buffers, play all songs starting from the focused buffer, until the last item in the list.
|
||||
* Send message: Send a message to a friend, which will open a conversation buffer if it does not exist already. Conversation buffers contain a full conversation, accommodating chat messages, between the current user and someone else. You can type your message in the provided box and press enter to send it to your friend. Additionally, you can add an attachment (for the moment, only attaching an audio file from your library is supported) and open attachments sent in the focused message by pressing tab and finding them in the attachments list.
|
||||
* Send message: Send a message to a friend, which will open a conversation buffer if it does not exist already. Conversation buffers contain a full conversation, accommodating chat messages, between the current user and someone else. You can type your message in the provided box and press enter to send it to your friend. Additionally, You can upload an attachment by pressing the "attach" button and choosing between uploading a photo, audio file or record a voice message in the dialog which will appear, and open attachments sent in the focused message by pressing tab and finding them in the attachments list.
|
||||
|
||||
Bear in mind that buttons will appear according to which actions are possible on the list you are browsing.
|
||||
|
||||
## Menus
|
||||
|
||||
Visually, Towards the top of the main application window, can be found a menu bar which contains many of the same functions as listed in the previous section, together with some additional items. To access the menu bar, press the alt key. You will find five menus listed: application, Me, buffer, player and help. This section describes the items on each one of them.
|
||||
Visually, Towards the top of the main application window, A menu bar can be found which contains many of the same functions as listed in the previous section, together with some additional items. To access the menu bar, press the alt key. You will find five menus listed: application, Me, buffer, player and help. This section describes the items on each one of them.
|
||||
|
||||
### Application menu
|
||||
|
||||
* Create: opens a menu where you can create a new album. At the moment, only video albums are supported.
|
||||
* Delete: opens a menu where you can delete an already existing album owned by yourself. Only video albums are supported at this time.
|
||||
* Create: opens a menu where you can create a new album. At the moment, only audio and video albums are supported.
|
||||
* Delete: opens a menu where you can delete an already existing album owned by yourself. Only audio and video albums are supported at this time.
|
||||
* blacklist: Opens a dialog which allows you to manage blocked people on VK.
|
||||
* Manage accounts: Opens up a dialogue from where you are able to add or delete an account in socializer. If you have more than an account, you will be asked at startup for the account you want to use in the application. You can use an account at once, but it is possible to have multiple accounts and switch between them by restarting the application.
|
||||
* Preferences: Opens a dialogue which lets you configure settings for the entire application.
|
||||
|
||||
### Me menu
|
||||
@@ -88,14 +94,15 @@ Visually, Towards the top of the main application window, can be found a menu ba
|
||||
* Profile: Opens a menu with several options to do in your profile:
|
||||
* View profile: Displays your profile in a dialog in the application.
|
||||
* Open in browser: Redirects you to your profile in vk.com.
|
||||
* Set status message: Opens up a dialog where you can write your status message. The status message is displayed in your profile and can contain up to 140 characters.
|
||||
|
||||
### Buffer menu
|
||||
|
||||
* New timeline: Lets you open a user's timeline by choosing the user in a dialog box. You can choose which items you want to track: wall posts, friends or audio items. It is created when you press enter. If you invoke this option relative to a user that has no items of the kind you specified, the operation will fail. If you try creating an existing timeline the program will warn you and will not create it again.
|
||||
* New timeline: Lets you open an user's timeline by choosing the user in a dialog box. You can choose which items you want to track: wall posts, videos, friends or audio items. It is created when you press enter. If you invoke this option relative to a user that has no items of the kind you specified, the operation will fail. If you try creating an existing timeline the program will warn you and will not create it again.
|
||||
* Search: Shows a menu where you can search for audios or videos on VK. Search results will be created in a new buffer inside "music" or "videos".
|
||||
* Update buffer: Performs a manual update operation in the buffer, which will retrieve all new items present in the social network since the last update.
|
||||
* Load previous items: This allows more items to be loaded for the specified buffer. Bear in mind that not all buffers support this setting.
|
||||
* Destroy: dismisses the list you're on, if possible.
|
||||
* Remove buffer: dismisses the list you're on, if possible.
|
||||
|
||||
### Player menu
|
||||
|
||||
@@ -115,14 +122,46 @@ Visually, Towards the top of the main application window, can be found a menu ba
|
||||
* Documentation: opens up this file, where you can read some useful program concepts.
|
||||
* Check for updates: every time you open the program it automatically checks for new versions. If an update is available, it will ask you if you want to download the update. If you accept, the updating process will commence. When complete, Socializer will be restarted. This item checks for new updates without having to restart the application.
|
||||
* Changelog: opens up a document with the list of changes from the current version to the earliest.
|
||||
* Open logs directory: Opens windows explorer in the logs directory, useful to include your logs in a bug report.
|
||||
* Open config directory: Opens Windows explorer in your config directory.
|
||||
* Report an error: opens up a dialogue box to report a bug by completing a small number of fields. Pressing enter will send the report. If the operation doesn't succeed the program will display a warning.
|
||||
|
||||
## Keyboard shortcuts
|
||||
|
||||
Socializer includes some keyboard shortcuts, available from any buffer. Here you have the list of the available shortcuts:
|
||||
|
||||
* Enter: Execute the default action for the focused item. It may be opening a post, view friends added by someone else, view audio details or opening an user profile. You need to be in the items list for using this key.
|
||||
* Alt+Up/down: Increase and decrease audio volume by 5%.
|
||||
* Control+P: Play/pause. If this is the firt time you press this keystroke, it will automatically play all items present in the focused buffer or in your audios.
|
||||
* control+Shift+P: Play all audio tracks. If the currently focused buffer does not contain audio items, it will play all items present in your audios buffer.
|
||||
* Alt+Left: Play the previous song.
|
||||
* Alt+Right: Play the next song.
|
||||
|
||||
## configuration
|
||||
|
||||
### The general tab
|
||||
As described above, this application has a preferences dialogue accessible under the application menu. Here you have a brief description of the settings present in this dialogue.
|
||||
|
||||
### The chats tab
|
||||
### General tab
|
||||
|
||||
* Language: allows you to switch the interface language for socializer. The application must be restarted after changing the language.
|
||||
* Load images in posts: Allows you to specify whether you want socializer to display all images when opening a post, or not. This can be useful for people with slow connections or not needing images.
|
||||
* Use proxy: for countries where Vk is blocked by the internet providers, this settings allows socializer to connect via a proxy server already included in the application.
|
||||
* Update channel: allows you to specify how often you will receive updates for the program. There are two update channels available: Alpha channel, which contains unstable versions of the application and gets updates almost dayly, and stable, which contain tested and more stable versions of the program, but gets updates once in a month, approximately.
|
||||
|
||||
### Buffer settings tab
|
||||
|
||||
* Number of items to load for newsfeed and wall buffers: Allows you to specify how many items should be retrieved from VK in the newsfeed buffer and when opening walls for other users. Default is 50 items, and maximum is 100.
|
||||
* Number of items to load in video buffers: Allows you to specify how many items should be retrieved from VK in video buffers. Default is 50, maximum value is 200.
|
||||
* Number of items to load in conversation buffers: allows you to specify how many messages Socializer will retrieve when loading a conversation. Default is 50, maximum value is 200.
|
||||
|
||||
### Chat settings tab
|
||||
|
||||
* Show notifications when users are online/offline: These two checkboxes allows you to specify if you want socializer to notify you when someone is connected or disconnected in the VK network.
|
||||
* Notification type: This setting allows you to specify the notification type you prefer to use in socializer. The options are native and custom. Native notifications send a system notification every time someone is online or offline, while custom notifications play a sound and announce the notification in the screen reader only.
|
||||
|
||||
### Optional buffers tab
|
||||
|
||||
This section allows you to specify which buffers should be precreated every time socializer starts. This kind of buffers, namely audio playlists, video albums and communities, have a special way of being created. When a buffer of the previously mentioned types is created, the buffer is added to the corresponding section but no data is loaded from VK. In order to load the data for one of these buffers you have to press the load button present in the buffer. From this tab you can mark and unmark the buffers Socializer will create when it starts. By default, buffers for audio playlists, video albums and communities are not created automatically when Socializer starts.
|
||||
|
||||
## License and source code
|
||||
|
||||
@@ -132,14 +171,15 @@ The source code of the program is available at <https://code.manuelcortez.net/ma
|
||||
|
||||
## Contact
|
||||
|
||||
If you still have questions after reading this document, if you wish to collaborate to the project in some other way, or if you simply want to get in touch with the application developer, follow the VK account of [Manuel Cortez.](https://vk.com/manuelcortez) You can also visit [The project website.](https://manuelcortez.net/socializer)
|
||||
If you still have questions after reading this document, if you wish to collaborate to the project in some other way, or if you simply want to get in touch with the team, [join the Socializer's community in VK.](https://vk.com/socializer.club) You can also visit [The project website.](http://socializer.su)
|
||||
|
||||
## Credits
|
||||
|
||||
Socializer is developed and mantained by [Manuel Cortez,](https://manuelcortez.net) with contributions by [Anibal Hernandez](https://dragodark.com)
|
||||
Socializer is developed and maintained by [Manuel Cortez.](https://manuelcortez.net)
|
||||
|
||||
We would also like to thank the translators of Socializer, who have allowed the spreading of the application.
|
||||
|
||||
* English: Manuel Cortéz.
|
||||
* Spanish: Manuel Cortéz.
|
||||
* Russian: Valeria K.
|
||||
* Russian: Дарья Ратникова.
|
||||
|
||||
Special thanks to Дарья Ратникова, as she also manages the Socializer's community in VK, translates the website and the documentation into Russian.
|
@@ -1,95 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
documentation = [
|
||||
_(u"""Socializer's manual """),
|
||||
"",_(u"""## Introduction"""),
|
||||
"",_(u"""Socializer is an application to use [VK.com](https://vk.com) in an easy and accessible way with minimal CPU resource usage. Socializer will allow you to interact with the VK social network by giving you access to the most relevant features such as:"""),
|
||||
"",_(u"""* Basic post creation in your wall (including photos)."""),
|
||||
_(u"""* (limited) audio support. (*)"""),
|
||||
_(u"""* Post comments."""),
|
||||
_(u"""* like, unlike and repost other's posts."""),
|
||||
_(u"""* Open other's timelines so you could track their friends, posts or audio files."""),
|
||||
_(u"""* Basic chat features."""),
|
||||
"",_(u"""\* Audio support in socializer is limited due to the restrictions VK has decided to apply for third party applications on december 2016."""),
|
||||
"",_(u"""## Usage"""),
|
||||
"",_(u"""In order to use socializer, you must have an account in the [VK](https://vk.com) website. The process for registering an account is very accessible and is not covered in this manual. In the documentation, it is assumed you have a registered account on VK and you are able to sign in in the website by providing your phone number or email address, and a password. You will require this data for signing in the application later."""),
|
||||
"",_(u"""## authorising the application"""),
|
||||
"",_(u"""First of all, it's necessary to authorise the application so it can access your VK account and act on your behalf. The authorisation process is quite simple, and will be required only once. In order to start the authorisation process, you just need to run the executable file called "socializer.exe" (on some computers it will appear only as socializer, depending if windows explorer is set to display file extensions or not). You may like to place a Windows shortcut in your desktop for an easier access to the application."""),
|
||||
"",_(u"""If this is the first time you have launched socializer, you will see a message dialog asking you to proceed with the account authorisation process. It consists in providing the authentication data you normally use to sign in VK. It is very important to know that this data will be stored in a folder called config, located in the same folder where are the socializer files. Your config folder is a very important storage for your authentication data, so you must be sure you never will share it with anyone, mostly because your data is stored as plain text (this will be fixed in a future release and your data will be properly encrypted). Socializer will need your authentication data for acting in your behalf and offering you a better experience that what it could do with a simple access token. You must provide your phone number or email address in the first text box, and your password in the second. When pressing OK, your data will be saved and the application will start to retrieve all the required information for showing your buffers."""),
|
||||
"",_(u"""Once started, the application will start loading your data (posts, audio files, conversations, friends). When done, it will show you a notification indicating that the program is ready."""),
|
||||
"",_(u"""## General concepts"""),
|
||||
"",_(u"""Before starting to describe Socializer's usage, we'll explain some concepts that will be used extensively throughout this manual."""),
|
||||
"",_(u"""### Buffer"""),
|
||||
"",_(u"""A buffer is a list of items that will manage the data which arrives from VK, after being processed by the application. When you configure your account on Socializer and start it, many buffers are created. Each of them may contain some of the items which this program works with: Newsfeed posts, wall posts, audio and video files, friendship requests and conversations. According to the buffer you are focusing, you will be able to do different actions with these items."""),
|
||||
"",_(u"""All buffers will be updated in one of the following ways:"""),
|
||||
"",_(u"""* Periodically: Most buffers containing posts, audio or video files and people, will be updated periodically to reflect the new additions to them. Updates will be every 2 minutes for every buffer, so if you posted something and did not see the post in the buffer, you may need to wait a moment. There is an option, located in the buffer menu on the menu bar, which allows you to trigger a manual update in the current buffer."""),
|
||||
_(u"""* Real time: Conversation buffers will be updated every time someone sends a message to you. When an user sends you a message, if there is not a conversation buffer created to receive the message, a new conversation buffer will be opened automatically and the message will be placed on it. If you already have an opened conversation for the user sending the message, the message will be placed at the end of the buffer. A different sound will indicate whether a new conversation has been opened or an existing buffer gets updated."""),
|
||||
"",_(u"""### item"""),
|
||||
"",_(u"""An item is an element representing some data provided by VK. Items are separated in buffers which stores items of the same type: Audio buffers will contain only audio files, wall buffers will be full of wall posts. The only exception to this rule is the newsfeed buffer, which can contain different kind of items. Actions are available in a per-item basis, allowing certain items to be treated differently than others and showing different dialogs, depending in the kind of data VK sends for them. All items show a menu with their available actions by focusing them in the list and pressing the menu key or a right mouse click."""),
|
||||
"",_(u"""The following is a brief description of the kind of items socializer can work with, and what actions are available for those."""),
|
||||
"",_(u"""* Newsfeed post: It represents a post displayed in your "home" page on VK. It may contain a variety of information based in what you or your friends do. A newsfeed item may contain information about new audios added to your friend's library, new people added to friends, wall posts, reposts and new photos added. Depending on the kind of data VK has supplied, the item can open a dialog showing information about the post, a list displaying the people added to friends, or a dialog displaying information for every audio added to library. Take into account that it is not possible to play an audio item from the newsfeed buffer due to limits placed by VK, however, you may add it to your library and play it from your "my music" folder. If a wall post contains a long message, the first 140 characters will be displayed only. You can open the post to read the full message in the dialog. Available options for this item are different depending in the information the item contains. You can open or view the profile of the user that generated the item, like, dislike or add a comment to a post."""),
|
||||
_(u"""* Wall post: Represent a post in an user's wall. This posts will be similar to wall posts displayed in the newsfeed. If a wall post contains a long message, the first 140 characters will be displayed only. You can open the post to read the full message in the dialog. When opened (by pressing enter or the open option in the associated menu), it will show a dialogue where you can read the message, see and interact with attachment files (by searching the list and pressing enter in the focused attachment to open it), see the photos included in the post, read information related to likes and times the post has been shared, and read all comments. Additionally, you can share the post, indicate you like it, or add a comment. You can cycle through every item in the dialog by pressing tab."""),
|
||||
_(u"""* Audio: It represent an audio uploaded to the VK'S platform. Actions available for this item are only opening the audio in a dialog and play it due to limitations in access to audio features. When opened, it will be displayed in a dialog allowing you to read the title of the song, artist name, duration and a few buttons: play and download. You can control playback of audio items from the buffer by using the player menu on the menu bar."""),
|
||||
_(u"""* Video: It represent a video uploaded to the VK'S platform. Actions available for this item are opening the video in your default web browser and move it to a video album. When opened, it will open a web browser and play the video automatically due to VK limitations in access to video files."""),
|
||||
_(u"""* person: It contains information about a VK user, this item is present in all buffers under the "people" category. Actions available for this item are view user profile, send message and create a timeline, which is a special buffer to track all posts, friends or audios owned by the user. When opened, it will display the profile of this user in a dialog and will provide actions to send a message to the user, or view other sections of her/his profile."""),
|
||||
_(u"""* Message: A message appears only in conversation buffers and represents a chat message. It may include a list of attached files that will be displayed in a separated list. You can tab to that list (from the history) and press enter in the attached file you want to open. Chat items are marked as read automatically as soon as they are focused."""),
|
||||
"",_(u"""## Main interface"""),
|
||||
"",_(u"""The graphical user interface of Socializer consists of a window containing:"""),
|
||||
"",_(u"""* a menu bar accomodating five menus (application, Me, buffer, player and help),"""),
|
||||
_(u"""* One tree view,"""),
|
||||
_(u"""* One list of items"""),
|
||||
_(u"""* Some buttons, depending which is the focused buffer."""),
|
||||
"",_(u"""The actions that are available for every item will be described later."""),
|
||||
"",_(u"""In summary, the GUI contains two core components. These are the controls you will find while pressing the Tab key within the program's interface, and the different elements present on the menu bar."""),
|
||||
"",_(u"""### Buttons in the application"""),
|
||||
"",_(u"""* Post: this button opens up a dialogue box to write a post in your wall. For the moment, only posting in your own wall is supported. You can upload a picture by pressing the "attach" button and the photo button in the dialog which will appear, check spelling or translate your message by selecting one of the available buttons in the dialogue box. In addition, you can tag a friend in your post by pressing the corresponding button for that purpose. Also it is possible to configure the privacy settings for your post by allowing all users or just your friends to read it. Press the send button to send the post."""),
|
||||
_(u"""* Play: In audio buffers, plays the focused song. In video buffers, this button will open a web browser for playing the focused video, due to a limitation VK placed to third party developers with videos."""),
|
||||
_(u"""* Play all: In audio buffers, play all songs starting from the focused buffer, until the last item in the list."""),
|
||||
_(u"""* Send message: Send a message to a friend, which will open a conversation buffer if it does not exist already. Conversation buffers contain a full conversation, accommodating chat messages, between the current user and someone else. You can type your message in the provided box and press enter to send it to your friend. Additionally, you can add an attachment (for the moment, only attaching an audio file from your library is supported) and open attachments sent in the focused message by pressing tab and finding them in the attachments list."""),
|
||||
"",_(u"""Bear in mind that buttons will appear according to which actions are possible on the list you are browsing."""),
|
||||
"",_(u"""## Menus"""),
|
||||
"",_(u"""Visually, Towards the top of the main application window, can be found a menu bar which contains many of the same functions as listed in the previous section, together with some additional items. To access the menu bar, press the alt key. You will find five menus listed: application, Me, buffer, player and help. This section describes the items on each one of them."""),
|
||||
"",_(u"""### Application menu"""),
|
||||
"",_(u"""* Create: opens a menu where you can create a new album. At the moment, only video albums are supported."""),
|
||||
_(u"""* Delete: opens a menu where you can delete an already existing album owned by yourself. Only video albums are supported at this time."""),
|
||||
_(u"""* Preferences: Opens a dialogue which lets you configure settings for the entire application."""),
|
||||
"",_(u"""### Me menu"""),
|
||||
"",_(u"""* Profile: Opens a menu with several options to do in your profile:"""),
|
||||
_(u""" * View profile: Displays your profile in a dialog in the application."""),
|
||||
_(u""" * Open in browser: Redirects you to your profile in vk.com."""),
|
||||
"",_(u"""### Buffer menu"""),
|
||||
"",_(u"""* New timeline: Lets you open a user's timeline by choosing the user in a dialog box. You can choose which items you want to track: wall posts, friends or audio items. It is created when you press enter. If you invoke this option relative to a user that has no items of the kind you specified, the operation will fail. If you try creating an existing timeline the program will warn you and will not create it again."""),
|
||||
_(u"""* Search: Shows a menu where you can search for audios or videos on VK. Search results will be created in a new buffer inside "music" or "videos"."""),
|
||||
_(u"""* Update buffer: Performs a manual update operation in the buffer, which will retrieve all new items present in the social network since the last update."""),
|
||||
_(u"""* Load previous items: This allows more items to be loaded for the specified buffer. Bear in mind that not all buffers support this setting."""),
|
||||
_(u"""* Destroy: dismisses the list you're on, if possible."""),
|
||||
"",_(u"""### Player menu"""),
|
||||
"",_(u"""* Play: Plays the currently focused audio item, if the current buffer contains audio files. If not, plays the focused audio in the "my music" buffer."""),
|
||||
_(u"""* Play all: Plays all audio items in the current buffer or the "my music" buffer, starting by the currently focused audio item until the last audio in the list."""),
|
||||
_(u"""* Stop: Stops audio playback."""),
|
||||
_(u"""* Previous: Plays the previous audio in the buffer or the last item in the list, if the current audio was the first on the buffer."""),
|
||||
_(u"""* Next: Plays the Next audio in the buffer or the first item in the list, if the current audio was the last on the buffer."""),
|
||||
_(u"""* Shuffle: Plays all audios in the current buffer or the "my music" buffer shuffled."""),
|
||||
_(u"""* Volume up: Increases volume by 5%."""),
|
||||
_(u"""* Volume down: decreases volume by 5%."""),
|
||||
_(u"""* Mute: Mutes audio playback, setting volume to 0%."""),
|
||||
"",_(u"""### help menu"""),
|
||||
"",_(u"""* About Socializer: shows the credits of the program."""),
|
||||
_(u"""* Documentation: opens up this file, where you can read some useful program concepts."""),
|
||||
_(u"""* Check for updates: every time you open the program it automatically checks for new versions. If an update is available, it will ask you if you want to download the update. If you accept, the updating process will commence. When complete, Socializer will be restarted. This item checks for new updates without having to restart the application."""),
|
||||
_(u"""* Changelog: opens up a document with the list of changes from the current version to the earliest."""),
|
||||
"",_(u"""## Keyboard shortcuts"""),
|
||||
"",_(u"""## configuration"""),
|
||||
"",_(u"""### The general tab"""),
|
||||
"",_(u"""### The chats tab"""),
|
||||
"",_(u"""## License and source code"""),
|
||||
"",_(u"""Socializer is free software, licensed under the GNU GPL license, either version 2 or, at your option, any later version. You can view the license in the file named license.txt, or online at <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>."""),
|
||||
"",_(u"""The source code of the program is available at <https://code.manuelcortez.net/manuelcortez/socializer>."""),
|
||||
"",_(u"""## Contact"""),
|
||||
"",_(u"""If you still have questions after reading this document, if you wish to collaborate to the project in some other way, or if you simply want to get in touch with the application developer, follow the VK account of [Manuel Cortez.](https://vk.com/manuelcortez) You can also visit [The project website.](https://manuelcortez.net/socializer)"""),
|
||||
"",_(u"""## Credits"""),
|
||||
"",_(u"""Socializer is developed and mantained by [Manuel Cortez,](https://manuelcortez.net) with contributions by [Anibal Hernandez](https://dragodark.com)"""),
|
||||
"",_(u"""We would also like to thank the translators of Socializer, who have allowed the spreading of the application."""),
|
||||
"",_(u"""* English: Manuel Cortéz."""),
|
||||
_(u"""* Spanish: Manuel Cortéz."""),
|
||||
_(u"""* Russian: Valeria K."""),
|
||||
]
|
5
doc/translate.py
Normal file
5
doc/translate.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from babel.messages.frontend import CommandLineInterface
|
||||
|
||||
CommandLineInterface().run(['pybabel', 'extract', '-o', 'socializer-documentation.pot', '.'])
|
||||
#CommandLineInterface().run(['pybabel','compile','-d','../src/locales'])
|
||||
CommandLineInterface().run(['pybabel','update', '--input-file', 'socializer-documentation.pot', '--domain', 'socializer-documentation', '--output-dir', '../src/locales'])
|
@@ -1,18 +1,28 @@
|
||||
wxpython
|
||||
wxpython==4.0.3
|
||||
pywin32
|
||||
markdown
|
||||
vk_api
|
||||
# For the moment we will use the modified vk_api version that does not try to include enum34 and
|
||||
# already fixed the caption for wall uploaded photos.
|
||||
# Hopefully I can uncomment this in the near future when my changes will get merged upstream.
|
||||
#vk_api
|
||||
bs4
|
||||
configobj
|
||||
pypubsub==3.3.0
|
||||
pypubsub
|
||||
requests-oauthlib
|
||||
future
|
||||
arrow
|
||||
backports.functools_lru_cache
|
||||
yandex.translate
|
||||
mutagen
|
||||
mock
|
||||
babel
|
||||
# cx_freeze for building the executable files.
|
||||
cx_freeze
|
||||
symspellpy
|
||||
# forked repositories previously found at http://q-continuum.net
|
||||
git+https://code.manuelcortez.net/manuelcortez/libloader
|
||||
git+https://code.manuelcortez.net/manuelcortez/platform_utils
|
||||
git+https://github.com/chrisnorman7/sound_lib
|
||||
git+https://code.manuelcortez.net/manuelcortez/accessible_output2
|
||||
git+https://code.manuelcortez.net/manuelcortez/accessible_output2
|
||||
# Modified vk_api.
|
||||
git+https://github.com/manuelcortez/vk_api
|
@@ -1,58 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Define paths for a regular use, if there are not paths for python32 or 64, these commands will be taken.
|
||||
pythonpath32="/C/python27x86"
|
||||
pandocpath="pandoc.exe"
|
||||
|
||||
help () {
|
||||
echo -e "$0 | usage:"
|
||||
echo -e "$0 | \t./build.sh [-py32path <path to python for 32 bits> | -h]"
|
||||
}
|
||||
|
||||
# parsing options from the command line
|
||||
while [[ $# > 1 ]]
|
||||
do
|
||||
key="$1"
|
||||
shift
|
||||
|
||||
case $key in
|
||||
-py32path)
|
||||
pythonpath32="$1"
|
||||
shift
|
||||
;;
|
||||
-help)
|
||||
help
|
||||
;;
|
||||
*)
|
||||
help
|
||||
esac
|
||||
done
|
||||
|
||||
cd ../src
|
||||
if [ -d build/ ];
|
||||
then
|
||||
rm -rf build
|
||||
fi
|
||||
if [ -d dist/ ];
|
||||
then
|
||||
rm -rf dist
|
||||
fi
|
||||
if [ -d documentation/ ];
|
||||
then
|
||||
rm -rf documentation
|
||||
fi
|
||||
mkdir documentation
|
||||
cp ../changelog.md documentation/changelog.md
|
||||
cd documentation
|
||||
$pandocpath -s changelog.md -o changelog.html
|
||||
rm changelog.md
|
||||
cd ..
|
||||
cd ../doc
|
||||
$pythonpath32/python.exe generator.py
|
||||
mv -f en ../src/documentation/
|
||||
mv -f es ../src/documentation/
|
||||
cd ../src
|
||||
$pythonpath32/python.exe "setup.py" "py2exe" "--quiet"
|
||||
mv -f dist ../nightly/socializer
|
||||
rm -rf build
|
||||
cd ../nightly
|
||||
$pythonpath32/python.exe make_zipversion.py
|
32
scripts/generate_update_file.py
Normal file
32
scripts/generate_update_file.py
Normal file
@@ -0,0 +1,32 @@
|
||||
#! /usr/bin/env python
|
||||
import os
|
||||
import json
|
||||
|
||||
print("Generating update files for Socializer...")# Determine if we are going to write stable or alpha update file.
|
||||
# Stable file is when we build tags and alpha otherwise.
|
||||
version = os.environ.get("CI_COMMIT_TAG") or os.environ.get("CI_COMMIT_SHORT_SHA")
|
||||
if os.environ.get("CI_COMMIT_TAG") == None:
|
||||
version_type = "alpha"
|
||||
else:
|
||||
version_type = "stable"
|
||||
print("Version detected: %s" % (version_type,))
|
||||
|
||||
# Read update description and URL'S
|
||||
if version_type == "alpha":
|
||||
description = os.environ.get("CI_COMMIT_MESSAGE")
|
||||
urls = dict(Windows32="http://socializer.su/static/files/alpha/socializer_x86_alpha.zip", Windows64="http://socializer.su/static/files/alpha/socializer_x64_alpha.zip")
|
||||
else:
|
||||
with open("update-description",'r') as f:
|
||||
description = f.read()
|
||||
urls=dict(Windows32="http://socializer.su/static/files/{v}/socializer_{v}_x86.zip".format(v=version[1:]), Windows64="http://socializer.su/static/files/{v}/socializer_{v}_x64.zip".format(v=version[1:]))
|
||||
|
||||
# build the main dict object
|
||||
data = dict(current_version=version, description=description, downloads=urls)
|
||||
print("Generating file with the following arguments: %r" % (data,))
|
||||
if version_type == "alpha":
|
||||
updatefile = "alpha.json"
|
||||
else:
|
||||
updatefile = "stable.json"
|
||||
f = open(updatefile, "w")
|
||||
json.dump(data, f, ensure_ascii=False)
|
||||
f.close()
|
@@ -2,6 +2,6 @@
|
||||
echo Generating file list..
|
||||
dir ..\src\*.py /L /B /S > %TEMP%\listfile.txt
|
||||
echo Generating .POT file...
|
||||
xgettext --language=Python -o socializer.pot --keyword=_ -d socializer -f %TEMP%\listfile.txt -c --no-location --no-wrap
|
||||
xgettext --language=Python --from-code=utf-8 -o socializer.pot --keyword=_ -d socializer -f %TEMP%\listfile.txt -c --no-location --no-wrap
|
||||
del %TEMP%\listfile.txt
|
||||
echo Done.
|
||||
|
@@ -1,13 +1,15 @@
|
||||
#! /usr/bin/env python# -*- coding: iso-8859-1 -*-
|
||||
import shutil
|
||||
import os
|
||||
import sys
|
||||
|
||||
def create_archive():
|
||||
os.chdir("..\\src")
|
||||
print "Creating zip archive..."
|
||||
shutil.make_archive("socializer", "zip", "dist")
|
||||
if os.path.exists("dist"):
|
||||
shutil.rmtree("dist")
|
||||
print("Creating zip archive...")
|
||||
folder = "dist"
|
||||
shutil.make_archive("socializer", "zip", folder)
|
||||
# if os.path.exists("dist"):
|
||||
# shutil.rmtree("dist")
|
||||
if os.path.exists("build"):
|
||||
shutil.rmtree("build")
|
||||
os.chdir("..\\scripts")
|
||||
|
@@ -1,669 +0,0 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
# Originally written by Barry Warsaw <barry@zope.com>
|
||||
#
|
||||
# Minimally patched to make it even more xgettext compatible
|
||||
# by Peter Funk <pf@artcom-gmbh.de>
|
||||
#
|
||||
# 2002-11-22 J<>rgen Hermann <jh@web.de>
|
||||
# Added checks that _() only contains string literals, and
|
||||
# command line args are resolved to module lists, i.e. you
|
||||
# can now pass a filename, a module or package name, or a
|
||||
# directory (including globbing chars, important for Win32).
|
||||
# Made docstring fit in 80 chars wide displays using pydoc.
|
||||
#
|
||||
|
||||
# for selftesting
|
||||
try:
|
||||
import fintl
|
||||
_ = fintl.gettext
|
||||
except ImportError:
|
||||
_ = lambda s: s
|
||||
|
||||
__doc__ = _("""pygettext -- Python equivalent of xgettext(1)
|
||||
|
||||
Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the
|
||||
internationalization of C programs. Most of these tools are independent of
|
||||
the programming language and can be used from within Python programs.
|
||||
Martin von Loewis' work[1] helps considerably in this regard.
|
||||
|
||||
There's one problem though; xgettext is the program that scans source code
|
||||
looking for message strings, but it groks only C (or C++). Python
|
||||
introduces a few wrinkles, such as dual quoting characters, triple quoted
|
||||
strings, and raw strings. xgettext understands none of this.
|
||||
|
||||
Enter pygettext, which uses Python's standard tokenize module to scan
|
||||
Python source code, generating .pot files identical to what GNU xgettext[2]
|
||||
generates for C and C++ code. From there, the standard GNU tools can be
|
||||
used.
|
||||
|
||||
A word about marking Python strings as candidates for translation. GNU
|
||||
xgettext recognizes the following keywords: gettext, dgettext, dcgettext,
|
||||
and gettext_noop. But those can be a lot of text to include all over your
|
||||
code. C and C++ have a trick: they use the C preprocessor. Most
|
||||
internationalized C source includes a #define for gettext() to _() so that
|
||||
what has to be written in the source is much less. Thus these are both
|
||||
translatable strings:
|
||||
|
||||
gettext("Translatable String")
|
||||
_("Translatable String")
|
||||
|
||||
Python of course has no preprocessor so this doesn't work so well. Thus,
|
||||
pygettext searches only for _() by default, but see the -k/--keyword flag
|
||||
below for how to augment this.
|
||||
|
||||
[1] http://www.python.org/workshops/1997-10/proceedings/loewis.html
|
||||
[2] http://www.gnu.org/software/gettext/gettext.html
|
||||
|
||||
NOTE: pygettext attempts to be option and feature compatible with GNU
|
||||
xgettext where ever possible. However some options are still missing or are
|
||||
not fully implemented. Also, xgettext's use of command line switches with
|
||||
option arguments is broken, and in these cases, pygettext just defines
|
||||
additional switches.
|
||||
|
||||
Usage: pygettext [options] inputfile ...
|
||||
|
||||
Options:
|
||||
|
||||
-a
|
||||
--extract-all
|
||||
Extract all strings.
|
||||
|
||||
-d name
|
||||
--default-domain=name
|
||||
Rename the default output file from messages.pot to name.pot.
|
||||
|
||||
-E
|
||||
--escape
|
||||
Replace non-ASCII characters with octal escape sequences.
|
||||
|
||||
-D
|
||||
--docstrings
|
||||
Extract module, class, method, and function docstrings. These do
|
||||
not need to be wrapped in _() markers, and in fact cannot be for
|
||||
Python to consider them docstrings. (See also the -X option).
|
||||
|
||||
-h
|
||||
--help
|
||||
Print this help message and exit.
|
||||
|
||||
-k word
|
||||
--keyword=word
|
||||
Keywords to look for in addition to the default set, which are:
|
||||
%(DEFAULTKEYWORDS)s
|
||||
|
||||
You can have multiple -k flags on the command line.
|
||||
|
||||
-K
|
||||
--no-default-keywords
|
||||
Disable the default set of keywords (see above). Any keywords
|
||||
explicitly added with the -k/--keyword option are still recognized.
|
||||
|
||||
--no-location
|
||||
Do not write filename/lineno location comments.
|
||||
|
||||
-n
|
||||
--add-location
|
||||
Write filename/lineno location comments indicating where each
|
||||
extracted string is found in the source. These lines appear before
|
||||
each msgid. The style of comments is controlled by the -S/--style
|
||||
option. This is the default.
|
||||
|
||||
-o filename
|
||||
--output=filename
|
||||
Rename the default output file from messages.pot to filename. If
|
||||
filename is `-' then the output is sent to standard out.
|
||||
|
||||
-p dir
|
||||
--output-dir=dir
|
||||
Output files will be placed in directory dir.
|
||||
|
||||
-S stylename
|
||||
--style stylename
|
||||
Specify which style to use for location comments. Two styles are
|
||||
supported:
|
||||
|
||||
Solaris # File: filename, line: line-number
|
||||
GNU #: filename:line
|
||||
|
||||
The style name is case insensitive. GNU style is the default.
|
||||
|
||||
-v
|
||||
--verbose
|
||||
Print the names of the files being processed.
|
||||
|
||||
-V
|
||||
--version
|
||||
Print the version of pygettext and exit.
|
||||
|
||||
-w columns
|
||||
--width=columns
|
||||
Set width of output to columns.
|
||||
|
||||
-x filename
|
||||
--exclude-file=filename
|
||||
Specify a file that contains a list of strings that are not be
|
||||
extracted from the input files. Each string to be excluded must
|
||||
appear on a line by itself in the file.
|
||||
|
||||
-X filename
|
||||
--no-docstrings=filename
|
||||
Specify a file that contains a list of files (one per line) that
|
||||
should not have their docstrings extracted. This is only useful in
|
||||
conjunction with the -D option above.
|
||||
|
||||
If `inputfile' is -, standard input is read.
|
||||
""")
|
||||
|
||||
import os
|
||||
import imp
|
||||
import sys
|
||||
import glob
|
||||
import time
|
||||
import getopt
|
||||
import token
|
||||
import tokenize
|
||||
import operator
|
||||
|
||||
__version__ = '1.5'
|
||||
|
||||
default_keywords = ['_']
|
||||
DEFAULTKEYWORDS = ', '.join(default_keywords)
|
||||
|
||||
EMPTYSTRING = ''
|
||||
|
||||
|
||||
|
||||
# The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
|
||||
# there.
|
||||
pot_header = _('''\
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR ORGANIZATION
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\\n"
|
||||
"POT-Creation-Date: %(time)s\\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\\n"
|
||||
"MIME-Version: 1.0\\n"
|
||||
"Content-Type: text/plain; charset=CHARSET\\n"
|
||||
"Content-Transfer-Encoding: ENCODING\\n"
|
||||
"Generated-By: pygettext.py %(version)s\\n"
|
||||
|
||||
''')
|
||||
|
||||
|
||||
def usage(code, msg=''):
|
||||
print >> sys.stderr, __doc__ % globals()
|
||||
if msg:
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(code)
|
||||
|
||||
|
||||
|
||||
escapes = []
|
||||
|
||||
def make_escapes(pass_iso8859):
|
||||
global escapes
|
||||
if pass_iso8859:
|
||||
# Allow iso-8859 characters to pass through so that e.g. 'msgid
|
||||
# "H<>he"' would result not result in 'msgid "H\366he"'. Otherwise we
|
||||
# escape any character outside the 32..126 range.
|
||||
mod = 128
|
||||
else:
|
||||
mod = 256
|
||||
for i in range(256):
|
||||
if 32 <= (i % mod) <= 126:
|
||||
escapes.append(chr(i))
|
||||
else:
|
||||
escapes.append("\\%03o" % i)
|
||||
escapes[ord('\\')] = '\\\\'
|
||||
escapes[ord('\t')] = '\\t'
|
||||
escapes[ord('\r')] = '\\r'
|
||||
escapes[ord('\n')] = '\\n'
|
||||
escapes[ord('\"')] = '\\"'
|
||||
|
||||
|
||||
def escape(s):
|
||||
global escapes
|
||||
s = list(s)
|
||||
for i in range(len(s)):
|
||||
s[i] = escapes[ord(s[i])]
|
||||
return EMPTYSTRING.join(s)
|
||||
|
||||
|
||||
def safe_eval(s):
|
||||
# unwrap quotes, safely
|
||||
return eval(s, {'__builtins__':{}}, {})
|
||||
|
||||
|
||||
def normalize(s):
|
||||
# This converts the various Python string types into a format that is
|
||||
# appropriate for .po files, namely much closer to C style.
|
||||
lines = s.split('\n')
|
||||
if len(lines) == 1:
|
||||
s = '"' + escape(s) + '"'
|
||||
else:
|
||||
if not lines[-1]:
|
||||
del lines[-1]
|
||||
lines[-1] = lines[-1] + '\n'
|
||||
for i in range(len(lines)):
|
||||
lines[i] = escape(lines[i])
|
||||
lineterm = '\\n"\n"'
|
||||
s = '""\n"' + lineterm.join(lines) + '"'
|
||||
return s
|
||||
|
||||
|
||||
def containsAny(str, set):
|
||||
"""Check whether 'str' contains ANY of the chars in 'set'"""
|
||||
return 1 in [c in str for c in set]
|
||||
|
||||
|
||||
def _visit_pyfiles(list, dirname, names):
|
||||
"""Helper for getFilesForName()."""
|
||||
# get extension for python source files
|
||||
if not globals().has_key('_py_ext'):
|
||||
global _py_ext
|
||||
_py_ext = [triple[0] for triple in imp.get_suffixes()
|
||||
if triple[2] == imp.PY_SOURCE][0]
|
||||
|
||||
# don't recurse into CVS directories
|
||||
if 'CVS' in names:
|
||||
names.remove('CVS')
|
||||
|
||||
# add all *.py files to list
|
||||
list.extend(
|
||||
[os.path.join(dirname, file) for file in names
|
||||
if os.path.splitext(file)[1] == _py_ext]
|
||||
)
|
||||
|
||||
|
||||
def _get_modpkg_path(dotted_name, pathlist=None):
|
||||
"""Get the filesystem path for a module or a package.
|
||||
|
||||
Return the file system path to a file for a module, and to a directory for
|
||||
a package. Return None if the name is not found, or is a builtin or
|
||||
extension module.
|
||||
"""
|
||||
# split off top-most name
|
||||
parts = dotted_name.split('.', 1)
|
||||
|
||||
if len(parts) > 1:
|
||||
# we have a dotted path, import top-level package
|
||||
try:
|
||||
file, pathname, description = imp.find_module(parts[0], pathlist)
|
||||
if file: file.close()
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
# check if it's indeed a package
|
||||
if description[2] == imp.PKG_DIRECTORY:
|
||||
# recursively handle the remaining name parts
|
||||
pathname = _get_modpkg_path(parts[1], [pathname])
|
||||
else:
|
||||
pathname = None
|
||||
else:
|
||||
# plain name
|
||||
try:
|
||||
file, pathname, description = imp.find_module(
|
||||
dotted_name, pathlist)
|
||||
if file:
|
||||
file.close()
|
||||
if description[2] not in [imp.PY_SOURCE, imp.PKG_DIRECTORY]:
|
||||
pathname = None
|
||||
except ImportError:
|
||||
pathname = None
|
||||
|
||||
return pathname
|
||||
|
||||
|
||||
def getFilesForName(name):
|
||||
"""Get a list of module files for a filename, a module or package name,
|
||||
or a directory.
|
||||
"""
|
||||
if not os.path.exists(name):
|
||||
# check for glob chars
|
||||
if containsAny(name, "*?[]"):
|
||||
files = glob.glob(name)
|
||||
list = []
|
||||
for file in files:
|
||||
list.extend(getFilesForName(file))
|
||||
return list
|
||||
|
||||
# try to find module or package
|
||||
name = _get_modpkg_path(name)
|
||||
if not name:
|
||||
return []
|
||||
|
||||
if os.path.isdir(name):
|
||||
# find all python files in directory
|
||||
list = []
|
||||
os.path.walk(name, _visit_pyfiles, list)
|
||||
return list
|
||||
elif os.path.exists(name):
|
||||
# a single file
|
||||
return [name]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
class TokenEater:
|
||||
def __init__(self, options):
|
||||
self.__options = options
|
||||
self.__messages = {}
|
||||
self.__state = self.__waiting
|
||||
self.__data = []
|
||||
self.__lineno = -1
|
||||
self.__freshmodule = 1
|
||||
self.__curfile = None
|
||||
|
||||
def __call__(self, ttype, tstring, stup, etup, line):
|
||||
# dispatch
|
||||
## import token
|
||||
## print >> sys.stderr, 'ttype:', token.tok_name[ttype], \
|
||||
## 'tstring:', tstring
|
||||
self.__state(ttype, tstring, stup[0])
|
||||
|
||||
def __waiting(self, ttype, tstring, lineno):
|
||||
opts = self.__options
|
||||
# Do docstring extractions, if enabled
|
||||
if opts.docstrings and not opts.nodocstrings.get(self.__curfile):
|
||||
# module docstring?
|
||||
if self.__freshmodule:
|
||||
if ttype == tokenize.STRING:
|
||||
self.__addentry(safe_eval(tstring), lineno, isdocstring=1)
|
||||
self.__freshmodule = 0
|
||||
elif ttype not in (tokenize.COMMENT, tokenize.NL):
|
||||
self.__freshmodule = 0
|
||||
return
|
||||
# class docstring?
|
||||
if ttype == tokenize.NAME and tstring in ('class', 'def'):
|
||||
self.__state = self.__suiteseen
|
||||
return
|
||||
if ttype == tokenize.NAME and tstring in opts.keywords:
|
||||
self.__state = self.__keywordseen
|
||||
|
||||
def __suiteseen(self, ttype, tstring, lineno):
|
||||
# ignore anything until we see the colon
|
||||
if ttype == tokenize.OP and tstring == ':':
|
||||
self.__state = self.__suitedocstring
|
||||
|
||||
def __suitedocstring(self, ttype, tstring, lineno):
|
||||
# ignore any intervening noise
|
||||
if ttype == tokenize.STRING:
|
||||
self.__addentry(safe_eval(tstring), lineno, isdocstring=1)
|
||||
self.__state = self.__waiting
|
||||
elif ttype not in (tokenize.NEWLINE, tokenize.INDENT,
|
||||
tokenize.COMMENT):
|
||||
# there was no class docstring
|
||||
self.__state = self.__waiting
|
||||
|
||||
def __keywordseen(self, ttype, tstring, lineno):
|
||||
if ttype == tokenize.OP and tstring == '(':
|
||||
self.__data = []
|
||||
self.__lineno = lineno
|
||||
self.__state = self.__openseen
|
||||
else:
|
||||
self.__state = self.__waiting
|
||||
|
||||
def __openseen(self, ttype, tstring, lineno):
|
||||
if ttype == tokenize.OP and tstring == ')':
|
||||
# We've seen the last of the translatable strings. Record the
|
||||
# line number of the first line of the strings and update the list
|
||||
# of messages seen. Reset state for the next batch. If there
|
||||
# were no strings inside _(), then just ignore this entry.
|
||||
if self.__data:
|
||||
self.__addentry(EMPTYSTRING.join(self.__data))
|
||||
self.__state = self.__waiting
|
||||
elif ttype == tokenize.STRING:
|
||||
self.__data.append(safe_eval(tstring))
|
||||
elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT,
|
||||
token.NEWLINE, tokenize.NL]:
|
||||
# warn if we see anything else than STRING or whitespace
|
||||
print >> sys.stderr, _(
|
||||
'*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"'
|
||||
) % {
|
||||
'token': tstring,
|
||||
'file': self.__curfile,
|
||||
'lineno': self.__lineno
|
||||
}
|
||||
self.__state = self.__waiting
|
||||
|
||||
def __addentry(self, msg, lineno=None, isdocstring=0):
|
||||
if lineno is None:
|
||||
lineno = self.__lineno
|
||||
if not msg in self.__options.toexclude:
|
||||
entry = (self.__curfile, lineno)
|
||||
self.__messages.setdefault(msg, {})[entry] = isdocstring
|
||||
|
||||
def set_filename(self, filename):
|
||||
self.__curfile = filename
|
||||
self.__freshmodule = 1
|
||||
|
||||
def write(self, fp):
|
||||
options = self.__options
|
||||
timestamp = time.strftime('%Y-%m-%d %H:%M+%Z')
|
||||
# The time stamp in the header doesn't have the same format as that
|
||||
# generated by xgettext...
|
||||
print >> fp, pot_header % {'time': timestamp, 'version': __version__}
|
||||
# Sort the entries. First sort each particular entry's keys, then
|
||||
# sort all the entries by their first item.
|
||||
reverse = {}
|
||||
for k, v in self.__messages.items():
|
||||
keys = v.keys()
|
||||
keys.sort()
|
||||
reverse.setdefault(tuple(keys), []).append((k, v))
|
||||
rkeys = reverse.keys()
|
||||
rkeys.sort()
|
||||
for rkey in rkeys:
|
||||
rentries = reverse[rkey]
|
||||
rentries.sort()
|
||||
for k, v in rentries:
|
||||
isdocstring = 0
|
||||
# If the entry was gleaned out of a docstring, then add a
|
||||
# comment stating so. This is to aid translators who may wish
|
||||
# to skip translating some unimportant docstrings.
|
||||
if reduce(operator.__add__, v.values()):
|
||||
isdocstring = 1
|
||||
# k is the message string, v is a dictionary-set of (filename,
|
||||
# lineno) tuples. We want to sort the entries in v first by
|
||||
# file name and then by line number.
|
||||
v = v.keys()
|
||||
v.sort()
|
||||
if not options.writelocations:
|
||||
pass
|
||||
# location comments are different b/w Solaris and GNU:
|
||||
elif options.locationstyle == options.SOLARIS:
|
||||
for filename, lineno in v:
|
||||
d = {'filename': filename, 'lineno': lineno}
|
||||
print >>fp, _(
|
||||
'# File: %(filename)s, line: %(lineno)d') % d
|
||||
elif options.locationstyle == options.GNU:
|
||||
# fit as many locations on one line, as long as the
|
||||
# resulting line length doesn't exceeds 'options.width'
|
||||
locline = '#:'
|
||||
for filename, lineno in v:
|
||||
d = {'filename': filename, 'lineno': lineno}
|
||||
s = _(' %(filename)s:%(lineno)d') % d
|
||||
if len(locline) + len(s) <= options.width:
|
||||
locline = locline + s
|
||||
else:
|
||||
print >> fp, locline
|
||||
locline = "#:" + s
|
||||
if len(locline) > 2:
|
||||
print >> fp, locline
|
||||
if isdocstring:
|
||||
print >> fp, '#, docstring'
|
||||
print >> fp, 'msgid', normalize(k)
|
||||
print >> fp, 'msgstr ""\n'
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
global default_keywords
|
||||
try:
|
||||
opts, args = getopt.getopt(
|
||||
sys.argv[1:],
|
||||
'ad:DEhk:Kno:p:S:Vvw:x:X:',
|
||||
['extract-all', 'default-domain=', 'escape', 'help',
|
||||
'keyword=', 'no-default-keywords',
|
||||
'add-location', 'no-location', 'output=', 'output-dir=',
|
||||
'style=', 'verbose', 'version', 'width=', 'exclude-file=',
|
||||
'docstrings', 'no-docstrings',
|
||||
])
|
||||
except getopt.error, msg:
|
||||
usage(1, msg)
|
||||
|
||||
# for holding option values
|
||||
class Options:
|
||||
# constants
|
||||
GNU = 1
|
||||
SOLARIS = 2
|
||||
# defaults
|
||||
extractall = 0 # FIXME: currently this option has no effect at all.
|
||||
escape = 0
|
||||
keywords = []
|
||||
outpath = ''
|
||||
outfile = 'messages.pot'
|
||||
writelocations = 1
|
||||
locationstyle = GNU
|
||||
verbose = 0
|
||||
width = 78
|
||||
excludefilename = ''
|
||||
docstrings = 0
|
||||
nodocstrings = {}
|
||||
|
||||
options = Options()
|
||||
locations = {'gnu' : options.GNU,
|
||||
'solaris' : options.SOLARIS,
|
||||
}
|
||||
|
||||
# parse options
|
||||
for opt, arg in opts:
|
||||
if opt in ('-h', '--help'):
|
||||
usage(0)
|
||||
elif opt in ('-a', '--extract-all'):
|
||||
options.extractall = 1
|
||||
elif opt in ('-d', '--default-domain'):
|
||||
options.outfile = arg + '.pot'
|
||||
elif opt in ('-E', '--escape'):
|
||||
options.escape = 1
|
||||
elif opt in ('-D', '--docstrings'):
|
||||
options.docstrings = 1
|
||||
elif opt in ('-k', '--keyword'):
|
||||
options.keywords.append(arg)
|
||||
elif opt in ('-K', '--no-default-keywords'):
|
||||
default_keywords = []
|
||||
elif opt in ('-n', '--add-location'):
|
||||
options.writelocations = 1
|
||||
elif opt in ('--no-location',):
|
||||
options.writelocations = 0
|
||||
elif opt in ('-S', '--style'):
|
||||
options.locationstyle = locations.get(arg.lower())
|
||||
if options.locationstyle is None:
|
||||
usage(1, _('Invalid value for --style: %s') % arg)
|
||||
elif opt in ('-o', '--output'):
|
||||
options.outfile = arg
|
||||
elif opt in ('-p', '--output-dir'):
|
||||
options.outpath = arg
|
||||
elif opt in ('-v', '--verbose'):
|
||||
options.verbose = 1
|
||||
elif opt in ('-V', '--version'):
|
||||
print _('pygettext.py (xgettext for Python) %s') % __version__
|
||||
sys.exit(0)
|
||||
elif opt in ('-w', '--width'):
|
||||
try:
|
||||
options.width = int(arg)
|
||||
except ValueError:
|
||||
usage(1, _('--width argument must be an integer: %s') % arg)
|
||||
elif opt in ('-x', '--exclude-file'):
|
||||
options.excludefilename = arg
|
||||
elif opt in ('-X', '--no-docstrings'):
|
||||
fp = open(arg)
|
||||
try:
|
||||
while 1:
|
||||
line = fp.readline()
|
||||
if not line:
|
||||
break
|
||||
options.nodocstrings[line[:-1]] = 1
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
# calculate escapes
|
||||
make_escapes(options.escape)
|
||||
|
||||
# calculate all keywords
|
||||
options.keywords.extend(default_keywords)
|
||||
|
||||
# initialize list of strings to exclude
|
||||
if options.excludefilename:
|
||||
try:
|
||||
fp = open(options.excludefilename)
|
||||
options.toexclude = fp.readlines()
|
||||
fp.close()
|
||||
except IOError:
|
||||
print >> sys.stderr, _(
|
||||
"Can't read --exclude-file: %s") % options.excludefilename
|
||||
sys.exit(1)
|
||||
else:
|
||||
options.toexclude = []
|
||||
|
||||
# resolve args to module lists
|
||||
expanded = []
|
||||
for arg in args:
|
||||
if arg == '-':
|
||||
expanded.append(arg)
|
||||
else:
|
||||
expanded.extend(getFilesForName(arg))
|
||||
args = expanded
|
||||
|
||||
# slurp through all the files
|
||||
eater = TokenEater(options)
|
||||
for filename in args:
|
||||
if filename == '-':
|
||||
if options.verbose:
|
||||
print _('Reading standard input')
|
||||
fp = sys.stdin
|
||||
closep = 0
|
||||
else:
|
||||
if options.verbose:
|
||||
print _('Working on %s') % filename
|
||||
fp = open(filename)
|
||||
closep = 1
|
||||
try:
|
||||
eater.set_filename(filename)
|
||||
try:
|
||||
tokenize.tokenize(fp.readline, eater)
|
||||
except tokenize.TokenError, e:
|
||||
print >> sys.stderr, '%s: %s, line %d, column %d' % (
|
||||
e[0], filename, e[1][0], e[1][1])
|
||||
finally:
|
||||
if closep:
|
||||
fp.close()
|
||||
|
||||
# write the output
|
||||
if options.outfile == '-':
|
||||
fp = sys.stdout
|
||||
closep = 0
|
||||
else:
|
||||
if options.outpath:
|
||||
options.outfile = os.path.join(options.outpath, options.outfile)
|
||||
fp = open(options.outfile, 'w')
|
||||
closep = 1
|
||||
try:
|
||||
eater.write(fp)
|
||||
finally:
|
||||
if closep:
|
||||
fp.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
# some more test strings
|
||||
_(u'a unicode string')
|
||||
# this one creates a warning
|
||||
_('*** Seen unexpected token "%(token)s"') % {'token': 'test'}
|
||||
_('more' 'than' 'one' 'string')
|
@@ -1,213 +0,0 @@
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-06-29 13:33-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#. Translators: the label for the Windows default NVDA interface language.
|
||||
msgid "User default"
|
||||
msgstr ""
|
||||
|
||||
msgid "socializer's manual "
|
||||
msgstr ""
|
||||
|
||||
msgid "## Introduction"
|
||||
msgstr ""
|
||||
|
||||
msgid "Socializer is an application to use [VK.com](https://vk.com) in an easy and accessible way with minimal CPU resource usage. Socializer will allow you to interact with the VK social network by giving you access to the most relevant features such as:"
|
||||
msgstr ""
|
||||
|
||||
msgid "* Basic post creation in your wall (including photos)."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Audio addition, removal, download and search."
|
||||
msgstr ""
|
||||
|
||||
msgid "* audio albums management (create, delete and add audios)."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Post comments."
|
||||
msgstr ""
|
||||
|
||||
msgid "* like, unlike and repost other's posts."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Open other's timelines so you could track someone's friends, posts or audio files."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Basic chat features."
|
||||
msgstr ""
|
||||
|
||||
msgid "Note: When new features are added to socializer they will be added to this section."
|
||||
msgstr ""
|
||||
|
||||
msgid "## Running"
|
||||
msgstr ""
|
||||
|
||||
msgid "If you are using a built version, unzip the file in a new directory with no special characters, and open the socializer.exe file. If you haven't configured your VK account, you will see a dialogue, just press yes and a new dialogue will prompt for an user email or phone number and the password for your account. Take into account that the provided information will be saved in a config file as plain text. This application will need your information for renegotiating the access token when it expires."
|
||||
msgstr ""
|
||||
|
||||
msgid "Note: Every time you grant access to socializer, probably You will receive an email from VK by telling you that someone has accessed to your account. It means that a new token has been negotiated between VK and socializer by using an authomatic process, you should ignore those advices, unless you receive an email when you are not logged in VK with socializer or other application. You can see your authorised applications in the configuration section in the VK website. New tokens are renegotiated every 24 hours."
|
||||
msgstr ""
|
||||
|
||||
msgid "## Main interface"
|
||||
msgstr ""
|
||||
|
||||
msgid "If you have used [TWBlue](https://github.com/manuelcortez/twblue) before, the socializer's interface is quite similar. Once you have authorised your account, you will see a window with the following elements:"
|
||||
msgstr ""
|
||||
|
||||
msgid "* A tree view at the left of the window, where you will see the list of buffers. These buffers are divided in three categories, posts, music and people. You could expand each category for seeing the child buffers. There are some additional buffers, timelines and chats, wich will be filled with timelines for your friends or with chats, when you start or receive a chat session."
|
||||
msgstr ""
|
||||
|
||||
msgid "* A button for making a post to your wall."
|
||||
msgstr ""
|
||||
|
||||
msgid "* In audio buffers, Two buttons: Play and play all."
|
||||
msgstr ""
|
||||
|
||||
msgid "* In audio album buffers, a button for loading music. By default, albums are empty, you have to press the load button for getting the album's items."
|
||||
msgstr ""
|
||||
|
||||
msgid "* A list where you will see the posts for the currently selected buffer."
|
||||
msgstr ""
|
||||
|
||||
msgid "* In people buffers, like the friends buffer, a button for sending a message to your friends. Pressing that button will cause a chat buffer to be created."
|
||||
msgstr ""
|
||||
|
||||
msgid "* A status bar where the program will put some useful information about what it's doing at the moment."
|
||||
msgstr ""
|
||||
|
||||
msgid "* And a menu bar."
|
||||
msgstr ""
|
||||
|
||||
msgid "When socializer starts, it will try to load your news items, wall, audios (your audios, recommended and populars) and friends. At the moment there are only a few supported actions for these items:"
|
||||
msgstr ""
|
||||
|
||||
msgid "* Audio files: You can play the currently selected song, view the song's details (including lyrics, if available), add or remove from your library, and download it to a desired place in your hard drive. You can find audio files in your news feed or in your own audios buffers. You can find audios as post's attachments. You can create an audios timeline for displaying other's audios."
|
||||
msgstr ""
|
||||
|
||||
msgid "* News feed's post: In your news feed buffer, you can press return in any post and socializer will open a new dialogue which can be different, depending in the kind of post you are when the return key was pressed. For example it will open the post if you are focusing a \"normal\" post, a list of people if you are in a post wich indicates that someone has added friends, an audio displayer if you are in a post wich indicates that someone has added an audio, etc."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Wall posts: It will show the post in a dialogue so you could interact with its attachments, view and post comments, or like/unlike/share the post."
|
||||
msgstr ""
|
||||
|
||||
msgid "* You can send a message to someone by pressing the send message button in the buffer where you are, if available. Deactivated accounts cannot receive messages."
|
||||
msgstr ""
|
||||
|
||||
msgid "### Making a post"
|
||||
msgstr ""
|
||||
|
||||
msgid "When you press the post button, a new dialogue will show up. This dialogue allows you to post something in your wall. In this dialogue you have to write a message. You can translate your message and fix your spelling mistakes. Also you can post an URL address, socializer will try to add it as an attachment, so you will not have to worry about this. When you're ready, just press the send button and it'll be done."
|
||||
msgstr ""
|
||||
|
||||
msgid "If you want to add some photos, you can press the attach button, then press the kind of attachment you want to add. After this, select the file you want to add and you will see it in the list, once processed. When you are done with attachments, press the OK button, and continue with your post. When you are ready, press the send button. Your post could take some time to be published, depending in the amount of files you have added, but it should be displayed in your wall and newsfeed as soon as it is posted."
|
||||
msgstr ""
|
||||
|
||||
msgid "### Working with posts in news feed"
|
||||
msgstr ""
|
||||
|
||||
msgid "You can press the return key in any post in your news feed for opening a new dialogue with some information. The information and dialogue will be different if you are viewing a friendship's notification (when someone has added some friends), an audio file, or a regular post."
|
||||
msgstr ""
|
||||
|
||||
msgid "If you open a regular post in your newsfeed, you will be able to see the comments in a list, indicate if you do like or dislike the post, repost or add a new comment. If the post has some attachments, you'll find a list populated with them, you can press return in an attachment to execute its default action, wich will be different depending on the kind of attachment that you are viewing."
|
||||
msgstr ""
|
||||
|
||||
msgid "For friend notifications, you can only view the new added friends in a list and there are some kind of posts that aren't handled. It should be improved."
|
||||
msgstr ""
|
||||
|
||||
msgid "Additionally, you can press the menu Key or the right click for displaying a menu with some quick actions available for the post you are focusing. These actions are different for every post type."
|
||||
msgstr ""
|
||||
|
||||
msgid "### Working with songs"
|
||||
msgstr ""
|
||||
|
||||
msgid "Note: the following applies to audio timelines too."
|
||||
msgstr ""
|
||||
|
||||
msgid "If you want to play or view audio's details, you'll have to navigate to the tree view, and, using the down arrow, look for \"my audios\", \"populars\" or \"Recommendations\". You will see two more buttons, play and play all. The play button will play the currently selected audio, and the play all button will play audios in the current buffer, starting with the current selected item. You can go to the song's list, look for a desired song and press the play button, or Ctrl+return, which is a keyboard shorcut. Take in to account that there are some keyboard shorcuts that only work in the list of items."
|
||||
msgstr ""
|
||||
|
||||
msgid "You can play audio from any buffer, just press ctrl+return for making the audio playback possible."
|
||||
msgstr ""
|
||||
|
||||
msgid "If someone has added multiple audios at once to his library, you will see something like this in your newsfeed: \"(friend) has added 4 audios: audio 1, audio2, audio3 and audio4\". You can press return in the post for opening the audio's details dialogue, where you will be able to see a list with these audios. By default the first detected song is selected, which means that you could read its details by pressing tab, download or add it to your library. If you change the audio in the list, the information will be updated and you will see details and actions will take effect in the new selected audio."
|
||||
msgstr ""
|
||||
|
||||
msgid "When an audio file is playing, you can press f5 and f6 for decreasing and increasing volume, respectively, or control+shift+return for play/pause."
|
||||
msgstr ""
|
||||
|
||||
msgid "If you want to see some details for the selected audio file, you can do it by pressing the return key. You will be able to read some useful information (title, artist, duration and the lyric, if available). Also you will be able to download the song to your hard drive, you have to press the download button in the details' dialogue."
|
||||
msgstr ""
|
||||
|
||||
msgid "When the download starts, you can close the details dialogue and check the status bar in the main window for seeing the current progress."
|
||||
msgstr ""
|
||||
|
||||
msgid "Additionally, you can search for audios by using the menu bar, in the buffer menu, select search, then audio. It will display a dialog where you have to set your search preferences."
|
||||
msgstr ""
|
||||
|
||||
msgid "If you press the menu key, you will see a menu where you will be able to do some actions, for example, add the audio to an album, or add/remove the song from your library."
|
||||
msgstr ""
|
||||
|
||||
msgid "## menu Bar"
|
||||
msgstr ""
|
||||
|
||||
msgid "You can go to the menu bar by pressing ALT. Right now, there are three menus, application, buffer and help:"
|
||||
msgstr ""
|
||||
|
||||
msgid "### Application menu"
|
||||
msgstr ""
|
||||
|
||||
msgid "* Create. Here you can create some things in VK. The only supported item at this moment is the audio album."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Delete: Removes items from the VK servers. The only supported item here is the audio album."
|
||||
msgstr ""
|
||||
|
||||
msgid "* you can set your preferences by opening the preferences dialog located in this menu."
|
||||
msgstr ""
|
||||
|
||||
msgid "### Buffer menu"
|
||||
msgstr ""
|
||||
|
||||
msgid "* new timeline: This option allows you to create a new timeline. This kind of buffers is capable of download all posts in an user's profile."
|
||||
msgstr ""
|
||||
|
||||
msgid "* search: This submenu allows you to create a new buffer, at the moment, you can create only a kind of buffer, an audio search. The audio search will be located in the music category and will have the last 299 results of your query."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Update current buffer: perform an update operation in the selected buffer, which will retrieve the new items."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Load previous items: Get the previous items for the currently focused buffer."
|
||||
msgstr ""
|
||||
|
||||
msgid "* Remove buffer: Tries to remove the current buffer. Default buffers can't be removed."
|
||||
msgstr ""
|
||||
|
||||
msgid "The help menu is self explanatory."
|
||||
msgstr ""
|
||||
|
||||
msgid "## Contributing"
|
||||
msgstr ""
|
||||
|
||||
msgid "If you notice some errors in this document, or features that are not documented yet, you can suggest those changes by contacting me (more information can be find in the following section)."
|
||||
msgstr ""
|
||||
|
||||
msgid "## contact"
|
||||
msgstr ""
|
||||
|
||||
msgid "If you have questions, don't esitate to contact me in [Twitter,](https://twitter.com/manuelcortez00) or sending me an email to manuel(at)manuelcortez(dot)net. Just replace the words in parentheses with the original signs."
|
||||
msgstr ""
|
File diff suppressed because it is too large
Load Diff
68
scripts/upload.py
Normal file
68
scripts/upload.py
Normal file
@@ -0,0 +1,68 @@
|
||||
#! /usr/bin/env python
|
||||
""" Upload socializer to the ftp server. This script has been created to be executed from a continuous integrations system.
|
||||
Important note: for this script to work, the following conditions should be met:
|
||||
* There must be ftp server data, via environment variables (FTP_SERVER, FTP_USERNAME and FTP_PASSWORD) or via arguments to the script call (in the prior order). Connection to this server is done via default ftp port.
|
||||
* If the version to upload is alpha, there's not need of an extra variable. Otherwise, CI_COMMIT_TAG should point to a version as vx.x, where v is a literal and x are numbers, example may be v0.18, v0.25, v0.3. This variable should be set in the environment.
|
||||
* Inside the ftp server, the following directory structure will be expected: socializer.su/static/files/. The script will create the <version> folder or alpha if needed.
|
||||
* The script will upload all .exe, .zip and .json files located in the root directory from where it was called. The json files are uploaded to socializer.su/static/files/update and other files are going to socializer.su/static/files/<version>.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
import glob
|
||||
import ftplib
|
||||
|
||||
transferred=0
|
||||
|
||||
def convert_bytes(n):
|
||||
K, M, G, T, P = 1 << 10, 1 << 20, 1 << 30, 1 << 40, 1 << 50
|
||||
if n >= P:
|
||||
return '%.2fPb' % (float(n) / T)
|
||||
elif n >= T:
|
||||
return '%.2fTb' % (float(n) / T)
|
||||
elif n >= G:
|
||||
return '%.2fGb' % (float(n) / G)
|
||||
elif n >= M:
|
||||
return '%.2fMb' % (float(n) / M)
|
||||
elif n >= K:
|
||||
return '%.2fKb' % (float(n) / K)
|
||||
else:
|
||||
return '%d' % n
|
||||
|
||||
def callback(progress):
|
||||
global transferred
|
||||
transferred = transferred+len(progress)
|
||||
print("Uploaded {}".format(convert_bytes(transferred),))
|
||||
|
||||
ftp_server = os.environ.get("FTP_SERVER") or sys.argv[1]
|
||||
ftp_username = os.environ.get("FTP_USERNAME") or sys.argv[2]
|
||||
ftp_password = os.environ.get("FTP_PASSWORD") or sys.argv[3]
|
||||
version = os.environ.get("CI_COMMIT_TAG") or "alpha"
|
||||
version = version.replace("v", "")
|
||||
|
||||
print("Uploading files to the Socializer server...")
|
||||
connection = ftplib.FTP(ftp_server)
|
||||
print("Connected to FTP server {}".format(ftp_server,))
|
||||
connection.login(user=ftp_username, passwd=ftp_password)
|
||||
print("Logged in successfully")
|
||||
connection.cwd("socializer.su/static/files/")
|
||||
if version not in connection.nlst():
|
||||
print("Creating version directory {} because does not exists...".format(version,))
|
||||
connection.mkd(version)
|
||||
|
||||
if "update" not in connection.nlst():
|
||||
print("Creating update info directory because does not exists...")
|
||||
connection.mkd("update")
|
||||
connection.cwd(version)
|
||||
print("Moved into version directory")
|
||||
files = glob.glob("*.zip")+glob.glob("*.exe")+glob.glob("*.json")
|
||||
print("These files will be uploaded into the version folder: {}".format(files,))
|
||||
for file in files:
|
||||
transferred = 0
|
||||
print("Uploading {}".format(file,))
|
||||
with open(file, "rb") as f:
|
||||
if file.endswith("json"):
|
||||
connection.storbinary('STOR ../update/%s' % file, f, callback=callback, blocksize=1024*1024)
|
||||
else:
|
||||
connection.storbinary('STOR %s' % file, f, callback=callback, blocksize=1024*1024)
|
||||
print("Upload completed. exiting...")
|
||||
connection.quit()
|
@@ -1,4 +1,11 @@
|
||||
[app-settings]
|
||||
username = string(default="")
|
||||
password = string(default="")
|
||||
language = string(default="system")
|
||||
language = string(default="system")
|
||||
use_proxy = boolean(default=False)
|
||||
first_start = boolean(default=True)
|
||||
|
||||
[sound]
|
||||
volume = integer(default=100)
|
||||
input_device = string(default="Default")
|
||||
output_device = string(default="Default")
|
||||
session_mute = boolean(default=False)
|
||||
current_soundpack = string(default="default")
|
@@ -1,22 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
name = "Socializer"
|
||||
version = "0.17"
|
||||
author = u"Manuel Cortez"
|
||||
version = "0.24"
|
||||
author = "Manuel Cortez"
|
||||
authorEmail = "manuel@manuelcortez.net"
|
||||
copyright = u"Copyright (C) 2016-2018, Manuel Cortez"
|
||||
description = unicode(name+" Is an accessible VK client for Windows.")
|
||||
url = "https://manuelcortez.net/socializer"
|
||||
copyright = "Copyright (C) 2016-2020, Manuel Cortez"
|
||||
description = name+" Is an accessible VK client for Windows."
|
||||
url = "http://socializer.su"
|
||||
# The short name will be used for detecting translation files. See languageHandler for more details.
|
||||
short_name = "socializer"
|
||||
translators = [u"Darya Ratnikova (Russian)", u"Manuel Cortez (Spanish)"]
|
||||
translators = ["Darya Ratnikova (Russian)", "Manuel Cortez (Spanish)"]
|
||||
bts_name = "socializer"
|
||||
bts_access_token = "U29jaWFsaXplcg"
|
||||
bts_url = "https://issues.manuelcortez.net"
|
||||
### Update information
|
||||
# URL to retrieve the latest updates for the stable branch.
|
||||
update_stable_url = "https://code.manuelcortez.net/manuelcortez/socializer/raw/master/update-files/socializer.json"
|
||||
update_stable_url = "http://socializer.su/static/files/update/stable.json"
|
||||
# URL to retrieve update information for the "next" branch. This is a channel made for alpha versions.
|
||||
# Every commit will trigger an update, so users wanting to have the bleeding edge code will get it as soon as it is committed here and build by a runner.
|
||||
update_next_url = "https://code.manuelcortez.net/api/v4/projects/4/repository/commits/master"
|
||||
update_next_url = "http://socializer.su/static/files/update/alpha.json"
|
||||
# Short_id of the last commit, this is set to none here because it will be set manually by the building tools.
|
||||
update_next_version = "03286a44"
|
103
src/authenticator/official.py
Normal file
103
src/authenticator/official.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Set of methods used to retrieve access tokens by simulating the official VK application for Android. """
|
||||
import random
|
||||
import requests
|
||||
import logging
|
||||
from hashlib import md5
|
||||
from .wxUI import two_factor_auth, bad_password
|
||||
|
||||
log = logging.getLogger("authenticator.official")
|
||||
|
||||
class AuthenticationError(Exception):
|
||||
pass
|
||||
|
||||
# Data extracted from official VK android APP.
|
||||
client_id = "2274003"
|
||||
client_secret = "hHbZxrka2uZ6jB1inYsH"
|
||||
api_ver="5.93"
|
||||
scope = "nohttps,all"
|
||||
user_agent = "VKAndroidApp/5.23-2978 (Android 4.4.2; SDK 19; x86; unknown Android SDK built for x86; en; 320x240)"
|
||||
|
||||
api_url = "https://api.vk.com/method/"
|
||||
|
||||
def get_device_id():
|
||||
""" Generate a random device ID, consisting in 16 alphanumeric characters."""
|
||||
return "".join(random.choice(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f"]) for _ in range(16))
|
||||
|
||||
def get_sig(method, values, secret):
|
||||
""" Create a signature for parameters passed to VK API. """
|
||||
postdata = ""
|
||||
for key in values:
|
||||
# None values should be excluded from SIG, otherwise VK won't validate it correctly.
|
||||
if values[key] != None:
|
||||
postdata = postdata + "{key}={value}&".format(key=key, value=values[key])
|
||||
# Remove the last "&" character.
|
||||
postdata = postdata[:-1]
|
||||
sig = md5(b"/method/"+method.encode("utf-8")+b"?"+postdata.encode("utf-8")+secret.encode("utf-8"))
|
||||
return sig.hexdigest()
|
||||
|
||||
def perform_request(method, postdata, secret):
|
||||
""" Send a request to VK servers by signing the data with the 'sig' parameter."""
|
||||
url = api_url+method
|
||||
sig = get_sig(method, postdata, secret)
|
||||
postdata.update(sig=sig)
|
||||
headers = {'User-Agent': user_agent}
|
||||
r = requests.post(url, data=postdata, headers=headers)
|
||||
return r.json()
|
||||
|
||||
def get_non_refreshed(login, password, scope=scope):
|
||||
""" Retrieves a non-refreshed token, this should be the first token needed to authenticate in VK.
|
||||
returns the access_token which still needs to be refreshed, device_id, and secret code, needed to sign all petitions in VK."""
|
||||
if not (login or password):
|
||||
raise ValueError("Both user and password are required.")
|
||||
device_id = get_device_id()
|
||||
# Let's authenticate.
|
||||
url = "https://oauth.vk.com/token"
|
||||
params = dict(grant_type="password",
|
||||
client_id=client_id, client_secret=client_secret, username=login,
|
||||
password=password, v=api_ver, scope=scope, lang="en", device_id=device_id, force_sms=1)
|
||||
# Add two factor auth later due to python's syntax.
|
||||
params["2fa_supported"] = 1
|
||||
headers = {'User-Agent': user_agent}
|
||||
r = requests.get(url, params=params, headers=headers)
|
||||
log.exception(r.json())
|
||||
# If a 401 error is raised, we need to use 2FA here.
|
||||
# see https://vk.com/dev/auth_direct (switch lang to russian, english docs are very incomplete in the matter)
|
||||
# ToDo: this needs testing after implemented official VK tokens.
|
||||
if r.status_code == 401 and "phone_mask" in r.text:
|
||||
t = r.json()
|
||||
code, remember = two_factor_auth()
|
||||
url = "https://oauth.vk.com/token"
|
||||
params = dict(grant_type="password", lang="en",
|
||||
client_id=client_id, client_secret=client_secret, username=login,
|
||||
password=password, v=api_ver, scope=scope, device_id=device_id, code=code)
|
||||
r = requests.get(url, params=params, headers=headers)
|
||||
if r.status_code == 200 and 'access_token' in r.text:
|
||||
res = r.json()
|
||||
# Retrieve access_token and secret.
|
||||
access_token = res['access_token']
|
||||
secret = res['secret']
|
||||
return access_token, secret, device_id
|
||||
else:
|
||||
raise AuthenticationError(r.text)
|
||||
|
||||
def refresh_token(token, secret, device_id):
|
||||
method = "execute.getUserInfo"
|
||||
postdata = dict(v=api_ver, https=1, androidVersion=19, androidModel="Android SDK built for x86", info_fields="audio_ads,audio_background_limit,country,discover_design_version,discover_preload,discover_preload_not_seen,gif_autoplay,https_required,inline_comments,intro,lang,menu_intro,money_clubs_p2p,money_p2p,money_p2p_params,music_intro,audio_restrictions,profiler_settings,raise_to_record_enabled,stories,masks,subscriptions,support_url,video_autoplay,video_player,vklive_app,community_comments,webview_authorization,story_replies,animated_stickers,community_stories,live_section,playlists_download,calls,security_issue,eu_user,wallet,vkui_community_create,vkui_profile_edit,vkui_community_manage,vk_apps,stories_photo_duration,stories_reposts,live_streaming,live_masks,camera_pingpong,role,video_discover", device_id=device_id, lang="en", func_v=11, androidManufacturer="unknown", fields="photo_100,photo_50,exports,country,sex,status,bdate,first_name_gen,last_name_gen,verified,trending", access_token=token)
|
||||
perform_request(method, postdata, secret)
|
||||
method = "auth.refreshToken"
|
||||
postdata = dict(v=api_ver, https=1, timestamp=0, receipt2="", device_id=device_id, receipt="", lang="en", nonce="", access_token=token)
|
||||
return perform_request(method, postdata, secret)
|
||||
|
||||
def login(user, password):
|
||||
try:
|
||||
access_token, secret, device_id = get_non_refreshed(user, password)
|
||||
response = refresh_token(access_token, secret, device_id)
|
||||
except AuthenticationError:
|
||||
bad_password()
|
||||
raise AuthenticationError("")
|
||||
try:
|
||||
return response["response"]["token"], secret, device_id
|
||||
except KeyError:
|
||||
log.exception("An exception has occurred while attempting to authenticate. Printing response returned by vk...")
|
||||
log.exception(response)
|
17
src/authenticator/wxUI.py
Normal file
17
src/authenticator/wxUI.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import time
|
||||
import wx
|
||||
import widgetUtils
|
||||
|
||||
def two_factor_auth():
|
||||
code = None
|
||||
dlg = wx.TextEntryDialog(None, _("Please provide the authentication code you have received from VK."), _("Two factor authentication code"))
|
||||
response = dlg.ShowModal()
|
||||
if response == widgetUtils.OK:
|
||||
code = dlg.GetValue()
|
||||
dlg.Destroy()
|
||||
return (code, True)
|
||||
|
||||
def bad_password():
|
||||
return wx.MessageDialog(None, _("Your password or email address are incorrect. Please fix the mistakes and try it again."), _("Wrong data"), wx.ICON_ERROR).ShowModal()
|
5
src/babel.cfg
Normal file
5
src/babel.cfg
Normal file
@@ -0,0 +1,5 @@
|
||||
[python: **.py]
|
||||
input_dirs = .
|
||||
output_file=socializer.pot
|
||||
msgid_bugs_address=manuel@manuelcortez.net
|
||||
copyright_holder=Manuel Cortez
|
@@ -45,7 +45,7 @@ def hist(keys):
|
||||
def find_problems(hist):
|
||||
"Takes a histogram and returns a list of items occurring more than once."
|
||||
res=[]
|
||||
for k,v in hist.items():
|
||||
for k,v in list(hist.items()):
|
||||
if v>1:
|
||||
res.append(k)
|
||||
return res
|
||||
|
@@ -1,134 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Attachment controller for different kind of posts in VK.
|
||||
this controller will take care of preparing data structures to be uploaded later, when the user decides to start the upload process by sending the post.
|
||||
"""
|
||||
import os
|
||||
import logging
|
||||
import widgetUtils
|
||||
import audioRecorder
|
||||
from mutagen.id3 import ID3
|
||||
from sessionmanager.utils import seconds_to_string
|
||||
from wxUI.dialogs import attach as gui
|
||||
from wxUI.dialogs import selector
|
||||
from wxUI.menus import attachMenu
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
class attach(object):
|
||||
""" Controller used in some sections of the application, it can do the following:
|
||||
|
||||
* Handle all user input related to adding local or online files (online files are those already uploaded in vk).
|
||||
* Prepare local files to be uploaded once a post will be sent (no uploading work is done here, but structured dicts will be generated).
|
||||
* Parse online files and allow addition of them as attachment, so this controller will add both local and online files in the same dialog.
|
||||
"""
|
||||
|
||||
def __init__(self, session, voice_messages=False):
|
||||
""" Constructor.
|
||||
@ session sessionmanager.session object: an object capable of calling all VK methods and accessing the session database.
|
||||
@voice_messages bool: If True, will add a button for sending voice messages. Functionality for this button has not been added yet.
|
||||
"""
|
||||
self.session = session
|
||||
# Self.attachments will hold a reference to all attachments added to the dialog.
|
||||
self.attachments = list()
|
||||
self.dialog = gui.attachDialog(voice_messages)
|
||||
widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.on_image)
|
||||
widgetUtils.connect_event(self.dialog.audio, widgetUtils.BUTTON_PRESSED, self.on_audio)
|
||||
if voice_messages:
|
||||
widgetUtils.connect_event(self.dialog.voice_message, widgetUtils.BUTTON_PRESSED, self.upload_voice_message)
|
||||
widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment)
|
||||
log.debug("Attachments controller started.")
|
||||
self.dialog.get_response()
|
||||
|
||||
def on_image(self, *args, **kwargs):
|
||||
""" display menu for adding image attachments. """
|
||||
m = attachMenu()
|
||||
# disable add from VK as it is not supported in images, yet.
|
||||
m.add.Enable(False)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.upload_image, menuitem=m.upload)
|
||||
self.dialog.PopupMenu(m, self.dialog.photo.GetPosition())
|
||||
|
||||
def on_audio(self, *args, **kwargs):
|
||||
""" display menu to add audio attachments."""
|
||||
m = attachMenu()
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.upload_audio, menuitem=m.upload)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.add_audio, menuitem=m.add)
|
||||
self.dialog.PopupMenu(m, self.dialog.audio.GetPosition())
|
||||
|
||||
def upload_image(self, *args, **kwargs):
|
||||
""" allows uploading an image from the computer.
|
||||
"""
|
||||
image, description = self.dialog.get_image()
|
||||
if image != None:
|
||||
# Define data structure for this attachment, as will be required by VK API later.
|
||||
imageInfo = {"type": "photo", "file": image, "description": description, "from": "local"}
|
||||
self.attachments.append(imageInfo)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds a photo.
|
||||
info = [_(u"Photo"), description]
|
||||
self.dialog.attachments.insert_item(False, *info)
|
||||
self.dialog.remove.Enable(True)
|
||||
|
||||
def upload_audio(self, *args, **kwargs):
|
||||
""" Allows uploading an audio file from the computer. Only mp3 files are supported. """
|
||||
audio = self.dialog.get_audio()
|
||||
if audio != None:
|
||||
# Define data structure for this attachment, as will be required by VK API later.
|
||||
# Let's extract the ID3 tags to show them in the list and send them to VK, too.
|
||||
audio_tags = ID3(audio)
|
||||
if "TIT2" in audio_tags:
|
||||
title = audio_tags["TIT2"].text[0]
|
||||
else:
|
||||
title = _(u"Untitled")
|
||||
if "TPE1" in audio_tags:
|
||||
artist = audio_tags["TPE1"].text[0]
|
||||
else:
|
||||
artist = _(u"Unknown artist")
|
||||
audioInfo = {"type": "audio", "file": audio, "from": "local", "title": title, "artist": artist}
|
||||
self.attachments.append(audioInfo)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
|
||||
info = [_(u"Audio file"), u"{title} - {artist}".format(title=title, artist=artist)]
|
||||
self.dialog.attachments.insert_item(False, *info)
|
||||
self.dialog.remove.Enable(True)
|
||||
|
||||
def upload_voice_message(self, *args, **kwargs):
|
||||
a = audioRecorder.audioRecorder()
|
||||
if a.file != None and a.duration != 0:
|
||||
audioInfo = {"type": "voice_message", "file": a.file, "from": "local"}
|
||||
self.attachments.append(audioInfo)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
|
||||
info = [_(u"Voice message"), seconds_to_string(a.duration,)]
|
||||
self.dialog.attachments.insert_item(False, *info)
|
||||
self.dialog.remove.Enable(True)
|
||||
|
||||
def add_audio(self, *args, **kwargs):
|
||||
""" Allow adding an audio directly from the user's audio library."""
|
||||
# Let's reuse the already downloaded audios.
|
||||
list_of_audios = self.session.db["me_audio"]["items"]
|
||||
audios = []
|
||||
for i in list_of_audios:
|
||||
audios.append(u"{0}, {1}".format(i["title"], i["artist"]))
|
||||
select = selector.selectAttachment(_(u"Select the audio files you want to send"), audios)
|
||||
if select.get_response() == widgetUtils.OK and select.attachments.GetCount() > 0:
|
||||
attachments = select.get_all_attachments()
|
||||
for i in attachments:
|
||||
info = dict(type="audio", id=list_of_audios[i]["id"], owner_id=list_of_audios[i]["owner_id"])
|
||||
info["from"] = "online"
|
||||
self.attachments.append(info)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
|
||||
info2 = [_(u"Audio file"), u"{0} - {1}".format(list_of_audios[i]["title"], list_of_audios[i]["artist"])]
|
||||
self.dialog.attachments.insert_item(False, *info2)
|
||||
self.check_remove_status()
|
||||
|
||||
def remove_attachment(self, *args, **kwargs):
|
||||
""" Remove the currently focused item from the attachments list."""
|
||||
current_item = self.dialog.attachments.get_selected()
|
||||
log.debug("Removing item %d" % (current_item,))
|
||||
if current_item == -1: current_item = 0
|
||||
self.attachments.pop(current_item)
|
||||
self.dialog.attachments.remove_item(current_item)
|
||||
self.check_remove_status()
|
||||
log.debug("Removed")
|
||||
|
||||
def check_remove_status(self):
|
||||
""" Checks whether the remove button should remain enabled."""
|
||||
if len(self.attachments) == 0 and self.dialog.attachments.get_count() == 0:
|
||||
self.dialog.remove.Enable(False)
|
@@ -1,131 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import os
|
||||
import tempfile
|
||||
import sound_lib
|
||||
import widgetUtils
|
||||
import sound
|
||||
import output
|
||||
from wxUI.dialogs import audioRecorder as gui
|
||||
from mysc.thread_utils import call_threaded
|
||||
|
||||
class audioRecorder(object):
|
||||
def __init__(self):
|
||||
self.dialog = gui.audioRecorderDialog()
|
||||
self.recorded = False
|
||||
self.recording = None
|
||||
self.duration = 0
|
||||
self.playing = None
|
||||
widgetUtils.connect_event(self.dialog.play, widgetUtils.BUTTON_PRESSED, self.on_play)
|
||||
widgetUtils.connect_event(self.dialog.pause, widgetUtils.BUTTON_PRESSED, self.on_pause)
|
||||
widgetUtils.connect_event(self.dialog.record, widgetUtils.BUTTON_PRESSED, self.on_record)
|
||||
widgetUtils.connect_event(self.dialog.discard, widgetUtils.BUTTON_PRESSED, self.on_discard)
|
||||
if self.dialog.get_response() == widgetUtils.OK:
|
||||
self.postprocess()
|
||||
|
||||
def on_pause(self, *args, **kwargs):
|
||||
if self.dialog.get("pause") == _(u"Pause"):
|
||||
self.recording.pause()
|
||||
self.dialog.set("pause", _(u"&Resume"))
|
||||
elif self.dialog.get("pause") == _(u"Resume"):
|
||||
self.recording.play()
|
||||
self.dialog.set("pause", _(U"&Pause"))
|
||||
|
||||
def on_record(self, *args, **kwargs):
|
||||
if self.recording != None:
|
||||
self.stop_recording()
|
||||
self.dialog.disable_control("pause")
|
||||
else:
|
||||
self.start_recording()
|
||||
self.dialog.enable_control("pause")
|
||||
|
||||
def start_recording(self):
|
||||
self.dialog.disable_control("attach_exists")
|
||||
self.file = tempfile.mktemp(suffix='.wav')
|
||||
self.recording = sound.get_recording(self.file)
|
||||
self.duration = time.time()
|
||||
self.recording.play()
|
||||
self.dialog.set("record", _(u"&Stop"))
|
||||
output.speak(_(u"Recording"))
|
||||
|
||||
def stop_recording(self):
|
||||
self.recording.stop()
|
||||
self.duration = int(time.time()-self.duration)
|
||||
self.recording.free()
|
||||
output.speak(_(u"Stopped"))
|
||||
self.recorded = True
|
||||
self.dialog.set("record", _(u"&Record"))
|
||||
self.file_attached()
|
||||
|
||||
def file_attached(self):
|
||||
self.dialog.set("pause", _(u"&Pause"))
|
||||
self.dialog.disable_control("record")
|
||||
self.dialog.enable_control("play")
|
||||
self.dialog.enable_control("discard")
|
||||
self.dialog.disable_control("attach_exists")
|
||||
self.dialog.enable_control("attach")
|
||||
self.dialog.play.SetFocus()
|
||||
|
||||
def on_discard(self, *args, **kwargs):
|
||||
if self.playing:
|
||||
self._stop()
|
||||
if self.recording != None:
|
||||
self.cleanup()
|
||||
self.dialog.disable_control("attach")
|
||||
self.dialog.disable_control("play")
|
||||
self.file = None
|
||||
self.dialog.enable_control("record")
|
||||
self.dialog.enable_control("attach_exists")
|
||||
self.dialog.record.SetFocus()
|
||||
self.dialog.disable_control("discard")
|
||||
self.recording = None
|
||||
output.speak(_(u"Discarded"))
|
||||
|
||||
def on_play(self, *args, **kwargs):
|
||||
if not self.playing:
|
||||
call_threaded(self._play)
|
||||
else:
|
||||
self._stop()
|
||||
|
||||
def _play(self):
|
||||
output.speak(_(u"Playing..."))
|
||||
# try:
|
||||
self.playing = sound_lib.stream.FileStream(file=unicode(self.file), flags=sound_lib.stream.BASS_UNICODE)
|
||||
self.playing.play()
|
||||
self.dialog.set("play", _(u"&Stop"))
|
||||
try:
|
||||
while self.playing.is_playing:
|
||||
pass
|
||||
self.dialog.set("play", _(u"&Play"))
|
||||
self.playing.free()
|
||||
self.playing = None
|
||||
except:
|
||||
pass
|
||||
|
||||
def _stop(self):
|
||||
output.speak(_(u"Stopped"))
|
||||
self.playing.stop()
|
||||
self.playing.free()
|
||||
self.dialog.set("play", _(u"&Play"))
|
||||
self.playing = None
|
||||
|
||||
def postprocess(self):
|
||||
if self.file.lower().endswith('.wav'):
|
||||
output.speak(_(u"Recoding audio..."))
|
||||
sound.recode_audio(self.file)
|
||||
self.wav_file = self.file
|
||||
self.file = '%s.ogg' % self.file[:-4]
|
||||
|
||||
def cleanup(self):
|
||||
if self.playing and self.playing.is_playing:
|
||||
self.playing.stop()
|
||||
if self.recording != None:
|
||||
if self.recording.is_playing:
|
||||
self.recording.stop()
|
||||
try:
|
||||
self.recording.free()
|
||||
except:
|
||||
pass
|
||||
os.remove(self.file)
|
||||
if hasattr(self, 'wav_file'):
|
||||
os.remove(self.wav_file)
|
File diff suppressed because it is too large
Load Diff
@@ -1,75 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import widgetUtils
|
||||
from wxUI.dialogs import configuration as configurationUI
|
||||
|
||||
class configuration(object):
|
||||
|
||||
def get_notification_type(self, value):
|
||||
if value == _(u"Native"):
|
||||
return "native"
|
||||
else:
|
||||
return "custom"
|
||||
|
||||
def get_notification_label(self, value):
|
||||
if value == "native":
|
||||
return _(u"Native")
|
||||
else:
|
||||
return _(u"Custom")
|
||||
|
||||
def get_update_channel_type(self, value):
|
||||
if value == _(u"Stable"):
|
||||
return "stable"
|
||||
elif value == _(u"Weekly"):
|
||||
return "weekly"
|
||||
else:
|
||||
return "alpha"
|
||||
|
||||
def get_update_channel_label(self, value):
|
||||
if value == "stable":
|
||||
return _(u"Stable")
|
||||
elif value == "weekly":
|
||||
return _(u"Weekly")
|
||||
else:
|
||||
return _(u"Alpha")
|
||||
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
self.dialog = configurationUI.configurationDialog(_(u"Preferences"))
|
||||
self.create_config()
|
||||
|
||||
def create_config(self):
|
||||
self.dialog.create_general()
|
||||
self.dialog.set_value("general", "wall_buffer_count", self.session.settings["buffers"]["count_for_wall_buffers"])
|
||||
self.dialog.set_value("general", "video_buffers_count", self.session.settings["buffers"]["count_for_video_buffers"])
|
||||
self.dialog.set_value("general", "load_images", self.session.settings["general"]["load_images"])
|
||||
self.dialog.set_value("general", "update_channel", self.get_update_channel_label(self.session.settings["general"]["update_channel"]))
|
||||
self.dialog.create_chat()
|
||||
self.dialog.set_value("chat", "notify_online", self.session.settings["chat"]["notify_online"])
|
||||
self.dialog.set_value("chat", "notify_offline", self.session.settings["chat"]["notify_offline"])
|
||||
self.dialog.set_value("chat", "open_unread_conversations", self.session.settings["chat"]["open_unread_conversations"])
|
||||
self.dialog.set_value("chat", "automove_to_conversations", self.session.settings["chat"]["automove_to_conversations"])
|
||||
self.dialog.set_value("chat", "notifications", self.get_notification_label(self.session.settings["chat"]["notifications"]))
|
||||
self.dialog.realize()
|
||||
self.response = self.dialog.get_response()
|
||||
|
||||
def save_configuration(self):
|
||||
self.session.settings["buffers"]["count_for_video_buffers"] = self.dialog.get_value("general", "video_buffers_count")
|
||||
self.session.settings["general"]["load_images"] = self.dialog.get_value("general", "load_images")
|
||||
update_channel = self.get_update_channel_type(self.dialog.get_value("general", "update_channel"))
|
||||
if update_channel != self.session.settings["general"]["update_channel"]:
|
||||
if update_channel == "stable":
|
||||
self.session.settings["general"]["update_channel"] = update_channel
|
||||
elif update_channel == "weekly":
|
||||
dialog = configurationUI.weekly_channel()
|
||||
if dialog == widgetUtils.YES:
|
||||
self.session.settings["general"]["update_channel"] = update_channel
|
||||
elif update_channel == "alpha":
|
||||
dialog = configurationUI.alpha_channel()
|
||||
if dialog == widgetUtils.YES:
|
||||
self.session.settings["general"]["update_channel"] = update_channel
|
||||
self.session.settings["chat"]["notify_online"] = self.dialog.get_value("chat", "notify_online")
|
||||
self.session.settings["chat"]["notify_offline"] = self.dialog.get_value("chat", "notify_offline")
|
||||
self.session.settings["chat"]["open_unread_conversations"] = self.dialog.get_value("chat", "open_unread_conversations")
|
||||
self.session.settings["chat"]["automove_to_conversations"] = self.dialog.get_value("chat", "automove_to_conversations")
|
||||
self.session.settings["chat"]["notifications"] = self.get_notification_type(self.dialog.get_value("chat", "notifications"))
|
||||
self.session.settings.write()
|
File diff suppressed because it is too large
Load Diff
@@ -1,80 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import widgetUtils
|
||||
import output
|
||||
from pubsub import pub
|
||||
import attach
|
||||
from wxUI.dialogs import message, selector
|
||||
from extra import SpellChecker, translator
|
||||
from logging import getLogger
|
||||
|
||||
log = getLogger("controller.message")
|
||||
|
||||
class post(object):
|
||||
def __init__(self, session, title, caption, text, post_type="post"):
|
||||
super(post, self).__init__()
|
||||
self.session = session
|
||||
self.title = title
|
||||
self.message = getattr(message, post_type)(title, caption, text)
|
||||
self.message.set_title(title)
|
||||
widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck)
|
||||
widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate)
|
||||
widgetUtils.connect_event(self.message.mention, widgetUtils.BUTTON_PRESSED, self.mention)
|
||||
self.images = []
|
||||
if hasattr(self.message, "attach"):
|
||||
widgetUtils.connect_event(self.message.attach, widgetUtils.BUTTON_PRESSED, self.show_attach_dialog)
|
||||
|
||||
def get_privacy_options(self):
|
||||
p = self.message.get("privacy")
|
||||
if p == _(u"Friends of friends"):
|
||||
privacy = 0
|
||||
elif p == _(u"All users"):
|
||||
privacy = 1
|
||||
return privacy
|
||||
|
||||
def mention(self, *args, **kwargs):
|
||||
try:
|
||||
fields = "id, first_name, last_name"
|
||||
friends = self.session.vk.client.friends.get(count=5000, fields=fields)
|
||||
except AttributeError:
|
||||
time.sleep(2)
|
||||
log.exception("Error retrieving friends...")
|
||||
return self.mention(*args, **kwargs)
|
||||
users = []
|
||||
for i in friends["items"]:
|
||||
users.append(u"{0} {1}".format(i["first_name"], i["last_name"]))
|
||||
select = selector.selectPeople(users)
|
||||
if select.get_response() == widgetUtils.OK and select.users.GetCount() > 0:
|
||||
self.tagged_people = []
|
||||
tagged_users = select.get_all_users()
|
||||
for i in tagged_users:
|
||||
self.tagged_people.append(u"[id%s|%s]" % (str(friends["items"][i]["id"]), friends["items"][i]["first_name"]))
|
||||
self.message.text.SetValue(self.message.text.GetValue()+ u", ".join(self.tagged_people))
|
||||
|
||||
def translate(self, *args, **kwargs):
|
||||
dlg = translator.gui.translateDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
text_to_translate = self.message.get_text()
|
||||
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
||||
msg = translator.translator.translate(text_to_translate, dest)
|
||||
self.message.set_text(msg)
|
||||
self.message.text_focus()
|
||||
output.speak(_(u"Translated"))
|
||||
dlg.Destroy()
|
||||
|
||||
def spellcheck(self, event=None):
|
||||
text = self.message.get_text()
|
||||
checker = SpellChecker.spellchecker.spellChecker(text, "")
|
||||
if hasattr(checker, "fixed_text"):
|
||||
self.message.set_text(checker.fixed_text)
|
||||
checker.clean()
|
||||
|
||||
def show_attach_dialog(self, *args, **kwargs):
|
||||
a = attach.attach(self.session)
|
||||
if len(a.attachments) != 0:
|
||||
self.attachments = a.attachments
|
||||
|
||||
class comment(post):
|
||||
def __init__(self, session, title, caption, text):
|
||||
super(comment, self).__init__(session, title, caption, text, "comment")
|
||||
self.message.set_title(_(u"New comment"))
|
@@ -1,118 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import random
|
||||
import output
|
||||
import sound_lib
|
||||
import logging
|
||||
|
||||
from sound_lib.stream import URLStream
|
||||
from sound_lib.main import BassError
|
||||
from mysc.repeating_timer import RepeatingTimer
|
||||
from pubsub import pub
|
||||
|
||||
player = None
|
||||
log = logging.getLogger("player")
|
||||
|
||||
def setup():
|
||||
global player
|
||||
if player == None:
|
||||
player = audioPlayer()
|
||||
|
||||
class audioPlayer(object):
|
||||
|
||||
def __init__(self):
|
||||
self.is_playing = False
|
||||
self.stream = None
|
||||
self.vol = 100
|
||||
self.is_working = False
|
||||
self.queue = []
|
||||
self.stopped = True
|
||||
|
||||
def play(self, url, set_info=True):
|
||||
if self.stream != None and self.stream.is_playing == True:
|
||||
try:
|
||||
self.stream.stop()
|
||||
except BassError:
|
||||
log.exception("error when stopping the file")
|
||||
self.stream = None
|
||||
self.stopped = True
|
||||
if hasattr(self, "worker") and self.worker != None:
|
||||
self.worker.cancel()
|
||||
self.worker = None
|
||||
self.queue = []
|
||||
# Make sure that there are no other sounds trying to be played.
|
||||
if self.is_working == False:
|
||||
self.is_working = True
|
||||
try:
|
||||
self.stream = URLStream(url=url["url"])
|
||||
except BassError:
|
||||
log.debug("Error when playing the file %r") % (url,)
|
||||
return
|
||||
# Translators: {0} will be replaced with a song's title and {1} with the artist.
|
||||
if set_info:
|
||||
msg = _(u"Playing {0} by {1}").format(url["title"], url["artist"])
|
||||
pub.sendMessage("update-status-bar", status=msg)
|
||||
self.stream.volume = self.vol/100.0
|
||||
self.stream.play()
|
||||
self.stopped = False
|
||||
self.is_working = False
|
||||
|
||||
def stop(self):
|
||||
if self.stream != None and self.stream.is_playing == True:
|
||||
self.stream.stop()
|
||||
self.stopped = True
|
||||
if hasattr(self, "worker") and self.worker != None:
|
||||
self.worker.cancel()
|
||||
self.worker = None
|
||||
self.queue = []
|
||||
|
||||
def pause(self):
|
||||
if self.stream != None:
|
||||
if self.stream.is_playing == True:
|
||||
self.stream.pause()
|
||||
self.stopped = True
|
||||
else:
|
||||
try:
|
||||
self.stream.play()
|
||||
self.stopped = False
|
||||
except BassError:
|
||||
pass
|
||||
|
||||
@property
|
||||
def volume(self):
|
||||
if self.stream != None:
|
||||
return self.vol
|
||||
|
||||
@volume.setter
|
||||
def volume(self, vol):
|
||||
if vol <= 100 and vol >= 0:
|
||||
self.vol = vol
|
||||
if self.stream != None:
|
||||
self.stream.volume = self.vol/100.0
|
||||
|
||||
def play_all(self, list_of_urls, shuffle=False):
|
||||
self.stop()
|
||||
# Skip all country restricted tracks as they are not playable here.
|
||||
self.queue = [i for i in list_of_urls if i["url"] != ""]
|
||||
if shuffle:
|
||||
random.shuffle(self.queue)
|
||||
self.play(self.queue[0])
|
||||
self.queue.remove(self.queue[0])
|
||||
self.worker = RepeatingTimer(5, self.player_function)
|
||||
self.worker.start()
|
||||
|
||||
def player_function(self):
|
||||
if self.stream != None and self.stream.is_playing == False and self.stopped == False and len(self.stream) == self.stream.position:
|
||||
if len(self.queue) == 0:
|
||||
self.worker.cancel()
|
||||
return
|
||||
self.play(self.queue[0])
|
||||
self.queue.remove(self.queue[0])
|
||||
|
||||
def check_is_playing(self):
|
||||
if self.stream == None:
|
||||
return False
|
||||
if self.stream != None and self.stream.is_playing == False:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
@@ -1,613 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import os
|
||||
import cStringIO
|
||||
import threading
|
||||
import arrow
|
||||
import messages
|
||||
import requests
|
||||
import languageHandler
|
||||
import widgetUtils
|
||||
import output
|
||||
import wx
|
||||
import webbrowser
|
||||
import logging
|
||||
from sessionmanager import session # We'll use some functions from there
|
||||
from sessionmanager import utils
|
||||
from pubsub import pub
|
||||
from wxUI.dialogs import postDialogs, urlList, profiles
|
||||
from extra import SpellChecker, translator
|
||||
from mysc.thread_utils import call_threaded
|
||||
from wxUI import menus
|
||||
|
||||
log = logging.getLogger("controller.post")
|
||||
|
||||
def get_user(id, profiles):
|
||||
""" Returns an user name and last name based in the id receibed."""
|
||||
for i in profiles:
|
||||
if i["id"] == id:
|
||||
return u"{0} {1}".format(i["first_name"], i["last_name"])
|
||||
# Translators: This string is used when socializer can't find the right user information.
|
||||
return _(u"Unknown username")
|
||||
|
||||
def get_message(status):
|
||||
message = ""
|
||||
if status.has_key("text"):
|
||||
message = utils.clean_text(status["text"])
|
||||
return message
|
||||
|
||||
class postController(object):
|
||||
""" Base class for post representation."""
|
||||
|
||||
def __init__(self, session, postObject):
|
||||
super(postController, self).__init__()
|
||||
self.session = session
|
||||
self.post = postObject
|
||||
# Posts from newsfeed contains this source_id instead from_id in walls. Also it uses post_id and walls use just id.
|
||||
if self.post.has_key("source_id"):
|
||||
self.user_identifier = "source_id"
|
||||
self.post_identifier = "post_id"
|
||||
else:
|
||||
# In wall's posts, if someone has posted in user's wall, owner_id should be used instead from_id
|
||||
# This will help for retrieving comments, do likes, etc.
|
||||
if not self.post.has_key("owner_id"):
|
||||
self.user_identifier = "from_id"
|
||||
else:
|
||||
self.user_identifier = "owner_id"
|
||||
self.post_identifier = "id"
|
||||
self.dialog = postDialogs.post()
|
||||
# self.dialog.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.show_comment)
|
||||
widgetUtils.connect_event(self.dialog.like, widgetUtils.BUTTON_PRESSED, self.post_like)
|
||||
widgetUtils.connect_event(self.dialog.comment, widgetUtils.BUTTON_PRESSED, self.add_comment)
|
||||
widgetUtils.connect_event(self.dialog.tools, widgetUtils.BUTTON_PRESSED, self.show_tools_menu)
|
||||
widgetUtils.connect_event(self.dialog.repost, widgetUtils.BUTTON_PRESSED, self.post_repost)
|
||||
# self.dialog.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.show_menu, self.dialog.comments.list)
|
||||
# self.dialog.Bind(wx.EVT_LIST_KEY_DOWN, self.show_menu_by_key, self.dialog.comments.list)
|
||||
self.worker = threading.Thread(target=self.load_all_components)
|
||||
self.worker.finished = threading.Event()
|
||||
self.worker.start()
|
||||
self.attachments = []
|
||||
self.load_images = False
|
||||
# We'll put images here, so it will be easier to work with them.
|
||||
self.images = []
|
||||
self.imageIndex = 0
|
||||
|
||||
def get_comments(self):
|
||||
""" Get comments and insert them in a list."""
|
||||
user = self.post[self.user_identifier]
|
||||
id = self.post[self.post_identifier]
|
||||
self.comments = self.session.vk.client.wall.getComments(owner_id=user, post_id=id, need_likes=1, count=100, extended=1, preview_length=0)
|
||||
comments_ = []
|
||||
for i in self.comments["items"]:
|
||||
# If comment has a "deleted" key it should not be displayed, obviously.
|
||||
if "deleted" in i:
|
||||
continue
|
||||
from_ = get_user(i["from_id"], self.comments["profiles"])
|
||||
if i.has_key("reply_to_user"):
|
||||
extra_info = get_user(i["reply_to_user"], self.comments["profiles"])
|
||||
from_ = _(u"{0} > {1}").format(from_, extra_info)
|
||||
# As we set the comment reply properly in the from_ field, let's remove the first username from here if it exists.
|
||||
fixed_text = re.sub("^\[id\d+\|\D+\], ", "", i["text"])
|
||||
if len(fixed_text) > 140:
|
||||
text = fixed_text[:141]
|
||||
else:
|
||||
text = fixed_text
|
||||
original_date = arrow.get(i["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.getLanguage())
|
||||
likes = str(i["likes"]["count"])
|
||||
comments_.append((from_, text, created_at, likes))
|
||||
try:
|
||||
self.dialog.insert_comments(comments_)
|
||||
except wx.PyDeadObjectError:
|
||||
pass
|
||||
|
||||
def get_post_information(self):
|
||||
from_ = self.session.get_user_name(self.post[self.user_identifier])
|
||||
if self.post.has_key("copy_history"):
|
||||
# Translators: {0} will be replaced with an user.
|
||||
title = _(u"repost from {0}").format(from_,)
|
||||
else:
|
||||
if self.post.has_key("from_id") and self.post.has_key("owner_id"):
|
||||
# Translators: {0} will be replaced with the user who is posting, and {1} with the wall owner.
|
||||
title = _(u"Post from {0} in the {1}'s wall").format(self.session.get_user_name(self.post["from_id"]), self.session.get_user_name(self.post["owner_id"]))
|
||||
else:
|
||||
title = _(u"Post from {0}").format(from_,)
|
||||
self.dialog.set_title(title)
|
||||
message = u""
|
||||
message = get_message(self.post)
|
||||
if self.post.has_key("copy_history"):
|
||||
nm = u"\n"
|
||||
for i in self.post["copy_history"]:
|
||||
nm += u"{0}: {1}\n\n".format(self.session.get_user_name(i["from_id"]), get_message(i))
|
||||
self.get_attachments(i)
|
||||
message += nm
|
||||
self.dialog.set_post(message)
|
||||
self.get_attachments(self.post)
|
||||
self.check_image_load()
|
||||
|
||||
def get_attachments(self, post):
|
||||
attachments = []
|
||||
if post.has_key("attachments"):
|
||||
for i in post["attachments"]:
|
||||
# We don't need the photos_list attachment, so skip it.
|
||||
if i["type"] == "photos_list":
|
||||
continue
|
||||
if i["type"] == "photo":
|
||||
if self.load_images == False: self.load_images = True
|
||||
self.images.append(i)
|
||||
attachments.append(utils.add_attachment(i))
|
||||
self.attachments.append(i)
|
||||
# Links in text are not treated like normal attachments, so we'll have to catch and add those to the list without title
|
||||
# We can't get a title because title is provided by the VK API and it will not work for links as simple text.
|
||||
urls = utils.find_urls_in_text(self.dialog.get("post_view"))
|
||||
if len(urls) > 0:
|
||||
links = []
|
||||
for i in urls:
|
||||
links.append({"link": {"title": _(U"Untitled link"), "url": i}, "type": "link"})
|
||||
for i in links:
|
||||
attachments.append(utils.add_attachment(i))
|
||||
self.attachments.append(i)
|
||||
if len(self.attachments) > 0:
|
||||
self.dialog.attachments.list.Enable(True)
|
||||
self.dialog.attachments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.open_attachment)
|
||||
self.dialog.insert_attachments(attachments)
|
||||
|
||||
def check_image_load(self):
|
||||
if self.load_images and len(self.images) > 0 and self.session.settings["general"]["load_images"]:
|
||||
self.dialog.image.Enable(True)
|
||||
nav = False # Disable navigation controls in photos
|
||||
if len(self.images) > 1:
|
||||
nav = True
|
||||
widgetUtils.connect_event(self.dialog.previous_photo, widgetUtils.BUTTON_PRESSED, self.set_previous_image)
|
||||
widgetUtils.connect_event(self.dialog.next_photo, widgetUtils.BUTTON_PRESSED, self.set_next_image)
|
||||
self.dialog.enable_photo_controls(navigation=nav)
|
||||
self.set_image(0)
|
||||
|
||||
def set_next_image(self, *args, **kwargs):
|
||||
if self.imageIndex < -1 or self.imageIndex == len(self.images)-1:
|
||||
self.imageIndex = -1
|
||||
if len(self.images) <= self.imageIndex+1:
|
||||
self.imageIndex = 0
|
||||
else:
|
||||
self.imageIndex = self.imageIndex + 1
|
||||
self.set_image(self.imageIndex)
|
||||
|
||||
def set_previous_image(self, *args, **kwargs):
|
||||
if self.imageIndex <= 0:
|
||||
self.imageIndex = len(self.images)
|
||||
self.imageIndex = self.imageIndex - 1
|
||||
self.set_image(self.imageIndex)
|
||||
|
||||
def set_image(self, index):
|
||||
if len(self.images) < index-1:
|
||||
log.exception("Error in loading image {0} in a list with {1} images".format(index, len(self.images)))
|
||||
return
|
||||
# Get's photo URL.
|
||||
url = self.get_photo_url(self.images[index]["photo"], "x")
|
||||
if url != "":
|
||||
img = requests.get(url)
|
||||
image = wx.Image(stream=cStringIO.StringIO(requests.get(url).content))
|
||||
try:
|
||||
self.dialog.image.SetBitmap(wx.Bitmap(image))
|
||||
except NameError:
|
||||
return
|
||||
self.dialog.SetClientSize(self.dialog.sizer.CalcMin())
|
||||
# Translators: {0} is the number of the current photo and {1} is the total number of photos.
|
||||
output.speak(_(u"Loaded photo {0} of {1}").format(index+1, len(self.images)))
|
||||
return
|
||||
|
||||
def get_photo_url(self, photo, size="x"):
|
||||
url = ""
|
||||
for i in photo["sizes"]:
|
||||
if i["type"] == size:
|
||||
url = i["url"]
|
||||
break
|
||||
return url
|
||||
|
||||
def load_all_components(self):
|
||||
self.get_post_information()
|
||||
self.get_likes()
|
||||
self.get_reposts()
|
||||
self.get_comments()
|
||||
if self.post["comments"]["can_post"] == 0:
|
||||
self.dialog.disable("comment")
|
||||
if self.post["likes"]["can_like"] == 0 and self.post["likes"]["user_likes"] == 0:
|
||||
self.dialog.disable("like")
|
||||
elif self.post["likes"]["user_likes"] == 1:
|
||||
self.dialog.set("like", _(u"&Dislike"))
|
||||
if self.post["likes"]["can_publish"] == 0:
|
||||
self.dialog.disable("repost")
|
||||
|
||||
def post_like(self, *args, **kwargs):
|
||||
if self.post.has_key("owner_id") == False:
|
||||
user = int(self.post[self.user_identifier])
|
||||
else:
|
||||
user = int(self.post["owner_id"])
|
||||
id = int(self.post[self.post_identifier])
|
||||
if self.post.has_key("type"):
|
||||
type_ = self.post["type"]
|
||||
else:
|
||||
type_ = "post"
|
||||
if self.dialog.get("like") == _(u"&Dislike"):
|
||||
l = self.session.vk.client.likes.delete(owner_id=user, item_id=id, type=type_)
|
||||
output.speak(_(u"You don't like this"))
|
||||
self.post["likes"]["count"] = l["likes"]
|
||||
self.post["likes"]["user_likes"] = 2
|
||||
self.get_likes()
|
||||
self.dialog.set("like", _(u"&Like"))
|
||||
else:
|
||||
l = self.session.vk.client.likes.add(owner_id=user, item_id=id, type=type_)
|
||||
output.speak(_(u"You liked this"))
|
||||
self.dialog.set("like", _(u"&Dislike"))
|
||||
self.post["likes"]["count"] = l["likes"]
|
||||
self.post["likes"]["user_likes"] = 1
|
||||
self.get_likes()
|
||||
|
||||
def post_repost(self, *args, **kwargs):
|
||||
object_id = "wall{0}_{1}".format(self.post[self.user_identifier], self.post[self.post_identifier])
|
||||
p = messages.post(session=self.session, title=_(u"Repost"), caption=_(u"Add your comment here"), text="")
|
||||
if p.message.get_response() == widgetUtils.OK:
|
||||
msg = p.message.get_text().encode("utf-8")
|
||||
self.session.vk.client.wall.repost(object=object_id, message=msg)
|
||||
|
||||
def get_likes(self):
|
||||
try:
|
||||
self.dialog.set_likes(self.post["likes"]["count"])
|
||||
except wx.PyDeadObjectError:
|
||||
pass
|
||||
|
||||
def get_reposts(self):
|
||||
try:
|
||||
self.dialog.set_shares(self.post["reposts"]["count"])
|
||||
except wx.PyDeadObjectError:
|
||||
pass
|
||||
|
||||
def add_comment(self, *args, **kwargs):
|
||||
comment = messages.comment(session=self.session, title=_(u"Add a comment"), caption="", text="")
|
||||
if comment.message.get_response() == widgetUtils.OK:
|
||||
msg = comment.message.get_text().encode("utf-8")
|
||||
try:
|
||||
user = self.post[self.user_identifier]
|
||||
id = self.post[self.post_identifier]
|
||||
self.session.vk.client.wall.addComment(owner_id=user, post_id=id, text=msg)
|
||||
output.speak(_(u"You've posted a comment"))
|
||||
if self.comments["count"] < 100:
|
||||
self.clear_comments_list()
|
||||
self.get_comments()
|
||||
except Exception as msg:
|
||||
log.error(msg)
|
||||
|
||||
def clear_comments_list(self):
|
||||
self.dialog.comments.clear()
|
||||
|
||||
def show_comment(self, *args, **kwargs):
|
||||
c = comment(self.session, self.comments["data"][self.dialog.comments.get_selected()])
|
||||
c.dialog.get_response()
|
||||
|
||||
def show_menu(self, *args, **kwargs):
|
||||
if self.dialog.comments.get_count() == 0: return
|
||||
menu = menus.commentMenu()
|
||||
widgetUtils.connect_event(self.dialog, widgetUtils.MENU, self.show_comment, menuitem=menu.open)
|
||||
widgetUtils.connect_event(self.dialog, widgetUtils.MENU, self.comment_like, menuitem=menu.like)
|
||||
widgetUtils.connect_event(self.dialog, widgetUtils.MENU, self.comment_unlike, menuitem=menu.unlike)
|
||||
self.dialog.PopupMenu(menu, self.dialog.comments.list.GetPosition())
|
||||
|
||||
def show_menu_by_key(self, ev):
|
||||
if ev.GetKeyCode() == wx.WXK_WINDOWS_MENU:
|
||||
self.show_menu()
|
||||
|
||||
def show_tools_menu(self, *args, **kwargs):
|
||||
menu = menus.toolsMenu()
|
||||
widgetUtils.connect_event(self.dialog, widgetUtils.MENU, self.open_url, menuitem=menu.url)
|
||||
widgetUtils.connect_event(self.dialog, widgetUtils.MENU, self.translate, menuitem=menu.translate)
|
||||
widgetUtils.connect_event(self.dialog, widgetUtils.MENU, self.spellcheck, menuitem=menu.CheckSpelling)
|
||||
self.dialog.PopupMenu(menu, self.dialog.tools.GetPosition())
|
||||
|
||||
def comment_like(self, *args, **kwargs):
|
||||
comment_id = self.comments["data"][self.dialog.comments.get_selected()]["id"]
|
||||
self.session.like(comment_id)
|
||||
output.speak(_(u"You do like this comment"))
|
||||
|
||||
def comment_unlike(self, *args, **kwargs):
|
||||
comment_id = self.comments["data"][self.dialog.comments.get_selected()]["id"]
|
||||
self.session.unlike(comment_id)
|
||||
output.speak(_(u"You don't like this comment"))
|
||||
|
||||
def translate(self, *args, **kwargs):
|
||||
dlg = translator.gui.translateDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
text_to_translate = self.dialog.post_view.GetValue().encode("utf-8")
|
||||
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
||||
msg = translator.translator.translate(text_to_translate, target=dest)
|
||||
self.dialog.post_view.ChangeValue(msg)
|
||||
output.speak(_(u"Translated"))
|
||||
else:
|
||||
return
|
||||
|
||||
def spellcheck(self, *args, **kwargs):
|
||||
text = self.dialog.post_view.GetValue()
|
||||
checker = SpellChecker.spellchecker.spellChecker(text, "")
|
||||
if hasattr(checker, "fixed_text"):
|
||||
self.dialog.post_view.ChangeValue(checker.fixed_text)
|
||||
|
||||
def open_attachment(self, *args, **kwargs):
|
||||
index = self.dialog.attachments.get_selected()
|
||||
attachment = self.attachments[index]
|
||||
if attachment["type"] == "audio":
|
||||
a = audio(session=self.session, postObject=[attachment["audio"]])
|
||||
a.dialog.get_response()
|
||||
a.dialog.Destroy()
|
||||
if attachment["type"] == "link":
|
||||
output.speak(_(u"Opening URL..."), True)
|
||||
webbrowser.open_new_tab(attachment["link"]["url"])
|
||||
elif attachment["type"] == "doc":
|
||||
output.speak(_(u"Opening document in web browser..."))
|
||||
webbrowser.open(attachment["doc"]["url"])
|
||||
elif attachment["type"] == "video":
|
||||
# it seems VK doesn't like to attach video links as normal URLS, so we'll have to
|
||||
# get the full video object and use its "player" key which will open a webbrowser in their site with a player for the video.
|
||||
# see https://vk.com/dev/attachments_w and and https://vk.com/dev/video.get
|
||||
# However, the flash player isn't good for visually impaired people (when you press play you won't be able to close the window with alt+f4), so it could be good to use the HTML5 player.
|
||||
# For firefox, see https://addons.mozilla.org/ru/firefox/addon/force-html5-video-player-at-vk/
|
||||
# May be I could use a dialogue here for inviting people to use this addon in firefox. It seems it isn't possible to use this html5 player from the player URL.
|
||||
object_id = "{0}_{1}".format(attachment["video"]["owner_id"], attachment["video"]["id"])
|
||||
video_object = self.session.vk.client.video.get(owner_id=attachment["video"]["owner_id"], videos=object_id)
|
||||
video_object = video_object["items"][0]
|
||||
output.speak(_(u"Opening video in web browser..."), True)
|
||||
webbrowser.open_new_tab(video_object["player"])
|
||||
elif attachment["type"] == "photo":
|
||||
output.speak(_(u"Opening photo in web browser..."), True)
|
||||
# Possible photo sizes for looking in the attachment information. Try to use the biggest photo available.
|
||||
possible_sizes = [1280, 604, 130, 75]
|
||||
url = ""
|
||||
for i in possible_sizes:
|
||||
if attachment["photo"].has_key("photo_{0}".format(i,)):
|
||||
url = attachment["photo"]["photo_{0}".format(i,)]
|
||||
break
|
||||
if url != "":
|
||||
webbrowser.open_new_tab(url)
|
||||
else:
|
||||
log.debug("Unhandled attachment: %r" % (attachment,))
|
||||
|
||||
def __del__(self):
|
||||
if hasattr(self, "worker"):
|
||||
self.worker.finished.set()
|
||||
|
||||
class comment(object):
|
||||
def __init__(self, session, comment_object):
|
||||
super(comment, self).__init__()
|
||||
self.session = session
|
||||
self.comment = comment_object
|
||||
self.dialog = postDialogs.comment()
|
||||
from_ = self.comment["from"]["name"]
|
||||
message = self.comment["message"]
|
||||
original_date = arrow.get(self.comment["created_time"], "YYYY-MM-DTHH:m:sZ", locale="en")
|
||||
created_at = original_date.humanize(locale=languageHandler.getLanguage())
|
||||
self.dialog.set_post(message)
|
||||
self.dialog.set_title(_(u"Comment from {0}").format(from_,))
|
||||
widgetUtils.connect_event(self.dialog.like, widgetUtils.BUTTON_PRESSED, self.post_like)
|
||||
call_threaded(self.get_likes)
|
||||
|
||||
def get_likes(self):
|
||||
self.likes = self.session.fb.client.get_connections(id=self.comment["id"], connection_name="likes", summary=True)
|
||||
self.dialog.set_likes(self.likes["summary"]["total_count"])
|
||||
|
||||
def post_like(self, *args, **kwargs):
|
||||
lk = self.session.like(self.comment["id"])
|
||||
self.get_likes()
|
||||
|
||||
class audio(postController):
|
||||
def __init__(self, session, postObject):
|
||||
self.added_audios = {}
|
||||
self.session = session
|
||||
self.post = postObject
|
||||
self.dialog = postDialogs.audio()
|
||||
widgetUtils.connect_event(self.dialog.list, widgetUtils.LISTBOX_CHANGED, self.handle_changes)
|
||||
self.load_audios()
|
||||
self.fill_information(0)
|
||||
widgetUtils.connect_event(self.dialog.download, widgetUtils.BUTTON_PRESSED, self.download)
|
||||
widgetUtils.connect_event(self.dialog.play, widgetUtils.BUTTON_PRESSED, self.play)
|
||||
widgetUtils.connect_event(self.dialog.add, widgetUtils.BUTTON_PRESSED, self.add_to_library)
|
||||
widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_from_library)
|
||||
|
||||
def add_to_library(self, *args, **kwargs):
|
||||
post = self.post[self.dialog.get_audio()]
|
||||
args = {}
|
||||
args["audio_id"] = post["id"]
|
||||
if post.has_key("album_id"):
|
||||
args["album_id"] = post["album_id"]
|
||||
args["owner_id"] = post["owner_id"]
|
||||
audio = self.session.vk.client.audio.add(**args)
|
||||
if audio != None and int(audio) > 21:
|
||||
self.added_audios[post["id"]] = audio
|
||||
self.dialog.change_state("add", False)
|
||||
self.dialog.change_state("remove", True)
|
||||
|
||||
def remove_from_library(self, *args, **kwargs):
|
||||
post = self.post[self.dialog.get_audio()]
|
||||
args = {}
|
||||
if self.added_audios.has_key(post["id"]):
|
||||
args["audio_id"] = self.added_audios[post["id"]]
|
||||
args["owner_id"] = self.session.user_id
|
||||
else:
|
||||
args["audio_id"] = post["id"]
|
||||
args["owner_id"] = post["owner_id"]
|
||||
result = self.session.vk.client.audio.delete(**args)
|
||||
if int(result) == 1:
|
||||
self.dialog.change_state("add", True)
|
||||
self.dialog.change_state("remove", False)
|
||||
if self.added_audios.has_key(post["id"]):
|
||||
self.added_audios.pop(post["id"])
|
||||
|
||||
def fill_information(self, index):
|
||||
post = self.post[index]
|
||||
if post.has_key("artist"):
|
||||
self.dialog.set("artist", post["artist"])
|
||||
if post.has_key("title"):
|
||||
self.dialog.set("title", post["title"])
|
||||
if post.has_key("duration"):
|
||||
self.dialog.set("duration", utils.seconds_to_string(post["duration"]))
|
||||
self.dialog.set_title(u"{0} - {1}".format(post["title"], post["artist"]))
|
||||
call_threaded(self.get_lyrics)
|
||||
if post["owner_id"] == self.session.user_id or self.added_audios.has_key(post["id"]) == True:
|
||||
self.dialog.change_state("remove", True)
|
||||
self.dialog.change_state("add", False)
|
||||
else:
|
||||
self.dialog.change_state("add", True)
|
||||
self.dialog.change_state("remove", False)
|
||||
|
||||
def get_lyrics(self):
|
||||
post = self.post[self.dialog.get_audio()]
|
||||
if post.has_key("lyrics_id"):
|
||||
l = self.session.vk.client.audio.getLyrics(lyrics_id=int(post["lyrics_id"]))
|
||||
self.dialog.set("lyric", l["text"])
|
||||
else:
|
||||
self.dialog.change_state("lyric", False)
|
||||
|
||||
def download(self, *args, **kwargs):
|
||||
post = self.post[self.dialog.get_audio()]
|
||||
f = u"{0} - {1}.mp3".format(post["title"], post["artist"])
|
||||
path = self.dialog.get_destination_path(f)
|
||||
if path != None:
|
||||
pub.sendMessage("download-file", url=post["url"], filename=path)
|
||||
|
||||
def play(self, *args, **kwargs):
|
||||
post = self.post[self.dialog.get_audio()]
|
||||
pub.sendMessage("play-audio", audio_object=post)
|
||||
|
||||
def load_audios(self):
|
||||
for i in self.post:
|
||||
s = u"{0} - {1}. {2}".format(i["title"], i["artist"], utils.seconds_to_string(i["duration"]))
|
||||
self.dialog.insert_audio(s)
|
||||
self.dialog.list.SetSelection(0)
|
||||
if len(self.post) == 1:
|
||||
self.dialog.list.Enable(False)
|
||||
self.dialog.title.SetFocus()
|
||||
|
||||
def handle_changes(self, *args, **kwargs):
|
||||
p = self.dialog.get_audio()
|
||||
self.fill_information(p)
|
||||
|
||||
class friendship(object):
|
||||
|
||||
def __init__(self, session, post):
|
||||
self.session = session
|
||||
self.post = post
|
||||
self.dialog = postDialogs.friendship()
|
||||
list_of_friends = self.get_friend_names()
|
||||
from_ = self.session.get_user_name(self.post["source_id"])
|
||||
title = _(u"{0} added the following friends").format(from_,)
|
||||
self.dialog.set_title(title)
|
||||
self.set_friends_list(list_of_friends)
|
||||
|
||||
def get_friend_names(self):
|
||||
self.friends = self.post["friends"]["items"]
|
||||
return [self.session.get_user_name(i["user_id"]) for i in self.friends]
|
||||
|
||||
def set_friends_list(self, friendslist):
|
||||
for i in friendslist:
|
||||
self.dialog.friends.insert_item(False, *[i])
|
||||
|
||||
class userProfile(object):
|
||||
|
||||
def __init__(self, session, user_id):
|
||||
self.person = None
|
||||
self.session = session
|
||||
self.user_id = user_id
|
||||
self.dialog = profiles.userProfile(title=_(u"Profile"))
|
||||
self.dialog.create_controls("main_info")
|
||||
self.dialog.realice()
|
||||
self.get_basic_information()
|
||||
if self.person != None:
|
||||
self.dialog.get_response()
|
||||
|
||||
def get_basic_information(self):
|
||||
""" Gets and inserts basic user information.
|
||||
See https://vk.com/dev/users.get"""
|
||||
fields = "first_name, last_name, bdate, city, country, home_town, photo_200_orig, online, site, status, last_seen, occupation, relation, relatives, personal, connections, activities, interests, music, movies, tv, books, games, about, quotes, can_write_private_message"
|
||||
person = self.session.vk.client.users.get(user_ids=self.user_id, fields=fields)
|
||||
if len(person) == 0:
|
||||
return output.speak(_(u"Information for groups is not supported, yet."))
|
||||
person = person[0]
|
||||
print person
|
||||
# Gets full name.
|
||||
n = u"{0} {1}".format(person["first_name"], person["last_name"])
|
||||
# Gets birthdate.
|
||||
if person.has_key("bdate") and person["bdate"] != "":
|
||||
self.dialog.main_info.enable("bdate")
|
||||
if len(person["bdate"]) <= 5:
|
||||
d = arrow.get(person["bdate"], "D.m")
|
||||
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D"), locale=languageHandler.getLanguage()))
|
||||
else:
|
||||
d = arrow.get(person["bdate"], "D.M.YYYY")
|
||||
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D, YYYY"), locale=languageHandler.getLanguage()))
|
||||
# Gets current city and home town
|
||||
city = ""
|
||||
if person.has_key("home_town") and person["home_town"] != "":
|
||||
home_town = person["home_town"]
|
||||
self.dialog.main_info.enable("home_town")
|
||||
self.dialog.main_info.set("home_town", home_town)
|
||||
if person.has_key("city") and len(person["city"]) > 0:
|
||||
city = person["city"]["title"]
|
||||
if person.has_key("country") and person["country"] != "":
|
||||
if city != "":
|
||||
city = city+u", {0}".format(person["country"]["title"])
|
||||
else:
|
||||
city = person["country"]["title"]
|
||||
self.dialog.main_info.enable("city")
|
||||
self.dialog.main_info.set("city", city)
|
||||
self.dialog.main_info.set("name", n)
|
||||
self.dialog.SetTitle(_(u"{name}'s profile").format(name=n,))
|
||||
# Gets website
|
||||
if person.has_key("site") and person["site"] != "":
|
||||
self.dialog.main_info.enable("website")
|
||||
self.dialog.main_info.set("website", person["site"])
|
||||
self.dialog.main_info.enable("go_site")
|
||||
widgetUtils.connect_event(self.dialog.main_info.go_site, widgetUtils.BUTTON_PRESSED, self.visit_website)
|
||||
if person.has_key("status") and person["status"] != "":
|
||||
self.dialog.main_info.enable("status")
|
||||
self.dialog.main_info.set("status", person["status"])
|
||||
if person.has_key("occupation") and person["occupation"] != None:
|
||||
if person["occupation"]["type"] == "work": c1 = _(u"Work ")
|
||||
elif person["occupation"]["type"] == "school": c1 = _(u"Student ")
|
||||
elif person["occupation"]["type"] == "university": c1 = _(u"Student ")
|
||||
if person["occupation"].has_key("name") and person["occupation"]["name"] != "":
|
||||
c2 = _(u"In {0}").format(person["occupation"]["name"],)
|
||||
else:
|
||||
c2 = ""
|
||||
self.dialog.main_info.enable("occupation")
|
||||
self.dialog.main_info.set("occupation", c1+c2)
|
||||
if person.has_key("relation") and person["relation"] != 0:
|
||||
print person["relation"]
|
||||
if person["relation"] == 1:
|
||||
r = _(u"Single")
|
||||
elif person["relation"] == 2:
|
||||
if person.has_key("relation_partner"):
|
||||
r = _(u"Dating with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
else:
|
||||
r = _(u"Dating")
|
||||
elif person["relation"] == 3:
|
||||
r = _(u"Engaged with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
elif person["relation"] == 4:
|
||||
r = _(u"Married with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
elif person["relation"] == 5:
|
||||
r = _(u"It's complicated")
|
||||
elif person["relation"] == 6:
|
||||
r = _(u"Actively searching")
|
||||
elif person["relation"] == 7:
|
||||
r = _(u"In love")
|
||||
self.dialog.main_info.enable("relation")
|
||||
self.dialog.main_info.relation.SetLabel(_(u"Relationship: ")+r)
|
||||
if person.has_key("last_seen") and person["last_seen"] != False:
|
||||
original_date = arrow.get(person["last_seen"]["time"])
|
||||
# Translators: This is the date of last seen
|
||||
last_seen = _(u"{0}").format(original_date.humanize(locale=languageHandler.getLanguage()),)
|
||||
self.dialog.main_info.enable("last_seen")
|
||||
self.dialog.main_info.set("last_seen", last_seen)
|
||||
log.info("getting info...")
|
||||
self.person = person
|
||||
self.dialog.SetClientSize(self.dialog.sizer.CalcMin())
|
||||
|
||||
def visit_website(self, *args, **kwargs):
|
||||
output.speak(_(u"Opening website..."))
|
||||
webbrowser.open_new_tab(self.person["site"])
|
@@ -1,161 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" A profile viewer and editor for VK user objects."""
|
||||
import cStringIO
|
||||
import webbrowser
|
||||
import logging
|
||||
import arrow
|
||||
import requests
|
||||
import languageHandler
|
||||
import widgetUtils
|
||||
import output
|
||||
import wx
|
||||
from wxUI.dialogs import urlList, profiles
|
||||
from sessionmanager import utils
|
||||
|
||||
log = logging.getLogger("controller.profiles")
|
||||
|
||||
class userProfile(object):
|
||||
""" Main controller to view an user profile. This controller will retrieve needed data from the VK website and display it appropiately."""
|
||||
|
||||
def __init__(self, session, user_id):
|
||||
""" Default constructor:
|
||||
@session vk.session: The main session object, capable of calling VK methods.
|
||||
@user_id integer: User ID to retrieve information of.
|
||||
At the current time, only users (and not communities) are supported.
|
||||
"""
|
||||
# self.person will hold a reference to the user object when retrieved from VK.
|
||||
self.person = None
|
||||
self.session = session
|
||||
self.user_id = user_id
|
||||
self.dialog = profiles.userProfile(title=_(u"Profile"))
|
||||
self.dialog.create_controls("main_info")
|
||||
self.dialog.realice()
|
||||
self.get_basic_information()
|
||||
if self.person != None:
|
||||
self.dialog.get_response()
|
||||
|
||||
def get_basic_information(self):
|
||||
""" Gets and inserts basic user information.
|
||||
See https://vk.com/dev/users.get"""
|
||||
# List of fields (information) to retrieve. For a list of fields available for user objects,
|
||||
# see https://vk.com/dev/fields
|
||||
fields = "first_name, last_name, bdate, city, country, home_town, photo_200_orig, online, site, status, last_seen, occupation, relation, relatives, personal, connections, activities, interests, music, movies, tv, books, games, about, quotes, can_write_private_message"
|
||||
# ToDo: this method supports multiple user IDS, I'm not sure if this may be of any help for profile viewer.
|
||||
person = self.session.vk.client.users.get(user_ids=self.user_id, fields=fields)
|
||||
# If VK does not return anything it is very likely we have found a community.
|
||||
if len(person) == 0:
|
||||
return output.speak(_(u"Information for groups is not supported, yet."))
|
||||
person = person[0]
|
||||
# toDo: remove this print when I will be done with creation of profile viewer logic.
|
||||
print(person)
|
||||
# From this part we will format data from VK so users will see it in the GUI control.
|
||||
# Format full name.
|
||||
n = u"{0} {1}".format(person["first_name"], person["last_name"])
|
||||
# Format birthdate.
|
||||
if person.has_key("bdate") and person["bdate"] != "":
|
||||
self.dialog.main_info.enable("bdate")
|
||||
# VK can display dd.mm or dd.mm.yyyy birthdates. So let's compare the string lenght to handle both cases accordingly.
|
||||
if len(person["bdate"]) <= 5: # dd.mm
|
||||
d = arrow.get(person["bdate"], "D.M")
|
||||
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D"), locale=languageHandler.curLang[:2]))
|
||||
else: # mm.dd.yyyy
|
||||
d = arrow.get(person["bdate"], "D.M.YYYY")
|
||||
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D, YYYY"), locale=languageHandler.curLang[:2]))
|
||||
# Format current city and home town
|
||||
city = ""
|
||||
if person.has_key("home_town") and person["home_town"] != "":
|
||||
home_town = person["home_town"]
|
||||
self.dialog.main_info.enable("home_town")
|
||||
self.dialog.main_info.set("home_town", home_town)
|
||||
if person.has_key("city") and len(person["city"]) > 0:
|
||||
city = person["city"]["title"]
|
||||
if person.has_key("country") and person["country"] != "":
|
||||
if city != "":
|
||||
city = city+u", {0}".format(person["country"]["title"])
|
||||
else:
|
||||
city = person["country"]["title"]
|
||||
self.dialog.main_info.enable("city")
|
||||
self.dialog.main_info.set("city", city)
|
||||
self.dialog.main_info.set("name", n)
|
||||
self.dialog.SetTitle(_(u"{name}'s profile").format(name=n,))
|
||||
# Format website (or websites, if there are multiple of them).
|
||||
if person.has_key("site") and person["site"] != "":
|
||||
self.dialog.main_info.enable("website")
|
||||
self.dialog.main_info.set("website", person["site"])
|
||||
self.dialog.main_info.enable("go_site")
|
||||
widgetUtils.connect_event(self.dialog.main_info.go_site, widgetUtils.BUTTON_PRESSED, self.visit_website)
|
||||
# Format status message.
|
||||
if person.has_key("status") and person["status"] != "":
|
||||
self.dialog.main_info.enable("status")
|
||||
self.dialog.main_info.set("status", person["status"])
|
||||
# Format occupation.
|
||||
# toDo: Research in this field is needed. Sometimes it returns university information even if users have active work places.
|
||||
if person.has_key("occupation") and person["occupation"] != None:
|
||||
if person["occupation"]["type"] == "work": c1 = _(u"Work ")
|
||||
elif person["occupation"]["type"] == "school": c1 = _(u"Student ")
|
||||
elif person["occupation"]["type"] == "university": c1 = _(u"Student ")
|
||||
if person["occupation"].has_key("name") and person["occupation"]["name"] != "":
|
||||
c2 = _(u"In {0}").format(person["occupation"]["name"],)
|
||||
else:
|
||||
c2 = ""
|
||||
self.dialog.main_info.enable("occupation")
|
||||
self.dialog.main_info.set("occupation", c1+c2)
|
||||
# format relationship status.
|
||||
# ToDo: When dating someone, the button associated to the information should point to the profile of the user.
|
||||
if person.has_key("relation") and person["relation"] != 0:
|
||||
if person["relation"] == 1:
|
||||
r = _(u"Single")
|
||||
elif person["relation"] == 2:
|
||||
if person.has_key("relation_partner"):
|
||||
r = _(u"Dating with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
else:
|
||||
r = _(u"Dating")
|
||||
elif person["relation"] == 3:
|
||||
r = _(u"Engaged with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
elif person["relation"] == 4:
|
||||
r = _(u"Married with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
elif person["relation"] == 5:
|
||||
r = _(u"It's complicated")
|
||||
elif person["relation"] == 6:
|
||||
r = _(u"Actively searching")
|
||||
elif person["relation"] == 7:
|
||||
r = _(u"In love")
|
||||
self.dialog.main_info.enable("relation")
|
||||
self.dialog.main_info.relation.SetLabel(_(u"Relationship: ")+r)
|
||||
# format last seen.
|
||||
if person.has_key("last_seen") and person["last_seen"] != False:
|
||||
original_date = arrow.get(person["last_seen"]["time"])
|
||||
# Translators: This is the date of last seen
|
||||
last_seen = _(u"{0}").format(original_date.humanize(locale=languageHandler.curLang[:2]),)
|
||||
self.dialog.main_info.enable("last_seen")
|
||||
self.dialog.main_info.set("last_seen", last_seen)
|
||||
self.person = person
|
||||
# Adds photo to the dialog.
|
||||
# ToDo: Need to ask if this has a visible effect in the dialog.
|
||||
if person.has_key("photo_200_orig"):
|
||||
img = requests.get(person["photo_200_orig"])
|
||||
image = wx.Image(stream=cStringIO.StringIO(requests.get(person["photo_200_orig"]).content))
|
||||
try:
|
||||
self.dialog.image.SetBitmap(wx.Bitmap(image))
|
||||
except ValueError:
|
||||
return
|
||||
self.dialog.panel.Layout()
|
||||
|
||||
def visit_website(self, *args, **kwargs):
|
||||
""" Allows to visit an user's website. """
|
||||
text = self.person["site"]
|
||||
# Let's search for URLS with a regexp, as there are users with multiple websites in their profiles.
|
||||
urls = utils.find_urls_in_text(text)
|
||||
if len(urls) == 0:
|
||||
output.speak(_(u"No URL addresses were detected."))
|
||||
return
|
||||
elif len(urls) == 1:
|
||||
selected_url = urls[0]
|
||||
else:
|
||||
dialog = urlList.urlList()
|
||||
dialog.populate_list(urls)
|
||||
if dialog.get_response() != widgetUtils.OK:
|
||||
return
|
||||
selected_url = urls[dialog.get_item()]
|
||||
output.speak(_(u"Opening URL..."))
|
||||
webbrowser.open_new_tab(selected_url)
|
@@ -1,4 +1,4 @@
|
||||
import spellchecker
|
||||
from . import spellchecker
|
||||
import platform
|
||||
if platform.system() == "Windows":
|
||||
from wx_ui import *
|
||||
from .wx_ui import *
|
115
src/extra/SpellChecker/checker.py
Normal file
115
src/extra/SpellChecker/checker.py
Normal file
@@ -0,0 +1,115 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" High level Spell checker module by using the SymSpellPy library. """
|
||||
import os
|
||||
import glob
|
||||
import shutil
|
||||
import logging
|
||||
import paths
|
||||
from symspellpy.symspellpy import SymSpell, Verbosity
|
||||
from codecs import open as open_
|
||||
|
||||
log = logging.getLogger("SpellChecker.checker")
|
||||
|
||||
loaded_dicts = dict()
|
||||
ready = False
|
||||
|
||||
def load_dicts():
|
||||
global loaded_dicts, ready
|
||||
log.debug("Start dictionary loading for spelling checker module...")
|
||||
if len(loaded_dicts) > 0:
|
||||
loaded_dicts = dict()
|
||||
path = os.path.join(paths.config_path(), "dicts")
|
||||
if os.path.isdir(path):
|
||||
log.debug("Loading language dictionaries from path %s" % (path,))
|
||||
files = glob.glob(os.path.join(path, "*.txt"))
|
||||
log.debug("%r files found." % (len(files)))
|
||||
for i in files:
|
||||
key = os.path.splitext(os.path.basename(i))[0]
|
||||
dictionary = SymSpell()
|
||||
dictionary.load_dictionary(i, 0, 1, encoding="utf-8")
|
||||
loaded_dicts[key] = dictionary
|
||||
log.debug("Added dictionary for language %s " % (key,))
|
||||
ready = True
|
||||
log.debug("All dicts were loaded.")
|
||||
|
||||
def prepare_dicts(language):
|
||||
""" Copy the main dictionary file to the user's config directory so it can be modified and read without needing to require privileged sessions.
|
||||
@ language: two letter language code.
|
||||
"""
|
||||
log.debug("preparing dictionary data...")
|
||||
path = os.path.join(paths.config_path(), "dicts")
|
||||
if os.path.exists(path) == False:
|
||||
log.debug("Creating dicts folder in config directory...")
|
||||
os.mkdir(path)
|
||||
original_file = os.path.join(paths.app_path(), "dictionaries", language+".txt")
|
||||
if os.path.exists(original_file) and os.path.exists(os.path.join(paths.config_path(), "dicts", language+".txt")) == False:
|
||||
log.debug("Dictionary for language %s is not present in user config. Coppying... " % (language,))
|
||||
dst_file = shutil.copy(original_file, os.path.join(paths.config_path(), "dicts"))
|
||||
|
||||
class SpellChecker(object):
|
||||
|
||||
def __init__(self, wordlist=None, *args, **kwargs):
|
||||
self.kwargs = kwargs
|
||||
self.dictionary = None
|
||||
self.ignored_words = []
|
||||
self.word_index = 0
|
||||
|
||||
def set_language(self, lang):
|
||||
global loaded_dicts
|
||||
if loaded_dicts.get(lang) != None:
|
||||
self.dictionary = loaded_dicts[lang]
|
||||
else:
|
||||
raise ValueError("Dictionary not found for the specified language")
|
||||
|
||||
def set_text(self, text):
|
||||
self.transformed_words = text.split()
|
||||
self.word_index = 0
|
||||
|
||||
def check_words(self):
|
||||
for word in range(0, len(self.transformed_words)):
|
||||
if self.transformed_words[word] in self.ignored_words:
|
||||
continue
|
||||
suggestions = self.dictionary.lookup(self.transformed_words[word], Verbosity.CLOSEST, 2, transfer_casing=True)
|
||||
valid_word = True
|
||||
if len(suggestions) == 0:
|
||||
continue
|
||||
for s in suggestions:
|
||||
if s.distance == 0:
|
||||
valid_word = False
|
||||
if valid_word == False:
|
||||
continue
|
||||
if word <= 10:
|
||||
if len(self.transformed_words) <= 10:
|
||||
context = " ".join(self.transformed_words)
|
||||
else:
|
||||
context = " ".join(self.transformed_words[0:10])
|
||||
elif word >= len(self.transformed_words)-9:
|
||||
context = " ".join(self.transformed_words[-10])
|
||||
else:
|
||||
context = " ".join(self.transformed_words[word-5:word+5])
|
||||
self.word_index = word
|
||||
yield (suggestions, context, word)
|
||||
|
||||
def replace(self, suggestion):
|
||||
if len(self.transformed_words) < self.word_index:
|
||||
raise ValueError("Word index is not present in the current text")
|
||||
self.transformed_words[self.word_index] = suggestion
|
||||
|
||||
def replace_all(self, word):
|
||||
existing_word = self.word
|
||||
for i in range(0, len(self.transformed_words)):
|
||||
if self.transformed_words[i] == existing_word:
|
||||
self.transformed_words[i] = word
|
||||
|
||||
def ignore_word(self, word):
|
||||
self.ignored_words.append(word)
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return " ".join(self.transformed_words)
|
||||
|
||||
@property
|
||||
def word(self):
|
||||
if len(self.transformed_words) == 0 or self.word_index >= len(self.transformed_words):
|
||||
return None
|
||||
return self.transformed_words[self.word_index]
|
@@ -1,34 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
import logging
|
||||
import wx_ui
|
||||
import widgetUtils
|
||||
import output
|
||||
import config
|
||||
import languageHandler
|
||||
from enchant.checker import SpellChecker
|
||||
from enchant.errors import DictNotFoundError
|
||||
from enchant import tokenize
|
||||
from platform_utils import paths
|
||||
from . import checker
|
||||
from . import wx_ui
|
||||
|
||||
log = logging.getLogger("extra.SpellChecker.spellChecker")
|
||||
|
||||
class spellChecker(object):
|
||||
def __init__(self, text, dictionary):
|
||||
def __init__(self, text):
|
||||
super(spellChecker, self).__init__()
|
||||
log.debug("Creating the SpellChecker object. Dictionary: %s" % (dictionary,))
|
||||
self.active = True
|
||||
self.checker = checker.SpellChecker()
|
||||
log.debug("Using language: %s" % (languageHandler.getLanguage(),))
|
||||
try:
|
||||
if config.app["app-settings"]["language"] == "system":
|
||||
log.debug("Using the system language")
|
||||
self.checker = SpellChecker(languageHandler.curLang, filters=[tokenize.EmailFilter, tokenize.URLFilter])
|
||||
else:
|
||||
log.debug("Using language: %s" % (languageHandler.getLanguage(),))
|
||||
self.checker = SpellChecker(languageHandler.curLang, filters=[tokenize.EmailFilter, tokenize.URLFilter])
|
||||
self.checker.set_text(text)
|
||||
except DictNotFoundError:
|
||||
print "no dict"
|
||||
log.exception("Dictionary for language %s not found." % (dictionary,))
|
||||
self.checker.set_language(languageHandler.curLang[:2])
|
||||
except ValueError:
|
||||
log.exception("Dictionary for language %s not found." % (languageHandler.curLang,))
|
||||
wx_ui.dict_not_found_error()
|
||||
self.active = False
|
||||
self.checker.set_text(text)
|
||||
self.generator = self.checker.check_words()
|
||||
if self.active == True:
|
||||
log.debug("Creating dialog...")
|
||||
self.dialog = wx_ui.spellCheckerDialog()
|
||||
@@ -38,16 +35,16 @@ class spellChecker(object):
|
||||
widgetUtils.connect_event(self.dialog.replaceAll, widgetUtils.BUTTON_PRESSED, self.replaceAll)
|
||||
self.check()
|
||||
self.dialog.get_response()
|
||||
self.fixed_text = self.checker.get_text()
|
||||
self.fixed_text = self.checker.text
|
||||
|
||||
def check(self):
|
||||
try:
|
||||
self.checker.next()
|
||||
textToSay = _(u"Misspelled word: %s") % (self.checker.word,)
|
||||
context = u"... %s %s %s" % (self.checker.leading_context(10), self.checker.word, self.checker.trailing_context(10))
|
||||
suggestions, context, self.wordIndex = next(self.generator)
|
||||
textToSay = _("Misspelled word: %s") % (self.checker.word,)
|
||||
context = context
|
||||
self.dialog.set_title(textToSay)
|
||||
output.speak(textToSay)
|
||||
self.dialog.set_word_and_suggestions(word=self.checker.word, context=context, suggestions=self.checker.suggest())
|
||||
self.dialog.set_word_and_suggestions(word=self.checker.word, context=context, suggestions=[suggestion.term for suggestion in suggestions])
|
||||
except StopIteration:
|
||||
log.debug("Process finished.")
|
||||
wx_ui.finished()
|
||||
@@ -57,7 +54,7 @@ class spellChecker(object):
|
||||
self.check()
|
||||
|
||||
def ignoreAll(self, ev):
|
||||
self.checker.ignore_always(word=self.checker.word)
|
||||
self.checker.ignore_word(word=self.checker.word)
|
||||
self.check()
|
||||
|
||||
def replace(self, ev):
|
||||
@@ -65,7 +62,7 @@ class spellChecker(object):
|
||||
self.check()
|
||||
|
||||
def replaceAll(self, ev):
|
||||
self.checker.replace_always(self.dialog.get_selected_suggestion())
|
||||
self.checker.replace_all(self.dialog.get_selected_suggestion())
|
||||
self.check()
|
||||
|
||||
def clean(self):
|
||||
|
@@ -16,6 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
############################################################
|
||||
from __future__ import unicode_literals
|
||||
import wx
|
||||
import application
|
||||
|
||||
@@ -24,25 +25,25 @@ class spellCheckerDialog(wx.Dialog):
|
||||
super(spellCheckerDialog, self).__init__(None, 1)
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
word = wx.StaticText(panel, -1, _(u"&Misspelled word"))
|
||||
word = wx.StaticText(panel, -1, _("&Misspelled word"))
|
||||
self.word = wx.TextCtrl(panel, -1)
|
||||
wordBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
wordBox.Add(word, 0, wx.ALL, 5)
|
||||
wordBox.Add(self.word, 0, wx.ALL, 5)
|
||||
context = wx.StaticText(panel, -1, _(u"Con&text"))
|
||||
context = wx.StaticText(panel, -1, _("Con&text"))
|
||||
self.context = wx.TextCtrl(panel, -1)
|
||||
contextBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
contextBox.Add(context, 0, wx.ALL, 5)
|
||||
contextBox.Add(self.context, 0, wx.ALL, 5)
|
||||
suggest = wx.StaticText(panel, -1, _(u"&Suggestions"))
|
||||
suggest = wx.StaticText(panel, -1, _("&Suggestions"))
|
||||
self.suggestions = wx.ListBox(panel, -1, choices=[], style=wx.LB_SINGLE)
|
||||
suggestionsBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
suggestionsBox.Add(suggest, 0, wx.ALL, 5)
|
||||
suggestionsBox.Add(self.suggestions, 0, wx.ALL, 5)
|
||||
self.ignore = wx.Button(panel, -1, _(u"&Ignore"))
|
||||
self.ignoreAll = wx.Button(panel, -1, _(u"Ignore &all"))
|
||||
self.replace = wx.Button(panel, -1, _(u"&Replace"))
|
||||
self.replaceAll = wx.Button(panel, -1, _(u"Replace a&ll"))
|
||||
self.ignore = wx.Button(panel, -1, _("&Ignore"))
|
||||
self.ignoreAll = wx.Button(panel, -1, _("Ignore &all"))
|
||||
self.replace = wx.Button(panel, -1, _("&Replace"))
|
||||
self.replaceAll = wx.Button(panel, -1, _("Replace a&ll"))
|
||||
close = wx.Button(panel, wx.ID_CANCEL)
|
||||
btnBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
btnBox.Add(self.ignore, 0, wx.ALL, 5)
|
||||
@@ -73,7 +74,7 @@ class spellCheckerDialog(wx.Dialog):
|
||||
return self.suggestions.GetStringSelection()
|
||||
|
||||
def dict_not_found_error():
|
||||
wx.MessageDialog(None, _(u"An error has occurred. There are no dictionaries available for the selected language in {0}").format(application.name,), _(u"Error"), wx.ICON_ERROR).ShowModal()
|
||||
wx.MessageDialog(None, _("An error has occurred. There are no dictionaries available for the selected language in {0}").format(application.name,), _("Error"), wx.ICON_ERROR).ShowModal()
|
||||
|
||||
def finished():
|
||||
wx.MessageDialog(None, _(u"Spell check complete."), application.name, style=wx.OK).ShowModal()
|
||||
wx.MessageDialog(None, _("Spell check complete."), application.name, style=wx.OK).ShowModal()
|
||||
|
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import translator
|
||||
import platform
|
||||
from . import translator
|
||||
if platform.system() == "Windows":
|
||||
import wx_ui as gui
|
||||
from . import wx_ui as gui
|
||||
|
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from builtins import zip
|
||||
from yandex_translate import YandexTranslate
|
||||
|
||||
def translate(text="", target="en"):
|
||||
@@ -9,97 +11,97 @@ def translate(text="", target="en"):
|
||||
supported_langs = None
|
||||
d = None
|
||||
languages = {
|
||||
"af": _(u"Afrikaans"),
|
||||
"sq": _(u"Albanian"),
|
||||
"am": _(u"Amharic"),
|
||||
"ar": _(u"Arabic"),
|
||||
"hy": _(u"Armenian"),
|
||||
"az": _(u"Azerbaijani"),
|
||||
"eu": _(u"Basque"),
|
||||
"be": _(u"Belarusian"),
|
||||
"bn": _(u"Bengali"),
|
||||
"bh": _(u"Bihari"),
|
||||
"bg": _(u"Bulgarian"),
|
||||
"my": _(u"Burmese"),
|
||||
"ca": _(u"Catalan"),
|
||||
"chr": _(u"Cherokee"),
|
||||
"zh": _(u"Chinese"),
|
||||
"zh-CN": _(u"Chinese_simplified"),
|
||||
"zh-TW": _(u"Chinese_traditional"),
|
||||
"hr": _(u"Croatian"),
|
||||
"cs": _(u"Czech"),
|
||||
"da": _(u"Danish"),
|
||||
"dv": _(u"Dhivehi"),
|
||||
"nl": _(u"Dutch"),
|
||||
"en": _(u"English"),
|
||||
"eo": _(u"Esperanto"),
|
||||
"et": _(u"Estonian"),
|
||||
"tl": _(u"Filipino"),
|
||||
"fi": _(u"Finnish"),
|
||||
"fr": _(u"French"),
|
||||
"gl": _(u"Galician"),
|
||||
"ka": _(u"Georgian"),
|
||||
"de": _(u"German"),
|
||||
"el": _(u"Greek"),
|
||||
"gn": _(u"Guarani"),
|
||||
"gu": _(u"Gujarati"),
|
||||
"iw": _(u"Hebrew"),
|
||||
"hi": _(u"Hindi"),
|
||||
"hu": _(u"Hungarian"),
|
||||
"is": _(u"Icelandic"),
|
||||
"id": _(u"Indonesian"),
|
||||
"iu": _(u"Inuktitut"),
|
||||
"ga": _(u"Irish"),
|
||||
"it": _(u"Italian"),
|
||||
"ja": _(u"Japanese"),
|
||||
"kn": _(u"Kannada"),
|
||||
"kk": _(u"Kazakh"),
|
||||
"km": _(u"Khmer"),
|
||||
"ko": _(u"Korean"),
|
||||
"ku": _(u"Kurdish"),
|
||||
"ky": _(u"Kyrgyz"),
|
||||
"lo": _(u"Laothian"),
|
||||
"lv": _(u"Latvian"),
|
||||
"lt": _(u"Lithuanian"),
|
||||
"mk": _(u"Macedonian"),
|
||||
"ms": _(u"Malay"),
|
||||
"ml": _(u"Malayalam"),
|
||||
"mt": _(u"Maltese"),
|
||||
"mr": _(u"Marathi"),
|
||||
"mn": _(u"Mongolian"),
|
||||
"ne": _(u"Nepali"),
|
||||
"no": _(u"Norwegian"),
|
||||
"or": _(u"Oriya"),
|
||||
"ps": _(u"Pashto"),
|
||||
"fa": _(u"Persian"),
|
||||
"pl": _(u"Polish"),
|
||||
"pt": _(u"Portuguese"),
|
||||
"pa": _(u"Punjabi"),
|
||||
"ro": _(u"Romanian"),
|
||||
"ru": _(u"Russian"),
|
||||
"sa": _(u"Sanskrit"),
|
||||
"sr": _(u"Serbian"),
|
||||
"sd": _(u"Sindhi"),
|
||||
"si": _(u"Sinhalese"),
|
||||
"sk": _(u"Slovak"),
|
||||
"sl": _(u"Slovenian"),
|
||||
"es": _(u"Spanish"),
|
||||
"sw": _(u"Swahili"),
|
||||
"sv": _(u"Swedish"),
|
||||
"tg": _(u"Tajik"),
|
||||
"ta": _(u"Tamil"),
|
||||
"tl": _(u"Tagalog"),
|
||||
"te": _(u"Telugu"),
|
||||
"th": _(u"Thai"),
|
||||
"bo": _(u"Tibetan"),
|
||||
"tr": _(u"Turkish"),
|
||||
"uk": _(u"Ukrainian"),
|
||||
"ur": _(u"Urdu"),
|
||||
"uz": _(u"Uzbek"),
|
||||
"ug": _(u"Uighur"),
|
||||
"vi": _(u"Vietnamese"),
|
||||
"cy": _(u"Welsh"),
|
||||
"yi": _(u"Yiddish")
|
||||
"af": _("Afrikaans"),
|
||||
"sq": _("Albanian"),
|
||||
"am": _("Amharic"),
|
||||
"ar": _("Arabic"),
|
||||
"hy": _("Armenian"),
|
||||
"az": _("Azerbaijani"),
|
||||
"eu": _("Basque"),
|
||||
"be": _("Belarusian"),
|
||||
"bn": _("Bengali"),
|
||||
"bh": _("Bihari"),
|
||||
"bg": _("Bulgarian"),
|
||||
"my": _("Burmese"),
|
||||
"ca": _("Catalan"),
|
||||
"chr": _("Cherokee"),
|
||||
"zh": _("Chinese"),
|
||||
"zh-CN": _("Chinese_simplified"),
|
||||
"zh-TW": _("Chinese_traditional"),
|
||||
"hr": _("Croatian"),
|
||||
"cs": _("Czech"),
|
||||
"da": _("Danish"),
|
||||
"dv": _("Dhivehi"),
|
||||
"nl": _("Dutch"),
|
||||
"en": _("English"),
|
||||
"eo": _("Esperanto"),
|
||||
"et": _("Estonian"),
|
||||
"tl": _("Filipino"),
|
||||
"fi": _("Finnish"),
|
||||
"fr": _("French"),
|
||||
"gl": _("Galician"),
|
||||
"ka": _("Georgian"),
|
||||
"de": _("German"),
|
||||
"el": _("Greek"),
|
||||
"gn": _("Guarani"),
|
||||
"gu": _("Gujarati"),
|
||||
"iw": _("Hebrew"),
|
||||
"hi": _("Hindi"),
|
||||
"hu": _("Hungarian"),
|
||||
"is": _("Icelandic"),
|
||||
"id": _("Indonesian"),
|
||||
"iu": _("Inuktitut"),
|
||||
"ga": _("Irish"),
|
||||
"it": _("Italian"),
|
||||
"ja": _("Japanese"),
|
||||
"kn": _("Kannada"),
|
||||
"kk": _("Kazakh"),
|
||||
"km": _("Khmer"),
|
||||
"ko": _("Korean"),
|
||||
"ku": _("Kurdish"),
|
||||
"ky": _("Kyrgyz"),
|
||||
"lo": _("Laothian"),
|
||||
"lv": _("Latvian"),
|
||||
"lt": _("Lithuanian"),
|
||||
"mk": _("Macedonian"),
|
||||
"ms": _("Malay"),
|
||||
"ml": _("Malayalam"),
|
||||
"mt": _("Maltese"),
|
||||
"mr": _("Marathi"),
|
||||
"mn": _("Mongolian"),
|
||||
"ne": _("Nepali"),
|
||||
"no": _("Norwegian"),
|
||||
"or": _("Oriya"),
|
||||
"ps": _("Pashto"),
|
||||
"fa": _("Persian"),
|
||||
"pl": _("Polish"),
|
||||
"pt": _("Portuguese"),
|
||||
"pa": _("Punjabi"),
|
||||
"ro": _("Romanian"),
|
||||
"ru": _("Russian"),
|
||||
"sa": _("Sanskrit"),
|
||||
"sr": _("Serbian"),
|
||||
"sd": _("Sindhi"),
|
||||
"si": _("Sinhalese"),
|
||||
"sk": _("Slovak"),
|
||||
"sl": _("Slovenian"),
|
||||
"es": _("Spanish"),
|
||||
"sw": _("Swahili"),
|
||||
"sv": _("Swedish"),
|
||||
"tg": _("Tajik"),
|
||||
"ta": _("Tamil"),
|
||||
"tl": _("Tagalog"),
|
||||
"te": _("Telugu"),
|
||||
"th": _("Thai"),
|
||||
"bo": _("Tibetan"),
|
||||
"tr": _("Turkish"),
|
||||
"uk": _("Ukrainian"),
|
||||
"ur": _("Urdu"),
|
||||
"uz": _("Uzbek"),
|
||||
"ug": _("Uighur"),
|
||||
"vi": _("Vietnamese"),
|
||||
"cy": _("Welsh"),
|
||||
"yi": _("Yiddish")
|
||||
}
|
||||
|
||||
def available_languages():
|
||||
|
@@ -16,15 +16,16 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
############################################################
|
||||
import translator
|
||||
from __future__ import unicode_literals
|
||||
import wx
|
||||
from . import translator
|
||||
|
||||
class translateDialog(wx.Dialog):
|
||||
def __init__(self):
|
||||
super(translateDialog, self).__init__(None, -1, title=_(u"Translate message"))
|
||||
super(translateDialog, self).__init__(None, -1, title=_("Translate message"))
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
staticDest = wx.StaticText(panel, -1, _(u"Target language"))
|
||||
staticDest = wx.StaticText(panel, -1, _("Target language"))
|
||||
self.dest_lang = wx.ComboBox(panel, -1, choices=[x[1] for x in translator.available_languages()], style = wx.CB_READONLY)
|
||||
self.dest_lang.SetFocus()
|
||||
self.dest_lang.SetSelection(0)
|
||||
|
@@ -1,13 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import sys
|
||||
from . import fix_requests
|
||||
|
||||
if hasattr(sys, "frozen"):
|
||||
from . import fix_win32com
|
||||
from . import fix_libloader
|
||||
#if hasattr(sys, "frozen"):
|
||||
from . import fix_win32com
|
||||
from . import fix_libloader
|
||||
|
||||
def setup():
|
||||
fix_requests.fix()
|
||||
if hasattr(sys, "frozen"):
|
||||
fix_libloader.fix()
|
||||
fix_win32com.fix()
|
||||
# if hasattr(sys, "frozen"):
|
||||
fix_libloader.fix()
|
||||
fix_win32com.fix()
|
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import win32com
|
||||
import paths
|
||||
win32com.__gen_path__=paths.com_path()
|
||||
win32com.__build_path__=paths.com_path()
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.join(win32com.__gen_path__, "."))
|
||||
|
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import requests
|
||||
import paths
|
||||
import os
|
||||
@@ -7,5 +8,5 @@ log = logging.getLogger("fixes.fix_requests")
|
||||
|
||||
def fix():
|
||||
log.debug("Applying fix for requests...")
|
||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(paths.app_path().decode(paths.fsencoding), "cacert.pem").encode(paths.fsencoding)
|
||||
log.debug("Changed CA path to %s" % (os.environ["REQUESTS_CA_BUNDLE"].decode(paths.fsencoding)))
|
||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(paths.app_path(), "cacert.pem")#.encode(paths.fsencoding)
|
||||
# log.debug("Changed CA path to %s" % (os.environ["REQUESTS_CA_BUNDLE"]))#.decode(paths.fsencoding)))
|
@@ -1,3 +1,4 @@
|
||||
from __future__ import unicode_literals
|
||||
import win32com.client
|
||||
def fix():
|
||||
if win32com.client.gencache.is_readonly == True:
|
||||
|
70
src/installer.nsi
Normal file
70
src/installer.nsi
Normal file
@@ -0,0 +1,70 @@
|
||||
!include "MUI2.nsh"
|
||||
!include "LogicLib.nsh"
|
||||
Unicode true
|
||||
CRCCheck on
|
||||
ManifestSupportedOS all
|
||||
XPStyle on
|
||||
Name "Socializer"
|
||||
OutFile "socializer_0.24_setup.exe"
|
||||
InstallDir "$PROGRAMFILES\socializer"
|
||||
InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "InstallLocation"
|
||||
RequestExecutionLevel admin
|
||||
SetCompress auto
|
||||
SetCompressor /solid lzma
|
||||
SetDatablockOptimize on
|
||||
VIAddVersionKey ProductName "Socializer"
|
||||
VIAddVersionKey LegalCopyright "Copyright 2019 Manuel Cortez."
|
||||
VIAddVersionKey ProductVersion "0.24"
|
||||
VIAddVersionKey FileVersion "0.24"
|
||||
VIProductVersion "0.24.0.0"
|
||||
VIFileVersion "0.24.0.0"
|
||||
!insertmacro MUI_PAGE_WELCOME
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
var StartMenuFolder
|
||||
!insertmacro MUI_PAGE_STARTMENU startmenu $StartMenuFolder
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
!define MUI_FINISHPAGE_LINK "Visit Socializer website"
|
||||
!define MUI_FINISHPAGE_LINK_LOCATION "http://socializer.su"
|
||||
!define MUI_FINISHPAGE_RUN "$INSTDIR\socializer.exe"
|
||||
!insertmacro MUI_PAGE_FINISH
|
||||
!insertmacro MUI_UNPAGE_CONFIRM
|
||||
!insertmacro MUI_UNPAGE_INSTFILES
|
||||
!insertmacro MUI_LANGUAGE "Russian"
|
||||
!insertmacro MUI_LANGUAGE "English"
|
||||
!insertmacro MUI_LANGUAGE "Spanish"
|
||||
|
||||
!insertmacro MUI_RESERVEFILE_LANGDLL
|
||||
Section
|
||||
SetShellVarContext All
|
||||
SetOutPath "$INSTDIR"
|
||||
File /r dist\*
|
||||
CreateShortCut "$DESKTOP\socializer.lnk" "$INSTDIR\socializer.exe"
|
||||
!insertmacro MUI_STARTMENU_WRITE_BEGIN startmenu
|
||||
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
|
||||
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\socializer.lnk" "$INSTDIR\socializer.exe"
|
||||
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Socializer on the web.lnk" "http://socializer.su"
|
||||
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
|
||||
!insertmacro MUI_STARTMENU_WRITE_END
|
||||
WriteUninstaller "$INSTDIR\Uninstall.exe"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "DisplayName" "Socializer"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall" "InstallLocation" $INSTDIR
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall" "Publisher" "Manuel Cortez"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "DisplayVersion" "0.24"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "URLInfoAbout" "http://socializer.su"
|
||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "VersionMajor" 0
|
||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "VersionMinor" 19
|
||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "NoModify" 1
|
||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "NoRepair" 1
|
||||
SectionEnd
|
||||
Section "Uninstall"
|
||||
SetShellVarContext All
|
||||
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer"
|
||||
RMDir /r /REBOOTOK $INSTDIR
|
||||
Delete "$DESKTOP\socializer.lnk"
|
||||
!insertmacro MUI_STARTMENU_GETFOLDER startmenu $StartMenuFolder
|
||||
RMDir /r "$SMPROGRAMS\$StartMenuFolder"
|
||||
SectionEnd
|
||||
Function .onInit
|
||||
!insertmacro MUI_LANGDLL_DISPLAY
|
||||
FunctionEnd
|
70
src/installer_alpha.nsi
Normal file
70
src/installer_alpha.nsi
Normal file
@@ -0,0 +1,70 @@
|
||||
!include "MUI2.nsh"
|
||||
!include "LogicLib.nsh"
|
||||
Unicode true
|
||||
CRCCheck on
|
||||
ManifestSupportedOS all
|
||||
XPStyle on
|
||||
Name "Socializer"
|
||||
OutFile "socializer_alpha_setup.exe"
|
||||
InstallDir "$PROGRAMFILES\socializer"
|
||||
InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "InstallLocation"
|
||||
RequestExecutionLevel admin
|
||||
SetCompress auto
|
||||
SetCompressor /solid lzma
|
||||
SetDatablockOptimize on
|
||||
VIAddVersionKey ProductName "Socializer"
|
||||
VIAddVersionKey LegalCopyright "Copyright 2019 Manuel Cortez."
|
||||
VIAddVersionKey ProductVersion "0.24"
|
||||
VIAddVersionKey FileVersion "0.24"
|
||||
VIProductVersion "0.24.0.0"
|
||||
VIFileVersion "0.24.0.0"
|
||||
!insertmacro MUI_PAGE_WELCOME
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
var StartMenuFolder
|
||||
!insertmacro MUI_PAGE_STARTMENU startmenu $StartMenuFolder
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
!define MUI_FINISHPAGE_LINK "Visit Socializer website"
|
||||
!define MUI_FINISHPAGE_LINK_LOCATION "http://socializer.su"
|
||||
!define MUI_FINISHPAGE_RUN "$INSTDIR\socializer.exe"
|
||||
!insertmacro MUI_PAGE_FINISH
|
||||
!insertmacro MUI_UNPAGE_CONFIRM
|
||||
!insertmacro MUI_UNPAGE_INSTFILES
|
||||
!insertmacro MUI_LANGUAGE "Russian"
|
||||
!insertmacro MUI_LANGUAGE "English"
|
||||
!insertmacro MUI_LANGUAGE "Spanish"
|
||||
|
||||
!insertmacro MUI_RESERVEFILE_LANGDLL
|
||||
Section
|
||||
SetShellVarContext All
|
||||
SetOutPath "$INSTDIR"
|
||||
File /r dist\*
|
||||
CreateShortCut "$DESKTOP\socializer.lnk" "$INSTDIR\socializer.exe"
|
||||
!insertmacro MUI_STARTMENU_WRITE_BEGIN startmenu
|
||||
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
|
||||
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\socializer.lnk" "$INSTDIR\socializer.exe"
|
||||
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Socializer on the web.lnk" "http://socializer.su"
|
||||
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
|
||||
!insertmacro MUI_STARTMENU_WRITE_END
|
||||
WriteUninstaller "$INSTDIR\Uninstall.exe"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "DisplayName" "Socializer"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "UninstallString" '"$INSTDIR\uninstall.exe"'
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall" "InstallLocation" $INSTDIR
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall" "Publisher" "Manuel Cortez"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "DisplayVersion" "0.24"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "URLInfoAbout" "http://socializer.su"
|
||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "VersionMajor" 0
|
||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "VersionMinor" 19
|
||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "NoModify" 1
|
||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer" "NoRepair" 1
|
||||
SectionEnd
|
||||
Section "Uninstall"
|
||||
SetShellVarContext All
|
||||
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\socializer"
|
||||
RMDir /r /REBOOTOK $INSTDIR
|
||||
Delete "$DESKTOP\socializer.lnk"
|
||||
!insertmacro MUI_STARTMENU_GETFOLDER startmenu $StartMenuFolder
|
||||
RMDir /r "$SMPROGRAMS\$StartMenuFolder"
|
||||
SectionEnd
|
||||
Function .onInit
|
||||
!insertmacro MUI_LANGDLL_DISPLAY
|
||||
FunctionEnd
|
8
src/interactors/__init__.py
Normal file
8
src/interactors/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from .base import *
|
||||
from .attach import *
|
||||
from . audioRecorder import *
|
||||
from . blacklist import *
|
||||
from .configuration import *
|
||||
from .postCreation import *
|
||||
from .postDisplayer import *
|
||||
from .profiles import *
|
93
src/interactors/attach.py
Normal file
93
src/interactors/attach.py
Normal file
@@ -0,0 +1,93 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import widgetUtils
|
||||
from pubsub import pub
|
||||
from wxUI.dialogs import selector
|
||||
from wxUI.menus import attachMenu
|
||||
from . import base
|
||||
|
||||
class attachInteractor(base.baseInteractor):
|
||||
|
||||
def insert_attachment(self, attachment):
|
||||
self.view.attachments.insert_item(False, *attachment)
|
||||
|
||||
def remove_attachment(self, attachment):
|
||||
self.view.attachments.remove_item(attachment)
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(attachInteractor, self).install(*args, **kwargs)
|
||||
widgetUtils.connect_event(self.view.photo, widgetUtils.BUTTON_PRESSED, self.on_image)
|
||||
widgetUtils.connect_event(self.view.audio, widgetUtils.BUTTON_PRESSED, self.on_audio)
|
||||
widgetUtils.connect_event(self.view.document, widgetUtils.BUTTON_PRESSED, self.on_document)
|
||||
if hasattr(self.view, "voice_message"):
|
||||
widgetUtils.connect_event(self.view.voice_message, widgetUtils.BUTTON_PRESSED, self.on_upload_voice_message)
|
||||
widgetUtils.connect_event(self.view.remove, widgetUtils.BUTTON_PRESSED, self.on_remove_attachment)
|
||||
pub.subscribe(self.insert_attachment, self.modulename+"_insert_attachment")
|
||||
pub.subscribe(self.remove_attachment, self.modulename+"_remove_attachment")
|
||||
|
||||
def uninstall(self):
|
||||
super(attachInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.insert_attachment, self.modulename+"_insert_attachment")
|
||||
pub.unsubscribe(self.remove_attachment, self.modulename+"_remove_attachment")
|
||||
|
||||
def on_image(self, *args, **kwargs):
|
||||
""" display menu for adding image attachments. """
|
||||
m = attachMenu()
|
||||
# disable add from VK as it is not supported in images, yet.
|
||||
m.add.Enable(False)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.on_upload_image, menuitem=m.upload)
|
||||
self.view.PopupMenu(m, self.view.photo.GetPosition())
|
||||
|
||||
def on_audio(self, *args, **kwargs):
|
||||
""" display menu to add audio attachments."""
|
||||
m = attachMenu()
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.on_upload_audio, menuitem=m.upload)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.on_add_audio, menuitem=m.add)
|
||||
self.view.PopupMenu(m, self.view.audio.GetPosition())
|
||||
|
||||
def on_document(self, *args, **kwargs):
|
||||
""" display menu for adding document attachments. """
|
||||
m = attachMenu()
|
||||
# disable add from VK as it is not supported in documents, yet.
|
||||
m.add.Enable(False)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.on_upload_document, menuitem=m.upload)
|
||||
self.view.PopupMenu(m, self.view.photo.GetPosition())
|
||||
|
||||
def on_upload_image(self, *args, **kwargs):
|
||||
""" allows uploading an image from the computer.
|
||||
"""
|
||||
image, description = self.view.get_image()
|
||||
if image != None:
|
||||
self.presenter.upload_image(image, description)
|
||||
|
||||
def on_upload_audio(self, *args, **kwargs):
|
||||
""" Allows uploading an audio file from the computer. Only mp3 files are supported. """
|
||||
audio = self.view.get_audio()
|
||||
if audio != None:
|
||||
self.presenter.upload_audio(audio)
|
||||
|
||||
def on_upload_document(self, *args, **kwargs):
|
||||
""" allows uploading a document from the computer.
|
||||
"""
|
||||
document = self.view.get_document()
|
||||
if document != None:
|
||||
if document.endswith(".mp3") or document.endswith(".exe"):
|
||||
self.view.invalid_attachment()
|
||||
return
|
||||
self.presenter.upload_document(document)
|
||||
|
||||
def on_upload_voice_message(self, *args, **kwargs):
|
||||
self.presenter.upload_voice_message()
|
||||
|
||||
def on_add_audio(self, *args, **kwargs):
|
||||
""" Allow adding an audio directly from the user's audio library."""
|
||||
audios = self.presenter.get_available_audios()
|
||||
select = selector.selectAttachment(_("Select the audio files you want to send"), audios)
|
||||
if select.get_response() == widgetUtils.OK and select.attachments.GetCount() > 0:
|
||||
attachments = select.get_all_attachments()
|
||||
self.presenter.take_audios(attachments)
|
||||
|
||||
def on_remove_attachment(self, *args, **kwargs):
|
||||
""" Remove the currently focused item from the attachments list."""
|
||||
current_item = self.view.attachments.get_selected()
|
||||
self.presenter.remove_attachment(current_item)
|
29
src/interactors/audioRecorder.py
Normal file
29
src/interactors/audioRecorder.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import widgetUtils
|
||||
from pubsub import pub
|
||||
from . import base
|
||||
|
||||
class audioRecorderInteractor(base.baseInteractor):
|
||||
def install(self, presenter, view, modulename="audiorecorder"):
|
||||
super(audioRecorderInteractor, self).install(view=view, presenter=presenter, modulename=modulename)
|
||||
widgetUtils.connect_event(view.play, widgetUtils.BUTTON_PRESSED, self.on_play)
|
||||
widgetUtils.connect_event(view.record, widgetUtils.BUTTON_PRESSED, self.on_record)
|
||||
widgetUtils.connect_event(view.discard, widgetUtils.BUTTON_PRESSED, self.on_discard)
|
||||
|
||||
def start(self):
|
||||
result = self.view.get_response()
|
||||
if result == widgetUtils.OK:
|
||||
self.on_postprocess()
|
||||
|
||||
def on_record(self, *args, **kwargs):
|
||||
self.presenter.toggle_recording()
|
||||
|
||||
def on_discard(self, *args, **kwargs):
|
||||
self.presenter.discard_recording()
|
||||
|
||||
def on_play(self, *args, **kwargs):
|
||||
self.presenter.play()
|
||||
|
||||
def on_postprocess(self):
|
||||
self.presenter.postprocess()
|
40
src/interactors/base.py
Normal file
40
src/interactors/base.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from pubsub import pub
|
||||
|
||||
class baseInteractor(object):
|
||||
|
||||
def install(self, view, presenter, modulename):
|
||||
self.modulename = modulename
|
||||
self.view = view
|
||||
self.presenter = presenter
|
||||
pub.subscribe(self.disable_control, "{modulename}_disable_control".format(modulename=modulename))
|
||||
pub.subscribe(self.enable_control, "{modulename}_enable_control".format(modulename=modulename))
|
||||
pub.subscribe(self.set_label, "{modulename}_set_label".format(modulename=modulename))
|
||||
pub.subscribe(self.focus_control, "{modulename}_focus_control".format(modulename=modulename))
|
||||
pub.subscribe(self.set_title, "{modulename}_set_title".format(modulename=modulename))
|
||||
|
||||
def uninstall(self):
|
||||
pub.unsubscribe(self.disable_control, "{modulename}_disable_control".format(modulename=self.modulename))
|
||||
pub.unsubscribe(self.enable_control, "{modulename}_enable_control".format(modulename=self.modulename))
|
||||
pub.unsubscribe(self.set_label, "{modulename}_set_label".format(modulename=self.modulename))
|
||||
pub.unsubscribe(self.focus_control, "{modulename}_focus_control".format(modulename=self.modulename))
|
||||
pub.unsubscribe(self.set_title, "{modulename}_set_title".format(modulename=self.modulename))
|
||||
self.view.Destroy()
|
||||
|
||||
def start(self):
|
||||
self.result = self.view.get_response()
|
||||
|
||||
def disable_control(self, control):
|
||||
self.view.disable(control)
|
||||
|
||||
def enable_control(self, control):
|
||||
self.view.enable(control)
|
||||
|
||||
def focus_control(self, control):
|
||||
getattr(self.view, control).SetFocus()
|
||||
|
||||
def set_label(self, control, label):
|
||||
self.view.set(control, label)
|
||||
|
||||
def set_title(self, value):
|
||||
self.view.SetTitle(value)
|
31
src/interactors/blacklist.py
Normal file
31
src/interactors/blacklist.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import widgetUtils
|
||||
from wxUI import commonMessages
|
||||
from pubsub import pub
|
||||
from . import base
|
||||
|
||||
class blacklistInteractor(base.baseInteractor):
|
||||
|
||||
def add_items(self, control, items):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
for i in items:
|
||||
getattr(self.view, control).insert_item(False, *i)
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(blacklistInteractor, self).install(*args, **kwargs)
|
||||
widgetUtils.connect_event(self.view.unblock, widgetUtils.BUTTON_PRESSED, self.on_unblock)
|
||||
pub.subscribe(self.add_items, self.modulename+"_add_items")
|
||||
|
||||
def uninstall(self):
|
||||
super(blacklistInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.add_items, self.modulename+"_add_items")
|
||||
|
||||
|
||||
def on_unblock(self, *args, **kwargs):
|
||||
question = commonMessages.unblock_person()
|
||||
if question == widgetUtils.NO:
|
||||
return
|
||||
item = self.view.persons.get_selected()
|
||||
if self.presenter.unblock_person(item) == 1:
|
||||
self.view.persons.remove_item(item)
|
72
src/interactors/configuration.py
Normal file
72
src/interactors/configuration.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import widgetUtils
|
||||
from pubsub import pub
|
||||
from wxUI.commonMessages import restart_program as restart_program_dialog
|
||||
from . import base
|
||||
|
||||
class configurationInteractor(base.baseInteractor):
|
||||
|
||||
def create_tab(self, tab, arglist=dict()):
|
||||
getattr(self.view, "create_"+tab)(**arglist)
|
||||
|
||||
def set_setting(self, tab, setting, value):
|
||||
self.view.set_value(tab, setting, value)
|
||||
|
||||
def restart(self):
|
||||
dlg = restart_program_dialog()
|
||||
if dlg == widgetUtils.YES:
|
||||
self.presenter.restart_application()
|
||||
|
||||
def set_language(self, language):
|
||||
self.view.general.language.SetSelection(language)
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(configurationInteractor, self).install(*args, **kwargs)
|
||||
pub.subscribe(self.create_tab, self.modulename+"_create_tab")
|
||||
pub.subscribe(self.set_setting, self.modulename+"_set")
|
||||
pub.subscribe(self.restart, self.modulename+"_restart_program")
|
||||
pub.subscribe(self.set_language, self.modulename+"_set_language")
|
||||
|
||||
def uninstall(self):
|
||||
super(configurationInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.create_tab, self.modulename+"_create_tab")
|
||||
pub.unsubscribe(self.set_setting, self.modulename+"_set")
|
||||
pub.unsubscribe(self.restart, self.modulename+"_restart_program")
|
||||
pub.unsubscribe(self.set_language, self.modulename+"_set_language")
|
||||
|
||||
def start(self):
|
||||
self.view.realize()
|
||||
result = self.view.get_response()
|
||||
if result == widgetUtils.OK:
|
||||
self.on_save_settings()
|
||||
|
||||
def on_save_settings(self, *args, **kwargs):
|
||||
self.presenter.update_setting(section="buffers", setting="count_for_wall_buffers", value=self.view.get_value("buffers", "wall_buffer_count"))
|
||||
self.presenter.update_setting(section="buffers", setting="count_for_video_buffers", value=self.view.get_value("buffers", "video_buffers_count"))
|
||||
self.presenter.update_setting(section="buffers", setting="count_for_chat_buffers", value=self.view.get_value("buffers", "chat_buffers_count"))
|
||||
self.presenter.update_setting(section="general", setting="load_images", value=self.view.get_value("general", "load_images"))
|
||||
update_channel = self.presenter.get_update_channel_type(self.view.get_value("general", "update_channel"))
|
||||
if update_channel != self.presenter.session.settings["general"]["update_channel"]:
|
||||
if update_channel == "stable":
|
||||
self.presenter.update_setting(section="general", setting="update_channel", value=update_channel)
|
||||
elif update_channel == "weekly":
|
||||
dialog = self.view.weekly_channel()
|
||||
if dialog == widgetUtils.YES:
|
||||
self.presenter.update_setting(section="general", setting="update_channel", value=update_channel)
|
||||
elif update_channel == "alpha":
|
||||
dialog = self.view.alpha_channel()
|
||||
if dialog == widgetUtils.YES:
|
||||
self.presenter.update_setting(section="general", setting="update_channel", value=update_channel)
|
||||
self.presenter.update_setting(section="chat", setting="notify_online", value=self.view.get_value("chat", "notify_online"))
|
||||
self.presenter.update_setting(section="chat", setting="notify_offline", value=self.view.get_value("chat", "notify_offline"))
|
||||
self.presenter.update_setting(section="chat", setting="notifications", value=self.presenter.get_notification_type(self.view.get_value("chat", "notifications")))
|
||||
self.presenter.update_setting(section="load_at_startup", setting="audio_albums", value=self.view.get_value("startup", "audio_albums"))
|
||||
self.presenter.update_setting(section="load_at_startup", setting="video_albums", value=self.view.get_value("startup", "video_albums"))
|
||||
self.presenter.update_setting(section="load_at_startup", setting="communities", value=self.view.get_value("startup", "communities"))
|
||||
self.presenter.update_app_setting(section="app-settings", setting="language", value=self.presenter.codes[self.view.general.language.GetSelection()])
|
||||
self.presenter.update_app_setting(section="sound", setting="input_device", value=self.view.get_value("sound", "input"))
|
||||
self.presenter.update_app_setting(section="sound", setting="output_device", value=self.view.get_value("sound", "output"))
|
||||
self.presenter.update_app_setting(section="app-settings", setting="use_proxy", value=self.view.get_value("general", "use_proxy"))
|
||||
self.presenter.save_app_settings_file()
|
||||
self.presenter.save_settings_file()
|
71
src/interactors/postCreation.py
Normal file
71
src/interactors/postCreation.py
Normal file
@@ -0,0 +1,71 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import widgetUtils
|
||||
from wxUI.dialogs import selector
|
||||
from pubsub import pub
|
||||
from extra import translator
|
||||
from .import base
|
||||
|
||||
class createPostInteractor(base.baseInteractor):
|
||||
|
||||
def set(self, control, value):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
getattr(self.view, control).SetValue(value)
|
||||
|
||||
def add_tagged_users(self, users):
|
||||
self.view.text.SetValue(self.view.text.GetValue()+", ".join(users))
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(createPostInteractor, self).install(*args, **kwargs)
|
||||
widgetUtils.connect_event(self.view.spellcheck, widgetUtils.BUTTON_PRESSED, self.on_spellcheck)
|
||||
widgetUtils.connect_event(self.view.translateButton, widgetUtils.BUTTON_PRESSED, self.on_translate)
|
||||
widgetUtils.connect_event(self.view.mention, widgetUtils.BUTTON_PRESSED, self.on_mention)
|
||||
if hasattr(self.view, "attach"):
|
||||
widgetUtils.connect_event(self.view.attach, widgetUtils.BUTTON_PRESSED, self.on_add_attachments)
|
||||
pub.subscribe(self.set, self.modulename+"_set")
|
||||
pub.subscribe(self.add_tagged_users, self.modulename+"_add_tagged_users")
|
||||
|
||||
def uninstall(self):
|
||||
super(createPostInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.set, self.modulename+"_set")
|
||||
pub.unsubscribe(self.add_tagged_users, self.modulename+"_add_tagged_users")
|
||||
|
||||
def start(self):
|
||||
self.result = self.view.get_response()
|
||||
if self.result == widgetUtils.OK:
|
||||
self.presenter.text = self.view.get_text()
|
||||
if hasattr(self.view, "privacy"):
|
||||
self.presenter.privacy = self.get_privacy_options()
|
||||
else:
|
||||
self.presenter.privacy = 0
|
||||
|
||||
def get_privacy_options(self):
|
||||
p = self.view.get("privacy")
|
||||
if p == _("Friends of friends"):
|
||||
privacy = 0
|
||||
elif p == _("All users"):
|
||||
privacy = 1
|
||||
return privacy
|
||||
|
||||
def on_mention(self, *args, **kwargs):
|
||||
users = self.presenter.get_friends()
|
||||
select = selector.selectPeople(users)
|
||||
if select.get_response() == widgetUtils.OK and select.users.GetCount() > 0:
|
||||
tagged_users = select.get_all_users()
|
||||
self.presenter.add_tagged_users(tagged_users)
|
||||
|
||||
def on_translate(self, *args, **kwargs):
|
||||
dlg = translator.gui.translateDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
text_to_translate = self.view.get_text()
|
||||
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
||||
self.presenter.translate(text_to_translate, dest)
|
||||
dlg.Destroy()
|
||||
|
||||
def on_spellcheck(self, event=None):
|
||||
text = self.view.get_text()
|
||||
self.presenter.spellcheck(text)
|
||||
|
||||
def on_add_attachments(self, *args, **kwargs):
|
||||
self.presenter.add_attachments()
|
286
src/interactors/postDisplayer.py
Normal file
286
src/interactors/postDisplayer.py
Normal file
@@ -0,0 +1,286 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import six
|
||||
import widgetUtils
|
||||
import wx
|
||||
from pubsub import pub
|
||||
from wxUI import menus
|
||||
from wxUI import commonMessages
|
||||
from .import base
|
||||
|
||||
class displayPostInteractor(base.baseInteractor):
|
||||
|
||||
def set(self, control, value):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
getattr(self.view, control).SetValue(value)
|
||||
|
||||
def load_image(self, image):
|
||||
image = wx.Image(stream=six.BytesIO(image.content))
|
||||
try:
|
||||
self.view.image.SetBitmap(wx.Bitmap(image))
|
||||
except ValueError:
|
||||
return
|
||||
self.view.panel.Layout()
|
||||
|
||||
def add_items(self, control, items):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
for i in items:
|
||||
getattr(self.view, control).insert_item(False, *i)
|
||||
|
||||
def add_item(self, control, item, reversed=False):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
getattr(self.view, control).insert_item(reversed, *item)
|
||||
|
||||
def enable_attachments(self):
|
||||
self.view.attachments.list.Enable(True)
|
||||
|
||||
def enable_photo_controls(self, navigation):
|
||||
self.view.enable_photo_controls(navigation)
|
||||
|
||||
def clean_list(self, list):
|
||||
if not hasattr(self.view, list):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
getattr(self.view, list).clear()
|
||||
|
||||
def post_deleted(self):
|
||||
msg = commonMessages.post_deleted()
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(displayPostInteractor, self).install(*args, **kwargs)
|
||||
if hasattr(self.view, "comments"):
|
||||
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_show_comment)
|
||||
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_comment_changed)
|
||||
self.view.attachments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_open_attachment)
|
||||
widgetUtils.connect_event(self.view.like, widgetUtils.BUTTON_PRESSED, self.on_like)
|
||||
widgetUtils.connect_event(self.view.comment, widgetUtils.BUTTON_PRESSED, self.on_add_comment)
|
||||
widgetUtils.connect_event(self.view.tools, widgetUtils.BUTTON_PRESSED, self.on_show_tools_menu)
|
||||
if hasattr(self.view, "likes"):
|
||||
widgetUtils.connect_event(self.view.likes, widgetUtils.BUTTON_PRESSED, self.on_show_likes_menu)
|
||||
if hasattr(self.view, "shares"):
|
||||
widgetUtils.connect_event(self.view.shares, widgetUtils.BUTTON_PRESSED, self.on_show_shares_menu)
|
||||
if hasattr(self.view, "repost"):
|
||||
widgetUtils.connect_event(self.view.repost, widgetUtils.BUTTON_PRESSED, self.on_repost)
|
||||
self.view.comments.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_focus)
|
||||
if hasattr(self.view, "reply"):
|
||||
widgetUtils.connect_event(self.view.reply, widgetUtils.BUTTON_PRESSED, self.on_reply)
|
||||
if hasattr(self.view, "load_more_comments"):
|
||||
widgetUtils.connect_event(self.view.load_more_comments, widgetUtils.BUTTON_PRESSED, self.on_load_more_comments)
|
||||
# self.view.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.on_show_menu, self.view.comments.list)
|
||||
# self.view.Bind(wx.EVT_LIST_KEY_DOWN, self.on_show_menu_by_key, self.view.comments.list)
|
||||
pub.subscribe(self.set, self.modulename+"_set")
|
||||
pub.subscribe(self.load_image, self.modulename+"_load_image")
|
||||
pub.subscribe(self.add_items, self.modulename+"_add_items")
|
||||
pub.subscribe(self.add_item, self.modulename+"_add_item")
|
||||
pub.subscribe(self.enable_attachments, self.modulename+"_enable_attachments")
|
||||
pub.subscribe(self.enable_photo_controls, self.modulename+"_enable_photo_controls")
|
||||
pub.subscribe(self.post_deleted, self.modulename+"_post_deleted")
|
||||
pub.subscribe(self.clean_list, self.modulename+"_clean_list")
|
||||
|
||||
def uninstall(self):
|
||||
super(displayPostInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.set, self.modulename+"_set")
|
||||
pub.unsubscribe(self.load_image, self.modulename+"_load_image")
|
||||
pub.unsubscribe(self.add_items, self.modulename+"_add_items")
|
||||
pub.unsubscribe(self.add_item, self.modulename+"_add_item")
|
||||
pub.unsubscribe(self.enable_attachments, self.modulename+"_enable_attachments")
|
||||
pub.unsubscribe(self.enable_photo_controls, self.modulename+"_enable_photo_controls")
|
||||
pub.unsubscribe(self.post_deleted, self.modulename+"_post_deleted")
|
||||
pub.unsubscribe(self.clean_list, self.modulename+"_clean_list")
|
||||
|
||||
def on_focus(self, *args, **kwargs):
|
||||
item = self.view.comments.get_selected()
|
||||
if item == -1:
|
||||
self.view.reply.Enable(False)
|
||||
else:
|
||||
self.view.reply.Enable(True)
|
||||
|
||||
def on_like(self, *args, **kwargs):
|
||||
self.presenter.post_like()
|
||||
|
||||
def on_repost(self, *args, **kwargs):
|
||||
self.presenter.post_repost()
|
||||
|
||||
def on_reply(self, *args, **kwargs):
|
||||
if hasattr(self.view, "comments") and (hasattr(self.view, "repost") or not hasattr(self, "post_view")):
|
||||
comment = self.view.comments.get_selected()
|
||||
self.presenter.reply(comment)
|
||||
else:
|
||||
self.presenter.reply()
|
||||
|
||||
def on_add_comment(self, *args, **kwargs):
|
||||
self.presenter.add_comment()
|
||||
|
||||
def on_load_more_comments(self, *args, **kwargs):
|
||||
if hasattr(self.presenter, "load_more_comments"):
|
||||
self.presenter.load_more_comments()
|
||||
|
||||
def on_show_tools_menu(self, *args, **kwargs):
|
||||
menu = menus.toolsMenu()
|
||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.on_open_url, menuitem=menu.url)
|
||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.on_translate, menuitem=menu.translate)
|
||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.on_spellcheck, menuitem=menu.CheckSpelling)
|
||||
self.view.PopupMenu(menu, self.view.tools.GetPosition())
|
||||
|
||||
def on_open_url(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def on_open_attachment(self, *args, **kwargs):
|
||||
attachment = self.view.attachments.get_selected()
|
||||
self.presenter.open_attachment(attachment)
|
||||
|
||||
def on_translate(self, *args, **kwargs):
|
||||
dlg = translator.gui.translateDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
text_to_translate = self.view.get("post_view")
|
||||
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
||||
self.presenter.translate(text_to_translate, dest)
|
||||
dlg.Destroy()
|
||||
|
||||
def on_spellcheck(self, event=None):
|
||||
text = self.view.get("post_view")
|
||||
self.presenter.spellcheck(text)
|
||||
|
||||
def on_show_comment(self, *args, **kwargs):
|
||||
comment = self.view.comments.get_selected()
|
||||
self.presenter.show_comment(comment)
|
||||
|
||||
def on_comment_changed(self, *args, **kwargs):
|
||||
if hasattr(self.presenter, "change_comment"):
|
||||
comment = self.view.comments.get_selected()
|
||||
self.presenter.change_comment(comment)
|
||||
|
||||
def on_show_likes_menu(self, *args, **kwargs):
|
||||
self.presenter.show_likes()
|
||||
|
||||
def on_show_shares_menu(self, *args, **kwargs):
|
||||
self.presenter.show_shares()
|
||||
|
||||
class displayAudioInteractor(base.baseInteractor):
|
||||
|
||||
def set(self, control, value):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
getattr(self.view, control).SetValue(value)
|
||||
|
||||
def add_items(self, control, items):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
for i in items:
|
||||
getattr(self.view, control).Append(i)
|
||||
getattr(self.view, control).SetSelection(0)
|
||||
|
||||
def change_label(self, stopped):
|
||||
|
||||
if stopped == False:
|
||||
self.view.play.SetLabel(_("P&ause"))
|
||||
else:
|
||||
self.view.play.SetLabel(_("P&lay"))
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(displayAudioInteractor, self).install(*args, **kwargs)
|
||||
widgetUtils.connect_event(self.view.list, widgetUtils.LISTBOX_CHANGED, self.on_change)
|
||||
widgetUtils.connect_event(self.view.download, widgetUtils.BUTTON_PRESSED, self.on_download)
|
||||
widgetUtils.connect_event(self.view.play, widgetUtils.BUTTON_PRESSED, self.on_play)
|
||||
widgetUtils.connect_event(self.view.add, widgetUtils.BUTTON_PRESSED, self.on_add_to_library)
|
||||
widgetUtils.connect_event(self.view.remove, widgetUtils.BUTTON_PRESSED, self.on_remove_from_library)
|
||||
pub.subscribe(self.set, self.modulename+"_set")
|
||||
pub.subscribe(self.add_items, self.modulename+"_add_items")
|
||||
pub.subscribe(self.change_label, "playback-changed")
|
||||
|
||||
def uninstall(self):
|
||||
super(displayAudioInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.set, self.modulename+"_set")
|
||||
pub.unsubscribe(self.add_items, self.modulename+"_add_items")
|
||||
pub.unsubscribe(self.change_label, "playback-changed")
|
||||
|
||||
def on_change(self, *args, **kwargs):
|
||||
post = self.view.get_audio()
|
||||
self.presenter.handle_changes(post)
|
||||
|
||||
def on_download(self, *args, **kwargs):
|
||||
post = self.view.get_audio()
|
||||
suggested_filename = self.presenter.get_suggested_filename(post)
|
||||
path = self.view.get_destination_path(suggested_filename)
|
||||
self.presenter.download(post, path)
|
||||
|
||||
def on_play(self, *args, **kwargs):
|
||||
post = self.view.get_audio()
|
||||
self.presenter.play(post)
|
||||
|
||||
def on_add_to_library(self, *args, **kwargs):
|
||||
post = self.view.get_audio()
|
||||
self.presenter.add_to_library(post)
|
||||
|
||||
def on_remove_from_library(self, *args, **kwargs):
|
||||
post = self.view.get_audio()
|
||||
self.presenter.remove_from_library(post)
|
||||
|
||||
class displayPollInteractor(base.baseInteractor):
|
||||
|
||||
def set(self, control, value):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
getattr(self.view, control).SetValue(value)
|
||||
|
||||
def done(self):
|
||||
self.view.done()
|
||||
|
||||
def add_options(self, options, multiple):
|
||||
self.view.add_options(options, multiple)
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(displayPollInteractor, self).install(*args, **kwargs)
|
||||
pub.subscribe(self.set, self.modulename+"_set")
|
||||
pub.subscribe(self.done, self.modulename+"_done")
|
||||
pub.subscribe(self.add_options, self.modulename+"_add_options")
|
||||
|
||||
def uninstall(self):
|
||||
super(displayPollInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.set, self.modulename+"_set")
|
||||
pub.unsubscribe(self.done, self.modulename+"_done")
|
||||
pub.unsubscribe(self.add_options, self.modulename+"_add_options")
|
||||
|
||||
def start(self, *args, **kwargs):
|
||||
super(displayPollInteractor, self).start(*args, **kwargs)
|
||||
if self.result == widgetUtils.OK: # USer votd.
|
||||
answers = self.view.get_answers()
|
||||
self.presenter.vote(answers)
|
||||
|
||||
class displayFriendshipInteractor(base.baseInteractor):
|
||||
|
||||
def add_items(self, control, items):
|
||||
if not hasattr(self.view, control):
|
||||
raise AttributeError("The control is not present in the view.")
|
||||
for i in items:
|
||||
getattr(self.view, control).insert_item(False, *[i])
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(displayFriendshipInteractor, self).install(*args, **kwargs)
|
||||
pub.subscribe(self.add_items, self.modulename+"_add_items")
|
||||
self.view.friends.list.Bind(wx.EVT_CONTEXT_MENU, self.on_context_menu)
|
||||
|
||||
def uninstall(self):
|
||||
super(displayFriendshipInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.add_items, self.modulename+"_add_items")
|
||||
|
||||
def on_context_menu(self, *args, **kwargs):
|
||||
item = self.view.friends.get_selected()
|
||||
if item < 0:
|
||||
return
|
||||
menu = menus.peopleMenu(False, False, True)
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.on_view_profile, menuitem=menu.view_profile)
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.on_open_in_browser, menuitem=menu.open_in_browser)
|
||||
# Generally message sending is blocked.
|
||||
menu.message.Enable(False)
|
||||
self.view.PopupMenu(menu, self.view.friends.list.GetPosition())
|
||||
|
||||
def on_view_profile(self, *args, **kwargs):
|
||||
item = self.view.friends.get_selected()
|
||||
self.presenter.view_profile(item)
|
||||
|
||||
def on_open_in_browser(self, *args, **kwargs):
|
||||
item = self.view.friends.get_selected()
|
||||
self.presenter.open_in_browser(item)
|
70
src/interactors/profiles.py
Normal file
70
src/interactors/profiles.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import six
|
||||
import wx
|
||||
import widgetUtils
|
||||
from pubsub import pub
|
||||
from views.dialogs import urlList
|
||||
from . import base
|
||||
|
||||
class userProfileInteractor(base.baseInteractor):
|
||||
|
||||
def enable_control(self, tab, control):
|
||||
if not hasattr(self.view, tab):
|
||||
raise AttributeError("The viw does not contain the specified tab.")
|
||||
tab = getattr(self.view, tab)
|
||||
if not hasattr(tab, control):
|
||||
raise AttributeError("The control is not present in the tab.")
|
||||
getattr(tab, control).Enable(True)
|
||||
|
||||
def set(self, tab, control, value):
|
||||
if not hasattr(self.view, tab):
|
||||
raise AttributeError("The view does not contain the specified tab.")
|
||||
tab = getattr(self.view, tab)
|
||||
if not hasattr(tab, control):
|
||||
raise AttributeError("The control is not present in the tab.")
|
||||
control = getattr(tab, control)
|
||||
control.SetValue(value)
|
||||
|
||||
def set_label(self, tab, control, value):
|
||||
if not hasattr(self.view, tab):
|
||||
raise AttributeError("The viw does not contain the specified tab.")
|
||||
tab = getattr(self.view, tab)
|
||||
if not hasattr(tab, control):
|
||||
raise AttributeError("The control is not present in the tab.")
|
||||
control = getattr(tab, control)
|
||||
control.SetLabel(value)
|
||||
|
||||
def load_image(self, image):
|
||||
image = wx.Image(stream=six.BytesIO(image.content))
|
||||
try:
|
||||
self.view.image.SetBitmap(wx.Bitmap(image))
|
||||
except ValueError:
|
||||
return
|
||||
self.view.panel.Layout()
|
||||
|
||||
def install(self, *args, **kwargs):
|
||||
super(userProfileInteractor, self).install(*args, **kwargs)
|
||||
pub.subscribe(self.set, self.modulename+"_set")
|
||||
pub.subscribe(self.load_image, self.modulename+"_load_image")
|
||||
self.view.create_controls("main_info")
|
||||
self.view.realice()
|
||||
widgetUtils.connect_event(self.view.main_info.go_site, widgetUtils.BUTTON_PRESSED, self.on_visit_website)
|
||||
|
||||
def uninstall(self):
|
||||
super(userProfileInteractor, self).uninstall()
|
||||
pub.unsubscribe(self.set, self.modulename+"_set")
|
||||
pub.unsubscribe(self.load_image, self.modulename+"_load_image")
|
||||
|
||||
|
||||
def on_visit_website(self, *args, **kwargs):
|
||||
urls = self.presenter.get_urls()
|
||||
if len(urls) == 1:
|
||||
self.presenter.visit_url(urls[0])
|
||||
else:
|
||||
dialog = urlList.urlList()
|
||||
dialog.populate_list(urls)
|
||||
if dialog.get_response() != widgetUtils.OK:
|
||||
return
|
||||
selected_url = urls[dialog.get_item()]
|
||||
self.presenter.visit_url(selected_url)
|
@@ -16,6 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
############################################################
|
||||
from __future__ import unicode_literals
|
||||
import wx
|
||||
import platform
|
||||
import requests
|
||||
@@ -51,7 +52,7 @@ class reportBug(object):
|
||||
issue_type = "issue" # for now just have issue
|
||||
app_type = paths.mode
|
||||
app_version = application.version
|
||||
reporter_name = u"{first_name} {last_name}".format(first_name=self.dialog.get("first_name"), last_name=self.dialog.get("last_name"))
|
||||
reporter_name = "{first_name} {last_name}".format(first_name=self.dialog.get("first_name"), last_name=self.dialog.get("last_name"))
|
||||
reporter_contact_type = "email" # For now just email is supported in the issue reporter
|
||||
reporter_contact_handle = self.dialog.get("email")
|
||||
operating_system = platform.platform()
|
||||
|
@@ -16,6 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
############################################################
|
||||
from __future__ import unicode_literals
|
||||
import wx
|
||||
import widgetUtils
|
||||
import application
|
||||
@@ -23,11 +24,11 @@ import application
|
||||
class reportBugDialog(widgetUtils.BaseDialog):
|
||||
def __init__(self):
|
||||
super(reportBugDialog, self).__init__(parent=None, id=wx.NewId())
|
||||
self.SetTitle(_(u"Report an error"))
|
||||
self.SetTitle(_("Report an error"))
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
summaryLabel = wx.StaticText(panel, -1, _(u"Briefly describe what happened. You will be able to thoroughly explain it later"), size=wx.DefaultSize)
|
||||
summaryLabel = wx.StaticText(panel, -1, _("Briefly describe what happened. You will be able to thoroughly explain it later"), size=wx.DefaultSize)
|
||||
self.summary = wx.TextCtrl(panel, -1)
|
||||
dc = wx.WindowDC(self.summary)
|
||||
dc.SetFont(self.summary.GetFont())
|
||||
@@ -37,7 +38,7 @@ class reportBugDialog(widgetUtils.BaseDialog):
|
||||
summaryB.Add(self.summary, 0, wx.ALL, 5)
|
||||
sizer.Add(summaryB, 0, wx.ALL, 5)
|
||||
|
||||
first_nameLabel = wx.StaticText(panel, -1, _(u"First Name"), size=wx.DefaultSize)
|
||||
first_nameLabel = wx.StaticText(panel, -1, _("First Name"), size=wx.DefaultSize)
|
||||
self.first_name = wx.TextCtrl(panel, -1)
|
||||
dc = wx.WindowDC(self.first_name)
|
||||
dc.SetFont(self.first_name.GetFont())
|
||||
@@ -47,7 +48,7 @@ class reportBugDialog(widgetUtils.BaseDialog):
|
||||
first_nameB.Add(self.first_name, 0, wx.ALL, 5)
|
||||
sizer.Add(first_nameB, 0, wx.ALL, 5)
|
||||
|
||||
last_nameLabel = wx.StaticText(panel, -1, _(u"Last Name"), size=wx.DefaultSize)
|
||||
last_nameLabel = wx.StaticText(panel, -1, _("Last Name"), size=wx.DefaultSize)
|
||||
self.last_name = wx.TextCtrl(panel, -1)
|
||||
dc = wx.WindowDC(self.last_name)
|
||||
dc.SetFont(self.last_name.GetFont())
|
||||
@@ -57,7 +58,7 @@ class reportBugDialog(widgetUtils.BaseDialog):
|
||||
last_nameB.Add(self.last_name, 0, wx.ALL, 5)
|
||||
sizer.Add(last_nameB, 0, wx.ALL, 5)
|
||||
|
||||
emailLabel = wx.StaticText(panel, -1, _(u"Email address (Will not be public)"), size=wx.DefaultSize)
|
||||
emailLabel = wx.StaticText(panel, -1, _("Email address (Will not be public)"), size=wx.DefaultSize)
|
||||
self.email = wx.TextCtrl(panel, -1)
|
||||
dc = wx.WindowDC(self.email)
|
||||
dc.SetFont(self.email.GetFont())
|
||||
@@ -67,7 +68,7 @@ class reportBugDialog(widgetUtils.BaseDialog):
|
||||
emailB.Add(self.email, 0, wx.ALL, 5)
|
||||
sizer.Add(emailB, 0, wx.ALL, 5)
|
||||
|
||||
descriptionLabel = wx.StaticText(panel, -1, _(u"Here, you can describe the bug in detail"), size=wx.DefaultSize)
|
||||
descriptionLabel = wx.StaticText(panel, -1, _("Here, you can describe the bug in detail"), size=wx.DefaultSize)
|
||||
self.description = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE)
|
||||
dc = wx.WindowDC(self.description)
|
||||
dc.SetFont(self.description.GetFont())
|
||||
@@ -77,12 +78,12 @@ class reportBugDialog(widgetUtils.BaseDialog):
|
||||
descBox.Add(descriptionLabel, 0, wx.ALL, 5)
|
||||
descBox.Add(self.description, 0, wx.ALL, 5)
|
||||
sizer.Add(descBox, 0, wx.ALL, 5)
|
||||
self.agree = wx.CheckBox(panel, -1, _(u"I know that the {0} bug system will get my email address to contact me and fix the bug quickly").format(application.name,))
|
||||
self.agree = wx.CheckBox(panel, -1, _("I know that the {0} bug system will get my email address to contact me and fix the bug quickly").format(application.name,))
|
||||
self.agree.SetValue(False)
|
||||
sizer.Add(self.agree, 0, wx.ALL, 5)
|
||||
self.ok = wx.Button(panel, wx.ID_OK, _(u"Send report"))
|
||||
self.ok = wx.Button(panel, wx.ID_OK, _("Send report"))
|
||||
self.ok.SetDefault()
|
||||
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"Cancel"))
|
||||
cancel = wx.Button(panel, wx.ID_CANCEL, _("Cancel"))
|
||||
btnBox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
btnBox.Add(self.ok, 0, wx.ALL, 5)
|
||||
btnBox.Add(cancel, 0, wx.ALL, 5)
|
||||
@@ -91,19 +92,19 @@ class reportBugDialog(widgetUtils.BaseDialog):
|
||||
self.SetClientSize(sizer.CalcMin())
|
||||
|
||||
def no_filled(self):
|
||||
wx.MessageDialog(self, _(u"You must fill out the following fields: first name, last name, email address and issue information."), _(u"Error"), wx.OK|wx.ICON_ERROR).ShowModal()
|
||||
wx.MessageDialog(self, _("You must fill out the following fields: first name, last name, email address and issue information."), _("Error"), wx.OK|wx.ICON_ERROR).ShowModal()
|
||||
|
||||
def no_checkbox(self):
|
||||
wx.MessageDialog(self, _(u"You need to mark the checkbox to provide us your email address to contact you if it is necessary."), _(u"Error"), wx.ICON_ERROR).ShowModal()
|
||||
wx.MessageDialog(self, _("You need to mark the checkbox to provide us your email address to contact you if it is necessary."), _("Error"), wx.ICON_ERROR).ShowModal()
|
||||
|
||||
def success(self, id):
|
||||
wx.MessageDialog(self, _(u"Thanks for reporting this bug! In future versions, you may be able to find it in the changes list. You have received an email with more information regarding your report. You've reported the bug number %i") % (id), _(u"reported"), wx.OK).ShowModal()
|
||||
wx.MessageDialog(self, _("Thanks for reporting this bug! In future versions, you may be able to find it in the changes list. You have received an email with more information regarding your report. You've reported the bug number %i") % (id), _("reported"), wx.OK).ShowModal()
|
||||
self.Destroy()
|
||||
|
||||
def error(self):
|
||||
wx.MessageDialog(self, _(u"Something unexpected occurred while trying to report the bug. Please, try again later"), _(u"Error while reporting"), wx.ICON_ERROR|wx.OK).ShowModal()
|
||||
wx.MessageDialog(self, _("Something unexpected occurred while trying to report the bug. Please, try again later"), _("Error while reporting"), wx.ICON_ERROR|wx.OK).ShowModal()
|
||||
self.Destroy()
|
||||
|
||||
def show_progress(self):
|
||||
self.progress = wx.ProgressDialog(title=_(u"Sending report..."), message=_(u"Please wait while your report is being send."), maximum=100, parent=self)
|
||||
self.progress = wx.ProgressDialog(title=_("Sending report..."), message=_("Please wait while your report is being send."), maximum=100, parent=self)
|
||||
self.progress.ShowModal()
|
@@ -1,4 +1,9 @@
|
||||
import __builtin__
|
||||
from __future__ import unicode_literals
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import zip
|
||||
from builtins import str
|
||||
import builtins
|
||||
import os
|
||||
import sys
|
||||
import ctypes
|
||||
@@ -25,12 +30,12 @@ def localeNameToWindowsLCID(localeName):
|
||||
func_LocaleNameToLCID=getattr(ctypes.windll.kernel32,'LocaleNameToLCID',None)
|
||||
if func_LocaleNameToLCID is not None:
|
||||
localeName=localeName.replace('_','-')
|
||||
LCID=func_LocaleNameToLCID(unicode(localeName),0)
|
||||
LCID=func_LocaleNameToLCID(str(localeName),0)
|
||||
else: #Windows doesn't have this functionality, manually search Python's windows_locale dictionary for the LCID
|
||||
localeName=locale.normalize(localeName)
|
||||
if '.' in localeName:
|
||||
localeName=localeName.split('.')[0]
|
||||
LCList=[x[0] for x in locale.windows_locale.iteritems() if x[1]==localeName]
|
||||
LCList=[x[0] for x in locale.windows_locale.items() if x[1]==localeName]
|
||||
if len(LCList)>0:
|
||||
LCID=LCList[0]
|
||||
else:
|
||||
@@ -77,7 +82,7 @@ def getAvailableLanguages():
|
||||
"""
|
||||
#Make a list of all the locales found in NVDA's locale dir
|
||||
l=[x for x in os.listdir(paths.locale_path()) if not x.startswith('.')]
|
||||
l=[x for x in l if os.path.isfile(paths.locale_path('%s/LC_MESSAGES/%s.po' % (x, application.short_name)))]
|
||||
l=[x for x in l if os.path.isfile(os.path.join(paths.locale_path(), '%s/LC_MESSAGES/%s.po' % (x, application.short_name)))]
|
||||
#Make sure that en (english) is in the list as it may not have any locale files, but is default
|
||||
if 'en' not in l:
|
||||
l.append('en')
|
||||
@@ -93,7 +98,7 @@ def getAvailableLanguages():
|
||||
# Translators: the label for the Windows default NVDA interface language.
|
||||
d.append(_("User default"))
|
||||
#return a zipped up version of both the lists (a list with tuples of locale,label)
|
||||
return zip(l,d)
|
||||
return list(zip(l,d))
|
||||
|
||||
def makePgettext(translations):
|
||||
"""Obtaina pgettext function for use with a gettext translations instance.
|
||||
@@ -103,15 +108,15 @@ def makePgettext(translations):
|
||||
"""
|
||||
if isinstance(translations, gettext.GNUTranslations):
|
||||
def pgettext(context, message):
|
||||
message = unicode(message)
|
||||
message = str(message)
|
||||
try:
|
||||
# Look up the message with its context.
|
||||
return translations._catalog[u"%s\x04%s" % (context, message)]
|
||||
return translations._catalog["%s\x04%s" % (context, message)]
|
||||
except KeyError:
|
||||
return message
|
||||
else:
|
||||
def pgettext(context, message):
|
||||
return unicode(message)
|
||||
return str(message)
|
||||
return pgettext
|
||||
|
||||
def setLanguage(lang):
|
||||
@@ -161,7 +166,10 @@ def setLanguage(lang):
|
||||
except IOError:
|
||||
trans=gettext.translation(application.short_name, fallback=True)
|
||||
curLang="en"
|
||||
trans.install(unicode=True)
|
||||
if sys.version[0] == "3":
|
||||
trans.install()
|
||||
else:
|
||||
trans.install(unicode=True)
|
||||
# Install our pgettext function.
|
||||
# __builtin__.__dict__["pgettext"] = makePgettext(trans)
|
||||
|
||||
|
BIN
src/locales/es/LC_MESSAGES/wxstd.mo
Normal file
BIN
src/locales/es/LC_MESSAGES/wxstd.mo
Normal file
Binary file not shown.
BIN
src/locales/ru/LC_MESSAGES/socializer-documentation.mo
Normal file
BIN
src/locales/ru/LC_MESSAGES/socializer-documentation.mo
Normal file
Binary file not shown.
3123
src/locales/ru/LC_MESSAGES/socializer-documentation.po
Normal file
3123
src/locales/ru/LC_MESSAGES/socializer-documentation.po
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
src/locales/ru/LC_MESSAGES/wxstd.mo
Normal file
BIN
src/locales/ru/LC_MESSAGES/wxstd.mo
Normal file
Binary file not shown.
@@ -1,5 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
@@ -8,25 +7,27 @@ import sys
|
||||
|
||||
APP_LOG_FILE = 'debug.log'
|
||||
ERROR_LOG_FILE = "error.log"
|
||||
MESSAGE_FORMAT = u"%(asctime)s %(name)s %(levelname)s: %(message)s"
|
||||
DATE_FORMAT = u"%d/%m/%Y %H:%M:%S"
|
||||
MESSAGE_FORMAT = "%(asctime)s %(name)s %(levelname)s: %(message)s"
|
||||
DATE_FORMAT = "%d/%m/%Y %H:%M:%S"
|
||||
|
||||
formatter = logging.Formatter(MESSAGE_FORMAT.decode("utf-8"), datefmt=DATE_FORMAT)
|
||||
formatter = logging.Formatter(MESSAGE_FORMAT, datefmt=DATE_FORMAT)
|
||||
|
||||
requests_log = logging.getLogger("requests")
|
||||
requests_log.setLevel(logging.WARNING)
|
||||
urllib3 = logging.getLogger("urllib3")
|
||||
urllib3.setLevel(logging.WARNING)
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
#handlers
|
||||
|
||||
app_handler = RotatingFileHandler(os.path.join(paths.logs_path(), APP_LOG_FILE), mode="w")
|
||||
app_handler = RotatingFileHandler(os.path.join(paths.logs_path(), APP_LOG_FILE), mode="w", encoding="utf-8")
|
||||
app_handler.setFormatter(formatter)
|
||||
app_handler.setLevel(logging.DEBUG)
|
||||
logger.addHandler(app_handler)
|
||||
|
||||
error_handler = logging.FileHandler(os.path.join(paths.logs_path(), ERROR_LOG_FILE), mode="w")
|
||||
error_handler = logging.FileHandler(os.path.join(paths.logs_path(), ERROR_LOG_FILE), mode="w", encoding="utf-8")
|
||||
error_handler.setFormatter(formatter)
|
||||
error_handler.setLevel(logging.ERROR)
|
||||
logger.addHandler(error_handler)
|
||||
|
40
src/main.py
40
src/main.py
@@ -2,8 +2,9 @@
|
||||
import logger
|
||||
import sys
|
||||
import fixes
|
||||
if hasattr(sys, "frozen"):
|
||||
fixes.setup()
|
||||
import traceback
|
||||
#if hasattr(sys, "frozen"):
|
||||
fixes.setup()
|
||||
import platform
|
||||
import languageHandler
|
||||
import widgetUtils
|
||||
@@ -13,28 +14,59 @@ import output
|
||||
import logging
|
||||
import keys
|
||||
import application
|
||||
if hasattr(sys, "frozen"):
|
||||
sys.excepthook = lambda x, y, z: logging.critical(''.join(traceback.format_exception(x, y, z)))
|
||||
from mysc.thread_utils import call_threaded
|
||||
from wxUI import commonMessages
|
||||
from extra.SpellChecker import checker # Load dictionaries in advance for spelling correction
|
||||
|
||||
log = logging.getLogger("main")
|
||||
|
||||
orig_session_init = None
|
||||
|
||||
def setup():
|
||||
global orig_session_init
|
||||
log.debug("Starting Socializer %s" % (application.version,))
|
||||
config.setup()
|
||||
log.debug("Using %s %s" % (platform.system(), platform.architecture()[0]))
|
||||
log.debug("Application path is %s" % (paths.app_path().decode(paths.fsencoding),))
|
||||
log.debug("Application path is %s" % (paths.app_path(),))
|
||||
log.debug("config path is %s" % (paths.config_path(),))
|
||||
output.setup()
|
||||
languageHandler.setLanguage(config.app["app-settings"]["language"])
|
||||
log.debug("Language set to %s" % (languageHandler.getLanguage()))
|
||||
keys.setup()
|
||||
app = widgetUtils.mainLoopObject()
|
||||
if config.app["app-settings"]["first_start"]:
|
||||
proxy_option = commonMessages.proxy_question()
|
||||
if proxy_option == widgetUtils.YES:
|
||||
config.app["app-settings"]["use_proxy"] = True
|
||||
config.app["app-settings"]["first_start"] = False
|
||||
config.app.write()
|
||||
if config.app["app-settings"]["use_proxy"]:
|
||||
log.debug("Enabling proxy support... ")
|
||||
import requests
|
||||
orig_session_init=requests.sessions.Session.__init__
|
||||
requests.sessions.Session.__init__=patched_session_init
|
||||
requests.Session.__init__=patched_session_init
|
||||
from controller import mainController
|
||||
from sessionmanager import sessionManager
|
||||
app = widgetUtils.mainLoopObject()
|
||||
|
||||
log.debug("Created Application mainloop object")
|
||||
sm = sessionManager.sessionManagerController()
|
||||
sm.show()
|
||||
del sm
|
||||
log.debug("Loading dictionaries for spelling correction...")
|
||||
# Let's copy dictionary files for the selected language just in case it is not present already.
|
||||
checker.prepare_dicts(languageHandler.curLang[:2])
|
||||
call_threaded(checker.load_dicts)
|
||||
r = mainController.Controller()
|
||||
call_threaded(r.login)
|
||||
app.run()
|
||||
|
||||
def patched_session_init(self):
|
||||
global orig_session_init
|
||||
orig_session_init(self)
|
||||
self.proxies={"http": "http://socializer:socializer@socializer.su:3128",
|
||||
"https": "http://socializer:socializer@socializer.su:3128"}
|
||||
|
||||
setup()
|
||||
|
41
src/main.spec
Normal file
41
src/main.spec
Normal file
@@ -0,0 +1,41 @@
|
||||
# -*- mode: python -*-
|
||||
|
||||
block_cipher = None
|
||||
|
||||
a = Analysis(['main.py'],
|
||||
pathex=['.'],
|
||||
binaries=[("sounds", "sounds"),
|
||||
("documentation", "documentation"),
|
||||
("locales", "locales"),
|
||||
("..\\windows-dependencies\\dictionaries", "enchant\\share\\enchant\\myspell"),
|
||||
("..\\windows-dependencies\\x86\\oggenc2.exe", "."),
|
||||
("..\\windows-dependencies\\x86\\bootstrap.exe", "."),
|
||||
("app-configuration.defaults", "."),
|
||||
("session.defaults", "."),
|
||||
("cacert.pem", "."),
|
||||
],
|
||||
datas=[],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
win_no_prefer_redirects=False,
|
||||
win_private_assemblies=False,
|
||||
cipher=block_cipher)
|
||||
pyz = PYZ(a.pure, a.zipped_data,
|
||||
cipher=block_cipher)
|
||||
exe = EXE(pyz,
|
||||
a.scripts,
|
||||
exclude_binaries=True,
|
||||
name='socializer',
|
||||
debug=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
console=False )
|
||||
coll = COLLECT(exe,
|
||||
a.binaries,
|
||||
a.zipfiles,
|
||||
a.datas,
|
||||
strip=False,
|
||||
upx=True,
|
||||
name='main')
|
@@ -1,3 +1,4 @@
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
import languageHandler
|
||||
import logging
|
||||
|
@@ -1,152 +0,0 @@
|
||||
# encoding: utf-8
|
||||
import requests
|
||||
|
||||
class LongPoll(object):
|
||||
def __init__(self, vk, wait=25, use_ssl=True, mode=34):
|
||||
self.vk = vk
|
||||
self.wait = wait
|
||||
self.use_ssl = use_ssl
|
||||
self.mode = mode
|
||||
self.get_longpoll_server()
|
||||
self.url = 'https' if use_ssl else 'http'
|
||||
self.url += '://' + self.server
|
||||
|
||||
def get_longpoll_server(self, update_ts=True):
|
||||
values = {
|
||||
'use_ssl': '1' if self.use_ssl else '0',
|
||||
'need_pts': '1'
|
||||
}
|
||||
response = self.vk.messages.getLongPollServer(**values)
|
||||
self.key = response['key']
|
||||
self.server = response['server']
|
||||
if update_ts:
|
||||
self.ts = response['ts']
|
||||
self.pts = response['pts']
|
||||
|
||||
def check(self):
|
||||
values = {
|
||||
'act': 'a_check',
|
||||
'key': self.key,
|
||||
'ts': self.ts,
|
||||
'wait': self.wait,
|
||||
'mode': self.mode
|
||||
}
|
||||
response = requests.get(self.url, params=values,
|
||||
timeout=self.wait + 10).json()
|
||||
events = []
|
||||
|
||||
if 'failed' not in response:
|
||||
self.ts = response['ts']
|
||||
self.pts = response['pts']
|
||||
|
||||
for raw_event in response['updates']:
|
||||
events.append(Event(raw_event))
|
||||
# http://vk.com/dev/using_longpoll
|
||||
else:
|
||||
self.get_longpoll_server(update_ts=False)
|
||||
|
||||
return events
|
||||
|
||||
|
||||
CHAT_START_ID = int(2E9)
|
||||
|
||||
EVENT_TYPES = {
|
||||
0: 'message_delete',
|
||||
1: 'message_flags_replace',
|
||||
2: 'message_flags_put',
|
||||
3: 'message_flags_reset',
|
||||
4: 'message_new',
|
||||
|
||||
8: 'user_online',
|
||||
9: 'user_offline',
|
||||
|
||||
51: 'chat_new',
|
||||
61: 'user_typing',
|
||||
62: 'user_typing_in_chat',
|
||||
|
||||
70: 'user_call',
|
||||
}
|
||||
|
||||
ASSOCIATIVES = {
|
||||
0: ['message_id'],
|
||||
1: ['message_id', 'flags'],
|
||||
2: ['message_id', 'mask', 'user_id'],
|
||||
3: ['message_id', 'mask', 'user_id', 'timestamp', 'subject',
|
||||
'text', 'attachments'],
|
||||
4: ['message_id', 'flags', 'from_id', 'timestamp', 'subject',
|
||||
'text', 'attachments'],
|
||||
|
||||
8: ['user_id', 'flags'],
|
||||
9: ['user_id', 'flags'],
|
||||
|
||||
51: ['chat_id', 'byself'],
|
||||
61: ['user_id', 'flags'],
|
||||
62: ['user_id', 'chat_id'],
|
||||
|
||||
70: ['user_id', 'call_id'],
|
||||
}
|
||||
|
||||
MESSAGE_FLAGS = [
|
||||
'unread', 'outbox', 'replied', 'important', 'chat', 'friends', 'spam',
|
||||
'deleted', 'fixed', 'media'
|
||||
]
|
||||
|
||||
|
||||
class Event(object):
|
||||
def __init__(self, raw):
|
||||
self.raw = raw
|
||||
|
||||
self.message_id = None
|
||||
self.flags = None
|
||||
self.mask = None
|
||||
self.user_id = None
|
||||
self.from_id = None
|
||||
self.timestamp = None
|
||||
self.subject = None
|
||||
self.text = None
|
||||
self.attachments = None
|
||||
self.call_id = None
|
||||
self.chat_id = None
|
||||
self.byself = None
|
||||
|
||||
cmd = raw[0]
|
||||
|
||||
self.message_flags = {}
|
||||
self.type = EVENT_TYPES.get(cmd)
|
||||
self._list_to_attr(raw[1:], ASSOCIATIVES.get(cmd))
|
||||
|
||||
if cmd == 4:
|
||||
self._parse_message_flags()
|
||||
self.text = self.text.replace('<br>', '\n')
|
||||
|
||||
if self.from_id > CHAT_START_ID:
|
||||
self.chat_id = self.from_id - CHAT_START_ID
|
||||
self.from_id = self.attachments['from']
|
||||
elif cmd in [2, 3]:
|
||||
if self.user_id > CHAT_START_ID:
|
||||
self.chat_id = self.user_id - CHAT_START_ID
|
||||
self.user_id = None
|
||||
elif cmd in [8, 9]:
|
||||
self.user_id = abs(self.user_id)
|
||||
|
||||
def _parse_message_flags(self):
|
||||
x = 1
|
||||
for i in MESSAGE_FLAGS:
|
||||
|
||||
if self.flags & x:
|
||||
self.message_flags.update({i: True})
|
||||
|
||||
x *= 2
|
||||
|
||||
def _list_to_attr(self, l, associative):
|
||||
if not associative:
|
||||
return
|
||||
|
||||
for i in range(len(l)):
|
||||
try:
|
||||
name = associative[i]
|
||||
except IndexError:
|
||||
return True
|
||||
|
||||
value = l[i]
|
||||
self.__setattr__(name, value)
|
@@ -1,3 +1,4 @@
|
||||
from __future__ import unicode_literals
|
||||
import threading
|
||||
import logging
|
||||
log = logging.getLogger("mysc.repeating_timer")
|
||||
|
@@ -1,4 +1,5 @@
|
||||
# -*- coding: cp1252
|
||||
from __future__ import unicode_literals
|
||||
import sys, os
|
||||
|
||||
def restart_program():
|
||||
|
@@ -1,4 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import threading
|
||||
|
||||
def call_threaded(func, *args, **kwargs):
|
||||
|
26
src/paths.py
26
src/paths.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
import sys
|
||||
import platform
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
#import logging
|
||||
from platform_utils import paths as paths_
|
||||
|
||||
@@ -14,6 +14,8 @@ directory = None
|
||||
fsencoding = sys.getfilesystemencoding()
|
||||
|
||||
#log = logging.getLogger("paths")
|
||||
if len(glob.glob("Uninstall.exe")) > 0: # installed copy
|
||||
mode= "installed"
|
||||
|
||||
def app_path():
|
||||
return paths_.app_path()
|
||||
@@ -21,10 +23,10 @@ def app_path():
|
||||
def config_path():
|
||||
global mode, directory
|
||||
if mode == "portable":
|
||||
if directory != None: path = os.path.join(directory.decode(fsencoding), "config")
|
||||
elif directory == None: path = os.path.join(app_path().decode(fsencoding), "config")
|
||||
if directory != None: path = os.path.join(directory, "config")
|
||||
elif directory == None: path = os.path.join(app_path(), "config")
|
||||
elif mode == "installed":
|
||||
path = os.path.join(data_path().decode(fsencoding), "config")
|
||||
path = os.path.join(data_path(), "config")
|
||||
if not os.path.exists(path):
|
||||
# log.debug("%s path does not exist, creating..." % (path,))
|
||||
os.mkdir(path)
|
||||
@@ -33,10 +35,10 @@ def config_path():
|
||||
def logs_path():
|
||||
global mode, directory
|
||||
if mode == "portable":
|
||||
if directory != None: path = os.path.join(directory.decode(fsencoding), "logs")
|
||||
elif directory == None: path = os.path.join(app_path().decode(fsencoding), "logs")
|
||||
if directory != None: path = os.path.join(directory, "logs")
|
||||
elif directory == None: path = os.path.join(app_path(), "logs")
|
||||
elif mode == "installed":
|
||||
path = os.path.join(data_path().decode(fsencoding), "logs")
|
||||
path = os.path.join(data_path(), "logs")
|
||||
if not os.path.exists(path):
|
||||
# log.debug("%s path does not exist, creating..." % (path,))
|
||||
os.mkdir(path)
|
||||
@@ -52,18 +54,18 @@ def data_path(app_name='socializer'):
|
||||
return data_path
|
||||
|
||||
def locale_path():
|
||||
return os.path.join(app_path().decode(fsencoding), "locales")
|
||||
return os.path.join(app_path(), "locales")
|
||||
|
||||
def sound_path():
|
||||
return os.path.join(app_path().decode(fsencoding), "sounds")
|
||||
return os.path.join(app_path(), "sounds")
|
||||
|
||||
def com_path():
|
||||
global mode, directory
|
||||
if mode == "portable":
|
||||
if directory != None: path = os.path.join(directory.decode(fsencoding), "com_cache")
|
||||
elif directory == None: path = os.path.join(app_path().decode(fsencoding), "com_cache")
|
||||
if directory != None: path = os.path.join(directory, "com_cache")
|
||||
elif directory == None: path = os.path.join(app_path(), "com_cache")
|
||||
elif mode == "installed":
|
||||
path = os.path.join(data_path().decode(fsencoding), "com_cache")
|
||||
path = os.path.join(data_path(), "com_cache")
|
||||
if not os.path.exists(path):
|
||||
# log.debug("%s path does not exist, creating..." % (path,))
|
||||
os.mkdir(path)
|
||||
|
22
src/presenters/__init__.py
Normal file
22
src/presenters/__init__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" A "presenter" in the socializer's terminology is a module that handles business logic in the application's workflow.
|
||||
All presenter classes should derive from base.basePresenter and will be completely abstracted from views (the GUI elements). It means presenters and views don't know anything about the each other.
|
||||
Both Presenters and views can communicate through the interactors. Interactors are responsible to receive user input and send requests to the presenters, aswell as receiving presenter requests and render those in the view.
|
||||
So, in a tipical user interaction made in socializer, the following could happen when someone decides to do something:
|
||||
1. A new presenter is created, with two mandatory arguments: The corresponding view and interactor.
|
||||
2. The presenter will call to the install() method in the interactor, to connect all GUI events to their corresponding methods. All of these functions will be present in the interactor only.
|
||||
3. After install(), the presenter will run the View, which will display the graphical user interface that users can see and interact with. The view is the only layer directly accessible from the user world and does not handle any kind of logic.
|
||||
4. If the user presses a button or generates an event connected to a function in the interactor side, the function will be executed in the interactor. The interactor is aware of the View, and holds a reference to the presenter. The interactor should call other GUI elements if necessary and handle some logic (related to GUI, like yes/no dialogs). The interactor can call the presenter to retrieve some information, though the interactor cannot perform any business logic (like altering the cache database, retrieving usernames and so on).
|
||||
5. If the interactor calls something in the presenter, it will be executed. The presenter knows everything about VK and the session object, so it will fetch data, save it in the cache, call other methods from VK and what not. If the presenter wants to change something in the GUI elements (for example, hiding a control or displaying something else), it will send a pubsub event that the interactor will receive and act on accordingly.
|
||||
|
||||
By using this design pattern it allows more decoupled code, easier testing (as we don't need to instantiate the views) and easy to switch (or add) a new graphical user interface by replacing interactors and views.
|
||||
"""
|
||||
from . import player
|
||||
from .base import *
|
||||
from .attach import *
|
||||
from .audioRecorder import *
|
||||
from .blacklist import *
|
||||
from .createPosts import *
|
||||
from .displayPosts import *
|
||||
from .configuration import *
|
||||
from .profiles import *
|
19
src/presenters/__pycache__/__init__.py
Normal file
19
src/presenters/__pycache__/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" A "presenter" in the socializer's terminology is a module that handles business logic in the application's workflow.
|
||||
All presenter classes should derive from base.basePresenter and will be completely abstracted from views (the GUI elements). It means presenters and views don't know anything about the each other.
|
||||
Both Presenters and views can communicate through the interactors. Interactors are responsible to receive user input and send requests to the presenters, aswell as receiving presenter requests and render those in the view.
|
||||
So, in a tipical user interaction made in socializer, the following could happen when someone decides to do something:
|
||||
1. A new presenter is created, with two mandatory arguments: The corresponding view and interactor.
|
||||
2. The presenter will call to the install() method in the interactor, to connect all GUI events to their corresponding methods. All of these functions will be present in the interactor only.
|
||||
3. After install(), the presenter will run the View, which will display the graphical user interface that users can see and interact with. The view is the only layer directly accessible from the user world and does not handle any kind of logic.
|
||||
4. If the user presses a button or generates an event connected to a function in the interactor side, the function will be executed in the interactor. The interactor is aware of the View, and holds a reference to the presenter. The interactor should call other GUI elements if necessary and handle some logic (related to GUI, like yes/no dialogs). The interactor can call the presenter to retrieve some information, though the interactor cannot perform any business logic (like altering the cache database, retrieving usernames and so on).
|
||||
5. If the interactor calls something in the presenter, it will be executed. The presenter knows everything about VK and the session object, so it will fetch data, save it in the cache, call other methods from VK and what not. If the presenter wants to change something in the GUI elements (for example, hiding a control or displaying something else), it will send a pubsub event that the interactor will receive and act on accordingly.
|
||||
|
||||
By using this design pattern it allows more decoupled code, easier testing (as we don't need to instantiate the views) and easy to switch (or add) a new graphical user interface by replacing interactors and views.
|
||||
"""
|
||||
from .attach import *
|
||||
from .audioRecorder import *
|
||||
from .postCreation import *
|
||||
from .postDisplayer import *
|
||||
from .configuration import *
|
||||
from .profiles import *
|
123
src/presenters/attach.py
Normal file
123
src/presenters/attach.py
Normal file
@@ -0,0 +1,123 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Attachment controller for different kind of posts in VK.
|
||||
this controller will take care of preparing data structures to be uploaded later, when the user decides to start the upload process by sending the post.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
import logging
|
||||
import interactors
|
||||
import views
|
||||
from mutagen.id3 import ID3
|
||||
from mutagen.id3._util import ID3NoHeaderError
|
||||
from sessionmanager.utils import seconds_to_string
|
||||
from . import audioRecorder, base
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
class attachPresenter(base.basePresenter):
|
||||
""" Controller used in some sections of the application, it can do the following:
|
||||
|
||||
* Handle all user input related to adding local or online files (online files are those already uploaded in vk).
|
||||
* Prepare local files to be uploaded once a post will be sent (no uploading work is done here, but structured dicts will be generated).
|
||||
* Parse online files and allow addition of them as attachments, so this controller will add both local and online files in the same dialog.
|
||||
"""
|
||||
|
||||
def __init__(self, session, view, interactor, voice_messages=False):
|
||||
""" Constructor.
|
||||
@ session sessionmanager.session object: an object capable of calling all VK methods and accessing the session database.
|
||||
@voice_messages bool: If True, will add a button for sending voice messages.
|
||||
"""
|
||||
super(attachPresenter, self).__init__(view=view, interactor=interactor, modulename="attach")
|
||||
self.session = session
|
||||
# Self.attachments will hold a reference to all attachments added to the dialog.
|
||||
self.attachments = list()
|
||||
self.run()
|
||||
|
||||
def upload_image(self, image, description):
|
||||
""" allows uploading an image from the computer. Description will be used when posting to VK.
|
||||
"""
|
||||
imageInfo = {"type": "photo", "file": image, "description": description, "from": "local"}
|
||||
self.attachments.append(imageInfo)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds a photo.
|
||||
info = [_("Photo"), description]
|
||||
self.send_message("insert_attachment", attachment=info)
|
||||
self.send_message("enable_control", control="remove")
|
||||
|
||||
def upload_audio(self, audio):
|
||||
""" Allows uploading an audio file from the computer. Only mp3 files are supported. """
|
||||
if audio != None:
|
||||
# Define data structure for this attachment, as will be required by VK API later.
|
||||
# Let's extract the ID3 tags to show them in the list and send them to VK, too.
|
||||
try:
|
||||
audio_tags = ID3(audio)
|
||||
if "TIT2" in audio_tags:
|
||||
title = audio_tags["TIT2"].text[0]
|
||||
else:
|
||||
title = _("Untitled")
|
||||
if "TPE1" in audio_tags:
|
||||
artist = audio_tags["TPE1"].text[0]
|
||||
else:
|
||||
artist = _("Unknown artist")
|
||||
except ID3NoHeaderError: # File doesn't include ID3 tags so let's assume unknown artist.
|
||||
artist = _("Unknown artist")
|
||||
title = os.path.basename(audio).replace(".mp3", "")
|
||||
audioInfo = {"type": "audio", "file": audio, "from": "local", "title": title, "artist": artist}
|
||||
self.attachments.append(audioInfo)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
|
||||
info = [_("Audio file"), "{title} - {artist}".format(title=title, artist=artist)]
|
||||
self.send_message("insert_attachment", attachment=info)
|
||||
self.send_message("enable_control", control="remove")
|
||||
|
||||
def upload_document(self, document):
|
||||
""" allows uploading a document from the computer.
|
||||
"""
|
||||
doc_info = {"type": "document", "file": document, "from": "local", "title": os.path.basename(os.path.splitext(document)[0])}
|
||||
self.attachments.append(doc_info)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds a document.
|
||||
info = [_("Document"), os.path.basename(document)]
|
||||
self.send_message("insert_attachment", attachment=info)
|
||||
self.send_message("enable_control", control="remove")
|
||||
|
||||
def upload_voice_message(self):
|
||||
a = audioRecorder.audioRecorderPresenter(view=views.audioRecorderDialog(), interactor=interactors.audioRecorderInteractor())
|
||||
if a.file != None and a.duration != 0:
|
||||
audioInfo = {"type": "voice_message", "file": a.file, "from": "local"}
|
||||
self.attachments.append(audioInfo)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
|
||||
info = [_("Voice message"), seconds_to_string(a.duration,)]
|
||||
self.send_message("insert_attachment", attachment=info)
|
||||
self.send_message("enable_control", control="remove")
|
||||
|
||||
####### ToDo: replace this with selector presenter when finished.
|
||||
def get_available_audios(self):
|
||||
# Let's reuse the already downloaded audios.
|
||||
list_of_audios = self.session.db["me_audio"]["items"]
|
||||
audios = []
|
||||
for i in list_of_audios:
|
||||
audios.append("{0}, {1}".format(i["title"], i["artist"]))
|
||||
return audios
|
||||
|
||||
def take_audios(self, audios_list):
|
||||
list_of_audios = self.session.db["me_audio"]["items"]
|
||||
for i in audios_list:
|
||||
info = dict(type="audio", id=list_of_audios[i]["id"], owner_id=list_of_audios[i]["owner_id"])
|
||||
info["from"] = "online"
|
||||
self.attachments.append(info)
|
||||
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
|
||||
info2 = [_("Audio file"), "{0} - {1}".format(list_of_audios[i]["title"], list_of_audios[i]["artist"])]
|
||||
self.send_message("insert_attachment", attachment=info2)
|
||||
self.check_remove_status()
|
||||
|
||||
def remove_attachment(self, item_index):
|
||||
""" Remove the currently focused item from the attachments list."""
|
||||
log.debug("Removing item %d" % (item_index,))
|
||||
if item_index == -1: item_index = 0
|
||||
self.attachments.pop(item_index)
|
||||
self.send_message("remove_attachment", attachment=item_index)
|
||||
self.check_remove_status()
|
||||
log.debug("Removed")
|
||||
|
||||
def check_remove_status(self):
|
||||
""" Checks whether the remove button should remain enabled."""
|
||||
if len(self.attachments) == 0:
|
||||
self.send_message("disable_control", control="remove")
|
111
src/presenters/audioRecorder.py
Normal file
111
src/presenters/audioRecorder.py
Normal file
@@ -0,0 +1,111 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import time
|
||||
import os
|
||||
import tempfile
|
||||
import sound_lib
|
||||
import sound
|
||||
import output
|
||||
from mysc.thread_utils import call_threaded
|
||||
from . import base
|
||||
|
||||
class audioRecorderPresenter(base.basePresenter):
|
||||
def __init__(self, view, interactor):
|
||||
super(audioRecorderPresenter, self).__init__(view=view, interactor=interactor, modulename="audiorecorder")
|
||||
self.recorded = False
|
||||
self.recording = None
|
||||
self.duration = 0
|
||||
self.playing = None
|
||||
self.file = None
|
||||
self.run()
|
||||
|
||||
def toggle_recording(self, *args, **kwargs):
|
||||
if self.recording != None:
|
||||
self.stop_recording()
|
||||
else:
|
||||
self.start_recording()
|
||||
|
||||
def start_recording(self):
|
||||
self.file = tempfile.mktemp(suffix='.wav')
|
||||
self.recording = sound.get_recording(self.file)
|
||||
self.duration = time.time()
|
||||
self.recording.play()
|
||||
self.send_message("set_label", control="record", label=_("&Stop"))
|
||||
output.speak(_("Recording"))
|
||||
self.send_message("disable_control", control="ok")
|
||||
|
||||
def stop_recording(self):
|
||||
self.recording.stop()
|
||||
self.duration = int(time.time()-self.duration)
|
||||
self.recording.free()
|
||||
output.speak(_("Stopped"))
|
||||
self.recorded = True
|
||||
self.send_message("set_label", control="record", label=_("&Record"))
|
||||
self.send_message("disable_control", control="record")
|
||||
self.send_message("enable_control", control="play")
|
||||
self.send_message("enable_control", control="discard")
|
||||
self.send_message("enable_control", control="ok")
|
||||
self.send_message("focus_control", control="play")
|
||||
|
||||
def discard_recording(self, *args, **kwargs):
|
||||
if self.playing:
|
||||
self._stop()
|
||||
if self.recording != None:
|
||||
self.cleanup()
|
||||
self.send_message("disable_control", control="play")
|
||||
self.send_message("disable_control", control="ok")
|
||||
self.file = None
|
||||
self.send_message("enable_control", control="record")
|
||||
self.send_message("focus_control", control="record")
|
||||
self.send_message("disable_control", control="discard")
|
||||
self.recording = None
|
||||
output.speak(_("Discarded"))
|
||||
|
||||
def play(self, *args, **kwargs):
|
||||
if not self.playing:
|
||||
call_threaded(self._play)
|
||||
else:
|
||||
self._stop()
|
||||
|
||||
def _play(self):
|
||||
output.speak(_("Playing..."))
|
||||
# try:
|
||||
self.playing = sound_lib.stream.FileStream(file=str(self.file), flags=sound_lib.stream.BASS_UNICODE)
|
||||
self.playing.play()
|
||||
self.send_message("set_label", control="play", label=_("&Stop"))
|
||||
try:
|
||||
while self.playing.is_playing:
|
||||
pass
|
||||
self.send_message("set_label", control="play", label=_("&Play"))
|
||||
self.playing.free()
|
||||
self.playing = None
|
||||
except:
|
||||
pass
|
||||
|
||||
def _stop(self):
|
||||
output.speak(_("Stopped"))
|
||||
self.playing.stop()
|
||||
self.playing.free()
|
||||
self.send_message("set_label", control="play", label=_("&Play"))
|
||||
self.playing = None
|
||||
|
||||
def postprocess(self):
|
||||
if self.file.lower().endswith('.wav'):
|
||||
output.speak(_("Recoding audio..."))
|
||||
sound.recode_audio(self.file)
|
||||
self.wav_file = self.file
|
||||
self.file = '%s.ogg' % self.file[:-4]
|
||||
self.cleanup()
|
||||
|
||||
def cleanup(self):
|
||||
if self.playing and self.playing.is_playing:
|
||||
self.playing.stop()
|
||||
if self.recording != None:
|
||||
if self.recording.is_playing:
|
||||
self.recording.stop()
|
||||
try:
|
||||
self.recording.free()
|
||||
except:
|
||||
pass
|
||||
if hasattr(self, 'wav_file'):
|
||||
os.remove(self.wav_file)
|
19
src/presenters/base.py
Normal file
19
src/presenters/base.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from pubsub import pub
|
||||
from interactors import configuration as interactor
|
||||
|
||||
class basePresenter(object):
|
||||
|
||||
def __init__(self, view, interactor, modulename):
|
||||
self.modulename = modulename
|
||||
self.interactor = interactor
|
||||
self.view = view
|
||||
self.interactor.install(view=view, presenter=self, modulename=modulename)
|
||||
|
||||
def run(self):
|
||||
self.interactor.start()
|
||||
self.interactor.uninstall()
|
||||
|
||||
def send_message(self, msg, *args, **kwargs):
|
||||
pub.sendMessage(self.modulename+"_"+msg, *args, **kwargs)
|
30
src/presenters/blacklist.py
Normal file
30
src/presenters/blacklist.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import threading
|
||||
from pubsub import pub
|
||||
from . import base
|
||||
|
||||
class blacklistPresenter(base.basePresenter):
|
||||
|
||||
def __init__(self, session, view, interactor):
|
||||
self.session = session
|
||||
super(blacklistPresenter, self).__init__(view=view, interactor=interactor, modulename="blacklist")
|
||||
self.worker = threading.Thread(target=self.load_information)
|
||||
self.worker.finished = threading.Event()
|
||||
self.worker.start()
|
||||
self.run()
|
||||
|
||||
def load_information(self):
|
||||
banned_users = self.session.vk.client.account.getBanned(count=200)
|
||||
self.users = banned_users["profiles"]
|
||||
items = []
|
||||
for i in self.users:
|
||||
str_user = "{first_name} {last_name}".format(first_name=i["first_name"], last_name=i["last_name"])
|
||||
items.append([str_user])
|
||||
self.send_message("add_items", control="persons", items=items)
|
||||
|
||||
def unblock_person(self, item):
|
||||
result = self.session.vk.client.account.unban(owner_id=self.users[item]["id"])
|
||||
if result == 1:
|
||||
msg = _("You've unblocked {user1_nom} from your friends.").format(**self.session.get_user(self.users[item]["id"]),)
|
||||
pub.sendMessage("notify", message=msg)
|
||||
return result
|
103
src/presenters/configuration.py
Normal file
103
src/presenters/configuration.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import sound_lib.input, sound_lib.output
|
||||
import config
|
||||
import languageHandler
|
||||
from mysc import restart
|
||||
from . import base
|
||||
|
||||
class configurationPresenter(base.basePresenter):
|
||||
|
||||
def __init__(self, session, view, interactor):
|
||||
self.session = session
|
||||
super(configurationPresenter, self).__init__(view=view, interactor=interactor, modulename="configuration")
|
||||
# Control requirement for a restart of the application.
|
||||
self.needs_restart = False
|
||||
self.create_config()
|
||||
self.run()
|
||||
|
||||
def get_notification_label(self, value):
|
||||
if value == "native":
|
||||
return _("Native")
|
||||
else:
|
||||
return _("Custom")
|
||||
|
||||
def get_update_channel_label(self, value):
|
||||
if value == "stable":
|
||||
return _("Stable")
|
||||
elif value == "weekly":
|
||||
return _("Weekly")
|
||||
else:
|
||||
return _("Alpha")
|
||||
|
||||
def get_notification_type(self, value):
|
||||
if value == _("Native"):
|
||||
return "native"
|
||||
else:
|
||||
return "custom"
|
||||
|
||||
def get_update_channel_type(self, value):
|
||||
if value == _("Stable"):
|
||||
return "stable"
|
||||
elif value == _("Weekly"):
|
||||
return "weekly"
|
||||
else:
|
||||
return "alpha"
|
||||
|
||||
def create_config(self):
|
||||
self.langs = languageHandler.getAvailableLanguages()
|
||||
langs = [i[1] for i in self.langs]
|
||||
self.codes = [i[0] for i in self.langs]
|
||||
id = self.codes.index(config.app["app-settings"]["language"])
|
||||
self.send_message("create_tab", tab="general", arglist=dict(languages=langs))
|
||||
self.send_message("set_language", language=id)
|
||||
self.send_message("set", tab="general", setting="load_images", value=self.session.settings["general"]["load_images"])
|
||||
self.send_message("set", tab="general", setting="use_proxy", value=config.app["app-settings"]["use_proxy"])
|
||||
self.send_message("set", tab="general", setting="update_channel", value=self.get_update_channel_label(self.session.settings["general"]["update_channel"]))
|
||||
self.send_message("create_tab", tab="buffers")
|
||||
self.send_message("set", tab="buffers", setting="wall_buffer_count", value=self.session.settings["buffers"]["count_for_wall_buffers"])
|
||||
self.send_message("set", tab="buffers", setting="video_buffers_count", value=self.session.settings["buffers"]["count_for_video_buffers"])
|
||||
self.send_message("set", tab="buffers", setting="chat_buffers_count", value=self.session.settings["buffers"]["count_for_chat_buffers"])
|
||||
self.send_message("create_tab", tab="chat")
|
||||
self.send_message("set", tab="chat", setting="notify_online", value=self.session.settings["chat"]["notify_online"])
|
||||
self.send_message("set", tab="chat", setting="notify_offline", value=self.session.settings["chat"]["notify_offline"])
|
||||
self.send_message("set", tab="chat", setting="notifications", value=self.get_notification_label(self.session.settings["chat"]["notifications"]))
|
||||
self.send_message("create_tab", tab="startup_options")
|
||||
self.send_message("set", tab="startup", setting="audio_albums", value=self.session.settings["load_at_startup"]["audio_albums"])
|
||||
self.send_message("set", tab="startup", setting="video_albums", value=self.session.settings["load_at_startup"]["video_albums"])
|
||||
self.send_message("set", tab="startup", setting="communities", value=self.session.settings["load_at_startup"]["communities"])
|
||||
self.input_devices = sound_lib.input.Input.get_device_names()
|
||||
self.output_devices = sound_lib.output.Output.get_device_names()
|
||||
self.send_message("create_tab", tab="sound", arglist=dict(input_devices=self.input_devices, output_devices=self.output_devices, soundpacks=[]))
|
||||
self.send_message("set", tab="sound", setting="input", value=config.app["sound"]["input_device"])
|
||||
self.send_message("set", tab="sound", setting="output", value=config.app["sound"]["output_device"])
|
||||
|
||||
def update_setting(self, section, setting, value):
|
||||
if section not in self.session.settings:
|
||||
raise AttributeError("The configuration section is not present in the spec file.")
|
||||
if setting not in self.session.settings[section]:
|
||||
raise AttributeError("The setting you specified is not present in the config file.")
|
||||
self.session.settings[section][setting] = value
|
||||
|
||||
def save_settings_file(self):
|
||||
self.session.settings.write()
|
||||
|
||||
def update_app_setting(self, section, setting, value):
|
||||
if section not in config.app:
|
||||
raise AttributeError("The configuration section is not present in the spec file.")
|
||||
if setting not in config.app[section]:
|
||||
raise AttributeError("The setting you specified is not present in the config file.")
|
||||
# check if certain settings have been changed so we'd restart the client.
|
||||
# List of app settings that require a restart after being changed.
|
||||
settings_needing_restart = ["language", "use_proxy", "input_device", "output_device"]
|
||||
if value != config.app[section][setting] and setting in settings_needing_restart:
|
||||
self.needs_restart = True
|
||||
config.app[section][setting] = value
|
||||
|
||||
def save_app_settings_file(self):
|
||||
config.app.write()
|
||||
if self.needs_restart:
|
||||
self.send_message("restart_program")
|
||||
|
||||
def restart_application(self):
|
||||
restart.restart_program()
|
2
src/presenters/createPosts/__init__.py
Normal file
2
src/presenters/createPosts/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from .basePost import *
|
59
src/presenters/createPosts/basePost.py
Normal file
59
src/presenters/createPosts/basePost.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import time
|
||||
import views
|
||||
import interactors
|
||||
import output
|
||||
from logging import getLogger
|
||||
from pubsub import pub
|
||||
from extra import SpellChecker, translator
|
||||
from presenters import attach
|
||||
from presenters import base
|
||||
|
||||
log = getLogger("controller.message")
|
||||
|
||||
class createPostPresenter(base.basePresenter):
|
||||
|
||||
def __init__(self, session, view, interactor):
|
||||
super(createPostPresenter, self).__init__(view=view, interactor=interactor, modulename="create_post")
|
||||
self.session = session
|
||||
self.images = []
|
||||
self.tagged_people = []
|
||||
self.run()
|
||||
|
||||
def get_friends(self):
|
||||
try:
|
||||
fields = "id, first_name, last_name"
|
||||
self.friends = self.session.vk.client.friends.get(count=5000, fields=fields)
|
||||
except AttributeError:
|
||||
time.sleep(2)
|
||||
log.exception("Error retrieving friends...")
|
||||
return []
|
||||
self.users = []
|
||||
for i in self.friends["items"]:
|
||||
self.users.append("{0} {1}".format(i["first_name"], i["last_name"]))
|
||||
return self.users
|
||||
|
||||
def add_tagged_users(self, tagged_users):
|
||||
self.tagged_people = []
|
||||
for i in tagged_users:
|
||||
self.tagged_people.append("[id%s|%s]" % (str(self.friends["items"][i]["id"]), self.friends["items"][i]["first_name"]))
|
||||
self.send_message("add_tagged_users", users=self.tagged_people)
|
||||
|
||||
def translate(self, text, language):
|
||||
msg = translator.translator.translate(text, language)
|
||||
self.send_message("set", control="text", value=msg)
|
||||
self.send_message("focus_control", control="text")
|
||||
output.speak(_("Translated"))
|
||||
|
||||
def spellcheck(self, text):
|
||||
checker = SpellChecker.spellchecker.spellChecker(text)
|
||||
if hasattr(checker, "fixed_text"):
|
||||
self.send_message("set", control="text", value=checker.fixed_text)
|
||||
self.send_message("focus_control", control="text")
|
||||
checker.clean()
|
||||
|
||||
def add_attachments(self):
|
||||
a = attach.attachPresenter(session=self.session, view=views.attachDialog(), interactor=interactors.attachInteractor())
|
||||
if len(a.attachments) != 0:
|
||||
self.attachments = a.attachments
|
8
src/presenters/displayPosts/__init__.py
Normal file
8
src/presenters/displayPosts/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from .basePost import *
|
||||
from .audio import *
|
||||
from .comment import *
|
||||
from .peopleList import *
|
||||
from .poll import *
|
||||
from .topic import *
|
||||
from .topicComment import *
|
100
src/presenters/displayPosts/audio.py
Normal file
100
src/presenters/displayPosts/audio.py
Normal file
@@ -0,0 +1,100 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
from sessionmanager import utils
|
||||
from pubsub import pub
|
||||
from mysc.thread_utils import call_threaded
|
||||
from presenters import base, player
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
class displayAudioPresenter(base.basePresenter):
|
||||
def __init__(self, session, postObject, view, interactor):
|
||||
super(displayAudioPresenter, self).__init__(view=view, interactor=interactor, modulename="display_audio")
|
||||
self.added_audios = {}
|
||||
self.session = session
|
||||
self.post = postObject
|
||||
self.load_audios()
|
||||
self.fill_information(0)
|
||||
self.run()
|
||||
|
||||
def add_to_library(self, audio_index):
|
||||
post = self.post[audio_index]
|
||||
args = {}
|
||||
args["audio_id"] = post["id"]
|
||||
if "album_id" in post:
|
||||
args["album_id"] = post["album_id"]
|
||||
args["owner_id"] = post["owner_id"]
|
||||
audio = self.session.vk.client.audio.add(**args)
|
||||
if audio != None and int(audio) > 21:
|
||||
self.added_audios[post["id"]] = audio
|
||||
self.send_message("disable_control", control="add")
|
||||
self.send_message("enable_control", control="remove")
|
||||
|
||||
def remove_from_library(self, audio_index):
|
||||
post = self.post[audio_index]
|
||||
args = {}
|
||||
if post["id"] in self.added_audios:
|
||||
args["audio_id"] = self.added_audios[post["id"]]
|
||||
args["owner_id"] = self.session.user_id
|
||||
else:
|
||||
args["audio_id"] = post["id"]
|
||||
args["owner_id"] = post["owner_id"]
|
||||
result = self.session.vk.client.audio.delete(**args)
|
||||
if int(result) == 1:
|
||||
self.send_message("enable_control", control="add")
|
||||
self.send_message("disable_control", control="remove")
|
||||
if post["id"] in self.added_audios:
|
||||
self.added_audios.pop(post["id"])
|
||||
|
||||
def fill_information(self, index):
|
||||
post = self.post[index]
|
||||
if "artist" in post:
|
||||
self.send_message("set", control="artist", value=post["artist"])
|
||||
if "title" in post:
|
||||
self.send_message("set", control="title", value=post["title"])
|
||||
if "duration" in post:
|
||||
self.send_message("set", control="duration", value=utils.seconds_to_string(post["duration"]))
|
||||
self.send_message("set_title", value="{0} - {1}".format(post["title"], post["artist"]))
|
||||
call_threaded(self.get_lyrics, index)
|
||||
if post["owner_id"] == self.session.user_id or (post["id"] in self.added_audios) == True:
|
||||
self.send_message("enable_control", control="remove")
|
||||
self.send_message("disable_control", control="add")
|
||||
else:
|
||||
self.send_message("enable_control", control="add")
|
||||
self.send_message("disable_control", control="remove")
|
||||
|
||||
def get_lyrics(self, audio_index):
|
||||
post = self.post[audio_index]
|
||||
if "lyrics_id" in post:
|
||||
l = self.session.vk.client.audio.getLyrics(lyrics_id=int(post["lyrics_id"]))
|
||||
self.send_message("set", control="lyric", value=l["text"])
|
||||
else:
|
||||
self.send_message("disable_control", control="lyric")
|
||||
|
||||
def get_suggested_filename(self, audio_index):
|
||||
post = self.post[audio_index]
|
||||
return utils.safe_filename("{0} - {1}.mp3".format(post["title"], post["artist"]))
|
||||
|
||||
def download(self, audio_index, path):
|
||||
post = self.post[audio_index]
|
||||
if path != None:
|
||||
pub.sendMessage("download-file", url=post["url"], filename=path)
|
||||
|
||||
def play(self, audio_index):
|
||||
post = self.post[audio_index]
|
||||
if player.player.check_is_playing() == True:
|
||||
return pub.sendMessage("stop")
|
||||
pub.sendMessage("play", object=post)
|
||||
|
||||
def load_audios(self):
|
||||
audios = []
|
||||
for i in self.post:
|
||||
s = "{0} - {1}. {2}".format(i["title"], i["artist"], utils.seconds_to_string(i["duration"]))
|
||||
audios.append(s)
|
||||
self.send_message("add_items", control="list", items=audios)
|
||||
if len(self.post) == 1:
|
||||
self.send_message("disable_control", control="list")
|
||||
self.send_message("focus_control", control="title")
|
||||
|
||||
def handle_changes(self, audio_index):
|
||||
self.fill_information(audio_index)
|
380
src/presenters/displayPosts/basePost.py
Normal file
380
src/presenters/displayPosts/basePost.py
Normal file
@@ -0,0 +1,380 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import threading
|
||||
import arrow
|
||||
import requests
|
||||
import languageHandler
|
||||
import views
|
||||
import interactors
|
||||
import output
|
||||
import webbrowser
|
||||
import logging
|
||||
from vk_api import upload
|
||||
from sessionmanager import session, renderers, utils # We'll use some functions from there
|
||||
from pubsub import pub
|
||||
from extra import SpellChecker, translator
|
||||
from mysc.thread_utils import call_threaded
|
||||
from presenters import base
|
||||
from presenters.createPosts.basePost import createPostPresenter
|
||||
from . import audio, poll
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
def get_message(status):
|
||||
message = ""
|
||||
if "text" in status:
|
||||
message = utils.clean_text(status["text"])
|
||||
return message
|
||||
|
||||
class displayPostPresenter(base.basePresenter):
|
||||
""" Base class for post representation."""
|
||||
|
||||
def __init__(self, session, postObject, view, interactor):
|
||||
super(displayPostPresenter, self).__init__(view=view, interactor=interactor, modulename="display_post")
|
||||
self.type = "post"
|
||||
self.session = session
|
||||
self.post = postObject
|
||||
# Posts from newsfeed contains this source_id instead from_id in walls. Also it uses post_id and walls use just id.
|
||||
if "source_id" in self.post:
|
||||
self.user_identifier = "source_id"
|
||||
self.post_identifier = "post_id"
|
||||
else:
|
||||
# In wall's posts, if someone has posted in user's wall, owner_id should be used instead from_id
|
||||
# This will help for retrieving comments, do likes, etc.
|
||||
if "owner_id" not in self.post:
|
||||
self.user_identifier = "from_id"
|
||||
else:
|
||||
self.user_identifier = "owner_id"
|
||||
self.post_identifier = "id"
|
||||
self.attachments = []
|
||||
self.load_images = False
|
||||
# We'll put images here, so it will be easier to work with them.
|
||||
self.images = []
|
||||
self.imageIndex = 0
|
||||
result = self.get_post_information()
|
||||
# Stop loading everything else if post was deleted.
|
||||
if result == False:
|
||||
self.interactor.uninstall()
|
||||
return
|
||||
self.worker = threading.Thread(target=self.load_all_components)
|
||||
self.worker.finished = threading.Event()
|
||||
self.worker.start()
|
||||
# connect here the pubsub event for successful posting of comments.
|
||||
pub.subscribe(self.posted, "posted")
|
||||
self.run()
|
||||
pub.unsubscribe(self.posted, "posted")
|
||||
|
||||
def posted(self, from_buffer=None):
|
||||
self.clear_comments_list()
|
||||
|
||||
def get_comments(self):
|
||||
""" Get comments and insert them in a list."""
|
||||
user = self.post[self.user_identifier]
|
||||
id = self.post[self.post_identifier]
|
||||
comments_data = self.session.vk.client.wall.getComments(owner_id=user, post_id=id, need_likes=1, count=100, extended=1, preview_length=0, thread_items_count=10)
|
||||
self.comments = dict(items=[], profiles=comments_data["profiles"])
|
||||
for i in comments_data["items"]:
|
||||
self.comments["items"].append(i)
|
||||
if i.get("thread") != None and i["thread"].get("count") > 0:
|
||||
for newI in i["thread"]["items"]:
|
||||
self.comments["items"].append(newI)
|
||||
comments_ = []
|
||||
# Save profiles in session local storage for a future usage.
|
||||
# Although community objects are returned here, we should not add those because their names are changed.
|
||||
# For example, self reference to a group is marked as "Administrator", which would ruin this profile to be rendered somewhere else.
|
||||
data = dict(groups=[], profiles=self.comments["profiles"])
|
||||
self.session.process_usernames(data)
|
||||
for i in self.comments["items"]:
|
||||
# If comment has a "deleted" key it should not be displayed, obviously.
|
||||
if "deleted" in i:
|
||||
continue
|
||||
from_ = self.session.get_user(i["from_id"])["user1_nom"]
|
||||
if "reply_to_user" in i:
|
||||
extra_info = self.session.get_user(i["reply_to_user"])["user1_nom"]
|
||||
from_ = _("{0} > {1}").format(from_, extra_info)
|
||||
# As we set the comment reply properly in the from_ field, let's remove the first username from here if it exists.
|
||||
fixed_text = utils.clean_text(i["text"])
|
||||
if len(fixed_text) > 140:
|
||||
text = fixed_text[:141]
|
||||
else:
|
||||
text = fixed_text
|
||||
original_date = arrow.get(i["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
|
||||
likes = str(i["likes"]["count"])
|
||||
comments_.append((from_, text, created_at, likes))
|
||||
self.send_message("add_items", control="comments", items=comments_)
|
||||
|
||||
def get_post_information(self):
|
||||
from_ = self.session.get_user(self.post[self.user_identifier])
|
||||
if "copy_history" in self.post:
|
||||
title = _("repost from {user1_nom}").format(**from_)
|
||||
else:
|
||||
if ("from_id" in self.post and "owner_id" in self.post) and (self.post["from_id"] != self.post["owner_id"]):
|
||||
# Translators: {0} will be replaced with the user who is posting, and {1} with the wall owner.
|
||||
user2 = self.session.get_user(self.post["owner_id"], "user2")
|
||||
user2.update(from_)
|
||||
title = _("Post from {user1_nom} in the {user2_nom}'s wall").format(**user2)
|
||||
else:
|
||||
title = _("Post from {user1_nom}").format(**from_)
|
||||
self.send_message("set_title", value=title)
|
||||
message = ""
|
||||
# Retrieve again the post, so we'll make sure to get the most up to date information.
|
||||
# And we add a counter for views.
|
||||
post = self.session.vk.client.wall.getById(posts="{owner_id}_{post_id}".format(owner_id=self.post[self.user_identifier], post_id=self.post[self.post_identifier]))
|
||||
# If this post has been deleted, let's send an event to the interactor so it won't be displayed.
|
||||
if len(post) == 0:
|
||||
self.send_message("post_deleted")
|
||||
return False
|
||||
self.post = post[0]
|
||||
if "views" in self.post and self.post["views"]["count"] > 0:
|
||||
self.send_message("set", control="views", value=str(self.post["views"]["count"]))
|
||||
else:
|
||||
self.send_message("disable_control", control="views")
|
||||
if "owner_id" not in self.post:
|
||||
self.user_identifier = "from_id"
|
||||
else:
|
||||
self.user_identifier = "owner_id"
|
||||
self.post_identifier = "id"
|
||||
message = get_message(self.post)
|
||||
if "copy_history" in self.post:
|
||||
nm = "\n"
|
||||
for i in self.post["copy_history"]:
|
||||
u = self.session.get_user(i["from_id"])
|
||||
u.update(message=get_message(i))
|
||||
nm += "{user1_nom}: {message}\n\n".format(**u)
|
||||
self.get_attachments(i, get_message(i))
|
||||
message += nm
|
||||
self.send_message("set", control="post_view", value=message)
|
||||
self.get_attachments(self.post, message)
|
||||
self.check_image_load()
|
||||
|
||||
def get_attachments(self, post, text):
|
||||
attachments = []
|
||||
self.attachments = []
|
||||
if "attachments" in post:
|
||||
for i in post["attachments"]:
|
||||
# We don't need the photos_list attachment, so skip it.
|
||||
if i["type"] == "photos_list":
|
||||
continue
|
||||
if i["type"] == "photo":
|
||||
if self.load_images == False: self.load_images = True
|
||||
self.images.append(i)
|
||||
attachments.append(renderers.add_attachment(i))
|
||||
self.attachments.append(i)
|
||||
# Links in text are not treated like normal attachments, so we'll have to catch and add those to the list without title
|
||||
# We can't get a title because title is provided by the VK API and it will not work for links as simple text.
|
||||
urls = utils.find_urls_in_text(text)
|
||||
if len(urls) > 0:
|
||||
links = []
|
||||
for i in urls:
|
||||
links.append({"link": {"title": _("Untitled link"), "url": i}, "type": "link"})
|
||||
for i in links:
|
||||
attachments.append(renderers.add_attachment(i))
|
||||
self.attachments.append(i)
|
||||
if len(self.attachments) > 0:
|
||||
self.send_message("enable_attachments")
|
||||
self.send_message("add_items", control="attachments", items=attachments)
|
||||
else:
|
||||
self.interactor.view.attachments.list.Enable(False)
|
||||
|
||||
def check_image_load(self):
|
||||
if self.load_images and len(self.images) > 0 and self.session.settings["general"]["load_images"]:
|
||||
self.send_message("enable_control", control="image")
|
||||
nav = False # Disable navigation controls in photos
|
||||
if len(self.images) > 1:
|
||||
nav = True
|
||||
self.send_message("enable_photo_controls", navigation=nav)
|
||||
self.set_image(0)
|
||||
|
||||
def set_next_image(self, *args, **kwargs):
|
||||
if self.imageIndex < -1 or self.imageIndex == len(self.images)-1:
|
||||
self.imageIndex = -1
|
||||
if len(self.images) <= self.imageIndex+1:
|
||||
self.imageIndex = 0
|
||||
else:
|
||||
self.imageIndex = self.imageIndex + 1
|
||||
self.set_image(self.imageIndex)
|
||||
|
||||
def set_previous_image(self, *args, **kwargs):
|
||||
if self.imageIndex <= 0:
|
||||
self.imageIndex = len(self.images)
|
||||
self.imageIndex = self.imageIndex - 1
|
||||
self.set_image(self.imageIndex)
|
||||
|
||||
def set_image(self, index):
|
||||
if len(self.images) < index-1:
|
||||
return
|
||||
# Get's photo URL.
|
||||
url = self.get_photo_url(self.images[index]["photo"], "x")
|
||||
if url != "":
|
||||
img = requests.get(url)
|
||||
self.send_message("load_image", image=img)
|
||||
# Translators: {0} is the number of the current photo and {1} is the total number of photos.
|
||||
output.speak(_("Loaded photo {0} of {1}").format(index+1, len(self.images)))
|
||||
return
|
||||
|
||||
def get_photo_url(self, photo, size="x"):
|
||||
url = ""
|
||||
for i in photo["sizes"]:
|
||||
if i["type"] == size:
|
||||
url = i["url"]
|
||||
break
|
||||
return url
|
||||
|
||||
def load_all_components(self):
|
||||
self.get_likes()
|
||||
self.get_reposts()
|
||||
self.get_comments()
|
||||
if self.post["comments"]["can_post"] == 0:
|
||||
self.send_message("disable_control", control="comment")
|
||||
if self.post["likes"]["can_like"] == 0 and self.post["likes"]["user_likes"] == 0:
|
||||
self.send_message("disable_control", "like")
|
||||
elif self.post["likes"]["user_likes"] == 1:
|
||||
self.send_message("set_label", control="like", label=_("&Dislike"))
|
||||
if self.post["likes"]["can_publish"] == 0:
|
||||
self.send_message("disable_control", control="repost")
|
||||
|
||||
def post_like(self):
|
||||
if ("owner_id" in self.post) == False:
|
||||
user = int(self.post[self.user_identifier])
|
||||
else:
|
||||
user = int(self.post["owner_id"])
|
||||
id = int(self.post[self.post_identifier])
|
||||
if "type" in self.post:
|
||||
type_ = self.post["type"]
|
||||
else:
|
||||
type_ = self.type
|
||||
if self.post["likes"]["user_likes"] == 1:
|
||||
l = self.session.vk.client.likes.delete(owner_id=user, item_id=id, type=type_)
|
||||
output.speak(_("You don't like this"))
|
||||
self.post["likes"]["count"] = l["likes"]
|
||||
self.post["likes"]["user_likes"] = 2
|
||||
self.get_likes()
|
||||
self.send_message("set_label", control="like", label=_("&Like"))
|
||||
else:
|
||||
l = self.session.vk.client.likes.add(owner_id=user, item_id=id, type=type_)
|
||||
output.speak(_("You liked this"))
|
||||
self.send_message("set_label", control="like", label=_("&Dislike"))
|
||||
self.post["likes"]["count"] = l["likes"]
|
||||
self.post["likes"]["user_likes"] = 1
|
||||
self.get_likes()
|
||||
|
||||
def post_repost(self):
|
||||
object_id = "wall{0}_{1}".format(self.post[self.user_identifier], self.post[self.post_identifier])
|
||||
p = createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Repost"), message=_("Add your comment here"), text="", mode="comment"))
|
||||
if hasattr(p, "text") or hasattr(p, "privacy"):
|
||||
post_arguments = dict(object=object_id, message=p.text)
|
||||
attachments = []
|
||||
if hasattr(p, "attachments"):
|
||||
attachments = p.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="wall", child_endpoint="repost", attachments_list=attachments, post_arguments=post_arguments)
|
||||
|
||||
def get_likes(self):
|
||||
self.send_message("set_label", control="likes", label=_("{0} people like this").format(self.post["likes"]["count"],))
|
||||
|
||||
def get_reposts(self):
|
||||
self.send_message("set_label", control="shares", label=_("Shared {0} times").format(self.post["reposts"]["count"],))
|
||||
|
||||
def add_comment(self):
|
||||
comment = createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Add a comment"), message="", text="", mode="comment"))
|
||||
if hasattr(comment, "text") or hasattr(comment, "privacy"):
|
||||
owner_id = self.post[self.user_identifier]
|
||||
post_id = self.post[self.post_identifier]
|
||||
post_arguments=dict(message=comment.text, owner_id=owner_id, post_id=post_id)
|
||||
attachments = []
|
||||
if hasattr(comment, "attachments"):
|
||||
attachments = comment.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="wall", child_endpoint="createComment", attachments_list=attachments, post_arguments=post_arguments)
|
||||
|
||||
def reply(self, comment):
|
||||
c = self.comments["items"][comment]
|
||||
comment = createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Reply to {user1_nom}").format(**self.session.get_user(c["from_id"])), message="", text="", mode="comment"))
|
||||
if hasattr(comment, "text") or hasattr(comment, "privacy"):
|
||||
post_id = self.post[self.post_identifier]
|
||||
post_arguments=dict(message=comment.text, owner_id=c["owner_id"], reply_to_comment=c["id"], post_id=c["post_id"], reply_to_user=c["owner_id"])
|
||||
attachments = []
|
||||
if hasattr(comment, "attachments"):
|
||||
attachments = comment.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="wall", child_endpoint="createComment", attachments_list=attachments, post_arguments=post_arguments)
|
||||
|
||||
def show_comment(self, comment_index):
|
||||
from . import comment
|
||||
c = self.comments["items"][comment_index]
|
||||
c["post_id"] = self.post[self.post_identifier]
|
||||
a = comment.displayCommentPresenter(session=self.session, postObject=c, interactor=interactors.displayPostInteractor(), view=views.displayComment())
|
||||
|
||||
def translate(self, text, language):
|
||||
msg = translator.translator.translate(text, language)
|
||||
self.send_message("set", control="post_view", value=msg)
|
||||
self.send_message("focus_control", control="post_view")
|
||||
output.speak(_("Translated"))
|
||||
|
||||
def spellcheck(self, text):
|
||||
checker = SpellChecker.spellchecker.spellChecker(text, "")
|
||||
if hasattr(checker, "fixed_text"):
|
||||
self.send_message("set", control="post_view", value=checker.fixed_text)
|
||||
self.send_message("focus_control", control="post_view")
|
||||
checker.clean()
|
||||
|
||||
def open_attachment(self, index):
|
||||
attachment = self.attachments[index]
|
||||
if attachment["type"] == "audio":
|
||||
a = audio.displayAudioPresenter(session=self.session, postObject=[attachment["audio"]], interactor=interactors.displayAudioInteractor(), view=views.displayAudio())
|
||||
elif attachment["type"] == "link":
|
||||
output.speak(_("Opening URL..."), True)
|
||||
webbrowser.open_new_tab(attachment["link"]["url"])
|
||||
elif attachment["type"] == "doc":
|
||||
output.speak(_("Opening document in web browser..."))
|
||||
webbrowser.open(attachment["doc"]["url"])
|
||||
elif attachment["type"] == "video":
|
||||
# it seems VK doesn't like to attach video links as normal URLS, so we'll have to
|
||||
# get the full video object and use its "player" key which will open a webbrowser in their site with a player for the video.
|
||||
# see https://vk.com/dev/attachments_w and and https://vk.com/dev/video.get
|
||||
# However, the flash player isn't good for visually impaired people (when you press play you won't be able to close the window with alt+f4), so it could be good to use the HTML5 player.
|
||||
# For firefox, see https://addons.mozilla.org/ru/firefox/addon/force-html5-video-player-at-vk/
|
||||
# May be I could use a dialogue here for inviting people to use this addon in firefox. It seems it isn't possible to use this html5 player from the player URL.
|
||||
object_id = "{0}_{1}".format(attachment["video"]["owner_id"], attachment["video"]["id"])
|
||||
video_object = self.session.vk.client.video.get(owner_id=attachment["video"]["owner_id"], videos=object_id)
|
||||
video_object = video_object["items"][0]
|
||||
output.speak(_("Opening video in web browser..."), True)
|
||||
webbrowser.open_new_tab(video_object["player"])
|
||||
elif attachment["type"] == "photo":
|
||||
output.speak(_("Opening photo in web browser..."), True)
|
||||
# Possible photo sizes for looking in the attachment information. Try to use the biggest photo available.
|
||||
possible_sizes = [1280, 604, 130, 75]
|
||||
url = ""
|
||||
for i in possible_sizes:
|
||||
if "photo_{0}".format(i,) in attachment["photo"]:
|
||||
url = attachment["photo"]["photo_{0}".format(i,)]
|
||||
break
|
||||
if url != "":
|
||||
webbrowser.open_new_tab(url)
|
||||
elif attachment["type"] == "poll":
|
||||
a = poll.displayPollPresenter(session=self.session, poll=attachment, interactor=interactors.displayPollInteractor(), view=views.displayPoll())
|
||||
elif attachment["type"] == "article":
|
||||
output.speak(_("Opening Article in web browser..."), True)
|
||||
webbrowser.open_new_tab(attachment["article"]["url"])
|
||||
else:
|
||||
log.debug("Unhandled attachment: %r" % (attachment,))
|
||||
|
||||
def __del__(self):
|
||||
if hasattr(self, "worker"):
|
||||
self.worker.finished.set()
|
||||
|
||||
def clear_comments_list(self):
|
||||
self.send_message("clean_list", list="comments")
|
||||
self.get_comments()
|
||||
|
||||
def show_likes(self):
|
||||
""" show likes for the specified post."""
|
||||
data = dict(type="post", owner_id=self.post[self.user_identifier], item_id=self.post["id"], extended=True, count=100, skip_own=True)
|
||||
result = self.session.vk.client.likes.getList(**data)
|
||||
if result["count"] > 0:
|
||||
post = {"source_id": self.post[self.user_identifier], "friends": {"items": result["items"]}}
|
||||
pub.sendMessage("open-post", post_object=post, controller_="displayFriendship", vars=dict(caption=_("people who liked this")))
|
||||
|
||||
def show_shares(self):
|
||||
data = dict(type="post", owner_id=self.post[self.user_identifier], item_id=self.post["id"], extended=True, count=1000, skip_own=True, filter="copies")
|
||||
result = self.session.vk.client.likes.getList(**data)
|
||||
if result["count"] > 0:
|
||||
post = {"source_id": self.post[self.user_identifier], "friends": {"items": result["items"]}}
|
||||
pub.sendMessage("open-post", post_object=post, controller_="displayFriendship", vars=dict(caption=_("people who shared this")))
|
89
src/presenters/displayPosts/comment.py
Normal file
89
src/presenters/displayPosts/comment.py
Normal file
@@ -0,0 +1,89 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import threading
|
||||
import arrow
|
||||
import languageHandler
|
||||
import views
|
||||
import interactors
|
||||
import logging
|
||||
from pubsub import pub
|
||||
from sessionmanager import renderers, utils # We'll use some functions from there
|
||||
from mysc.thread_utils import call_threaded
|
||||
from presenters import base
|
||||
from presenters.createPosts.basePost import createPostPresenter
|
||||
from . import basePost
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
def get_message(status):
|
||||
message = ""
|
||||
if "text" in status:
|
||||
message = utils.clean_text(status["text"])
|
||||
return message
|
||||
|
||||
class displayCommentPresenter(basePost.displayPostPresenter):
|
||||
|
||||
def __init__(self, session, postObject, view, interactor):
|
||||
self.type = "comment"
|
||||
self.modulename = "display_comment"
|
||||
self.interactor = interactor
|
||||
self.view = view
|
||||
self.interactor.install(view=view, presenter=self, modulename=self.modulename)
|
||||
self.session = session
|
||||
self.post = postObject
|
||||
self.user_identifier = "from_id"
|
||||
self.post_identifier = "id"
|
||||
self.worker = threading.Thread(target=self.load_all_components)
|
||||
self.worker.finished = threading.Event()
|
||||
self.worker.start()
|
||||
self.attachments = []
|
||||
self.load_images = False
|
||||
# We'll put images here, so it will be easier to work with them.
|
||||
self.images = []
|
||||
self.imageIndex = 0
|
||||
# connect here the pubsub event for successful posting of comments.
|
||||
pub.subscribe(self.posted, "posted")
|
||||
self.run()
|
||||
pub.unsubscribe(self.posted, "posted")
|
||||
|
||||
def load_all_components(self):
|
||||
self.get_post_information()
|
||||
self.get_likes()
|
||||
self.send_message("disable_control", control="comment")
|
||||
if self.post["likes"]["can_like"] == 0 and self.post["likes"]["user_likes"] == 0:
|
||||
self.send_message("disable_control", "like")
|
||||
elif self.post["likes"]["user_likes"] == 1:
|
||||
self.send_message("set_label", control="like", label=_("&Dislike"))
|
||||
|
||||
def get_post_information(self):
|
||||
from_ = self.session.get_user(self.post[self.user_identifier])
|
||||
if ("from_id" in self.post and "owner_id" in self.post):
|
||||
user2 = self.session.get_user(self.post["owner_id"], "user2")
|
||||
user2.update(from_)
|
||||
title = _("Comment from {user1_nom} in the {user2_nom}'s post").format(**user2)
|
||||
self.send_message("set_title", value=title)
|
||||
message = ""
|
||||
message = get_message(self.post)
|
||||
self.send_message("set", control="post_view", value=message)
|
||||
self.get_attachments(self.post, message)
|
||||
self.check_image_load()
|
||||
|
||||
def reply(self, *args, **kwargs):
|
||||
comment = createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Reply to {user1_nom}").format(**self.session.get_user(self.post["from_id"])), message="", text="", mode="comment"))
|
||||
if hasattr(comment, "text") or hasattr(comment, "privacy"):
|
||||
post_arguments = dict(owner_id=self.post["owner_id"], reply_to_comment=self.post["id"], post_id=self.post["post_id"], reply_to_user=self.post["owner_id"], message=comment.text)
|
||||
attachments = []
|
||||
if hasattr(comment, "attachments"):
|
||||
attachments = comment.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="wall", child_endpoint="createComment", attachments_list=attachments, post_arguments=post_arguments)
|
||||
|
||||
def show_likes(self):
|
||||
""" show likes for the specified post."""
|
||||
data = dict(type="comment", owner_id=self.post["owner_id"], item_id=self.post["id"], extended=True, count=100, skip_own=True)
|
||||
result = self.session.vk.client.likes.getList(**data)
|
||||
if result["count"] > 0:
|
||||
post = {"source_id": self.post[self.user_identifier], "friends": {"items": result["items"]}}
|
||||
pub.sendMessage("open-post", post_object=post, controller_="displayFriendship", vars=dict(caption=_("people who liked this")))
|
||||
|
||||
def posted(self, from_buffer=None):
|
||||
self.interactor.uninstall()
|
||||
return
|
50
src/presenters/displayPosts/peopleList.py
Normal file
50
src/presenters/displayPosts/peopleList.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import webbrowser
|
||||
import logging
|
||||
from pubsub import pub
|
||||
from presenters import base
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
class displayFriendshipPresenter(base.basePresenter):
|
||||
|
||||
def __init__(self, session, postObject, view, interactor, caption=""):
|
||||
self.session = session
|
||||
self.post = postObject
|
||||
super(displayFriendshipPresenter, self).__init__(view=view, interactor=interactor, modulename="display_friendship")
|
||||
list_of_friends = self.get_friend_names()
|
||||
from_ = self.session.get_user(self.post["source_id"])
|
||||
title = caption.format(**from_)
|
||||
self.send_message("set_title", value=title)
|
||||
self.set_friends_list(list_of_friends)
|
||||
self.run()
|
||||
|
||||
def get_friend_names(self):
|
||||
self.friends = self.post["friends"]["items"]
|
||||
friends = list()
|
||||
for i in self.friends:
|
||||
if "user_id" in i:
|
||||
friends.append(self.session.get_user(i["user_id"])["user1_nom"])
|
||||
else:
|
||||
friends.append(self.session.get_user(i["id"])["user1_nom"])
|
||||
return friends
|
||||
|
||||
def set_friends_list(self, friendslist):
|
||||
self.send_message("add_items", control="friends", items=friendslist)
|
||||
|
||||
def view_profile(self, item):
|
||||
user = self.friends[item]
|
||||
if "user_id" in user:
|
||||
id = user["user_id"]
|
||||
else:
|
||||
id = user["id"]
|
||||
pub.sendMessage("user-profile", person=id)
|
||||
|
||||
def open_in_browser(self, item):
|
||||
user = self.friends[item]
|
||||
if "user_id" in user:
|
||||
id = user["user_id"]
|
||||
else:
|
||||
id = user["id"]
|
||||
url = "https://vk.com/id{user_id}".format(user_id=id)
|
||||
webbrowser.open_new_tab(url)
|
55
src/presenters/displayPosts/poll.py
Normal file
55
src/presenters/displayPosts/poll.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import output
|
||||
import logging
|
||||
from presenters import base
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
class displayPollPresenter(base.basePresenter):
|
||||
|
||||
def __init__(self, session, poll, view, interactor, show_results=False):
|
||||
super(displayPollPresenter, self).__init__(view=view, interactor=interactor, modulename="display_poll")
|
||||
self.poll = poll["poll"]
|
||||
self.session = session
|
||||
self.get_poll()
|
||||
self.load_poll(show_results)
|
||||
self.run()
|
||||
|
||||
def get_poll(self):
|
||||
# Retrieve the poll again so we will have a fresh and updated object.
|
||||
data = dict(owner_id=self.poll["owner_id"], is_board=int(self.poll["is_board"]), poll_id=self.poll["id"])
|
||||
self.poll = self.session.vk.client.polls.getById(**data)
|
||||
|
||||
def load_poll(self, load_results=False):
|
||||
user = self.session.get_user(self.poll["author_id"])
|
||||
title = _("Poll from {user1_nom}").format(**user)
|
||||
self.send_message("set_title", value=title)
|
||||
self.send_message("set", control="question", value=self.poll["question"])
|
||||
if len(self.poll["answer_ids"]) > 0 or ("is_closed" in self.poll and self.poll["is_closed"] == True) or load_results == True or ("can_vote" in self.poll and self.poll["can_vote"] == False):
|
||||
options = []
|
||||
for i in self.poll["answers"]:
|
||||
options.append((i["text"], i["votes"], i["rate"]))
|
||||
self.send_message("add_options", options=options, multiple=self.poll["multiple"])
|
||||
self.send_message("done")
|
||||
self.send_message("disable_control", control="ok")
|
||||
else:
|
||||
options = []
|
||||
for i in self.poll["answers"]:
|
||||
options.append(i["text"])
|
||||
self.send_message("add_options", options=options, multiple=self.poll["multiple"])
|
||||
self.send_message("done")
|
||||
|
||||
def vote(self, answers):
|
||||
ids = ""
|
||||
for i in range(0, len(self.poll["answers"])):
|
||||
if answers[i] == True:
|
||||
ids = ids+"{answer_id},".format(answer_id=self.poll["answers"][i]["id"])
|
||||
if self.poll["multiple"] == False:
|
||||
break
|
||||
if ids == "":
|
||||
log.exception("An error occurred when retrieving answer IDS for the following poll: %r. Provided answer list: %r" % (self.poll, answers))
|
||||
return
|
||||
data = dict(owner_id=self.poll["owner_id"], poll_id=self.poll["id"], answer_ids=ids, is_board=int(self.poll["is_board"]))
|
||||
result = self.session.vk.client.polls.addVote(**data)
|
||||
if result == 1:
|
||||
output.speak(_("Your vote has been added to this poll."))
|
168
src/presenters/displayPosts/topic.py
Normal file
168
src/presenters/displayPosts/topic.py
Normal file
@@ -0,0 +1,168 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import threading
|
||||
import arrow
|
||||
import languageHandler
|
||||
import views
|
||||
import interactors
|
||||
import output
|
||||
import logging
|
||||
from pubsub import pub
|
||||
from sessionmanager import utils # We'll use some functions from there
|
||||
from mysc.thread_utils import call_threaded
|
||||
from presenters import base
|
||||
from presenters.createPosts.basePost import createPostPresenter
|
||||
from . import basePost
|
||||
from .topicComment import *
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
class displayTopicPresenter(basePost.displayPostPresenter):
|
||||
|
||||
def __init__(self, session, postObject, group_id, view, interactor):
|
||||
self.type = "topic"
|
||||
self.modulename = "display_topic"
|
||||
self.interactor = interactor
|
||||
self.view = view
|
||||
self.interactor.install(view=view, presenter=self, modulename=self.modulename)
|
||||
self.session = session
|
||||
self.post = postObject
|
||||
self.group_id = group_id
|
||||
self.load_images = False
|
||||
# We'll put images here, so it will be easier to work with them.
|
||||
self.images = []
|
||||
self.imageIndex = 0
|
||||
result = self.get_post_information()
|
||||
# Stop loading everything else if post was deleted.
|
||||
if result == False:
|
||||
self.interactor.uninstall()
|
||||
return
|
||||
self.worker = threading.Thread(target=self.load_all_components)
|
||||
self.worker.finished = threading.Event()
|
||||
self.worker.start()
|
||||
self.attachments = []
|
||||
# connect pubsub event for posted comments.
|
||||
pub.subscribe(self.posted, "posted")
|
||||
self.run()
|
||||
pub.unsubscribe(self.posted, "posted")
|
||||
|
||||
def load_all_components(self):
|
||||
self.get_comments()
|
||||
|
||||
def get_post_information(self):
|
||||
title = self.post["title"]
|
||||
self.send_message("set_title", value=title)
|
||||
return True
|
||||
|
||||
def get_comments(self):
|
||||
""" Get comments and insert them in a list."""
|
||||
self.comments = self.session.vk.client.board.getComments(group_id=self.group_id, topic_id=self.post["id"], need_likes=1, count=100, extended=1, sort="desc")
|
||||
comments_ = []
|
||||
data = dict(profiles=self.comments["profiles"], groups=[])
|
||||
self.session.process_usernames(data)
|
||||
self.comments["items"].reverse()
|
||||
# If there are less than 100 comments in the topic we should disable the "load previous" button.
|
||||
if self.comments["count"] <= 100:
|
||||
self.send_message("disable_control", control="load_more_comments")
|
||||
else:
|
||||
left_comments = self.comments["count"]-len(self.comments["items"])
|
||||
if left_comments > 100:
|
||||
left_comments = 100
|
||||
self.send_message("set_label", control="load_more_comments", label=_("Load {comments} previous comments").format(comments=left_comments))
|
||||
for i in self.comments["items"]:
|
||||
# If comment has a "deleted" key it should not be displayed, obviously.
|
||||
if "deleted" in i:
|
||||
continue
|
||||
from_ = self.session.get_user(i["from_id"])["user1_nom"]
|
||||
# match user mentions inside text comment.
|
||||
original_date = arrow.get(i["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
|
||||
likes = str(i["likes"]["count"])
|
||||
text = utils.clean_text(text=i["text"])
|
||||
comments_.append((from_, text, created_at, likes))
|
||||
self.send_message("add_items", control="comments", items=comments_)
|
||||
|
||||
def post_like(self):
|
||||
c = self.interactor.view.comments.get_selected()
|
||||
id = self.comments["items"][c]["id"]
|
||||
if self.comments["items"][c]["likes"]["user_likes"] == 1:
|
||||
l = self.session.vk.client.likes.delete(owner_id=-1*self.group_id, item_id=id, type="topic_comment")
|
||||
output.speak(_("You don't like this"))
|
||||
self.comments["items"][c]["likes"]["count"] = l["likes"]
|
||||
self.comments["items"][c]["likes"]["user_likes"] = 2
|
||||
self.send_message("set_label", control="like", label=_("&Like"))
|
||||
else:
|
||||
l = self.session.vk.client.likes.add(owner_id=-1*self.group_id, item_id=id, type="topic_comment")
|
||||
output.speak(_("You liked this"))
|
||||
self.send_message("set_label", control="like", label=_("&Dislike"))
|
||||
self.comments["items"][c]["likes"]["count"] = l["likes"]
|
||||
self.comments["items"][c]["likes"]["user_likes"] = 1
|
||||
self.clear_comments_list()
|
||||
|
||||
def change_comment(self, comment):
|
||||
comment = self.comments["items"][comment]
|
||||
self.send_message("clean_list", list="attachments")
|
||||
self.get_attachments(comment, "")
|
||||
if comment["likes"]["user_likes"] == 1:
|
||||
self.send_message("set_label", control="like", label=_("&Dislike"))
|
||||
else:
|
||||
self.send_message("set_label", control="like", label=_("&Like"))
|
||||
|
||||
def add_comment(self):
|
||||
comment = createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Add a comment"), message="", text="", mode="comment"))
|
||||
if hasattr(comment, "text") or hasattr(comment, "privacy"):
|
||||
post_arguments = dict(group_id=self.group_id, topic_id=self.post["id"], message=comment.text)
|
||||
attachments = []
|
||||
if hasattr(comment, "attachments"):
|
||||
attachments = comment.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="board", child_endpoint="createComment", attachments_list=attachments, post_arguments=post_arguments)
|
||||
|
||||
def reply(self, comment):
|
||||
c = self.comments["items"][comment]
|
||||
comment = createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=_("Reply to {user1_nom}").format(**self.session.get_user(c["from_id"])), message="", text="", mode="comment"))
|
||||
if hasattr(comment, "text") or hasattr(comment, "privacy"):
|
||||
user = self.session.get_user(c["from_id"])
|
||||
name = user["user1_nom"].split(" ")[0]
|
||||
comment.text = "[post{post_id}|{name}], {text}".format(post_id=c["id"], text=comment.text, name=name)
|
||||
group_id = self.group_id
|
||||
topic_id = self.post["id"]
|
||||
post_arguments = dict(group_id=group_id, topic_id=topic_id, reply_to_comment=c["id"], message=comment.text)
|
||||
attachments = []
|
||||
if hasattr(comment, "attachments"):
|
||||
attachments = comment.attachments
|
||||
call_threaded(pub.sendMessage, "post", parent_endpoint="board", child_endpoint="createComment", attachments_list=attachments, post_arguments=post_arguments)
|
||||
|
||||
def show_comment(self, comment_index):
|
||||
c = self.comments["items"][comment_index]
|
||||
c["post_id"] = self.post["id"]
|
||||
c["group_id"] = -1*self.group_id
|
||||
a = displayTopicCommentPresenter(session=self.session, postObject=c, interactor=interactors.displayPostInteractor(), view=views.displayComment())
|
||||
|
||||
def load_more_comments(self):
|
||||
offset = len(self.comments["items"])
|
||||
comments = self.session.vk.client.board.getComments(group_id=self.group_id, topic_id=self.post["id"], need_likes=1, count=100, extended=1, sort="desc", offset=offset)
|
||||
data = dict(profiles=comments["profiles"], groups=[])
|
||||
self.session.process_usernames(data)
|
||||
# If there are less than 100 comments in the topic we should disable the "load previous" button.
|
||||
for i in comments["items"]:
|
||||
self.comments["items"].insert(0, i)
|
||||
for i in comments["items"]:
|
||||
# If comment has a "deleted" key it should not be displayed, obviously.
|
||||
if "deleted" in i:
|
||||
continue
|
||||
from_ = self.session.get_user(i["from_id"])["user1_nom"]
|
||||
# match user mentions inside text comment.
|
||||
original_date = arrow.get(i["date"])
|
||||
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
|
||||
likes = str(i["likes"]["count"])
|
||||
text = utils.clean_text(text=i["text"])
|
||||
self.send_message("add_item", control="comments", item=(from_, text, created_at, likes), reversed=True)
|
||||
if len(self.comments["items"]) == self.comments["count"]:
|
||||
self.send_message("disable_control", control="load_more_comments")
|
||||
else:
|
||||
left_comments = self.comments["count"]-len(self.comments["items"])
|
||||
if left_comments > 100:
|
||||
left_comments = 100
|
||||
self.send_message("set_label", control="load_more_comments", label=_("Load {comments} previous comments").format(comments=left_comments))
|
||||
|
||||
def posted(self, from_buffer=None):
|
||||
self.clear_comments_list()
|
53
src/presenters/displayPosts/topicComment.py
Normal file
53
src/presenters/displayPosts/topicComment.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
import output
|
||||
from pubsub import pub
|
||||
from sessionmanager import renderers, utils # We'll use some functions from there
|
||||
from presenters import base
|
||||
from presenters.createPosts.basePost import createPostPresenter
|
||||
from . import comment
|
||||
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
def get_message(status):
|
||||
message = ""
|
||||
if "text" in status:
|
||||
message = utils.clean_text(status["text"])
|
||||
return message
|
||||
|
||||
class displayTopicCommentPresenter(comment.displayCommentPresenter):
|
||||
|
||||
def get_post_information(self):
|
||||
from_ = self.session.get_user(self.post[self.user_identifier])
|
||||
title = from_["user1_nom"]
|
||||
self.send_message("set_title", value=title)
|
||||
message = ""
|
||||
message = get_message(self.post)
|
||||
self.send_message("set", control="post_view", value=message)
|
||||
self.get_attachments(self.post, message)
|
||||
self.check_image_load()
|
||||
self.send_message("disable_control", control="reply")
|
||||
|
||||
def post_like(self):
|
||||
id = self.post["id"]
|
||||
if self.post["likes"]["user_likes"] == 1:
|
||||
l = self.session.vk.client.likes.delete(owner_id=self.post["group_id"], item_id=id, type="topic_comment")
|
||||
output.speak(_("You don't like this"))
|
||||
self.post["likes"]["count"] = l["likes"]
|
||||
self.post["likes"]["user_likes"] = 2
|
||||
self.send_message("set_label", control="like", label=_("&Like"))
|
||||
else:
|
||||
l = self.session.vk.client.likes.add(owner_id=self.post["group_id"], item_id=id, type="topic_comment")
|
||||
output.speak(_("You liked this"))
|
||||
self.send_message("set_label", control="like", label=_("&Dislike"))
|
||||
self.post["likes"]["count"] = l["likes"]
|
||||
self.post["likes"]["user_likes"] = 1
|
||||
self.get_likes()
|
||||
|
||||
def show_likes(self):
|
||||
""" show likes for the specified post."""
|
||||
data = dict(type="topic_comment", owner_id=self.post["group_id"], item_id=self.post["id"], extended=True, count=100, skip_own=True)
|
||||
result = self.session.vk.client.likes.getList(**data)
|
||||
if result["count"] > 0:
|
||||
post = {"source_id": self.post["group_id"], "friends": {"items": result["items"]}}
|
||||
pub.sendMessage("open-post", post_object=post, controller_="displayFriendship", vars=dict(caption=_("people who liked this")))
|
@@ -23,5 +23,7 @@ class worker(threading.Thread):
|
||||
pub.sendMessage("user-online", event=event)
|
||||
elif event.type == VkEventType.USER_OFFLINE:
|
||||
pub.sendMessage("user-offline", event=event)
|
||||
elif event.type == VkEventType.USER_TYPING:
|
||||
pub.sendMessage("user-typing", obj=event)
|
||||
except:
|
||||
pub.sendMessage("longpoll-read-timeout")
|
836
src/presenters/main.py
Normal file
836
src/presenters/main.py
Normal file
@@ -0,0 +1,836 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import os
|
||||
import webbrowser
|
||||
import logging
|
||||
import output
|
||||
import interactors
|
||||
import views
|
||||
import config
|
||||
from vk_api.exceptions import LoginRequired, VkApiError
|
||||
from requests.exceptions import ConnectionError
|
||||
from pubsub import pub
|
||||
from mysc.repeating_timer import RepeatingTimer
|
||||
from mysc.thread_utils import call_threaded
|
||||
from mysc import localization
|
||||
from sessionmanager import session, utils, renderers
|
||||
from update import updater
|
||||
from issueReporter import issueReporter
|
||||
from controller import buffers, selector
|
||||
from . import player, longpollthread
|
||||
from . import base
|
||||
|
||||
log = logging.getLogger("controller.main")
|
||||
|
||||
class Controller(base.basePresenter):
|
||||
|
||||
def search(self, tab_name):
|
||||
for i in range(0, len(self.buffers)):
|
||||
if self.buffers[i].name == tab_name:
|
||||
return self.buffers[i]
|
||||
return False
|
||||
|
||||
def get_all_buffers(self, contains):
|
||||
results = []
|
||||
for i in self.buffers:
|
||||
if contains in i.name:
|
||||
results.append(i)
|
||||
return results
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Controller, self).__init__(*args, **kwargs)
|
||||
log.debug("Starting main controller...")
|
||||
self.buffers = []
|
||||
player.setup()
|
||||
self.session = session.sessions[list(session.sessions.keys())[0]]
|
||||
self.create_controls()
|
||||
call_threaded(updater.do_update, update_type=self.session.settings["general"]["update_channel"])
|
||||
|
||||
def create_buffer(self, buffer_type="baseBuffer", buffer_title="", parent_tab=None, loadable=False, get_items=False, kwargs={}):
|
||||
if not hasattr(buffers, buffer_type):
|
||||
raise AttributeError("Specified buffer type does not exist.")
|
||||
buffer = getattr(buffers, buffer_type)(**kwargs)
|
||||
if loadable:
|
||||
buffer.can_get_items = False
|
||||
self.buffers.append(buffer)
|
||||
if parent_tab == None:
|
||||
self.send_message("add_buffer", widget=buffer.tab, title=buffer_title)
|
||||
else:
|
||||
self.send_message("insert_buffer", widget=buffer.tab, title=buffer_title, parent=parent_tab)
|
||||
if get_items:
|
||||
call_threaded(buffer.get_items)
|
||||
|
||||
def create_empty_buffer(self, buffer_type="empty", buffer_title="", parent_tab=None, kwargs={}):
|
||||
if not hasattr(buffers, buffer_type):
|
||||
raise AttributeError("Specified buffer type does not exist.")
|
||||
buffer = getattr(buffers, buffer_type)(**kwargs)
|
||||
self.buffers.append(buffer)
|
||||
if parent_tab == None:
|
||||
self.window.add_buffer(buffer.tab, buffer_title)
|
||||
else:
|
||||
self.window.insert_buffer(buffer.tab, buffer_title, self.window.search(parent_tab))
|
||||
|
||||
def create_controls(self):
|
||||
log.debug("Creating controls for the window...")
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("Posts"), kwargs=dict(parent=self.window.tb, name="posts"))
|
||||
pub.sendMessage("create_buffer", buffer_type="baseBuffer", buffer_title=_("Home"), parent_tab="posts", kwargs=dict(parent=self.window.tb, name="home_timeline", session=self.session, composefunc="render_newsfeed_item", endpoint="newsfeed", count=self.session.settings["buffers"]["count_for_wall_buffers"]))
|
||||
pub.sendMessage("create_buffer", buffer_type="feedBuffer", buffer_title=_("My wall"), parent_tab="posts", kwargs=dict(parent=self.window.tb, name="me_feed", composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"]))
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("Music"), kwargs=dict(parent=self.window.tb, name="audios"))
|
||||
pub.sendMessage("create_buffer", buffer_type="audioBuffer", buffer_title=_("My audios"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="me_audio", composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio"))
|
||||
if self.session.settings["vk"]["use_alternative_tokens"] == False:
|
||||
pub.sendMessage("create_buffer", buffer_type="audioBuffer", buffer_title=_("Populars"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="popular_audio", composefunc="render_audio", session=self.session, endpoint="getPopular", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"]))
|
||||
pub.sendMessage("create_buffer", buffer_type="audioBuffer", buffer_title=_("Recommendations"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="recommended_audio", composefunc="render_audio", session=self.session, endpoint="getRecommendations", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"]))
|
||||
pub.sendMessage("create_empty_buffer", buffer_type="empty", buffer_title=_("Albums"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="albums"))
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("Video"), kwargs=dict(parent=self.window.tb, name="videos"))
|
||||
pub.sendMessage("create_buffer", buffer_type="videoBuffer", buffer_title=_("My videos"), parent_tab="videos", kwargs=dict(parent=self.window.tb, name="me_video", composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"]))
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("Albums"), parent_tab="videos", kwargs=dict(parent=self.window.tb, name="video_albums"))
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("People"), kwargs=dict(parent=self.window.tb, name="people"))
|
||||
pub.sendMessage("create_buffer", buffer_type="peopleBuffer", buffer_title=_("Friends"), parent_tab="people", kwargs=dict(parent=self.window.tb, name="friends_", composefunc="render_person", session=self.session, endpoint="get", parent_endpoint="friends", count=5000, order="hints", fields="uid, first_name, last_name, last_seen"))
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("Friendship requests"), parent_tab="people", kwargs=dict(parent=self.window.tb, name="requests"))
|
||||
pub.sendMessage("create_buffer", buffer_type="requestsBuffer", buffer_title=_("Pending requests"), parent_tab="requests", kwargs=dict(parent=self.window.tb, name="friend_requests", composefunc="render_person", session=self.session, count=1000))
|
||||
pub.sendMessage("create_buffer", buffer_type="requestsBuffer", buffer_title=_("I follow"), parent_tab="requests", kwargs=dict(parent=self.window.tb, name="friend_requests_sent", composefunc="render_person", session=self.session, count=1000, out=1))
|
||||
pub.sendMessage("create_buffer", buffer_type="requestsBuffer", buffer_title=_("Subscribers"), parent_tab="requests", kwargs=dict(parent=self.window.tb, name="subscribers", composefunc="render_person", session=self.session, count=1000, need_viewed=1))
|
||||
pub.sendMessage("create_buffer", buffer_type="documentBuffer", buffer_title=_("Documents"), parent_tab=None, loadable=True, kwargs=dict(parent=self.window.tb, name="documents", composefunc="render_document", session=self.session, endpoint="get", parent_endpoint="docs"))
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("Communities"), kwargs=dict(parent=self.window.tb, name="communities"))
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("Chats"), kwargs=dict(parent=self.window.tb, name="chats"))
|
||||
pub.sendMessage("create_empty_buffer", buffer_title=_("Timelines"), kwargs=dict(parent=self.window.tb, name="timelines"))
|
||||
self.window.realize()
|
||||
self.repeatedUpdate = RepeatingTimer(120, self.update_all_buffers)
|
||||
self.repeatedUpdate.start()
|
||||
self.readMarker = RepeatingTimer(60, self.mark_as_read)
|
||||
self.readMarker.start()
|
||||
|
||||
def connect_events(self):
|
||||
log.debug("Connecting events to responses...")
|
||||
pub.subscribe(self.in_post, "posted")
|
||||
pub.subscribe(self.download, "download-file")
|
||||
pub.subscribe(self.play_audio, "play-audio")
|
||||
pub.subscribe(self.play_audios, "play-audios")
|
||||
pub.subscribe(self.view_post, "open-post")
|
||||
pub.subscribe(self.update_status_bar, "update-status-bar")
|
||||
pub.subscribe(self.chat_from_id, "new-chat")
|
||||
pub.subscribe(self.authorisation_failed, "authorisation-failed")
|
||||
pub.subscribe(self.user_profile, "user-profile")
|
||||
pub.subscribe(self.user_online, "user-online")
|
||||
pub.subscribe(self.user_offline, "user-offline")
|
||||
pub.subscribe(self.notify, "notify")
|
||||
pub.subscribe(self.handle_longpoll_read_timeout, "longpoll-read-timeout")
|
||||
pub.subscribe(self.create_buffer, "create_buffer")
|
||||
pub.subscribe(self.create_empty_buffer, "create_empty_buffer")
|
||||
pub.subscribe(self.user_typing, "user-typing")
|
||||
widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.window.about_dialog, menuitem=self.window.about)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_audios, menuitem=self.window.search_audios)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_videos, menuitem=self.window.search_videos)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU,self.remove_buffer, menuitem=self.window.remove_buffer_)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.get_more_items, menuitem=self.window.load_previous_items)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.changelog, menuitem=self.window.changelog)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.configuration, menuitem=self.window.settings_dialog)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.new_timeline, menuitem=self.window.timeline)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_audio_album, menuitem=self.window.audio_album)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_audio_album, menuitem=self.window.delete_audio_album)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_video_album, menuitem=self.window.video_album)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_video_album, menuitem=self.window.delete_video_album)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_documentation, menuitem=self.window.documentation)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_pause, menuitem=self.window.player_play)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_next, menuitem=self.window.player_next)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_previous, menuitem=self.window.player_previous)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_all, menuitem=self.window.player_play_all)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_volume_down, menuitem=self.window.player_volume_down)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_volume_up, menuitem=self.window.player_volume_up)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_mute, menuitem=self.window.player_mute)
|
||||
pub.subscribe(self.get_chat, "order-sent-message")
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile, menuitem=self.window.view_profile)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile_in_browser, menuitem=self.window.open_in_browser)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.set_status, menuitem=self.window.set_status)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_report_error, menuitem=self.window.report)
|
||||
self.window.tb.Bind(wx.EVT_CONTEXT_MENU, self.on_context_menu)
|
||||
|
||||
def disconnect_events(self):
|
||||
log.debug("Disconnecting some events...")
|
||||
pub.unsubscribe(self.in_post, "posted")
|
||||
pub.unsubscribe(self.download, "download-file")
|
||||
pub.unsubscribe(self.play_audio, "play-audio")
|
||||
pub.unsubscribe(self.authorisation_failed, "authorisation-failed")
|
||||
pub.unsubscribe(self.play_audios, "play-audios")
|
||||
pub.unsubscribe(self.view_post, "open-post")
|
||||
pub.unsubscribe(self.update_status_bar, "update-status-bar")
|
||||
pub.unsubscribe(self.user_online, "user-online")
|
||||
pub.unsubscribe(self.user_offline, "user-offline")
|
||||
pub.unsubscribe(self.notify, "notify")
|
||||
|
||||
def on_context_menu(self, event, *args, **kwargs):
|
||||
""" Handles context menu event in the tree buffers."""
|
||||
# If the focus is not in the TreeCtrl of the Treebook, then we should not display any menu.
|
||||
if isinstance(self.window.FindFocus(), wx.TreeCtrl) == False:
|
||||
event.Skip()
|
||||
return
|
||||
menu = None
|
||||
# Get the current buffer and let's choose a different menu depending on the selected buffer.
|
||||
current_buffer = self.get_current_buffer()
|
||||
# Deal with menu for community buffers.
|
||||
if current_buffer.name.endswith("_community"):
|
||||
menu = menus.communityBufferMenu()
|
||||
# disable post loading if the community has already loaded posts.
|
||||
if current_buffer.can_get_items:
|
||||
menu.load_posts.Enable(False)
|
||||
# Disable loading of audios, videos, documents or topics depending in two conditions.
|
||||
# 1. If the buffer already exists, which means they are already loaded, or
|
||||
# 2. If the group_info does not have counters for such items, which would indicate there are no items posted yet.
|
||||
if self.search(current_buffer.name+"_audios") != False:
|
||||
menu.load_audios.Enable(False)
|
||||
elif hasattr(current_buffer, "group_info") and "audios" not in current_buffer.group_info["counters"]:
|
||||
menu.load_audios.Enable(False)
|
||||
if self.search(current_buffer.name+"_videos") != False:
|
||||
menu.load_videos.Enable(False)
|
||||
elif hasattr(current_buffer, "group_info") and "videos" not in current_buffer.group_info["counters"]:
|
||||
menu.load_videos.Enable(False)
|
||||
if self.search(current_buffer.name+"_topics") != False:
|
||||
menu.load_topics.Enable(False)
|
||||
elif hasattr(current_buffer, "group_info") and "topics" not in current_buffer.group_info["counters"]:
|
||||
menu.load_topics.Enable(False)
|
||||
|
||||
if self.search(current_buffer.name+"_documents") != False:
|
||||
menu.load_documents.Enable(False)
|
||||
elif hasattr(current_buffer, "group_info") and "docs" not in current_buffer.group_info["counters"]:
|
||||
menu.load_documents.Enable(False)
|
||||
# Connect the rest of the functions.
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_posts, menuitem=menu.load_posts)
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_topics, menuitem=menu.load_topics)
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_audios, menuitem=menu.load_audios)
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_videos, menuitem=menu.load_videos)
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_documents, menuitem=menu.load_documents)
|
||||
# Deal with the communities section itself.
|
||||
if current_buffer.name == "communities":
|
||||
menu = wx.Menu()
|
||||
# Insert a different option depending if group buffers are loaded or scheduled to be loaded or not.
|
||||
if self.session.settings["load_at_startup"]["communities"] == False and not hasattr(self.session, "groups"):
|
||||
option = menu.Append(wx.NewId(), _("Load groups"))
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_buffers, menuitem=option)
|
||||
else:
|
||||
option = menu.Append(wx.NewId(), _("Discard groups"))
|
||||
widgetUtils.connect_event(menu, widgetUtils.MENU, self.unload_community_buffers, menuitem=option)
|
||||
if menu != None:
|
||||
self.window.PopupMenu(menu, self.window.FindFocus().GetPosition())
|
||||
# If there are no available menus, let's indicate it.
|
||||
else:
|
||||
output.speak(_("menu unavailable for this buffer."))
|
||||
|
||||
def authorisation_failed(self):
|
||||
commonMessages.bad_authorisation()
|
||||
|
||||
def login(self):
|
||||
self.window.change_status(_("Logging in VK"))
|
||||
self.session.login()
|
||||
self.window.change_status(_("Ready"))
|
||||
for i in self.buffers:
|
||||
if hasattr(i, "get_items"):
|
||||
# Translators: {0} will be replaced with the name of a buffer.
|
||||
self.window.change_status(_("Loading items for {0}").format(i.name,))
|
||||
i.get_items()
|
||||
self.window.change_status(_("Ready"))
|
||||
self.create_unread_messages()
|
||||
self.status_setter = RepeatingTimer(280, self.set_online)
|
||||
self.status_setter.start()
|
||||
self.set_online(notify=True)
|
||||
self.get_audio_albums(self.session.user_id)
|
||||
self.get_video_albums(self.session.user_id)
|
||||
self.get_communities(self.session.user_id)
|
||||
self.create_longpoll_thread()
|
||||
|
||||
def create_longpoll_thread(self, notify=False):
|
||||
try:
|
||||
self.longpoll = longpollthread.worker(self.session)
|
||||
self.longpoll.start()
|
||||
if notify:
|
||||
self.notify(message=_("Chat server reconnected"))
|
||||
except ConnectionError:
|
||||
pub.sendMessage("longpoll-read-timeout")
|
||||
|
||||
def in_post(self, buffer):
|
||||
buffer = self.search(buffer)
|
||||
buffer.get_items()
|
||||
buffer = self.search("home_timeline")
|
||||
buffer.get_items()
|
||||
|
||||
def update_all_buffers(self):
|
||||
log.debug("Updating buffers...")
|
||||
self.get_audio_albums(self.session.user_id, create_buffers=False)
|
||||
self.get_video_albums(self.session.user_id, create_buffers=False)
|
||||
for i in self.buffers:
|
||||
if hasattr(i, "get_items"):
|
||||
i.get_items()
|
||||
log.debug("Updated %s" % (i.name))
|
||||
|
||||
def download(self, url, filename):
|
||||
log.debug("downloading %s URL to %s filename" % (url, filename,))
|
||||
call_threaded(utils.download_file, url, filename, self.window)
|
||||
|
||||
def play_audio(self, audio_object):
|
||||
# Restricted audios don't include an URL paramether.
|
||||
# Restriction can be due to licensed content to unauthorized countries.
|
||||
if "url" in audio_object and audio_object["url"] =="":
|
||||
self.notify(message=_("This file could not be played because it is not allowed in your country"))
|
||||
return
|
||||
call_threaded(player.player.play, audio_object, fresh=True)
|
||||
|
||||
def play_audios(self, audios):
|
||||
player.player.play_all(audios, shuffle=self.window.player_shuffle.IsChecked())
|
||||
|
||||
def view_post(self, post_object, controller_):
|
||||
p = getattr(presenters, controller_+"Presenter")(session=self.session, postObject=post_object, interactor=getattr(interactors, controller_+"Interactor")(), view=getattr(views, controller_)())
|
||||
|
||||
def exit(self, *args, **kwargs):
|
||||
log.debug("Receibed an exit signal. closing...")
|
||||
self.set_offline()
|
||||
self.disconnect_events()
|
||||
volume = player.player.volume
|
||||
config.app["sound"]["volume"] = volume
|
||||
config.app.write()
|
||||
self.window.Destroy()
|
||||
wx.GetApp().ExitMainLoop()
|
||||
|
||||
def update_buffer(self, *args, **kwargs):
|
||||
b = self.get_current_buffer()
|
||||
b.get_items()
|
||||
|
||||
def get_more_items(self, *args, **kwargs):
|
||||
b = self.get_current_buffer()
|
||||
b.get_more_items()
|
||||
|
||||
def check_for_updates(self, *args, **kwargs):
|
||||
update = updater.do_update(update_type=self.session.settings["general"]["update_channel"])
|
||||
if update == False:
|
||||
commonMessages.no_update_available()
|
||||
|
||||
def search_audios(self, *args, **kwargs):
|
||||
dlg = searchDialogs.searchAudioDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
q = dlg.get("term")
|
||||
auto_complete = True
|
||||
count = 300
|
||||
performer_only = dlg.get_state("title")
|
||||
sort = dlg.get_sort_order()
|
||||
newbuff = buffers.audioBuffer(parent=self.window.tb, name="{0}_audiosearch".format(q,), session=self.session, composefunc="render_audio", parent_endpoint="audio", endpoint="search", q=q, auto_complete=auto_complete, count=count, performer_only=performer_only, sort=sort)
|
||||
self.buffers.append(newbuff)
|
||||
call_threaded(newbuff.get_items)
|
||||
# Translators: {0} will be replaced with the search term.
|
||||
self.window.insert_buffer(newbuff.tab, _("Search for {0}").format(q,), self.window.search("audios"))
|
||||
|
||||
def search_videos(self, *args, **kwargs):
|
||||
dlg = searchDialogs.searchVideoDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
params = {}
|
||||
params["q"] = dlg.get("term")
|
||||
params["count"] = 200
|
||||
hd = dlg.get_checkable("hd")
|
||||
if hd != 0:
|
||||
params["hd"] = 1
|
||||
params["adult"] = dlg.get_checkable("safe_search")
|
||||
params["sort"] = dlg.get_sort_order()
|
||||
# params["filters"] = "youtube, vimeo, short, long, mp4"
|
||||
print(params)
|
||||
newbuff = buffers.videoBuffer(parent=self.window.tb, name="{0}_videosearch".format(params["q"],), session=self.session, composefunc="render_video", parent_endpoint="video", endpoint="search", **params)
|
||||
self.buffers.append(newbuff)
|
||||
call_threaded(newbuff.get_items)
|
||||
# Translators: {0} will be replaced with the search term.
|
||||
self.window.insert_buffer(newbuff.tab, _("Search for {0}").format(params["q"],), self.window.search("videos"))
|
||||
|
||||
def update_status_bar(self, status):
|
||||
self.window.change_status(status)
|
||||
|
||||
def remove_buffer(self, event, mandatory=False, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
buff = self.window.search(buffer.name)
|
||||
answer = buffer.remove_buffer(mandatory)
|
||||
if answer == False:
|
||||
return
|
||||
self.window.remove_buffer(buff)
|
||||
self.buffers.remove(buffer)
|
||||
del buffer
|
||||
|
||||
def changelog(self, *args, **kwargs):
|
||||
lang = localization.get("documentation")
|
||||
os.chdir("documentation/%s" % (lang,))
|
||||
webbrowser.open("changelog.html")
|
||||
os.chdir("../../")
|
||||
|
||||
def configuration(self, *args, **kwargs):
|
||||
""" Opens the global settings dialogue."""
|
||||
presenter = presenters.configurationPresenter(session=self.session, view=views.configurationDialog(title=_("Preferences")), interactor=interactors.configurationInteractor())
|
||||
|
||||
def new_timeline(self, *args, **kwargs):
|
||||
b = self.get_current_buffer()
|
||||
# If executing this method from an empty buffer we should get the newsfeed buffer.
|
||||
if not hasattr(b, "get_users"):
|
||||
b = self.search("home_timeline")
|
||||
# Get a list of (id, user) objects.
|
||||
d = []
|
||||
for i in self.session.db["users"]:
|
||||
d.append((i, self.session.get_user(i)["user1_gen"]))
|
||||
# Do the same for communities.
|
||||
for i in self.session.db["groups"]:
|
||||
d.append((-i, self.session.get_user(-i)["user1_nom"]))
|
||||
a = timeline.timelineDialog([i[1] for i in d])
|
||||
if a.get_response() == widgetUtils.OK:
|
||||
user = a.get_user()
|
||||
buffertype = a.get_buffer_type()
|
||||
user_id = ""
|
||||
for i in d:
|
||||
if i[1] == user:
|
||||
user_id = i[0]
|
||||
if user_id == "":
|
||||
user_data = self.session.vk.client.utils.resolveScreenName(screen_name=user)
|
||||
if type(user_data) == list:
|
||||
commonMessages.no_user_exist()
|
||||
return
|
||||
user_id = user_data["object_id"]
|
||||
if buffertype == "audio":
|
||||
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio".format(user_id,), composefunc="render_audio", session=self.session, create_tab=False, endpoint="get", parent_endpoint="audio", owner_id=user_id)
|
||||
user = self.session.get_user(user_id, key="user1")
|
||||
name_ = _("{user1_nom}'s audios").format(**user)
|
||||
elif buffertype == "wall":
|
||||
buffer = buffers.feedBuffer(parent=self.window.tb, name="{0}_feed".format(user_id,), composefunc="render_status", session=self.session, create_tab=False, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=user_id)
|
||||
user = self.session.get_user(user_id, key="user1")
|
||||
name_ = _("{user1_nom}'s posts").format(**user)
|
||||
elif buffertype == "friends":
|
||||
buffer = buffers.peopleBuffer(parent=self.window.tb, name="friends_{0}".format(user_id,), composefunc="render_person", session=self.session, create_tab=False, endpoint="get", parent_endpoint="friends", count=5000, fields="uid, first_name, last_name, last_seen", user_id=user_id)
|
||||
user = self.session.get_user(user_id, key="user1")
|
||||
name_ = _("{user1_nom}'s friends").format(**user)
|
||||
wx.CallAfter(self.complete_buffer_creation, buffer=buffer, name_=name_, position=self.window.search("timelines"))
|
||||
|
||||
def complete_buffer_creation(self, buffer, name_, position):
|
||||
answer = buffer.get_items()
|
||||
if answer is not True:
|
||||
commonMessages.show_error_code(answer)
|
||||
return
|
||||
self.buffers.append(buffer)
|
||||
self.window.insert_buffer(buffer.tab, name_, position)
|
||||
|
||||
def search_chat_buffer(self, user_id):
|
||||
for i in self.buffers:
|
||||
if "_messages" in i.name:
|
||||
if "peer_id" in i.kwargs and i.kwargs["peer_id"] == user_id: return i
|
||||
return None
|
||||
|
||||
def chat_from_id(self, user_id, setfocus=True, unread=False):
|
||||
b = self.search_chat_buffer(user_id)
|
||||
if b != None:
|
||||
pos = self.window.search(b.name)
|
||||
if setfocus:
|
||||
self.window.change_buffer(pos)
|
||||
return b.tab.text.SetFocus()
|
||||
return
|
||||
# Get name based in the ID.
|
||||
# for users.
|
||||
if user_id > 0 and user_id < 2000000000:
|
||||
user = self.session.get_user(user_id, key="user1")
|
||||
name = user["user1_nom"]
|
||||
elif user_id > 2000000000:
|
||||
chat = self.session.vk.client.messages.getChat(chat_id=user_id-2000000000)
|
||||
name = chat["title"]
|
||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="chatBuffer", buffer_title=name, parent_tab="chats", get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_messages".format(user_id,), composefunc="render_message", session=self.session, unread=unread, count=200, peer_id=user_id, rev=0, extended=True, fields="id, user_id, date, read_state, out, body, attachments, deleted"))
|
||||
# if setfocus:
|
||||
# pos = self.window.search(buffer.name)
|
||||
# self.window.change_buffer(pos)
|
||||
# call_threaded(buffer.get_items, unread=unread)
|
||||
# if setfocus: buffer.tab.text.SetFocus()
|
||||
# return True
|
||||
|
||||
def user_online(self, event):
|
||||
if self.session.settings["chat"]["notify_online"] == False:
|
||||
return
|
||||
user_name = self.session.get_user(event.user_id)
|
||||
msg = _("{user1_nom} is online.").format(**user_name)
|
||||
sound = "friend_online.ogg"
|
||||
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
|
||||
|
||||
def user_offline(self, event):
|
||||
if self.session.settings["chat"]["notify_offline"] == False:
|
||||
return
|
||||
user_name = self.session.get_user(event.user_id)
|
||||
msg = _("{user1_nom} is offline.").format(**user_name)
|
||||
sound = "friend_offline.ogg"
|
||||
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
|
||||
|
||||
def user_typing(self, obj):
|
||||
buffer = self.search_chat_buffer(obj.user_id)
|
||||
if buffer != None and buffer == self.get_current_buffer():
|
||||
user = self.session.get_user(obj.user_id)
|
||||
output.speak(_("{user1_nom} is typing...").format(**user))
|
||||
|
||||
def get_chat(self, obj=None):
|
||||
""" Searches or creates a chat buffer with the id of the user that is sending or receiving a message.
|
||||
obj vk_api.longpoll.EventType: an event wich defines some data from the vk's long poll server."""
|
||||
message = {}
|
||||
uid = obj.peer_id
|
||||
buffer = self.search_chat_buffer(uid)
|
||||
if obj.from_me:
|
||||
message.update(out=0)
|
||||
# If there is no buffer, we must create one in a wxThread so it will not crash.
|
||||
if buffer == None:
|
||||
wx.CallAfter(self.chat_from_id, uid, setfocus=self.session.settings["chat"]["automove_to_conversations"], unread=True)
|
||||
self.session.soundplayer.play("conversation_opened.ogg")
|
||||
return
|
||||
# If the chat already exists, let's create a dictionary wich will contains data of the received message.
|
||||
message.update(id=obj.message_id, user_id=uid, date=obj.timestamp, body=utils.clean_text(obj.text), attachments=obj.attachments)
|
||||
# if attachments is true, let's request for the full message with attachments formatted in a better way.
|
||||
# ToDo: code improvements. We shouldn't need to request the same message again just for these attachments.
|
||||
if len(message["attachments"]) != 0:
|
||||
message_ids = message["id"]
|
||||
results = self.session.vk.client.messages.getById(message_ids=message_ids)
|
||||
message = results["items"][0]
|
||||
if obj.from_me:
|
||||
message["from_id"] = self.session.user_id
|
||||
else:
|
||||
message.update(read_state=0, out=0)
|
||||
message["from_id"] = obj.user_id
|
||||
data = [message]
|
||||
# Let's add this to the buffer.
|
||||
# ToDo: Clean this code and test how is the database working with this set to True.
|
||||
num = self.session.order_buffer(buffer.name, data, True)
|
||||
buffer.insert(self.session.db[buffer.name]["items"][-1], False)
|
||||
self.session.soundplayer.play("message_received.ogg")
|
||||
wx.CallAfter(self.reorder_buffer, buffer)
|
||||
# Check if we have to read the message aloud
|
||||
if buffer == self.get_current_buffer():
|
||||
rendered_message = renderers.render_message(message, self.session)
|
||||
output.speak(rendered_message[0])
|
||||
|
||||
def set_online(self, notify=False):
|
||||
try:
|
||||
r = self.session.vk.client.account.setOnline()
|
||||
except:
|
||||
log.error("Error in setting online for the current user")
|
||||
if notify:
|
||||
self.window.notify("Socializer", "online now!")
|
||||
|
||||
def set_offline(self):
|
||||
try:
|
||||
r = self.session.vk.client.account.setOffline()
|
||||
except:
|
||||
log.error("Error in setting offline status for the current user")
|
||||
|
||||
def create_unread_messages(self):
|
||||
if self.session.settings["chat"]["open_unread_conversations"] == False:
|
||||
return
|
||||
try:
|
||||
log.debug("Getting possible unread messages.")
|
||||
msgs = self.session.vk.client.messages.getConversations(count=200)
|
||||
except VkApiError as ex:
|
||||
if ex.code == 6:
|
||||
log.exception("Something went wrong when getting messages. Waiting a second to retry")
|
||||
for i in msgs["items"]:
|
||||
call_threaded(self.chat_from_id, i["last_message"]["peer_id"], setfocus=False, unread=False)
|
||||
time.sleep(0.6)
|
||||
|
||||
def mark_as_read(self):
|
||||
for i in self.buffers:
|
||||
if hasattr(i, "reads") and len(i.reads) != 0:
|
||||
response = self.session.vk.client.messages.markAsRead(peer_id=i.kwargs["peer_id"])
|
||||
i.clear_reads()
|
||||
i.reads = []
|
||||
time.sleep(1)
|
||||
|
||||
def get_audio_albums(self, user_id=None, create_buffers=True):
|
||||
if self.session.settings["load_at_startup"]["audio_albums"] == False:
|
||||
return
|
||||
log.debug("Create audio albums...")
|
||||
if self.session.settings["vk"]["use_alternative_tokens"]:
|
||||
albums = self.session.vk.client_audio.get_albums(owner_id=user_id)
|
||||
else:
|
||||
albums = self.session.vk.client.audio.getPlaylists(owner_id=user_id)
|
||||
albums = albums["items"]
|
||||
self.session.audio_albums = albums
|
||||
if create_buffers:
|
||||
for i in albums:
|
||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="audioAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="albums", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=user_id, album_id=i["id"]))
|
||||
time.sleep(0.6)
|
||||
|
||||
def get_video_albums(self, user_id=None, create_buffers=True):
|
||||
if self.session.settings["load_at_startup"]["video_albums"] == False:
|
||||
return
|
||||
log.debug("Create video albums...")
|
||||
albums = self.session.vk.client.video.getAlbums(owner_id=user_id)
|
||||
self.session.video_albums = albums["items"]
|
||||
if create_buffers:
|
||||
for i in albums["items"]:
|
||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="videoAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="video_albums", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_video_album".format(i["id"],), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=user_id, album_id=i["id"]))
|
||||
time.sleep(0.15)
|
||||
|
||||
def get_communities(self, user_id=None, create_buffers=True, force_action=False):
|
||||
if self.session.settings["vk"]["invited_to_group"] == False:
|
||||
self.session.settings["vk"]["invited_to_group"] = True
|
||||
self.session.settings.write()
|
||||
socializer_group = self.session.vk.client.groups.getById(group_ids="175825000")[0]
|
||||
if socializer_group["is_member"] ==False:
|
||||
d = commonMessages.join_group()
|
||||
self.session.settings["vk"]["invited_to_group"] = True
|
||||
self.session.settings.write()
|
||||
if d == widgetUtils.YES:
|
||||
result = self.session.vk.client.groups.join(group_id=socializer_group["id"])
|
||||
if result == 1:
|
||||
commonMessages.group_joined()
|
||||
else:
|
||||
log.error("Invalid result when joining the Socializer's group: %d" % (result))
|
||||
if self.session.settings["load_at_startup"]["communities"] == False and force_action == False:
|
||||
return
|
||||
log.debug("Create community buffers...")
|
||||
groups= self.session.vk.client.groups.get(user_id=user_id, extended=1, count=1000)
|
||||
self.session.groups=groups["items"]
|
||||
# Let's feed the local database cache with new groups coming from here.
|
||||
data= dict(profiles=[], groups=self.session.groups)
|
||||
self.session.process_usernames(data)
|
||||
if create_buffers:
|
||||
for i in self.session.groups:
|
||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="communityBuffer", buffer_title=i["name"], parent_tab="communities", loadable=True, get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_community".format(i["id"],), composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=-1*i["id"]))
|
||||
time.sleep(0.15)
|
||||
|
||||
def create_audio_album(self, *args, **kwargs):
|
||||
d = creation.audio_album()
|
||||
if d.get_response() == widgetUtils.OK and d.get("title") != "":
|
||||
response = self.session.vk.client.audio.createPlaylist(owner_id=self.session.user_id, title=d.get("title"))
|
||||
if "id" not in response:
|
||||
return
|
||||
album_id = response["id"]
|
||||
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(album_id,), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=self.session.user_id, album_id=album_id)
|
||||
buffer.can_get_items = False
|
||||
# Translators: {0} will be replaced with an audio album's title.
|
||||
name_ = _("Album: {0}").format(d.get("title"),)
|
||||
self.buffers.append(buffer)
|
||||
self.window.insert_buffer(buffer.tab, name_, self.window.search("albums"))
|
||||
buffer.get_items()
|
||||
self.get_audio_albums(user_id=self.session.user_id, create_buffers=False)
|
||||
|
||||
def delete_audio_album(self, *args, **kwargs):
|
||||
if len(self.session.audio_albums) == 0:
|
||||
return commonMessages.no_audio_albums()
|
||||
answer = selector.album(_("Select the album you want to delete"), self.session)
|
||||
if answer.item == None:
|
||||
return
|
||||
response = commonMessages.delete_audio_album()
|
||||
if response != widgetUtils.YES: return
|
||||
removal = self.session.vk.client.audio.deletePlaylist(playlist_id=answer.item, owner_id=self.session.user_id)
|
||||
if removal == 1:
|
||||
buffer = self.search("{0}_audio_album".format(answer.item,))
|
||||
buff = self.window.search(buffer.name)
|
||||
self.window.remove_buffer(buff)
|
||||
self.buffers.remove(buffer)
|
||||
del buffer
|
||||
self.get_audio_albums(user_id=self.session.user_id, create_buffers=False)
|
||||
|
||||
def create_video_album(self, *args, **kwargs):
|
||||
d = creation.audio_album()
|
||||
if d.get_response() == widgetUtils.OK and d.get("title") != "":
|
||||
response = self.session.vk.client.video.addAlbum(title=d.get("title"))
|
||||
if ("album_id" in response) == False: return
|
||||
album_id = response["album_id"]
|
||||
buffer = buffers.videoAlbum(parent=self.window.tb, name="{0}_video_album".format(album_id,), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=self.session.user_id, album_id=album_id)
|
||||
buffer.can_get_items = False
|
||||
# Translators: {0} will be replaced with a video album's title.
|
||||
name_ = _("Album: {0}").format(d.get("title"),)
|
||||
self.buffers.append(buffer)
|
||||
self.window.insert_buffer(buffer.tab, name_, self.window.search("video_albums"))
|
||||
buffer.get_items()
|
||||
self.session.video_albums = self.session.vk.client.video.getAlbums(owner_id=self.session.user_id)["items"]
|
||||
|
||||
def delete_video_album(self, *args, **kwargs):
|
||||
if len(self.session.video_albums) == 0:
|
||||
return commonMessages.no_video_albums()
|
||||
answer = selector.album(_("Select the album you want to delete"), self.session, "video_albums")
|
||||
if answer.item == None:
|
||||
return
|
||||
response = commonMessages.delete_audio_album()
|
||||
if response != widgetUtils.YES: return
|
||||
removal = self.session.vk.client.video.deleteAlbum(album_id=answer.item)
|
||||
buffer = self.search("{0}_video_album".format(answer.item,))
|
||||
buff = self.window.search(buffer.name)
|
||||
self.window.remove_buffer(buff)
|
||||
self.buffers.remove(buffer)
|
||||
del buffer
|
||||
self.session.video_albums = self.session.vk.client.video.getAlbums(owner_id=self.session.user_id)["items"]
|
||||
|
||||
def check_documentation(self, *args, **kwargs):
|
||||
lang = localization.get("documentation")
|
||||
os.chdir("documentation/%s" % (lang,))
|
||||
webbrowser.open("manual.html")
|
||||
os.chdir("../../")
|
||||
|
||||
def menu_play_pause(self, *args, **kwargs):
|
||||
if player.player.stream != None:
|
||||
return player.player.pause()
|
||||
else:
|
||||
b = self.get_current_buffer()
|
||||
if hasattr(b, "play_all"):
|
||||
b.play_all()
|
||||
else:
|
||||
self.search("me_audio").play_all()
|
||||
|
||||
def menu_play_next(self, *args, **kwargs):
|
||||
return player.player.play_next()
|
||||
# b = self.get_current_buffer()
|
||||
# if hasattr(b, "play_next"):
|
||||
# b.play_next()
|
||||
# else:
|
||||
# self.search("me_audio").play_next()
|
||||
|
||||
def menu_play_previous(self, *args, **kwargs):
|
||||
return player.player.play_previous()
|
||||
# b = self.get_current_buffer()
|
||||
# if hasattr(b, "play_previous"):
|
||||
# b.play_previous()
|
||||
# else:
|
||||
# self.search("me_audio").play_previous()
|
||||
|
||||
def menu_play_all(self, *args, **kwargs):
|
||||
b = self.get_current_buffer()
|
||||
if hasattr(b, "play_all"):
|
||||
b.play_all()
|
||||
else:
|
||||
self.search("me_audio").play_all()
|
||||
|
||||
def menu_volume_down(self, *args, **kwargs):
|
||||
player.player.volume = player.player.volume-5
|
||||
|
||||
def menu_volume_up(self, *args, **kwargs):
|
||||
player.player.volume = player.player.volume+5
|
||||
|
||||
def menu_mute(self, *args, **kwargs):
|
||||
player.player.volume = 0
|
||||
|
||||
def user_profile(self, person):
|
||||
p = presenters.userProfilePresenter(session=self.session, user_id=person, view=views.userProfileDialog(), interactor=interactors.userProfileInteractor())
|
||||
|
||||
def view_my_profile(self, *args, **kwargs):
|
||||
self.user_profile(self.session.user_id)
|
||||
|
||||
def view_my_profile_in_browser(self, *args, **kwargs):
|
||||
webbrowser.open_new_tab("https://vk.com/id{id}".format(id=self.session.user_id,))
|
||||
|
||||
def notify(self, message="", sound="", type="native"):
|
||||
if type == "native":
|
||||
self.window.notify(_("Socializer"), message)
|
||||
else:
|
||||
if sound != "":
|
||||
self.session.soundplayer.play(sound)
|
||||
if message != "":
|
||||
output.speak(message)
|
||||
|
||||
def handle_longpoll_read_timeout(self):
|
||||
if hasattr(self, "longpoll"):
|
||||
self.notify(message=_("Chat disconnected. Trying to connect in 60 seconds"))
|
||||
time.sleep(60)
|
||||
if hasattr(self, "longpoll"):
|
||||
del self.longpoll
|
||||
self.create_longpoll_thread(notify=True)
|
||||
|
||||
def set_status(self, *args, **kwargs):
|
||||
dlg = wx.TextEntryDialog(self.window, _("Write your status message"), _("Set status"))
|
||||
if dlg.ShowModal() == widgetUtils.OK:
|
||||
result = dlg.GetValue()
|
||||
info = self.session.vk.client.account.saveProfileInfo(status=result)
|
||||
commonMessages.updated_status()
|
||||
dlg.Destroy()
|
||||
|
||||
def on_report_error(self, *args, **kwargs):
|
||||
r = issueReporter.reportBug()
|
||||
|
||||
def reorder_buffer(self, buffer):
|
||||
""" this puts the chat buffers at the top of the list when there are new incoming messages.
|
||||
In order to do so, we search for the current buffer's tab, remove the page from the TreeCtrl (without destroying the associated tab)
|
||||
and reinsert it as a new child of the chat buffer.
|
||||
Lastly we ensure the user is focused in the same buffer than before."""
|
||||
buffer_window = self.window.search(buffer.name)
|
||||
# If buffer window is already in the first position after chat, we should not do anything here because calculations for moving buffers are expensive.
|
||||
if buffer_window == self.window.search("chats")+1:
|
||||
return
|
||||
# Gets buffer title so we don't have to generate it again in future.
|
||||
buffer_title = self.window.get_buffer_text(buffer_window)
|
||||
# Determine if the current buffer is the buffer receiving a new message.
|
||||
if buffer == self.get_current_buffer():
|
||||
focused_buffer = True
|
||||
else:
|
||||
focused_buffer = False
|
||||
# This call will not destroy the associated tab for the chat buffer, thus allowing us to readd it in other position.
|
||||
self.window.remove_buffer_from_position(buffer_window)
|
||||
self.window.insert_chat_buffer(buffer.tab, buffer_title, self.window.search("chats")+1)
|
||||
# Let's manipulate focus so users will not notice the change in buffers.
|
||||
if focused_buffer:
|
||||
new_position = self.window.search(buffer.name)
|
||||
self.window.change_buffer(new_position)
|
||||
else:
|
||||
new_position = self.window.search(self.get_current_buffer().name)
|
||||
self.window.change_buffer(new_position)
|
||||
|
||||
def load_community_posts(self, *args, **kwargs):
|
||||
""" Load community posts. It just calls to the needed method in the community buffer."""
|
||||
current_buffer = self.get_current_buffer()
|
||||
if current_buffer.name.endswith("_community"):
|
||||
current_buffer.load_community()
|
||||
|
||||
def load_community_audios(self, *args, **kwargs):
|
||||
""" Load community audios if they are not loaded already."""
|
||||
current_buffer = self.get_current_buffer()
|
||||
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
||||
if not hasattr(current_buffer, "group_info"):
|
||||
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
||||
current_buffer.group_info = group_info
|
||||
if "audios" not in current_buffer.group_info["counters"]:
|
||||
commonMessages.community_no_items()
|
||||
return
|
||||
new_name = current_buffer.name+"_audios"
|
||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="audioBuffer", buffer_title=_("Audios"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=current_buffer.kwargs["owner_id"]))
|
||||
|
||||
def load_community_videos(self, *args, **kwargs):
|
||||
""" Load community videos if they are not loaded already."""
|
||||
current_buffer = self.get_current_buffer()
|
||||
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
||||
if not hasattr(current_buffer, "group_info"):
|
||||
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
||||
current_buffer.group_info = group_info
|
||||
if "videos" not in current_buffer.group_info["counters"]:
|
||||
commonMessages.community_no_items()
|
||||
return
|
||||
new_name = current_buffer.name+"_videos"
|
||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="videoBuffer", buffer_title=_("Videos"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], owner_id=current_buffer.kwargs["owner_id"]))
|
||||
|
||||
def load_community_topics(self, *args, **kwargs):
|
||||
""" Load community topics."""
|
||||
current_buffer = self.get_current_buffer()
|
||||
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
||||
if not hasattr(current_buffer, "group_info"):
|
||||
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
||||
current_buffer.group_info = group_info
|
||||
if "topics" not in current_buffer.group_info["counters"]:
|
||||
commonMessages.community_no_items()
|
||||
return
|
||||
new_name = current_buffer.name+"_topics"
|
||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="topicBuffer", buffer_title=_("Topics"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_topic", session=self.session, endpoint="getTopics", parent_endpoint="board", count=100, group_id=-1*current_buffer.kwargs["owner_id"], extended=1))
|
||||
|
||||
def load_community_documents(self, *args, **kwargs):
|
||||
current_buffer = self.get_current_buffer()
|
||||
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
||||
if not hasattr(current_buffer, "group_info"):
|
||||
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
||||
current_buffer.group_info = group_info
|
||||
if "docs" not in current_buffer.group_info["counters"]:
|
||||
commonMessages.community_no_items()
|
||||
return
|
||||
new_name = current_buffer.name+"_documents"
|
||||
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="documentCommunityBuffer", buffer_title=_("Documents"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_document", session=self.session, endpoint="get", parent_endpoint="docs", owner_id=current_buffer.kwargs["owner_id"]))
|
||||
|
||||
def load_community_buffers(self, *args, **kwargs):
|
||||
""" Load all community buffers regardless of the setting present in optional buffers tab of the preferences dialog."""
|
||||
call_threaded(self.get_communities, self.session.user_id, force_action=True)
|
||||
|
||||
def unload_community_buffers(self, *args, **kwargs):
|
||||
""" Delete all buffers belonging to groups."""
|
||||
communities = self.get_all_buffers("_community")
|
||||
for buffer in communities:
|
||||
buff = self.window.search(buffer.name)
|
||||
self.window.remove_buffer(buff)
|
||||
self.buffers.remove(buffer)
|
||||
del self.session.groups
|
||||
|
257
src/presenters/player.py
Normal file
257
src/presenters/player.py
Normal file
@@ -0,0 +1,257 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Audio player module for socializer.
|
||||
As this player does not have (still) an associated GUI, I have decided to place here the code for the interactor, which connects a bunch of pubsub events, and the presenter itself.
|
||||
"""
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import sound_lib
|
||||
import output
|
||||
import config
|
||||
from sound_lib.config import BassConfig
|
||||
from sound_lib.stream import URLStream
|
||||
from sound_lib.main import BassError
|
||||
from pubsub import pub
|
||||
from mysc.repeating_timer import RepeatingTimer
|
||||
from mysc.thread_utils import call_threaded
|
||||
from sessionmanager import utils
|
||||
|
||||
player = None
|
||||
log = logging.getLogger("player")
|
||||
|
||||
def setup():
|
||||
global player
|
||||
if player == None:
|
||||
player = audioPlayer()
|
||||
|
||||
class audioPlayer(object):
|
||||
""" A media player which will play all passed URLS."""
|
||||
|
||||
def __init__(self):
|
||||
# control variable for checking if another file has been sent to the player before,
|
||||
# thus avoiding double file playback and other oddities happening in sound_lib from time to time.
|
||||
self.is_playing = False
|
||||
# This will be the URLStream handler
|
||||
self.stream = None
|
||||
self.message = None
|
||||
self.vol = config.app["sound"]["volume"]
|
||||
# this variable is set to true when the URLPlayer is decoding something, thus it will block other calls to the play method.
|
||||
self.is_working = False
|
||||
# Playback queue.
|
||||
self.queue = []
|
||||
# Index of the currently playing track.
|
||||
self.playing_track = 0
|
||||
self.playing_all = False
|
||||
self.worker = RepeatingTimer(5, self.player_function)
|
||||
self.worker.start()
|
||||
# Status of the player.
|
||||
self.stopped = True
|
||||
# Modify some default settings present in Bass so it will increase timeout connection, thus causing less "connection timed out" errors when playing.
|
||||
bassconfig = BassConfig()
|
||||
# Set timeout connection to 30 seconds.
|
||||
bassconfig["net_timeout"] = 30000
|
||||
# subscribe all pubsub events.
|
||||
pub.subscribe(self.play, "play")
|
||||
pub.subscribe(self.play_message, "play-message")
|
||||
pub.subscribe(self.play_all, "play-all")
|
||||
pub.subscribe(self.pause, "pause")
|
||||
pub.subscribe(self.stop, "stop")
|
||||
pub.subscribe(self.play_next, "play-next")
|
||||
pub.subscribe(self.play_previous, "play-previous")
|
||||
pub.subscribe(self.seek, "seek")
|
||||
|
||||
# Stopped has a special function here, hence the decorator
|
||||
# when stopped will be set to True, it will send a pubsub event to inform other parts of the application about the status change.
|
||||
# this is useful for changing labels between play and pause, and so on, in buttons.
|
||||
@property
|
||||
def stopped(self):
|
||||
return self._stopped
|
||||
|
||||
@stopped.setter
|
||||
def stopped(self, value):
|
||||
self._stopped = value
|
||||
pub.sendMessage("playback-changed", stopped=value)
|
||||
|
||||
def play(self, object, set_info=True, fresh=False):
|
||||
""" Play an URl Stream.
|
||||
@object dict: typically an audio object as returned by VK, with a "url" component which must be a valid URL to a media file.
|
||||
@set_info bool: If true, will set information about the currently playing audio in the application status bar.
|
||||
@fresh bool: If True, will remove everything playing in the queue and start this file only. otherwise it will play the new file but not remove the current queue."""
|
||||
if "url" in object and object["url"] =="":
|
||||
pub.sendMessage("notify", message=_("This file could not be played because it is not allowed in your country"))
|
||||
return
|
||||
if self.stream != None and (self.stream.is_playing == True or self.stream.is_stalled == True):
|
||||
try:
|
||||
self.stream.stop()
|
||||
except BassError:
|
||||
log.exception("error when stopping the file")
|
||||
self.stream = None
|
||||
self.stopped = True
|
||||
if fresh == True:
|
||||
self.queue = []
|
||||
# Make sure that there are no other sounds trying to be played.
|
||||
if self.is_working == False:
|
||||
self.is_working = True
|
||||
# Let's encode the URL as bytes if on Python 3
|
||||
url_ = utils.transform_audio_url(object["url"])
|
||||
url_ = bytes(url_, "utf-8")
|
||||
try:
|
||||
self.stream = URLStream(url=url_)
|
||||
except:
|
||||
log.error("Unable to play URL %s" % (url_))
|
||||
return
|
||||
# Translators: {0} will be replaced with a song's title and {1} with the artist.
|
||||
if set_info:
|
||||
msg = _("Playing {0} by {1}").format(object["title"], object["artist"])
|
||||
pub.sendMessage("update-status-bar", status=msg)
|
||||
self.stream.volume = self.vol/100.0
|
||||
self.stream.play()
|
||||
self.stopped = False
|
||||
self.is_working = False
|
||||
|
||||
def play_message(self, message_url):
|
||||
if self.message != None and (self.message.is_playing == True or self.message.is_stalled == True):
|
||||
return self.stop_message()
|
||||
output.speak(_("Playing..."))
|
||||
url_ = utils.transform_audio_url(message_url)
|
||||
url_ = bytes(url_, "utf-8")
|
||||
try:
|
||||
self.message = URLStream(url=url_)
|
||||
except:
|
||||
log.error("Unable to play URL %s" % (url_))
|
||||
return
|
||||
self.message.volume = self.vol/100.0
|
||||
self.message.play()
|
||||
volume_percent = self.volume*0.25
|
||||
volume_step = self.volume*0.15
|
||||
while self.stream.volume*100 > volume_percent:
|
||||
self.stream.volume = self.stream.volume-(volume_step/100)
|
||||
time.sleep(0.1)
|
||||
|
||||
def stop(self):
|
||||
""" Stop audio playback. """
|
||||
if self.stream != None and self.stream.is_playing == True:
|
||||
self.stream.stop()
|
||||
self.stopped = True
|
||||
self.queue = []
|
||||
|
||||
def stop_message(self):
|
||||
if hasattr(self, "message") and self.message != None and self.message.is_playing == True:
|
||||
self.message.stop()
|
||||
volume_step = self.volume*0.15
|
||||
while self.stream.volume*100 < self.volume:
|
||||
self.stream.volume = self.stream.volume+(volume_step/100)
|
||||
time.sleep(0.1)
|
||||
self.message = None
|
||||
|
||||
def pause(self):
|
||||
""" pause the current playback, without destroying the queue or the current stream. If the stream is already paused this function will resume the playback. """
|
||||
if self.stream != None:
|
||||
if self.stream.is_playing == True:
|
||||
self.stream.pause()
|
||||
self.stopped = True
|
||||
else:
|
||||
try:
|
||||
self.stream.play()
|
||||
self.stopped = False
|
||||
except BassError:
|
||||
pass
|
||||
if self.playing_all == False and len(self.queue) > 0:
|
||||
self.playing_all = True
|
||||
|
||||
@property
|
||||
def volume(self):
|
||||
return self.vol
|
||||
|
||||
@volume.setter
|
||||
def volume(self, vol):
|
||||
if vol <= 100 and vol >= 0:
|
||||
self.vol = vol
|
||||
elif vol < 0:
|
||||
self.vol = 0
|
||||
elif vol > 100:
|
||||
self.vol = 100
|
||||
if self.stream != None:
|
||||
if self.message != None and self.message.is_playing:
|
||||
self.stream.volume = (self.vol*0.25)/100.0
|
||||
self.message.volume = self.vol/100.0
|
||||
else:
|
||||
self.stream.volume = self.vol/100.0
|
||||
|
||||
def play_all(self, list_of_songs, shuffle=False):
|
||||
""" Play all passed songs and adds all of those to the queue.
|
||||
@list_of_songs list: A list of audio objects returned by VK.
|
||||
@shuffle bool: If True, the files will be played randomly."""
|
||||
if self.is_working:
|
||||
return
|
||||
self.playing_track = 0
|
||||
self.stop()
|
||||
# Skip all country restricted tracks as they are not playable here.
|
||||
self.queue = [i for i in list_of_songs if i["url"] != ""]
|
||||
if shuffle:
|
||||
random.shuffle(self.queue)
|
||||
call_threaded(self.play, self.queue[self.playing_track])
|
||||
self.playing_all = True
|
||||
|
||||
def player_function(self):
|
||||
""" Check if the stream has reached the end of the file so it will play the next song. """
|
||||
if self.message != None and self.message.is_playing == False and len(self.message) == self.message.position:
|
||||
volume_step = self.volume*0.15
|
||||
while self.stream != None and self.stream.volume*100 < self.volume:
|
||||
self.stream.volume = self.stream.volume+(volume_step/100)
|
||||
time.sleep(0.1)
|
||||
if self.stream != None and self.stream.is_playing == False and self.stopped == False and len(self.stream) == self.stream.position:
|
||||
if self.playing_track >= len(self.queue):
|
||||
self.stopped = True
|
||||
self.playing_all = False
|
||||
return
|
||||
elif self.playing_all == False:
|
||||
self.stopped = True
|
||||
return
|
||||
elif self.playing_track < len(self.queue):
|
||||
self.playing_track += 1
|
||||
self.play(self.queue[self.playing_track])
|
||||
|
||||
def play_next(self):
|
||||
""" Play the next song in the queue. """
|
||||
if len(self.queue) == 0:
|
||||
return
|
||||
if self.is_working:
|
||||
return
|
||||
if self.playing_track < len(self.queue)-1:
|
||||
self.playing_track += 1
|
||||
else:
|
||||
self.playing_track = 0
|
||||
call_threaded(self.play, self.queue[self.playing_track])
|
||||
|
||||
def play_previous(self):
|
||||
""" Play the previous song in the queue. """
|
||||
if len(self.queue) == 0:
|
||||
return
|
||||
if self.is_working:
|
||||
return
|
||||
if self.playing_track <= 0:
|
||||
self.playing_track = len(self.queue)-1
|
||||
else:
|
||||
self.playing_track -= 1
|
||||
call_threaded(self.play, self.queue[self.playing_track])
|
||||
|
||||
def seek(self, ms=0):
|
||||
if self.check_is_playing():
|
||||
if self.stream.position < 500000 and ms < 0:
|
||||
self.stream.position = 0
|
||||
else:
|
||||
try:
|
||||
self.stream.position = self.stream.position+ms
|
||||
except:
|
||||
pass
|
||||
|
||||
def check_is_playing(self):
|
||||
""" check if the player is already playing a stream. """
|
||||
if self.stream == None:
|
||||
return False
|
||||
if self.stream != None and self.stream.is_playing == False and self.stream.is_stalled == False:
|
||||
return False
|
||||
else:
|
||||
return True
|
168
src/presenters/profiles.py
Normal file
168
src/presenters/profiles.py
Normal file
@@ -0,0 +1,168 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" A profile viewer and editor for VK user objects."""
|
||||
from __future__ import unicode_literals
|
||||
import webbrowser
|
||||
import logging
|
||||
import arrow
|
||||
import requests
|
||||
import languageHandler
|
||||
import output
|
||||
from mysc.thread_utils import call_threaded
|
||||
from sessionmanager import utils
|
||||
from . import base
|
||||
|
||||
log = logging.getLogger("controller.profiles")
|
||||
|
||||
class userProfilePresenter(base.basePresenter):
|
||||
|
||||
def __init__(self, session, user_id, view, interactor):
|
||||
""" Default constructor:
|
||||
@session vk.session: The main session object, capable of calling VK methods.
|
||||
@user_id integer: User ID to retrieve information of.
|
||||
At the current time, only users (and not communities) are supported.
|
||||
"""
|
||||
super(userProfilePresenter, self).__init__(view=view, interactor=interactor, modulename="user_profile")
|
||||
# self.person will hold a reference to the user object when retrieved from VK.
|
||||
self.person = None
|
||||
self.session = session
|
||||
self.user_id = user_id
|
||||
# Get information in a threaded way here.
|
||||
# Note: We do not handle any race condition here because due to the presenter only sending pubsub messages,
|
||||
# Nothing happens if the pubsub send messages to the interactor after the latter has been destroyed.
|
||||
# Pubsub messages are just skipped if there are no listeners for them.
|
||||
call_threaded(self.get_basic_information)
|
||||
self.run()
|
||||
|
||||
def get_basic_information(self):
|
||||
""" Gets and inserts basic user information.
|
||||
See https://vk.com/dev/users.get"""
|
||||
# List of fields (information) to retrieve. For a list of fields available for user objects,
|
||||
# see https://vk.com/dev/fields
|
||||
fields = "first_name, last_name, bdate, city, country, home_town, photo_200_orig, online, site, status, last_seen, occupation, relation, relatives, personal, connections, activities, interests, music, movies, tv, books, games, about, quotes, can_write_private_message, contacts, has_mobile, universities, education, schools"
|
||||
# ToDo: this method supports multiple user IDS, I'm not sure if this may be of any help for profile viewer.
|
||||
person = self.session.vk.client.users.get(user_ids=self.user_id, fields=fields)
|
||||
# If VK does not return anything it is very likely we have found a community.
|
||||
if len(person) == 0:
|
||||
return output.speak(_("Information for groups is not supported, yet."))
|
||||
person = person[0]
|
||||
# toDo: remove this print when I will be done with creation of profile viewer logic.
|
||||
# print(person)
|
||||
# From this part we will format data from VK so users will see it in the GUI control.
|
||||
# Format full name.
|
||||
n = "{0} {1}".format(person["first_name"], person["last_name"])
|
||||
# format phones
|
||||
if person.get("mobile_phone") != None and person.get("mobile_phone") != "":
|
||||
self.send_message("enable_control", tab="main_info", control="mobile_phone")
|
||||
self.send_message("set", tab="main_info", control="mobile_phone", value=person["mobile_phone"])
|
||||
if person.get("home_phone") != None and person.get("home_phone") != "":
|
||||
self.send_message("enable_control", tab="main_info", control="home_phone")
|
||||
self.send_message("set", tab="main_info", control="home_phone", value=person["home_phone"])
|
||||
# Format birthdate.
|
||||
if "bdate" in person and person["bdate"] != "":
|
||||
self.send_message("enable_control", tab="main_info", control="bdate")
|
||||
# VK can display dd.mm or dd.mm.yyyy birthdates. So let's compare the string lenght to handle both cases accordingly.
|
||||
if len(person["bdate"]) <= 5: # dd.mm
|
||||
d = arrow.get(person["bdate"], "D.M")
|
||||
self.send_message("set", tab="main_info", control="bdate", value=d.format(_("MMMM D"), locale=languageHandler.curLang[:2]))
|
||||
else: # mm.dd.yyyy
|
||||
d = arrow.get(person["bdate"], "D.M.YYYY")
|
||||
# Calculate user's years.
|
||||
now = arrow.get()
|
||||
timedelta = now-d
|
||||
years = int(timedelta.days/365)
|
||||
date = d.format(_("MMMM D, YYYY"), locale=languageHandler.curLang[:2])
|
||||
msg = _("{date} ({age} years)").format(date=date, age=years)
|
||||
self.send_message("set", tab="main_info", control="bdate", value=msg)
|
||||
# Format current city and home town
|
||||
city = ""
|
||||
if "home_town" in person and person["home_town"] != "":
|
||||
home_town = person["home_town"]
|
||||
self.send_message("enable_control", tab="main_info", control="home_town")
|
||||
self.send_message("set", tab="main_info", control="home_town", value=home_town)
|
||||
if "city" in person and len(person["city"]) > 0:
|
||||
city = person["city"]["title"]
|
||||
if "country" in person and person["country"] != "":
|
||||
if city != "":
|
||||
city = city+", {0}".format(person["country"]["title"])
|
||||
else:
|
||||
city = person["country"]["title"]
|
||||
self.send_message("enable_control", tab="main_info", control="city")
|
||||
self.send_message("set", tab="main_info", control="city", value=city)
|
||||
self.send_message("set", tab="main_info", control="name", value=n)
|
||||
# Format title
|
||||
user = self.session.get_user(person["id"])
|
||||
self.send_message("set_title", value=_("{user1_nom}'s profile").format(**user))
|
||||
# Format website (or websites, if there are multiple of them).
|
||||
if "site" in person and person["site"] != "":
|
||||
self.send_message("enable_control", tab="main_info", control="website")
|
||||
self.send_message("set", tab="main_info", control="website", value=person["site"])
|
||||
self.send_message("enable_control", tab="main_info", control="go_site")
|
||||
# Format status message.
|
||||
if "status" in person and person["status"] != "":
|
||||
self.send_message("enable_control", tab="main_info", control="status")
|
||||
self.send_message("set", tab="main_info", control="status", value=person["status"])
|
||||
# Format occupation.
|
||||
# toDo: Research in this field is needed. Sometimes it returns university information even if users have active work places.
|
||||
if "occupation" in person and person["occupation"] != None:
|
||||
if person["occupation"]["type"] == "work": c1 = _("Work ")
|
||||
elif person["occupation"]["type"] == "school": c1 = _("Student ")
|
||||
elif person["occupation"]["type"] == "university": c1 = _("Student ")
|
||||
if "name" in person["occupation"] and person["occupation"]["name"] != "":
|
||||
c2 = _("In {0}").format(person["occupation"]["name"],)
|
||||
else:
|
||||
c2 = ""
|
||||
self.send_message("enable_control", tab="main_info", control="occupation")
|
||||
self.send_message("set", tab="main_info", control="occupation", value=c1+c2)
|
||||
# format relationship status.
|
||||
# ToDo: When dating someone, the button associated to the information should point to the profile of the user.
|
||||
if "relation" in person and person["relation"] != 0:
|
||||
if person["relation"] == 1:
|
||||
r = _("Single")
|
||||
elif person["relation"] == 2:
|
||||
if "relation_partner" in person:
|
||||
r = _("Dating with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
else:
|
||||
r = _("Dating")
|
||||
elif person["relation"] == 3:
|
||||
r = _("Engaged with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
elif person["relation"] == 4:
|
||||
if "relation_partner" in person:
|
||||
r = _("Married to {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
|
||||
else:
|
||||
r = _("Married")
|
||||
elif person["relation"] == 5:
|
||||
r = _("It's complicated")
|
||||
elif person["relation"] == 6:
|
||||
r = _("Actively searching")
|
||||
elif person["relation"] == 7:
|
||||
r = _("In love")
|
||||
self.send_message("enable_control", tab="main_info", control="relation")
|
||||
self.send_message("set_label", tab="main_info", control="relation", value=_("Relationship: ")+r)
|
||||
# format last seen.
|
||||
if "last_seen" in person and person["last_seen"] != False:
|
||||
original_date = arrow.get(person["last_seen"]["time"])
|
||||
# Translators: This is the date of last seen
|
||||
last_seen = _("{0}").format(original_date.humanize(locale=languageHandler.curLang[:2]),)
|
||||
self.send_message("enable_control", tab="main_info", control="last_seen")
|
||||
self.send_message("set", tab="main_info", control="last_seen", value=last_seen)
|
||||
self.person = person
|
||||
# Adds photo to the dialog.
|
||||
# ToDo: Need to ask if this has a visible effect in the dialog.
|
||||
if "photo_200_orig" in person:
|
||||
img = requests.get(person["photo_200_orig"])
|
||||
self.send_message("load_image", image=requests.get(person["photo_200_orig"]))
|
||||
output.speak(_("Profile loaded"))
|
||||
|
||||
def get_urls(self, *args, **kwargs):
|
||||
""" Allows to visit an user's website. """
|
||||
text = self.person["site"]
|
||||
# Let's search for URLS with a regexp, as there are users with multiple websites in their profiles.
|
||||
urls = utils.find_urls_in_text(text)
|
||||
if len(urls) == 0:
|
||||
output.speak(_("No URL addresses were detected."))
|
||||
return
|
||||
return urls
|
||||
|
||||
def visit_url(self, url):
|
||||
output.speak(_("Opening URL..."))
|
||||
webbrowser.open_new_tab(url)
|
22
src/run_tests.py
Normal file
22
src/run_tests.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest
|
||||
import languageHandler
|
||||
|
||||
languageHandler.setLanguage("en")
|
||||
|
||||
|
||||
testmodules = ["test.test_setup_py2exe", "test.test_base_interactor", "test.test_audiorecorder", "test.test_renderers"]
|
||||
|
||||
suite = unittest.TestSuite()
|
||||
|
||||
for t in testmodules:
|
||||
try:
|
||||
# If the module defines a suite() function, call it to get the suite.
|
||||
mod = __import__(t, globals(), locals(), ['suite'])
|
||||
suitefn = getattr(mod, 'suite')
|
||||
suite.addTest(suitefn())
|
||||
except (ImportError, AttributeError):
|
||||
# else, just load all the test cases from the module.
|
||||
suite.addTest(unittest.defaultTestLoader.loadTestsFromName(t))
|
||||
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user