# -*- coding: utf-8 -*-

import gtk

import adesk.plugin as Plg
import adesk.menu as Menu
import adesk.ui as UI
import adesk.core as Core

MENU_WIDTH = 400

class Plugin(Plg.Plugin):
    def __init__(self, bar, settings):
        Plg.Plugin.__init__(self, bar, settings)
        self.bar = bar
        self.settings = settings
        self.can_zoom = True
        self.menu = Menu_UI(self, bar)

    def onClick(self, widget, event):
        self.menu.toggle(self.menu)

    def resize(self):
        self.set_size_request(self.cfg['icon_size'], self.cfg['icon_size'])

class Menu_UI(UI.PopupWindow):
    def __init__(self, plugin, bar):
        UI.PopupWindow.__init__(self, bar, plugin)
        self.set_size_request(MENU_WIDTH,-1)

        self.nbook = gtk.Notebook()
        self.nbook.set_tab_pos(gtk.POS_LEFT)
        self.nbook.set_border_width(0)
        self.nbook.show()
        self.add(self.nbook)
        terminal = plugin.settings['terminal']

        menu_ui = Menu.MakeMenu(bar.menu, self.nbook, self.executeAction, terminal)
        menu_ui.start()

    def executeAction(self, widget, event, application):
        if event.button == 1: # left click
            Core.launch_command(application[0])
            self.toggle()
        if event.button == 3: # right click
            print widget.get_name()
