示例#1
0
    def on_contextmenu_tag_location(self, widget, plugin_api):
        wTree = Gtk.glade.XML(self.glade_file, "TagLocation")
        dialog = wTree.get_widget("TagLocation")
        plugin_api.set_parent_window(dialog)

        btn_zoom_in = wTree.get_widget("btn_zoom_in")
        btn_zoom_out = wTree.get_widget("btn_zoom_out")
        vbox_map = wTree.get_widget("vbox_map")

        tag = plugin_api.get_tagpopup_tag()
        dialog.set_title(tag.get_attribute("name") + "'s Location")

        # get the tag's location
        try:
            tag_location = eval(tag.get_attribute("location"))
        except:
            tag_location = None

        # get the tag's color
        try:
            tag_color = self.HTMLColorToRGB(tag.get_attribute("color"))
        except:
            tag_color = None

        champlain_view = champlain.View()
        champlain_view.set_property("scroll-mode",
                                    champlain.SCROLL_MODE_KINETIC)

        layer = MarkerLayer()

        marker_tag = None
        if tag_location:
            marker_tag = layer.add_marker(tag.get_attribute("name"),
                                          tag_location[0], tag_location[1],
                                          tag_color)
        else:
            try:
                if self.location['longitude'] and self.location['latitude']:
                    marker_tag = layer.add_marker(tag.get_attribute("name"),
                                                  self.location['latitude'],
                                                  self.location['longitude'],
                                                  tag_color)
            except:
                marker_tag = layer.add_marker(tag.get_attribute("name"), None,
                                              None)

        champlain_view.add_layer(layer)

        embed = GtkClutter.Embed()
        embed.set_size_request(400, 300)

        champlain_view.set_reactive(True)
        champlain_view.connect("button-release-event",
                               self.champlain__tag_change_marker,
                               champlain_view, marker_tag)

        layer.show_all()

        if tag_location:
            champlain_view.set_property("zoom-level", 9)
        elif self.location:
            champlain_view.set_property("zoom-level", 5)
        else:
            champlain_view.set_property("zoom-level", 1)

        vbox_map.add(embed)

        embed.realize()
        stage = embed.get_stage()
        champlain_view.set_size(400, 300)
        stage.add(champlain_view)

        # connect the toolbar buttons for zoom
        btn_zoom_in.connect("clicked", self.zoom_in, champlain_view)
        btn_zoom_out.connect("clicked", self.zoom_out, champlain_view)
        dialog.connect("response", self.tag_location_close, tag, marker_tag)

        dialog.show_all()

        if tag_location:
            champlain_view.center_on(marker_tag.get_property('latitude'),
                                     marker_tag.get_property('longitude'))
        else:
            try:
                if self.location['longitude'] and self.location['latitude']:
                    champlain_view.center_on(self.location['latitude'],
                                             self.location['longitude'])
            except:
                pass
