initial commit
This commit is contained in:
commit
8700488bb5
|
@ -0,0 +1,2 @@
|
||||||
|
*pyc
|
||||||
|
__pycache__/*
|
|
@ -0,0 +1,96 @@
|
||||||
|
import gi
|
||||||
|
import math
|
||||||
|
import cairo
|
||||||
|
import subprocess as sp
|
||||||
|
gi.require_version("Gtk","3.0")
|
||||||
|
gi.require_version("Gdk","3.0")
|
||||||
|
from gi.repository import Gtk
|
||||||
|
from gi.repository import Gdk
|
||||||
|
|
||||||
|
width = 1920
|
||||||
|
height = 1080
|
||||||
|
|
||||||
|
def point_on_circle(r, point, angle):
|
||||||
|
x = point[0] + r * math.cos(angle)
|
||||||
|
y = point[1] + r * math.sin(angle)
|
||||||
|
return [x,y]
|
||||||
|
|
||||||
|
def gradient(x1,y1,x2,y2):
|
||||||
|
return y1-y2/x1-x2
|
||||||
|
|
||||||
|
class MenuWindow(Gtk.Window):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.set_title("PieMenu")
|
||||||
|
self.width = width/3
|
||||||
|
self.height = height
|
||||||
|
self.options = [["Keyboard","onboard"], ["Terminal","termite"],["Launcher","rofi -show run"], ["Notes","echo \"hello world\""], ["Placeholder 1","echo \"p\""], ["A long option","echo \"long\""], ["Exit",None]]
|
||||||
|
self.selected = None
|
||||||
|
self.connect("destroy",Gtk.main_quit)
|
||||||
|
self.set_default_size(width/3,height)
|
||||||
|
self.move(width-self.width,0)
|
||||||
|
self.set_resizable(False)
|
||||||
|
self.set_decorated(False)
|
||||||
|
self.mouse_x = 0
|
||||||
|
self.mouse_y = 0
|
||||||
|
self.area = Gtk.DrawingArea()
|
||||||
|
self.area.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
|
||||||
|
self.area.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
|
||||||
|
self.area.add_events(Gdk.EventMask.BUTTON_MOTION_MASK)
|
||||||
|
self.area.connect("draw",self.draw_area)
|
||||||
|
self.area.connect("button_release_event",self.click)
|
||||||
|
self.area.connect("motion_notify_event",self.on_move)
|
||||||
|
self.add(self.area)
|
||||||
|
|
||||||
|
def click(self,widget,data):
|
||||||
|
if self.options[self.selected][1] != None:
|
||||||
|
sp.Popen(self.options[self.selected][1].split(" "),)
|
||||||
|
self.destroy()
|
||||||
|
|
||||||
|
def on_move(self,widget,data):
|
||||||
|
self.area.queue_draw()
|
||||||
|
self.mouse_x = data.x
|
||||||
|
self.mouse_y = data.y
|
||||||
|
mouse_angle = -(math.atan2(self.mouse_x-self.center[0],self.mouse_y-self.center[1]) + (math.pi/2))
|
||||||
|
current = 0
|
||||||
|
for number, angle in enumerate(self.lines):
|
||||||
|
if mouse_angle < angle:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
current = number
|
||||||
|
self.selected = current
|
||||||
|
|
||||||
|
def draw_area(self, widget, cr):
|
||||||
|
self.lines = []
|
||||||
|
width = widget.get_allocated_width()
|
||||||
|
height = widget.get_allocated_height()
|
||||||
|
cr.translate(width,height/2) # All coordinates are relative to right center
|
||||||
|
cp = cr.get_current_point()
|
||||||
|
self.center = cr.user_to_device(cp[0],cp[1])
|
||||||
|
cr.select_font_face("monospace",cairo.FontSlant.NORMAL,cairo.FontWeight.BOLD)
|
||||||
|
cr.set_line_width(4)
|
||||||
|
cr.set_font_size(20)
|
||||||
|
start_angle = (-math.pi/16)*(len(self.options)/2)
|
||||||
|
cr.rotate(start_angle)
|
||||||
|
angle = start_angle
|
||||||
|
cr.set_source_rgb(1,1,1)
|
||||||
|
for i, o in enumerate(self.options):
|
||||||
|
if self.selected != None:
|
||||||
|
if i == self.selected:
|
||||||
|
cr.set_source_rgb(0,0.4,0.4)
|
||||||
|
else:
|
||||||
|
cr.set_source_rgb(1,1,1)
|
||||||
|
extents = cr.text_extents(o[0])
|
||||||
|
cr.rotate(math.pi/16)
|
||||||
|
angle += math.pi/16
|
||||||
|
self.lines.append(angle)
|
||||||
|
cr.move_to(-width,0)
|
||||||
|
cp = cr.get_current_point()
|
||||||
|
cr.show_text(o[0])
|
||||||
|
cr.move_to(-width+extents.width,-extents.height/4)
|
||||||
|
cr.line_to(0,0)
|
||||||
|
cr.stroke()
|
||||||
|
|
||||||
|
win = MenuWindow()
|
||||||
|
win.show_all()
|
||||||
|
Gtk.main()
|
Reference in New Issue