예제 #1
0
 def create_menu_structure(self):
     base_subdir = self.app_directory.rstrip('/')
     for subdir_path in self.subdir_paths:
         self.subdir_menu_contents[subdir_path] = []
     for subdir_path in self.subdir_paths:
         if subdir_path == base_subdir:
             continue
         parent_path = os.path.split(subdir_path)[0]
         menu_name = self.get_subdir_menu_name(subdir_path)
         subdir_entry = Entry(menu_name, type="dir", path=subdir_path)
         self.subdir_menu_contents[parent_path].append(subdir_entry)
     subdir_menu_paths = self.subdir_menu_contents.keys()
     for app_path, app_obj in self.app_list.items():
         if self.app_has_callback(app_obj):
             subdir_menu_name = max(
                 [n for n in subdir_menu_paths if app_path.startswith(n)])
             menu_name = self.get_app_name(app_obj, app_path)
             app_entry = Entry(menu_name,
                               type="app",
                               obj=app_obj,
                               path=app_path)
             self.subdir_menu_contents[subdir_menu_name].append(app_entry)
     for path, subdir_contents in self.subdir_menu_contents.items():
         ordering = self.get_ordering(path)
         unordered_contents = self.prepare_menu_contents_for_ordering(
             subdir_contents)
         menu_contents = self.order_contents_by_ordering(
             unordered_contents, ordering)
         creator = self.subdir_menu_creators.get(path,
                                                 self.create_subdir_menu)
         menu = creator(path, menu_contents)
         for overlay_cb in self.subdir_menu_overlays.get(path, []):
             overlay_cb(menu)
         self.subdir_menus[path] = menu
     return self.subdir_menus[base_subdir]
예제 #2
0
    def __init__(self, **kwargs):
        Renderer.__init__(self, **kwargs)
        self.label = Label(padding=self.padding,
                           overflow=pango.EllipsizeMode.END)
        self.label.graphics = self.graphics
        self._prev_dict = {}

        self._editor = Entry()
예제 #3
0
 def test_shows_data_on_screen_with_entries(self):
     """Tests whether the Listbox outputs data on screen when it's ran - using entries"""
     num_elements = 3
     contents = [
         Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements)
     ]
     self.shows_data_on_screen_runner(contents)
예제 #4
0
 def test_returns_on_enter_entry(self):
     num_elements = 3
     contents = [
         Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements)
     ]
     self.returns_on_enter_runner(contents, num_elements, contents[0].name,
                                  contents[-1].name)
예제 #5
0
 def test_selected_entry(self):
     num_elements = 3
     contents = [
         Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements)
     ]
     selected = contents[1].name
     self.selected_runner(contents, selected)
예제 #6
0
파일: test_menu.py 프로젝트: hpagseddy/ZPUI
 def test_graphical_display_entry_eh2_redraw(self):
     num_elements = 3
     contents = [
         Entry(["A" + str(i), "B" + str(i)], name="a" + str(i))
         for i in range(num_elements)
     ]
     self.graphical_display_redraw_eh2_wrapper(contents)
예제 #7
0
    def __init__(self, **kwargs):
        Renderer.__init__(self, **kwargs)
        self.label = Label(padding=self.padding, overflow=pango.EllipsizeMode.END)
        self.label.graphics = self.graphics
        self._prev_dict = {}

        self._editor = Entry()
예제 #8
0
파일: test_menu.py 프로젝트: hpagseddy/ZPUI
 def test_entry_callback_is_executed(self):
     num_elements = 2
     contents = [Entry("A" + str(i)) for i in range(num_elements)]
     cb1 = Mock()
     cb2 = Mock()
     contents[0].cb = cb1
     contents[1].cb = cb2
     self.callback_is_executed_wrapper(contents, cb1, cb2)
예제 #9
0
	def on_start(self):
		dir = "resources/"
                icons = [f for f in os.listdir(dir) if f.endswith(".png")]
                icon_paths = [[f, os.path.join(dir, f)] for f in icons]
		grid_contents = [Entry(f.rsplit('.', 1)[0].capitalize(), icon=Image.open(p), cb=lambda x=f: test_func(x)) \
                                   for f,p in icon_paths]

		self.gm = GridMenu(grid_contents, self.i, self.o, entry_width=32, draw_lines=False)
                self.overlay1 = GridMenuLabelOverlay()
                self.overlay1.apply_to(self.gm)
                self.overlay2 = GridMenuSidebarOverlay(self.sidebar_cb)
                self.overlay2.apply_to(self.gm)
		self.gm.activate()
