fit widget position on screen

This commit is contained in:
antoine 2016-07-23 21:19:06 +02:00
parent 5909b62ce8
commit 32f8354649
21 changed files with 404 additions and 2 deletions

View File

@ -4,10 +4,24 @@ from ..VDM import VDM
import os import os
import i3 import i3
# get screen resolution
import tkinter
root = tkinter.Tk()
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
from kivy.config import Config from kivy.config import Config
Config.set('graphics','fullscreen', 0)
Config.set('graphics','resizable',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 from kivy.core.window import Window
Window.size = (600, 150)
import kivy import kivy
from kivy.app import App from kivy.app import App
@ -65,4 +79,4 @@ class guiApp(GridLayout):
class kivyApp(App): class kivyApp(App):
def build(self): def build(self):
return guiApp(cols=3) return guiApp(cols=3, pos=(0,0))

60
VDM_API.egg-info/PKG-INFO Normal file
View File

@ -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=<pathToDistIncludeIntoGitClone> 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

View File

@ -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

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,3 @@
[console_scripts]
vdm = VDMAPI:main

View File

@ -0,0 +1 @@
VDMAPI

View File

@ -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"

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,23 @@
#:kivy 1.0
<guiApp>:
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()

View File

@ -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))

View File

@ -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_())

View File

@ -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('<Left>', self.prevAction)
self.root.bind('<Right>', 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()

View File

@ -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)

View File

@ -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()

View File

@ -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

36
build/lib/VDMAPI/VDM.py Normal file
View File

@ -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)

View File

View File

@ -0,0 +1 @@
version = '1.0'

Binary file not shown.

Binary file not shown.