diff --git a/VDMAPI/Display/kivyDisplay.py b/VDMAPI/Display/kivyDisplay.py index d05682d..61d80bf 100755 --- a/VDMAPI/Display/kivyDisplay.py +++ b/VDMAPI/Display/kivyDisplay.py @@ -4,10 +4,24 @@ from ..VDM import VDM import os import i3 +# get screen resolution +import tkinter +root = tkinter.Tk() +width = root.winfo_screenwidth() +height = root.winfo_screenheight() + from kivy.config import Config +Config.set('graphics','fullscreen', 0) Config.set('graphics','resizable',0) +Config.set('graphics','position', 'custom') +Config.set('graphics','width', 600) +Config.set('graphics','height', 150) + +# align bottom and 50 px from right +Config.set('graphics','left', width-Config.getint('graphics', 'width')-45) +Config.set('graphics','top', height-Config.getint('graphics', 'height')-17) + from kivy.core.window import Window -Window.size = (600, 150) import kivy from kivy.app import App @@ -65,4 +79,4 @@ class guiApp(GridLayout): class kivyApp(App): def build(self): - return guiApp(cols=3) + return guiApp(cols=3, pos=(0,0)) diff --git a/VDM_API.egg-info/PKG-INFO b/VDM_API.egg-info/PKG-INFO new file mode 100644 index 0000000..65098c8 --- /dev/null +++ b/VDM_API.egg-info/PKG-INFO @@ -0,0 +1,60 @@ +Metadata-Version: 1.1 +Name: VDM-API +Version: 1.0 +Summary: VDM API: an API for recover random VDM from vdm.fr website +Home-page: git://176.189.130.29/python/vdmAPI.git +Author: Antoine Roux +Author-email: antoinroux@hotmail.fr +License: Beerware +Download-URL: git://176.189.130.29/python/vdmAPI.git/tags +Description: ******* + VDM API + ******* + V1.0 + + **VDM API** is a python api for pull random api. + + Use case + ======== + You can use this API in python langage by instanciate a VDM() object : + :: + + from VDMAPI.VDM import VDM + + if __name__ == "__main__": + vdm = VDM() + lstAllVDM = vdm.get() + for i, vdm in enumerate(lstAllVDM): + print(str(i)+" : "+vdm) + + + Available GUI + ============= + + **VDM API** include four display mode : + + - **i3** : this GUI use dmenu for display the list of VDM + - **tkinter** : this use tkinter native interface + - **kivy** : use kivy library + - **console** : this last mode display the list of VDM in plain text mode + + Installing + ========== + + For **setup** you could do with this : + :: + + pip install --no-index --find-links= VDM_API + +Platform: any +Classifier: License :: FSF approved :: Beerware License +Classifier: Operating System :: POSIX :: Linux +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 2.6 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.2 +Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Topic :: Software Development :: Libraries :: Python Modules diff --git a/VDM_API.egg-info/SOURCES.txt b/VDM_API.egg-info/SOURCES.txt new file mode 100644 index 0000000..946b9c3 --- /dev/null +++ b/VDM_API.egg-info/SOURCES.txt @@ -0,0 +1,22 @@ +MANIFEST.in +README.html +README.rst +setup.py +VDMAPI/HtmlParser.py +VDMAPI/VDM.py +VDMAPI/__init__.py +VDMAPI/version.py +VDMAPI/Display/__init__.py +VDMAPI/Display/console.py +VDMAPI/Display/i3.py +VDMAPI/Display/kivy.kv +VDMAPI/Display/kivyDisplay.py +VDMAPI/Display/pyside.py +VDMAPI/Display/tkinter.py +VDMAPI/Display/windows.py +VDMAPI/Display/wxpython.py +VDM_API.egg-info/PKG-INFO +VDM_API.egg-info/SOURCES.txt +VDM_API.egg-info/dependency_links.txt +VDM_API.egg-info/entry_points.txt +VDM_API.egg-info/top_level.txt \ No newline at end of file diff --git a/VDM_API.egg-info/dependency_links.txt b/VDM_API.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/VDM_API.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/VDM_API.egg-info/entry_points.txt b/VDM_API.egg-info/entry_points.txt new file mode 100644 index 0000000..6b89213 --- /dev/null +++ b/VDM_API.egg-info/entry_points.txt @@ -0,0 +1,3 @@ +[console_scripts] +vdm = VDMAPI:main + diff --git a/VDM_API.egg-info/top_level.txt b/VDM_API.egg-info/top_level.txt new file mode 100644 index 0000000..b60ebbe --- /dev/null +++ b/VDM_API.egg-info/top_level.txt @@ -0,0 +1 @@ +VDMAPI diff --git a/build/lib/VDMAPI/Display/__init__.py b/build/lib/VDMAPI/Display/__init__.py new file mode 100644 index 0000000..7bcea61 --- /dev/null +++ b/build/lib/VDMAPI/Display/__init__.py @@ -0,0 +1,7 @@ +# import all module include into current package +__name__ = "VDMAPI" +__version__ = 1.0 +__author__ = "antoine roux" +__author_email__= "antoinroux@hotmail.fr" +__url__ = "antoine-roux.tk" +__description__ = "an api for recover a list of random vdm from vdm.fr and display it on different GUI (i3, tkinter, windows or commande line" diff --git a/build/lib/VDMAPI/Display/console.py b/build/lib/VDMAPI/Display/console.py new file mode 100644 index 0000000..7317811 --- /dev/null +++ b/build/lib/VDMAPI/Display/console.py @@ -0,0 +1,12 @@ +from ..VDM import VDM + +class console(object): + """display all vdm into console""" + def __init__(self): + super(console, self).__init__() + self.v = VDM() + + def render(self): + lstAllVDM = self.v.get() + for i, vdm in enumerate(lstAllVDM): + print(str(i)+" : "+vdm) diff --git a/build/lib/VDMAPI/Display/i3.py b/build/lib/VDMAPI/Display/i3.py new file mode 100644 index 0000000..9fb48b3 --- /dev/null +++ b/build/lib/VDMAPI/Display/i3.py @@ -0,0 +1,20 @@ +from ..VDM import VDM +import subprocess +import i3 + +class i3(object): + """display all vdm into i3 menu""" + def __init__(self): + super(i3, self).__init__() + self.v = VDM() + + def render(self): + lstAllVDM = self.v.get() + + dmenu = subprocess.Popen(['/usr/bin/dmenu', '-i','-l', str(len(lstAllVDM))], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + + menu_str = '\n'.join(lstAllVDM) + win_str = dmenu.communicate(menu_str.encode('utf-8'))[0].decode('utf-8').rstrip() + print(win_str) \ No newline at end of file diff --git a/build/lib/VDMAPI/Display/kivy.kv b/build/lib/VDMAPI/Display/kivy.kv new file mode 100644 index 0000000..90b13c4 --- /dev/null +++ b/build/lib/VDMAPI/Display/kivy.kv @@ -0,0 +1,23 @@ +#:kivy 1.0 + +: + Button: + id: prev + + size_hint_x: None + width: 100 + + text: '<<' + on_press: root._prevAction() + Label: + text_size: 300, None + id: Message + text: 'no VDM load for the moment' + Button: + id: next + + size_hint_x: None + + width: 100 + text: '>>' + on_press: root._nextAction() \ No newline at end of file diff --git a/build/lib/VDMAPI/Display/kivyDisplay.py b/build/lib/VDMAPI/Display/kivyDisplay.py new file mode 100644 index 0000000..61d80bf --- /dev/null +++ b/build/lib/VDMAPI/Display/kivyDisplay.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +from ..VDM import VDM +import os +import i3 + +# get screen resolution +import tkinter +root = tkinter.Tk() +width = root.winfo_screenwidth() +height = root.winfo_screenheight() + +from kivy.config import Config +Config.set('graphics','fullscreen', 0) +Config.set('graphics','resizable',0) +Config.set('graphics','position', 'custom') +Config.set('graphics','width', 600) +Config.set('graphics','height', 150) + +# align bottom and 50 px from right +Config.set('graphics','left', width-Config.getint('graphics', 'width')-45) +Config.set('graphics','top', height-Config.getint('graphics', 'height')-17) + +from kivy.core.window import Window + +import kivy +from kivy.app import App +from kivy.properties import * +from kivy.uix.gridlayout import GridLayout + +class guiApp(GridLayout): + """ display all vdm into kivy interface """ + + # https://kivy.org/docs/api-kivy.properties.html#kivy.properties.ListProperty + # NumericProperty, StringProperty, ListProperty, ObjectProperty, + # BooleanProperty, BoundedNumericProperty, OptionProperty, ReferenceListProperty, AliasProperty, DictProperty + + indice = NumericProperty(0) + vdm = ListProperty([]) + + def __init__(self, **kwargs): + super(guiApp, self).__init__(**kwargs) + + self._keyboard = Window.request_keyboard(self._keyboard_closed, self) + self._keyboard.bind(on_key_down = self._on_keyboard_down) + + self.v = VDM() + self.vdm = self.v.get() + self.render() + i3.msg("command", "floating enable") + + def _nextAction(self): + if self.indice == len(self.vdm)-1: + self.vdm = self.v.get() + self.indice = 0 + else: + self.indice += 1 + self.render() + + def _prevAction(self): + if self.indice > 0: + self.indice -= 1 + self.render() + + def _keyboard_closed(self): + self._keyboard.unbind(on_key_down = self._on_keyboard_down) + self._keyboard = None + + def _on_keyboard_down(self, *args): + if args[1][1] == 'right': + self._nextAction() + + elif args[1][1] == 'left': + self._prevAction() + + def render(self): + print(self.indice) + self.ids["Message"].text = self.vdm[self.indice] + +class kivyApp(App): + def build(self): + return guiApp(cols=3, pos=(0,0)) diff --git a/build/lib/VDMAPI/Display/pyside.py b/build/lib/VDMAPI/Display/pyside.py new file mode 100644 index 0000000..760e267 --- /dev/null +++ b/build/lib/VDMAPI/Display/pyside.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +import sys +import PySide + +app = QtGui.QApplication(sys.argv) + +hello = QtGui.QLabel("hello Qt") +hello.show() +x, y, w, h = 100, 100, 100, 100 +hello.setGeometry(x, y, w, h) + +sys.exit(app.exec_()) \ No newline at end of file diff --git a/build/lib/VDMAPI/Display/tkinter.py b/build/lib/VDMAPI/Display/tkinter.py new file mode 100644 index 0000000..0f8d2fe --- /dev/null +++ b/build/lib/VDMAPI/Display/tkinter.py @@ -0,0 +1,51 @@ +from ..VDM import VDM +import tkinter as tk +import i3 +from tkinter import ttk +import os + +class tkinter: + def __init__(self): + """ init vdm object and create GUI """ + self.v = VDM() + self.indice = 0 + self.vdm = self.v.get() + + self.root = tk.Tk() + self.gui(self.root) + + def nextAction(self, event=None): + if self.indice == len(self.vdm)-1: + self.vdm = self.v.get() + self.indice = 0 + else: + self.indice+=1 + self.render() + + def prevAction(self, event=None): + if self.indice > 0: + self.indice-=1 + self.render() + + def gui(self, master): + self.mainwindow = ttk.Frame(master) + self.message = tk.Message(master, text="No VDM load for the moment", width="400") + + self.next = ttk.Button(master, text=">>", command=self.nextAction) + self.prev = ttk.Button(master, text="<<", command=self.prevAction) + self.root.bind('', self.prevAction) + self.root.bind('', self.nextAction) + + self.message.pack(fill="y", side="left", padx="5", pady="5") + self.prev.pack(fill="y", side="left", pady="1") + self.next.pack(fill="y", side="right", pady="1") + + def _floatingDisabler(self): + i3.msg("command", "floating enable") + + def render(self): + print("indice {}".format(self.indice)) + + self.message.configure(text=self.vdm[self.indice]) + self.root.after(1, self._floatingDisabler) + self.root.mainloop() diff --git a/build/lib/VDMAPI/Display/windows.py b/build/lib/VDMAPI/Display/windows.py new file mode 100644 index 0000000..8974669 --- /dev/null +++ b/build/lib/VDMAPI/Display/windows.py @@ -0,0 +1,12 @@ +from ..VDM import VDM + +class windows(object): + """display all vdm into windows os""" + def __init__(self): + super(windows, self).__init__() + v = VDM() + + def render(self): + lstAllVDM = self.v.get() + for i, vdm in enumerate(lstAllVDM): + print(str(i)+" : "+vdm) \ No newline at end of file diff --git a/build/lib/VDMAPI/Display/wxpython.py b/build/lib/VDMAPI/Display/wxpython.py new file mode 100644 index 0000000..684c194 --- /dev/null +++ b/build/lib/VDMAPI/Display/wxpython.py @@ -0,0 +1,18 @@ +#!/usr/bin/python + +import wx + +def onButton(event): + print "Button pressed." + +app = wx.App() +frame = wx.Frame(None, -1, 'win.py') +frame.SetDimensions(0,0,200,50) + +panel = wx.Panel(frame, wx.ID_ANY) +button = wx.Button(panel, wx.ID_ANY, 'Test', (10, 10)) +button.Bind(wx.EVT_BUTTON, onButton) + +frame.Show() +frame.Centre() +app.MainLoop() \ No newline at end of file diff --git a/build/lib/VDMAPI/HtmlParser.py b/build/lib/VDMAPI/HtmlParser.py new file mode 100644 index 0000000..c03a52d --- /dev/null +++ b/build/lib/VDMAPI/HtmlParser.py @@ -0,0 +1,26 @@ +from html.parser import HTMLParser +from html.entities import name2codepoint + +class MyHTMLParser(HTMLParser): + def __init__(self): + super(MyHTMLParser, self).__init__() + self.vdm = [] + self.save = False + + def _searchClass(self, listTuple, className="post article"): + for v in listTuple: + if v[0] == 'class' and v[1] == className: + return True + return False + + def handle_starttag(self, tag, attrs): + if tag == "p" and self._searchClass(attrs, className="content"): + self.save = True + + def handle_data(self, data): + if self.save: + self.vdm.append(data) + self.save = False + + def getText(self): + return self.vdm \ No newline at end of file diff --git a/build/lib/VDMAPI/VDM.py b/build/lib/VDMAPI/VDM.py new file mode 100644 index 0000000..9717016 --- /dev/null +++ b/build/lib/VDMAPI/VDM.py @@ -0,0 +1,36 @@ +from .HtmlParser import MyHTMLParser +import requests + +class VDM(object): + """VDM module for recover random VDM""" + + def __init__(self): + self.url = "http://www.viedemerde.fr/aleatoire" + self.vdm = {} + + def get(self): + try: + r = requests.get(self.url) + r.encoding = 'utf-8' # ISO-8859-1 + + if(r.status_code == requests.codes.ok): + parser = MyHTMLParser() + parser.feed(r.text) + self.vdm = parser.getText() + + print("Sucess {}".format(r.status_code)) + + return self.vdm + else: + print("Error {}".format(r.status_code)) + + except requests.exceptions.ConnectionError as e: + raise errorVDM("network error") + + except HTTPError as e: + raise errorVDM("HTTP Error") + +class errorVDM(Exception): + def __init__(self, message): + super(errorVDM, self).__init__(message) + \ No newline at end of file diff --git a/build/lib/VDMAPI/__init__.py b/build/lib/VDMAPI/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/build/lib/VDMAPI/version.py b/build/lib/VDMAPI/version.py new file mode 100644 index 0000000..050eddb --- /dev/null +++ b/build/lib/VDMAPI/version.py @@ -0,0 +1 @@ +version = '1.0' \ No newline at end of file diff --git a/dist/VDM API-1.0.tar.gz b/dist/VDM API-1.0.tar.gz index 8527153..8f86891 100644 Binary files a/dist/VDM API-1.0.tar.gz and b/dist/VDM API-1.0.tar.gz differ diff --git a/dist/VDM_API-1.0-py2.py3-none-any.whl b/dist/VDM_API-1.0-py2.py3-none-any.whl index 78e5c3e..87287cf 100644 Binary files a/dist/VDM_API-1.0-py2.py3-none-any.whl and b/dist/VDM_API-1.0-py2.py3-none-any.whl differ