예제 #10
0
파일: main.py 프로젝트: hpagseddy/ZPUI
def get_scan_results_contents():
    network_menu_contents = []
    networks = wpa_cli.get_scan_results()
    for network in networks:
        if network["ssid"] == '':
            ui_ssid = '[Hidden]'
        else:
            ui_ssid = network["ssid"]
        network_cache = wpa_cli.list_configured_networks()
        network_names = [n["ssid"] for n in network_cache]
        network_is_known = network["ssid"] in network_names
        network_is_secured = False if wpa_cli.is_open_network(
            network) else True
        network["known"] = network_is_known
        network["secured"] = network_is_secured
        cb = lambda x=network: network_info_menu(x)
        network_menu_contents.append(Entry(ui_ssid, cb=cb, \
                                           network_secured=network_is_secured, \
                                           network_known=network_is_known
                                           ))
    return network_menu_contents
예제 #11
0
 def test_entering_value_with_entries_no_name(self):
     contents = [Entry(x) for x in ("1", "3", "2")]
     self.entering_value_runner(contents)
예제 #12
0
class LabelRenderer(Renderer):
    padding = 5
    expand = True

    color = "#333"  #: font color
    color_current = "#fff"  #: font color when the row is selected

    color_disabled = "#aaa"  #: color of the text when item is disabled
    color_disabled_current = "#fff"  #: selected row font color when item is disabled

    def __init__(self, **kwargs):
        Renderer.__init__(self, **kwargs)
        self.label = Label(padding=self.padding,
                           overflow=pango.EllipsizeMode.END)
        self.label.graphics = self.graphics
        self._prev_dict = {}

        self._editor = Entry()

    def __setattr__(self, name, val):
        Widget.__setattr__(self, name, val)
        if name.startswith("padding") and hasattr(self, "label"):
            setattr(self.label, name, val)

    def get_min_size(self, row):
        return max(self.min_width or 0,
                   10), max(self.min_height or 0,
                            self.label.vertical_padding + 15)

    def get_mouse_cursor(self):
        if self.editable:
            return gdk.CursorType.XTERM
        return False

    def show_editor(self, target, cell, event=None):
        if not self.editable:
            return

        self._target, self._cell = target, cell
        target.add_child(self._editor)

        self._editor.x, self._editor.y = cell['x'], cell['y']
        self._editor.alloc_w, self._editor.alloc_h = cell['width'], cell[
            'height']
        self._editor.text = cell['data']

        if event:
            event.x, event.y = self._editor.from_scene_coords(event.x, event.y)
            self._editor._Entry__on_mouse_down(self._editor, event)
        self._target = target
        self._editor.grab_focus()

    def hide_editor(self):
        if self._target:
            self._target.remove_child(self._editor)
            self._target.rows[self._cell['row']][
                self._cell['col']] = self._editor.text
            self._target = self._cell = None

    def set_data(self, data):
        # apply data to the renderer
        self._prev_dict = {}
        if isinstance(data, dict):
            for key, val in data.iteritems():
                self._prev_dict[key] = getattr(self.label, key,
                                               "")  #store original state
                setattr(self.label, key, val)
        else:
            self.label.text = data

    def restore_data(self):
        # restore renderer's data representation to the original state
        for key, val in self._prev_dict.iteritems():
            setattr(self.label, key, val)

    def render(self, context, w, h, data, state, enabled=True):
        self.label.alloc_w = w
        if enabled:
            self.label.color = self.color_current if state == "current" else self.color
        else:
            self.label.color = self.color_disabled_current if state == "current" else self.color_disabled

        context.save()
        context.translate((w - self.label.width) * self.x_align,
                          (h - self.label.height) * self.y_align)
        self.label._draw(context)
        context.restore()
