예제 #1
0
    def _show_tool_romans(self, caller, data=None):
        dialog = gtk.Dialog("Roman Numbers", self.window,
                            gtk.DIALOG_DESTROY_WITH_PARENT, ())
        #dialog.set_size_request(800, 480)

        source = hildon.Entry(gtk.HILDON_SIZE_AUTO)
        source.set_property("hildon-input-mode",
                            gtk.HILDON_GTK_INPUT_MODE_NUMERIC)
        dialog.vbox.pack_start(hildon.Caption(None, "Arabic", source, None, 0))
        destination = hildon.Entry(gtk.HILDON_SIZE_AUTO)
        dialog.vbox.pack_start(
            hildon.Caption(None, "Roman", destination, None, 0))

        inhibit = [False]

        def to_roman(widget):
            if inhibit[0] == True:
                return
            try:
                text = HildonToolsDialog._int_to_roman(int(source.get_text()))
            except ValueError:
                text = ''
            inhibit[0] = True
            destination.set_text(text)
            inhibit[0] = False

        def to_arabic(widget):
            if inhibit[0] == True:
                return
            try:
                text = str(
                    HildonToolsDialog._roman_to_int(destination.get_text()))
            except ValueError:
                text = ''
            inhibit[0] = True
            source.set_text(text)
            inhibit[0] = False

        source.connect('changed', to_roman)
        destination.connect('changed', to_arabic)

        dialog.show_all()
        dialog.run()
        dialog.hide()
예제 #2
0
    def _show_tool_heading(self, caller, data=None):
        RESULT_WPT, RESULT_TARGET = range(2)
        dialog = gtk.Dialog("Coordinate Projection", self.window,
                            gtk.DIALOG_DESTROY_WITH_PARENT,
                            ("as target", RESULT_TARGET))
        if self.current_cache != None:
            dialog.add_button("add waypoint", RESULT_WPT)
        #dialog.set_size_request(800, 480)

        def select_origin(widget, data=None):
            start = self._get_best_coordinate(
            ) if origin[0] == None else origin[0]
            new = self._show_target_input_list(start, show_current=True)
            if new != None:
                origin[0] = new
                text = new.get_latlon()
                button.set_value(text)
                recalc(None)

        button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
                               hildon.BUTTON_ARRANGEMENT_VERTICAL)
        button.set_title("Select Origin")
        button.set_value("current Target")
        button.connect("clicked", select_origin, None)
        dialog.vbox.pack_start(button)

        origin = [self.core.current_target]

        direction = hildon.Entry(gtk.HILDON_SIZE_AUTO)
        direction.set_property("hildon-input-mode",
                               gtk.HILDON_GTK_INPUT_MODE_NUMERIC)

        dialog.vbox.pack_start(
            hildon.Caption(None, "Heading in Degrees", direction, None, 0))

        distance = hildon.Entry(gtk.HILDON_SIZE_AUTO)
        distance.set_property("hildon-input-mode",
                              gtk.HILDON_GTK_INPUT_MODE_NUMERIC)
        dialog.vbox.pack_start(
            hildon.Caption(None, "Distance in Meters", distance, None, 0))

        result = gtk.Label()
        dialog.vbox.pack_start(
            hildon.Caption(None, "Resulting Point", result, None, 0))

        resulting_coordinate = [None]

        def recalc(widget):
            try:
                res = origin[0].transform(-float(direction.get_text()),
                                          float(distance.get_text()))
                text = res.get_latlon()
            except Exception:
                res = None
                text = 'enter values...'
            resulting_coordinate[0] = res
            result.set_text(text)

        direction.connect('changed', recalc)
        distance.connect('changed', recalc)

        dialog.show_all()
        res = dialog.run()
        dialog.hide()
        if res == RESULT_WPT:
            if resulting_coordinate[0] == None:
                return
            distance = resulting_coordinate[0].format_distance(
                float(distance.get_text()))
            heading = int(direction.get_text())
            name = "hdg %s, %d deg from %s" % (distance, heading,
                                               origin[0].get_latlon())
            self.current_cache.get_user_coordinates(None)
            self.current_cache.set_user_coordinate(
                geocaching.GeocacheCoordinate.USER_TYPE_COORDINATE,
                (resulting_coordinate[0].lat, resulting_coordinate[0].lon),
                name)
            self.core.save_cache_attribute(self.current_cache,
                                           'user_coordinates')
            self._on_cache_changed(None, self.current_cache)

        elif res == RESULT_TARGET:
            if resulting_coordinate[0] == None:
                return
            self.set_target(resulting_coordinate[0])
