added non-selection area

This commit is contained in:
Nihilazo 2020-07-19 12:29:55 +01:00
parent 358b8fc508
commit 4a527540d4
1 changed files with 27 additions and 21 deletions

48
main.py
View File

@ -45,17 +45,20 @@ class MenuWindow(Gtk.Window):
self.add(self.area)
def click(self,widget,data):
opt = self.options[self.selected]
if opt["type"] == "shell":
sp.Popen(opt["command"].split(" "))
self.destroy()
elif opt["type"] == "internal":
if opt["command"] == "exit":
if self.selected != None:
opt = self.options[self.selected]
if opt["type"] == "shell":
sp.Popen(opt["command"].split(" "))
self.destroy()
elif opt["type"] == "submenu":
self.options = opt["options"]
self.selected = None
self.area.queue_draw()
elif opt["type"] == "internal":
if opt["command"] == "exit":
self.destroy()
elif opt["type"] == "submenu":
self.options = opt["options"]
self.selected = None
self.area.queue_draw()
else:
self.destroy()
def on_move(self,widget,data):
self.area.queue_draw()
@ -63,14 +66,17 @@ class MenuWindow(Gtk.Window):
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
if self.mouse_x > self.width-(self.width/8):
self.selected = None
else:
for number, angle in enumerate(self.lines):
if mouse_angle < angle:
break
else:
current = number
self.selected = current
def draw_option(self, cr, i, option, width, height):
def draw_option(self, cr, i, option):
if self.selected != None:
if i == self.selected:
cr.set_source_rgb(0,0.4,0.4)
@ -78,10 +84,10 @@ class MenuWindow(Gtk.Window):
cr.set_source_rgb(1,1,1)
extents = cr.text_extents(option["label"])
cr.move_to(-width,0)
cr.move_to(-self.width,0)
cr.show_text(option["label"])
cr.move_to(-width+extents.width,-extents.height/4)
cr.line_to(0,0)
cr.move_to(-self.width+extents.width,-extents.height/4)
cr.line_to(-self.width/8,0)
cr.stroke()
@ -100,7 +106,7 @@ class MenuWindow(Gtk.Window):
angle = start_angle
cr.set_source_rgb(1,1,1)
for i, o in enumerate(self.options):
self.draw_option(cr, i, o, width, height)
self.draw_option(cr, i, o)
cr.rotate(math.pi/16)
self.lines.append(angle)
angle += math.pi/16