예제 #13
0
class LabelRenderer(Renderer):
    padding = 5
    expand = True

    color = "#333"  #: font color
    color_current = "#fff"  #: font color when the row is selected

    color_disabled = "#aaa"  #: color of the text when item is disabled
    color_disabled_current = "#fff"  #: selected row font color when item is disabled

    def __init__(self, **kwargs):
        Renderer.__init__(self, **kwargs)
        self.label = Label(padding=self.padding, overflow=pango.EllipsizeMode.END)
        self.label.graphics = self.graphics
        self._prev_dict = {}

        self._editor = Entry()

    def __setattr__(self, name, val):
        Widget.__setattr__(self, name, val)
        if name.startswith("padding") and hasattr(self, "label"):
            setattr(self.label, name, val)

    def get_min_size(self, row):
        return max(self.min_width or 0, 10), max(self.min_height or 0, self.label.vertical_padding + 15)

    def get_mouse_cursor(self):
        if self.editable:
            return gdk.CursorType.XTERM
        return False

    def show_editor(self, target, cell, event=None):
        if not self.editable:
            return

        self._target, self._cell = target, cell
        target.add_child(self._editor)

        self._editor.x, self._editor.y = cell["x"], cell["y"]
        self._editor.alloc_w, self._editor.alloc_h = cell["width"], cell["height"]
        self._editor.text = cell["data"]

        if event:
            event.x, event.y = self._editor.from_scene_coords(event.x, event.y)
            self._editor._Entry__on_mouse_down(self._editor, event)
        self._target = target
        self._editor.grab_focus()

    def hide_editor(self):
        if self._target:
            self._target.remove_child(self._editor)
            self._target.rows[self._cell["row"]][self._cell["col"]] = self._editor.text
            self._target = self._cell = None

    def set_data(self, data):
        # apply data to the renderer
        self._prev_dict = {}
        if isinstance(data, dict):
            for key, val in data.iteritems():
                self._prev_dict[key] = getattr(self.label, key, "")  # store original state
                setattr(self.label, key, val)
        else:
            self.label.text = data

    def restore_data(self):
        # restore renderer's data representation to the original state
        for key, val in self._prev_dict.iteritems():
            setattr(self.label, key, val)

    def render(self, context, w, h, data, state, enabled=True):
        self.label.alloc_w = w
        if enabled:
            self.label.color = self.color_current if state == "current" else self.color
        else:
            self.label.color = self.color_disabled_current if state == "current" else self.color_disabled

        context.save()
        context.translate((w - self.label.width) * self.x_align, (h - self.label.height) * self.y_align)
        self.label._draw(context)
        context.restore()
예제 #14
0
 def test_entry_shows_data_on_screen(self):
     """Tests whether the BaseListUIElement outputs data on screen when it's ran"""
     num_elements = 3
     contents = [Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements)]
     self.shows_data_on_screen_runner(contents)
예제 #15
0
 def test_enter_on_last_returns_right_with_entries(self):
     num_elements = 3
     contents = [
         Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements)
     ]
     self.enter_on_last_returns_right_runner(contents, num_elements)
예제 #16
0
 def test_shows_entry_data_on_screen(self):
     """Tests whether the OrderAdjust outputs data on screen when it's ran"""
     o = get_mock_output()
     contents = [Entry(str(x)) for x in range(o.rows + 4)]
     self.shows_data_on_screen_wrapper(contents, o)
예제 #17
0
 def test_entering_value_with_entries(self):
     contents = [
         Entry("Entry {}".format(x), name=x) for x in ("1", "3", "2")
     ]
     self.entering_value_runner(contents)
예제 #18
0
 def test_selected_single_el_entry(self):
     num_elements = 3
     contents = [Entry("A" + str(i)) for i in range(num_elements)]
     selected = contents[1].text
     self.selected_single_el_entry_runner(contents, selected)
예제 #19
0
파일: main.py 프로젝트: hpagseddy/ZPUI
def callback():
    contents = [
        Entry("Hello1", cb=lambda: print("1")),
        Entry("Hello2", cb=lambda: print("2"), cb2=lambda: print("3"))
    ]
    Menu(contents, i, o, "Entry object test menu").activate()
예제 #20
0
 def test_graphical_display_redraw_with_entries(self):
     num_elements = 2
     contents = [
         Entry("A" + str(i), name="a" + str(i)) for i in range(num_elements)
     ]
     self.graphical_display_redraw_runner(contents)