예제 #3
0
    def _on_show_search(self, widget, data):

        name = hildon.Entry(gtk.HILDON_SIZE_AUTO_WIDTH
                            | gtk.HILDON_SIZE_FINGER_HEIGHT)
        name.set_placeholder("search for name...")
        name_hbox = hildon.Caption(None, "Name", name, None,
                                   hildon.CAPTION_OPTIONAL)

        sel_dist_type = hildon.TouchSelector(text=True)
        sel_dist_type.append_text('anywhere')
        sel_dist_type.append_text('around my position')
        sel_dist_type.append_text('around the current map center')
        pick_dist_type = hildon.PickerButton(
            gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
            hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
        pick_dist_type.set_selector(sel_dist_type)
        pick_dist_type.set_title("Search")
        sel_dist_type.select_iter(0,
                                  sel_dist_type.get_model(0).get_iter(1),
                                  False)

        list_dist_radius = (1, 5, 10, 20, 50, 100, 200)
        sel_dist_radius = hildon.TouchSelector(text=True)
        for x in list_dist_radius:
            sel_dist_radius.append_text('%d km' % x)
        pick_dist_radius = hildon.PickerButton(
            gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
            hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
        pick_dist_radius.set_selector(sel_dist_radius)
        pick_dist_radius.set_title("Radius")
        pick_dist_type.connect(
            'value-changed', lambda caller: pick_dist_radius.set_sensitive(
                sel_dist_type.get_selected_rows(0)[0][0] != 0))
        sel_dist_radius.select_iter(0,
                                    sel_dist_radius.get_model(0).get_iter(1),
                                    False)

        sel_size = hildon.TouchSelector(text=True)
        sel_size.append_text('micro')
        sel_size.append_text('small')
        sel_size.append_text('regular')
        sel_size.append_text('huge')
        sel_size.append_text('other')
        sel_size.set_column_selection_mode(
            hildon.TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)
        pick_size = hildon.PickerButton(
            gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
            hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
        pick_size.set_selector(sel_size)
        pick_size.set_title("Select Size(s)")
        for i in xrange(5):
            sel_size.select_iter(0, sel_size.get_model(0).get_iter(i), False)

        sel_type = hildon.TouchSelector(text=True)
        sel_type.append_text('traditional')
        sel_type.append_text('multi-stage')
        sel_type.append_text('virtual')
        sel_type.append_text('earth')
        sel_type.append_text('event')
        sel_type.append_text('mystery')
        sel_type.append_text('all')
        sel_type.set_column_selection_mode(
            hildon.TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)
        pick_type = hildon.PickerButton(
            gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
            hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
        pick_type.set_selector(sel_type)
        pick_type.set_title("Select Type(s)")
        sel_type.unselect_all(0)
        sel_type.select_iter(0, sel_type.get_model(0).get_iter(6), False)

        sel_status = hildon.TouchSelector(text=True)
        sel_status.append_text('any')
        sel_status.append_text("Geocaches I haven't found")
        sel_status.append_text("Geocaches I have found")
        sel_status.append_text("Marked Geocaches")
        sel_status.append_text("Marked Geocaches I haven't found")
        pick_status = hildon.PickerButton(
            gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
            hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
        pick_status.set_selector(sel_status)
        pick_status.set_title("Select Status")

        sel_status.unselect_all(0)
        sel_status.select_iter(0, sel_status.get_model(0).get_iter(0), False)

        sel_diff = hildon.TouchSelector(text=True)
        sel_diff.append_text('1..2.5')
        sel_diff.append_text('3..4')
        sel_diff.append_text('4.5..5')
        sel_diff.set_column_selection_mode(
            hildon.TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)
        pick_diff = hildon.PickerButton(
            gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
            hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
        pick_diff.set_selector(sel_diff)
        pick_diff.set_title("Select Difficulty")
        for i in xrange(3):
            sel_diff.select_iter(0, sel_diff.get_model(0).get_iter(i), False)

        sel_terr = hildon.TouchSelector(text=True)
        sel_terr.append_text('1..2.5')
        sel_terr.append_text('3..4')
        sel_terr.append_text('4.5..5')
        sel_terr.set_column_selection_mode(
            hildon.TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE)
        pick_terr = hildon.PickerButton(
            gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
            hildon.BUTTON_ARRANGEMENT_HORIZONTAL)
        pick_terr.set_selector(sel_terr)
        pick_terr.set_title("Select Terrain")
        for i in xrange(3):
            sel_terr.select_iter(0, sel_terr.get_model(0).get_iter(i), False)

        RESPONSE_SHOW_LIST, RESPONSE_RESET, RESPONSE_LAST_RESULTS = range(3)
        dialog = gtk.Dialog("Search", self.window,
                            gtk.DIALOG_DESTROY_WITH_PARENT,
                            ("OK", RESPONSE_SHOW_LIST))
        dialog.add_button("Filter Map", gtk.RESPONSE_ACCEPT)
        if self.map_filter_active:
            dialog.add_button("Reset Filter", RESPONSE_RESET)
        if self.old_search_window != None:
            dialog.add_button("Last Results", RESPONSE_LAST_RESULTS)
        dialog.set_size_request(800, 800)
        pan = hildon.PannableArea()
        options = gtk.VBox()
        pan.add_with_viewport(options)
        dialog.vbox.pack_start(pan)

        options.pack_start(gtk.Label("Search Geocaches"))
        options.pack_start(name_hbox)
        options.pack_start(pick_dist_type)
        options.pack_start(pick_dist_radius)
        options.pack_start(pick_type)
        options.pack_start(pick_status)

        options.pack_start(gtk.Label("Details..."))
        w = gtk.Label(
            "If you select something here, only geocaches for which details were downloaded will be shown in the result."
        )
        w.set_line_wrap(True)
        w.set_alignment(0, 0.5)
        options.pack_start(w)

        options.pack_start(pick_size)
        options.pack_start(pick_diff)
        options.pack_start(pick_terr)

        while True:
            dialog.show_all()
            response = dialog.run()
            dialog.hide()

            if response == RESPONSE_RESET:
                self.core.reset_filter()
                self.map_filter_active = False
                self.show_success("Showing all geocaches.")
                return
            elif response == RESPONSE_LAST_RESULTS:
                if self.old_search_window == None:
                    return
                hildon.WindowStack.get_default().push_1(self.old_search_window)

                return

            name_search = name.get_text().strip().lower()

            sizes = [x + 1 for x, in sel_size.get_selected_rows(0)]
            if sizes == [1, 2, 3, 4, 5]:
                sizes = None

            typelist = [
                geocaching.GeocacheCoordinate.TYPE_REGULAR,
                geocaching.GeocacheCoordinate.TYPE_MULTI,
                geocaching.GeocacheCoordinate.TYPE_VIRTUAL,
                geocaching.GeocacheCoordinate.TYPE_EARTH,
                geocaching.GeocacheCoordinate.TYPE_EVENT,
                geocaching.GeocacheCoordinate.TYPE_MYSTERY,
                geocaching.GeocacheCoordinate.TYPE_UNKNOWN
            ]

            types = [typelist[x] for x, in sel_type.get_selected_rows(0)]
            if geocaching.GeocacheCoordinate.TYPE_UNKNOWN in types:
                types = None

            # found, marked
            statuslist = [
                (None, None),
                (False, None),
                (True, None),
                (None, True),
                (False, True),
            ]
            found, marked = statuslist[sel_status.get_selected_rows(0)[0][0]]

            numberlist = [[1, 1.5, 2, 2.5], [3, 3.5, 4], [4.5, 5]]

            difficulties = []
            count = 0
            for x, in sel_diff.get_selected_rows(0):
                difficulties += numberlist[x]
                count += 1
            if count == len(numberlist):
                difficulties = None

            terrains = []
            count = 0
            for x, in sel_terr.get_selected_rows(0):
                terrains += numberlist[x]
                count += 1
            if count == len(numberlist):
                terrains = None

            center = None
            dist_type = sel_dist_type.get_selected_rows(0)[0][0]
            if dist_type == 1:
                try:
                    center = self.gps_last_good_fix.position
                except AttributeError:
                    logger.debug("No current Fix.")
                    pass
            elif dist_type == 2:
                center = self.map.get_center()
            if center != None:
                radius = list_dist_radius[sel_dist_radius.get_selected_rows(0)
                                          [0][0]]
                sqrt_2 = 1.41421356
                c1 = center.transform(-45, radius * 1000 * sqrt_2)
                c2 = center.transform(-45 + 180, radius * 1000 * sqrt_2)
                location = (c1, c2)
            else:
                location = None

            if response == RESPONSE_SHOW_LIST:
                points, truncated = self.core.get_points_filter(
                    found=found,
                    name_search=name_search,
                    size=sizes,
                    terrain=terrains,
                    diff=difficulties,
                    ctype=types,
                    marked=marked,
                    location=location)
                if len(points) > 0:
                    self._display_results(points, truncated)
                    break
                else:
                    self.show_error(
                        "Search returned no geocaches. Please remember that search works only within the downloaded geocaches."
                    )

            elif response == gtk.RESPONSE_ACCEPT:
                self.core.set_filter(found=found,
                                     name_search=name_search,
                                     size=sizes,
                                     terrain=terrains,
                                     diff=difficulties,
                                     ctype=types,
                                     marked=marked)
                self.show_success(
                    "Filter for map activated, ignoring distance restrictions."
                )
                self.map_filter_active = True
                break
            else:
                break
예제 #4
0
 def test_constructor(self):
     b = gtk.Button("Button")
     c = hildon.Caption(None, "Caption", b, None, hildon.CAPTION_OPTIONAL)
     self.assertTrue(isinstance(c, hildon.Caption))