示例#2
0
    def on_contextmenu_tag_location(self, widget, plugin_api):
        wTree = gtk.glade.XML(self.glade_file, "TagLocation")
        dialog = wTree.get_widget("TagLocation")
        plugin_api.set_parent_window(dialog)

        btn_zoom_in = wTree.get_widget("btn_zoom_in")
        btn_zoom_out = wTree.get_widget("btn_zoom_out")
        vbox_map = wTree.get_widget("vbox_map")

        tag = plugin_api.get_tagpopup_tag()
        dialog.set_title(tag.get_attribute("name") + "'s Location")

        # get the tag's location
        try:
            tag_location = eval(tag.get_attribute("location"))
        except:
            tag_location = None

        # get the tag's color
        try:
            tag_color = self.HTMLColorToRGB(tag.get_attribute("color"))
        except:
            tag_color = None

        champlain_view = champlain.View()
        champlain_view.set_property("scroll-mode",
                                    champlain.SCROLL_MODE_KINETIC)

        layer = MarkerLayer()

        marker_tag = None
        if tag_location:
            marker_tag = layer.add_marker(tag.get_attribute("name"),
                                          tag_location[0], tag_location[1],
                                          tag_color)
        else:
            try:
                if self.location['longitude'] and self.location['latitude']:
                    marker_tag = layer.add_marker(tag.get_attribute("name"),
                                                  self.location['latitude'],
                                                  self.location['longitude'],
                                                  tag_color)
            except:
                marker_tag = layer.add_marker(tag.get_attribute("name"),
                                              None, None)

        champlain_view.add_layer(layer)

        embed = cluttergtk.Embed()
        embed.set_size_request(400, 300)

        champlain_view.set_reactive(True)
        champlain_view.connect("button-release-event",
                               self.champlain__tag_change_marker,
                               champlain_view, marker_tag)

        layer.show_all()

        if tag_location:
            champlain_view.set_property("zoom-level", 9)
        elif self.location:
            champlain_view.set_property("zoom-level", 5)
        else:
            champlain_view.set_property("zoom-level", 1)

        vbox_map.add(embed)

        embed.realize()
        stage = embed.get_stage()
        champlain_view.set_size(400, 300)
        stage.add(champlain_view)

        # connect the toolbar buttons for zoom
        btn_zoom_in.connect("clicked", self.zoom_in, champlain_view)
        btn_zoom_out.connect("clicked", self.zoom_out, champlain_view)
        dialog.connect("response", self.tag_location_close, tag, marker_tag)

        dialog.show_all()

        if tag_location:
            champlain_view.center_on(
                marker_tag.get_property('latitude'),
                marker_tag.get_property('longitude'))
        else:
            try:
                if self.location['longitude'] and self.location['latitude']:
                    champlain_view.center_on(self.location['latitude'],
                                             self.location['longitude'])
            except:
                pass
