fin fonctionnel i3, tkinter et kivy avec fenétre flottante pour i3

This commit is contained in:
antoine 2016-07-17 23:15:18 +02:00
parent f8f3420527
commit d3177525d1
8 changed files with 177 additions and 63 deletions

24
VDMAPI/Display/kivy.kv Normal file
View File

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

67
VDMAPI/Display/kivyDisplay.py Executable file
View File

@ -0,0 +1,67 @@
#!/usr/bin/env python
from ..VDM import VDM
import os
import kivy
import i3
from kivy.app import App
from kivy.properties import *
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
from kivy.config import Config
Config.set('graphics', 'width', '600')
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)
i3.msg("command", "floating enable")
self.v = VDM()
self.vdm = self.v.get()
self.render()
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)

13
VDMAPI/Display/pyside.py Executable file
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

@ -1,18 +1,51 @@
from ..VDM import VDM from ..VDM import VDM
import tkinter as tk import tkinter as tk
import pygubu import i3
import VDMAPI from tkinter import ttk
import os import os
class tkinter: class tkinter:
def __init__(self): def __init__(self):
self.root = tk.Tk() """ init vdm object and create GUI """
self.v = VDM()
builder = builder = pygubu.Builder() self.indice = 0
uiPath = os.path.join(VDMAPI.__path__[0], './', 'tkinter.ui') self.vdm = self.v.get()
builder.add_from_file(uiPath)
mainwindow = builder.get_object('frame', self.root)
def render(self): self.root = tk.Tk()
self.root.mainloop() 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,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

@ -1,46 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<interface>
<object class="tk.Frame" id="frame">
<property name="height">200</property>
<property name="width">200</property>
<layout>
<property name="column">0</property>
<property name="propagate">True</property>
<property name="row">0</property>
</layout>
<child>
<object class="tk.Button" id="btn_prev">
<property name="height">3</property>
<property name="text" translatable="yes">&lt;&lt;</property>
<layout>
<property name="column">0</property>
<property name="propagate">True</property>
<property name="row">0</property>
<property name="sticky">w</property>
</layout>
</object>
</child>
<child>
<object class="tk.Button" id="btn_next">
<property name="height">3</property>
<property name="text" translatable="yes">&gt;&gt;</property>
<layout>
<property name="column">2</property>
<property name="propagate">True</property>
<property name="row">0</property>
<property name="sticky">e</property>
</layout>
</object>
</child>
<child>
<object class="tk.Message" id="lbl_vdm">
<property name="text" translatable="yes">No vdm pull for the moment</property>
<layout>
<property name="column">1</property>
<property name="propagate">True</property>
<property name="row">0</property>
</layout>
</object>
</child>
</object>
</interface>

15
main.py
View File

@ -15,16 +15,21 @@ if __name__ == "__main__":
elif displayType == "tkinter": elif displayType == "tkinter":
from VDMAPI.Display.tkinter import tkinter as display from VDMAPI.Display.tkinter import tkinter as display
elif displayType == "windows": elif displayType == "kivy":
from VDMAPI.Display.windows import windows as display from VDMAPI.Display.kivyDisplay import kivyApp as display
d = display()
d.run()
sys.exit()
elif displayType == "console": elif displayType == "console":
None pass
else: else:
print("Error bad display mode accepted value are : i3, tkinter, windows of console") print("Error bad display mode accepted value are : i3, tkinter, kivy of console")
sys.exit()
else: else:
print("Error too few argument -d need value : i3, tkinter, windows of console") print("Error too few argument -d need value : i3, tkinter, kivy of console")
sys.exit()
d = display() d = display()
d.render() d.render()