Exemple #1
0
    def __init__(self, run_installed=True):

        self.run_installed = run_installed

        self.img_path = ""
        self.doc_path = ""
        if run_installed:
            self.img_path = self.local_share_dir + self.appname + "/"
            self.doc_path = self.local_share_dir + "doc/" + self.appname + "/"

        self.status_message_list = [
            "ALT+arrowkeys move!",
            # 			"Supports "+RocketManager.launcher_types[0]+" and "+RocketManager.launcher_types[1]+" Launcher!"
            "Supports Striker II and Dream Cheeky Models!",
        ]

        # create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        # 		self.window.set_title(u"Dream Cheeky\u0099 Control")	# The "TM" symbol doesn't work in GNOME
        # 		self.window.set_title(u"Dream Cheeky\u00AE Control")
        self.window.set_title("USB Rocket Launcher Control")

        icon_path = self.img_path + "pyrocket.png"
        self.window.set_icon_from_file(icon_path)
        self.status_icon = gtk.status_icon_new_from_file(icon_path)
        self.status_icon.set_visible(True)

        self.window.set_resizable(False)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("key_press_event", self.handle_keyboard_press_event)
        self.window.connect("key_release_event", self.handle_keyboard_release_event)
        self.window.set_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK)

        self.window.connect("destroy", self.destroy)

        self.button_array = []
        for i, label in enumerate(self.button_labels):
            button = gtk.Button(label)
            button.set_use_underline(True)
            button_image = gtk.Image()
            button_image.set_from_stock(self.button_stock_icons[i], gtk.ICON_SIZE_BUTTON)
            button.set_image(button_image)
            self.button_array.append(button)

        vbox = gtk.VBox(False, 5)
        self.window.add(vbox)

        # ----------------------------

        top_menu = gtk.MenuBar()
        vbox.pack_start(top_menu, False, False)

        view_menu = gtk.MenuItem("_View")
        view_submenu = gtk.Menu()
        view_menu.set_submenu(view_submenu)
        self.camera_widget_visible = gtk.CheckMenuItem("Camera")
        self.camera_widget_visible.connect("toggled", self.cb_toggle_show_camera)
        view_submenu.append(self.camera_widget_visible)

        top_menu.append(view_menu)

        help_menu = gtk.MenuItem("_Application")
        help_submenu = gtk.Menu()
        help_menu.set_submenu(help_submenu)
        about_item = gtk.MenuItem("_About")
        about_item.connect("activate", self.cb_about_dialog)
        help_submenu.append(about_item)

        quit_item = gtk.MenuItem("_Quit")
        quit_item.connect("activate", self.destroy)
        help_submenu.append(quit_item)

        top_menu.append(help_menu)

        # ----------------------------

        self.video = VideoWindow()
        self.video.set_no_show_all(True)
        vbox.pack_start(self.video, False, False)

        # ----------------------------

        self.joystick_hbox = gtk.HBox(False, 5)
        vbox.pack_start(self.joystick_hbox, False, False)

        joystick_image = gtk.Image()
        joystick_image.set_from_file(self.img_path + "joystick.svg")
        self.joystick_hbox.pack_start(joystick_image, False, False)
        mini_joystick_vbox = gtk.VBox(False, 0)
        mini_joystick_vbox.pack_start(gtk.Label("Joystick detected:"), False, False)
        self.joystick_name_label = gtk.Label("")
        mini_joystick_vbox.pack_start(self.joystick_name_label, False, False)
        self.joystick_hbox.pack_start(mini_joystick_vbox, False, False)

        self.joystick_hbox.set_no_show_all(True)

        # ----------------------------
        control_hbox = gtk.HBox(False, 5)
        vbox.pack_start(control_hbox, False, False)
        control_hbox.pack_start(gtk.Label("Launcher ID:"), False, False)

        myadj = gtk.Adjustment(1, 0, 16, 1)
        self.laucher_id = gtk.SpinButton(myadj, 0, 0)
        self.laucher_id.set_numeric(True)
        self.laucher_id.connect("value-changed", self.cb_select_new_launcher)
        control_hbox.pack_start(self.laucher_id, False, False)

        self.limit_override = gtk.CheckButton("Override Limits")
        self.limit_override.connect("toggled", self.cb_limit_override)
        control_hbox.pack_end(self.limit_override, True, False)

        main_hbox = gtk.HBox(True, 5)
        vbox.pack_start(main_hbox, False, False)

        for button in self.button_array[:4]:
            main_hbox.pack_start(button, True, True)

        charging_options_hbox = gtk.HBox(False, 5)
        vbox.pack_start(charging_options_hbox, False, False)

        self.button_array[4].set_tooltip_text("Let 'er rip!")
        charging_options_hbox.pack_start(self.button_array[4], False, False)

        sub_vbox = gtk.VBox(False, 5)
        charging_options_hbox.pack_start(sub_vbox, True, True)

        charge_options = gtk.RadioButton(group=None, label="Charge Continuously")
        sub_vbox.pack_start(charge_options, False, False)

        charge_options = gtk.RadioButton(group=charge_options, label="Precharge (for sneak attacks)")
        sub_vbox.pack_start(charge_options, False, False)
        self.stop_charge = gtk.RadioButton(group=charge_options, label="Fire once")
        self.stop_charge.set_active(True)
        sub_vbox.pack_start(self.stop_charge, False, False)

        self.toggle_laser_button = gtk.Button("Toggle _Laser")
        self.toggle_laser_button.set_use_underline(True)
        button_image = gtk.Image()
        button_image.set_from_stock(gtk.STOCK_MEDIA_RECORD, gtk.ICON_SIZE_BUTTON)
        self.toggle_laser_button.set_image(button_image)
        vbox.pack_start(self.toggle_laser_button, False, False)

        self.status_bar = gtk.Statusbar()
        self.status_bar.set_has_resize_grip(False)
        vbox.pack_start(self.status_bar, False, False)

        self.window.show_all()

        self.connect_everything()
        self.cb_select_new_launcher(self.laucher_id)

        StatefulJoystick.__init__(self)

        self.status_message_index = 1
        self.last_message_id = None
        self.cycle_status_message()