示例#3
0
    def set_task_location(self, widget, plugin_api, location=None):
        wTree = Gtk.glade.XML(self.glade_file, "SetTaskLocation")
        dialog = wTree.get_widget("SetTaskLocation")
        plugin_api.set_parent_window(dialog)

        btn_zoom_in = wTree.get_widget("btn_zoom_in")
        btn_zoom_out = wTree.get_widget("btn_zoom_out")

        dialog_action_area_btn = wTree.get_widget("dialog_action_area_btn")
        btn_ok = wTree.get_widget("btn_ok")
        btn_cancel = wTree.get_widget("btn_cancel")
        btn_close = wTree.get_widget("btn_close")

        self.radiobutton1 = wTree.get_widget("radiobutton1")
        self.radiobutton2 = wTree.get_widget("radiobutton2")
        self.txt_new_tag = wTree.get_widget("txt_new_tag")
        self.cmb_existing_tag = wTree.get_widget("cmb_existing_tag")

        tabela = wTree.get_widget("tabela_set_task")

        vbox_map = wTree.get_widget("vbox_map")
        vbox_opt = wTree.get_widget("vbox_opt")

        champlain_view = champlain.View()
        champlain_view.set_property("scroll-mode",
                                    champlain.SCROLL_MODE_KINETIC)
        # champlain_view.set_property("zoom-on-double-click", False)

        # create a list of the tags and their attributes
        tag_list = []
        for tag in plugin_api.get_tags():
            tmp_tag = {}
            for attr in tag.get_all_attributes():
                if attr == "color":
                    color = self.HTMLColorToRGB(tag.get_attribute(attr))
                    tmp_tag[attr] = color
                    tmp_tag['has_color'] = "yes"
                elif attr == "location":
                    tmp_tag[attr] = eval(tag.get_attribute(attr))
                else:
                    tmp_tag[attr] = tag.get_attribute(attr)
            tag_list.append(tmp_tag)

        # checks if there is one tag with a location
        task_has_location = False
        for tag in tag_list:
            for key, item in list(tag.items()):
                if key == "location":
                    task_has_location = True
                    break

        # set the markers
        layer = MarkerLayer()

        self.marker_list = []
        if task_has_location:
            for tag in tag_list:
                for key, item in list(tag.items()):
                    if key == "location":
                        color = None
                        try:
                            if tag['has_color'] == "yes":
                                color = tag['color']
                        except:
                            # PROBLEM: the tag doesn't have color
                            # Possibility, use a color from another tag
                            pass

                        self.marker_list.append(
                            layer.add_marker(plugin_api.get_task_title(),
                                             tag['location'][0],
                                             tag['location'][1], color))
        else:
            try:
                if self.location['longitude'] and self.location['latitude']:
                    self.marker_list.append(
                        layer.add_marker(plugin_api.get_task_title(),
                                         self.location['latitude'],
                                         self.location['longitude']))
            except:
                self.marker_list.append(
                    layer.add_marker(plugin_api.get_task_title(), None, None))

        champlain_view.add_layer(layer)

        embed = GtkClutter.Embed()
        embed.set_size_request(400, 300)

        if not task_has_location:
            # method that will change the marker's position
            champlain_view.set_reactive(True)
            champlain_view.connect("button-release-event",
                                   self.champlain_change_marker,
                                   champlain_view)

        layer.show_all()

        if task_has_location:
            champlain_view.set_property("zoom-level", 9)
        elif self.location:
            champlain_view.set_property("zoom-level", 5)
        else:
            champlain_view.set_property("zoom-level", 1)

        vbox_map.add(embed)

        embed.realize()
        stage = embed.get_stage()
        champlain_view.set_size(400, 300)
        stage.add(champlain_view)

        # connect the toolbar buttons for zoom
        btn_zoom_in.connect("clicked", self.zoom_in, champlain_view)
        btn_zoom_out.connect("clicked", self.zoom_out, champlain_view)

        if task_has_location:
            dialog_action_area_btn.remove(btn_ok)
            dialog_action_area_btn.remove(btn_cancel)
            dialog.connect("response", self.task_location_close)
        else:
            dialog_action_area_btn.remove(btn_close)
            # show a close button or the ok/cancel
            dialog.connect("response", self.set_task_location_close,
                           plugin_api)

        # if there is no location set, we want to set it
        if not task_has_location:
            self.location_defined = False
            if len(plugin_api.get_tags()) > 0:
                liststore = Gtk.ListStore(str)
                self.cmb_existing_tag.set_model(liststore)
                for tag in plugin_api.get_tags():
                    liststore.append([tag.get_attribute("name")])
                self.cmb_existing_tag.set_text_column(0)
                self.cmb_existing_tag.set_active(0)
            else:
                # remove radiobutton2 and the comboboxentry
                tabela.remove(self.radiobutton1)
                tabela.remove(self.radiobutton2)
                tabela.remove(self.cmb_existing_tag)
                label = Gtk.Label()
                label.set_text("Associate with new tag: ")
                tabela.attach(label, 0, 1, 0, 1)
                label.show()
        else:
            self.location_defined = True
            vbox_opt.remove(tabela)
            dialog.set_title("View the task's location")

        dialog.show_all()

        if task_has_location:
            champlain_view.center_on(
                self.marker_list[0].get_property('latitude'),
                self.marker_list[0].get_property('longitude'))
        else:
            try:
                if self.location['longitude'] and self.location['latitude']:
                    champlain_view.center_on(self.location['latitude'],
                                             self.location['longitude'])
            except:
                pass
示例#4
0
    def set_task_location(self, widget, plugin_api, location=None):
        wTree = gtk.glade.XML(self.glade_file, "SetTaskLocation")
        dialog = wTree.get_widget("SetTaskLocation")
        plugin_api.set_parent_window(dialog)

        btn_zoom_in = wTree.get_widget("btn_zoom_in")
        btn_zoom_out = wTree.get_widget("btn_zoom_out")

        dialog_action_area_btn = wTree.get_widget("dialog_action_area_btn")
        btn_ok = wTree.get_widget("btn_ok")
        btn_cancel = wTree.get_widget("btn_cancel")
        btn_close = wTree.get_widget("btn_close")

        self.radiobutton1 = wTree.get_widget("radiobutton1")
        self.radiobutton2 = wTree.get_widget("radiobutton2")
        self.txt_new_tag = wTree.get_widget("txt_new_tag")
        self.cmb_existing_tag = wTree.get_widget("cmb_existing_tag")

        tabela = wTree.get_widget("tabela_set_task")

        vbox_map = wTree.get_widget("vbox_map")
        vbox_opt = wTree.get_widget("vbox_opt")

        champlain_view = champlain.View()
        champlain_view.set_property("scroll-mode",
                                    champlain.SCROLL_MODE_KINETIC)
        # champlain_view.set_property("zoom-on-double-click", False)

        # create a list of the tags and their attributes
        tag_list = []
        for tag in plugin_api.get_tags():
            tmp_tag = {}
            for attr in tag.get_all_attributes():
                if attr == "color":
                    color = self.HTMLColorToRGB(tag.get_attribute(attr))
                    tmp_tag[attr] = color
                    tmp_tag['has_color'] = "yes"
                elif attr == "location":
                    tmp_tag[attr] = eval(tag.get_attribute(attr))
                else:
                    tmp_tag[attr] = tag.get_attribute(attr)
            tag_list.append(tmp_tag)

        # checks if there is one tag with a location
        task_has_location = False
        for tag in tag_list:
            for key, item in tag.items():
                if key == "location":
                    task_has_location = True
                    break

        # set the markers
        layer = MarkerLayer()

        self.marker_list = []
        if task_has_location:
            for tag in tag_list:
                for key, item in tag.items():
                    if key == "location":
                        color = None
                        try:
                            if tag['has_color'] == "yes":
                                color = tag['color']
                        except:
                            # PROBLEM: the tag doesn't have color
                            # Possibility, use a color from another tag
                            pass

                        self.marker_list.append(layer.add_marker(
                            plugin_api.get_task_title(), tag['location'][0],
                            tag['location'][1], color))
        else:
            try:
                if self.location['longitude'] and self.location['latitude']:
                    self.marker_list.append(layer.add_marker(
                        plugin_api.get_task_title(),
                        self.location['latitude'],
                        self.location['longitude']))
            except:
                self.marker_list.append(layer.add_marker(
                    plugin_api.get_task_title(), None, None))

        champlain_view.add_layer(layer)

        embed = cluttergtk.Embed()
        embed.set_size_request(400, 300)

        if not task_has_location:
            # method that will change the marker's position
            champlain_view.set_reactive(True)
            champlain_view.connect("button-release-event",
                                   self.champlain_change_marker,
                                   champlain_view)

        layer.show_all()

        if task_has_location:
            champlain_view.set_property("zoom-level", 9)
        elif self.location:
            champlain_view.set_property("zoom-level", 5)
        else:
            champlain_view.set_property("zoom-level", 1)

        vbox_map.add(embed)

        embed.realize()
        stage = embed.get_stage()
        champlain_view.set_size(400, 300)
        stage.add(champlain_view)

        # connect the toolbar buttons for zoom
        btn_zoom_in.connect("clicked", self.zoom_in, champlain_view)
        btn_zoom_out.connect("clicked", self.zoom_out, champlain_view)

        if task_has_location:
            dialog_action_area_btn.remove(btn_ok)
            dialog_action_area_btn.remove(btn_cancel)
            dialog.connect("response", self.task_location_close)
        else:
            dialog_action_area_btn.remove(btn_close)
            # show a close button or the ok/cancel
            dialog.connect("response", self.set_task_location_close,
                           plugin_api)

        # if there is no location set, we want to set it
        if not task_has_location:
            self.location_defined = False
            if len(plugin_api.get_tags()) > 0:
                liststore = gtk.ListStore(str)
                self.cmb_existing_tag.set_model(liststore)
                for tag in plugin_api.get_tags():
                    liststore.append([tag.get_attribute("name")])
                self.cmb_existing_tag.set_text_column(0)
                self.cmb_existing_tag.set_active(0)
            else:
                # remove radiobutton2 and the comboboxentry
                tabela.remove(self.radiobutton1)
                tabela.remove(self.radiobutton2)
                tabela.remove(self.cmb_existing_tag)
                label = gtk.Label()
                label.set_text("Associate with new tag: ")
                tabela.attach(label, 0, 1, 0, 1)
                label.show()
        else:
            self.location_defined = True
            vbox_opt.remove(tabela)
            dialog.set_title("View the task's location")

        dialog.show_all()

        if task_has_location:
            champlain_view.center_on(
                self.marker_list[0].get_property('latitude'),
                self.marker_list[0].get_property('longitude'))
        else:
            try:
                if self.location['longitude'] and self.location['latitude']:
                    champlain_view.center_on(self.location['latitude'],
                                             self.location['longitude'])
            except:
                pass