Exemplo n.º 1
0
    def update(self):
        client = self.client
        dir = client.directory

        def filter(name):
            path = os.path.join(dir, name)
            return os.path.isdir(path) or self.client.filter(path)

        try:
            content = os.walk(dir)
            for a, dirnames, filenames in content:
                dirnames.sort()
                filenames.sort()
                break
            try:
                self.names = [unicode(name, 'utf-8') for name in dirnames + filenames if filter(name)]
            except:
                self.names = [name for name in dirnames + filenames if filter(name)]
        except EnvironmentError as e:
            alert(u"%s: %s" % (dir, e))
            self.names = []
        self.rows = [Row([Image(self.icons[os.path.isdir(os.path.join(dir, a))]),
                          Label(a, margin=0)], margin=0, spacing=2) for a in self.names]
        self.selected_item_index = None
        self.scroll_to_item(0)
Exemplo n.º 2
0
 def __init__(self, shell):
     Screen.__init__(self, shell)
     self.model = DemoControlsModel()
     width_field = FloatField(ref=AttrRef(self.model, 'width'))
     height_field = FloatField(ref=AttrRef(self.model, 'height'))
     area_display = ValueDisplay(ref=AttrRef(self.model, 'area'),
                                 format="%.2f")
     shape = AttrRef(self.model, 'shape')
     shape_choices = Row([
         RadioButton(setting='rectangle', ref=shape),
         Label("Rectangle"),
         RadioButton(setting='triangle', ref=shape),
         Label("Triangle"),
         RadioButton(setting='ellipse', ref=shape),
         Label("Ellipse"),
         ProgressBar(100, 50, ref=AttrRef(self.model, 'area')),
     ])
     grid = Grid([
         [Label("Width"), width_field],
         [Label("Height"), height_field],
         [Label("Shape"), shape_choices],
         [Label("Area"), area_display],
     ])
     back = Button("Menu", action=shell.show_menu)
     contents = Column([grid, back])
     self.add_centered(contents)
     width_field.focus()
Exemplo n.º 3
0
 def __init__(self, prompt=None, suffixes=None, **kwds):
     Dialog.__init__(self, **kwds)
     label = None
     d = self.margin
     self.suffixes = suffixes or ("", )
     up_button = Button(self.up_button_text, action=self.go_up)
     dir_box = DirPathView(self.box_width + 250, self)
     self.dir_box = dir_box
     top_row = Row([dir_box, up_button])
     list_box = FileListView(self.box_width - 16, self)
     self.list_box = list_box
     tree = FSTree(self, inner_width=250, directory='/')
     self.tree = tree
     row = Row((tree, list_box), margin=0)
     ctrls = [top_row, row]
     prompt = prompt or self.default_prompt
     if prompt:
         label = Label(prompt)
     if self.saving:
         filename_box = TextFieldWrapped(self.box_width)
         filename_box.change_action = self.update_filename
         filename_box._enter_action = filename_box.enter_action
         filename_box.enter_action = self.enter_action
         self.filename_box = filename_box
         ctrls.append(Column([label, filename_box], align='l', spacing=0))
     else:
         if label:
             ctrls.insert(0, label)
     ok_button = Button(self.ok_label,
                        action=self.ok,
                        enable=self.ok_enable)
     self.ok_button = ok_button
     cancel_button = Button("Cancel", action=self.cancel)
     vbox = Column(ctrls, align='l', spacing=d)
     vbox.topleft = (d, d)
     y = vbox.bottom + d
     ok_button.topleft = (vbox.left, y)
     cancel_button.topright = (vbox.right, y)
     self.add(vbox)
     self.add(ok_button)
     self.add(cancel_button)
     self.shrink_wrap()
     self._directory = None
     self.directory = os.getcwdu()
     #print "FileDialog: cwd =", repr(self.directory) ###
     if self.saving:
         filename_box.focus()
Exemplo n.º 4
0
class FileListView(ScrollPanel):
    def __init__(self, width, client, **kwds):
        font = self.predict_font(kwds)
        h = font.get_linesize()
        d = 2 * self.predict(kwds, 'margin')
        kwds['align'] = kwds.get('align', 'l')
        ScrollPanel.__init__(self, inner_width=width, **kwds)
        self.icons = {
            True: scale(folder_image, (self.row_height, self.row_height)),
            False: scale(file_image, (self.row_height, self.row_height))
        }
        self.client = client
        self.names = []

    def update(self):
        client = self.client
        dir = client.directory

        def filter(name):
            path = os.path.join(dir, name)
            return os.path.isdir(path) or self.client.filter(path)

        try:
            content = os.walk(dir)
            for a, dirnames, filenames in content:
                dirnames.sort()
                filenames.sort()
                break
            try:
                self.names = [
                    unicode(name, 'utf-8') for name in dirnames + filenames
                    if filter(name)
                ]
            except:
                self.names = [
                    name for name in dirnames + filenames if filter(name)
                ]
        except EnvironmentError, e:
            alert(u"%s: %s" % (dir, e))
            self.names = []
        self.rows = [
            Row([
                Image(self.icons[os.path.isdir(os.path.join(dir, a))]),
                Label(a, margin=0)
            ],
                margin=0,
                spacing=2) for a in self.names
        ]
        self.selected_item_index = None
        self.scroll_to_item(0)
Exemplo n.º 5
0
    def __init__(self, current_tick_time=0, **kwds):
        super(TimeEditor, self).__init__(**kwds)

        self._current_tick_time = current_tick_time
        self._current_time = self.fromTicks(self.doTimeAdjustment(self._current_tick_time))

        self.__original_value = current_tick_time
        self.__original_time = self._current_time

        self.last_pos = (None, None)

        self.day_input = IntField(value=self.__original_time[0], min=1)

        __deg = self.ticksToDegrees(current_tick_time)

        self.rot_image = RotatableImage(
            image=pygame.image.load(directories.getDataFile("toolicons", "day_night_cycle.png")),
            min_angle=-self._maxRotation,
            max_angle=0,
            angle=__deg
        )
        self.rot_image.mouse_drag = self.mouse_drag
        self.rot_image.mouse_up = self.mouse_up
        self.rot_image.tooltipText = "Left-Click and drag to the left or the right"

        self.time_field = ModifiedTimeField(
            value=(self.__original_time[1], self.__original_time[2]),
            callback=self._timeFieldCallback
        )
        # __time_field_old_value = self.time_field.value
        self.add(Column((
            Row((Label("Day: "), self.day_input)),
            self.rot_image,
            Row((Label("Time of day:"), self.time_field))
        ))
        )
        self.shrink_wrap()
Exemplo n.º 6
0
    def __init__(self, editor):
        Panel.__init__(self, name='Panel.ControlPanel')
        self.editor = editor

        self.bg_color = (0, 0, 0, 0.8)

        header = self.getHeader()
        keysColumn = [Label("")]
        buttonsColumn = [header]

        hotkeys = ([
            (config.keys.newWorld.get(), "Create New World",
             editor.mcedit.createNewWorld),
            (config.keys.quickLoad.get(), "Quick Load", editor.askLoadWorld),
            (config.keys.open.get(), "Open...", editor.askOpenFile),
            (config.keys.save.get(), "Save", editor.saveFile),
            (config.keys.saveAs.get(), "Save As", editor.saveAs),
            (config.keys.reloadWorld.get(), "Reload", editor.reload),
            (config.keys.closeWorld.get(), "Close", editor.closeEditor),
            (config.keys.uploadWorld.get(), "Upload to FTP Server",
             editor.uploadChanges),
            (config.keys.gotoPanel.get(), "Waypoints/Goto",
             editor.showWaypointsDialog),
            (config.keys.worldInfo.get(), "World Info", editor.showWorldInfo),
            (config.keys.undo.get(), "Undo", editor.undo),
            (config.keys.redo.get(), "Redo", editor.redo),
            (config.keys.selectAll.get(), "Select All", editor.selectAll),
            (config.keys.deselect.get(), "Deselect", editor.deselect),
            (config.keys.viewDistance.get(),
             AttrRef(editor,
                     'viewDistanceLabelText'), editor.swapViewDistance),
            (config.keys.quit.get(), "Quit", editor.quit),
        ])

        buttons = HotkeyColumn(hotkeys,
                               keysColumn,
                               buttonsColumn,
                               item_spacing=2)

        sideColumn1 = editor.mcedit.makeSideColumn1()
        sideColumn2 = editor.mcedit.makeSideColumn2()
        spaceLabel = Label("")
        sideColumn = Column((sideColumn1, spaceLabel, sideColumn2))

        self.add(Row([buttons, sideColumn]))
        self.shrink_wrap()
Exemplo n.º 7
0
    def __init__(self,
                 prompt=None,
                 suffixes=None,
                 default_suffix=None,
                 **kwds):
        Dialog.__init__(self, **kwds)
        label = None
        d = self.margin
        self.suffixes = suffixes or ("", )
        self.file_type = self.suffixes[0]  # To be removed
        self.compute_file_types()
        self.default_suffix = default_suffix  # The default file extension. Will be searched in 'suffixes'.
        up_button = Button(self.up_button_text, action=self.go_up)
        dir_box = DirPathView(self.box_width + 250, self)
        self.dir_box = dir_box
        top_row = Row([dir_box, up_button])
        list_box = FileListView(self.box_width - 16, self)
        self.list_box = list_box
        tree = FSTree(self, inner_width=250, directory='/')
        self.tree = tree
        row = Row((tree, list_box), margin=0)
        ctrls = [top_row, row]
        prompt = prompt or self.default_prompt
        if prompt:
            label = Label(prompt)
        if suffixes:
            filetype_label = Label("File type", width=250)

            def set_file_type():
                self.file_type = self.filetype_button.get_value(
                )  # To be removed
                self.compute_file_types(self.filetype_button.get_value())
                self.list_box.update()

            filetype_button = ChoiceButton(choices=self.suffixes,
                                           width=250,
                                           choose=set_file_type)
            if default_suffix:
                v = next((s for s in self.suffixes
                          if ("*.%s;" % default_suffix in s or "*.%s)" %
                              default_suffix in s)), None)
                if v:
                    filetype_button.selectedChoice = v
                    self.compute_file_types(v)
            self.filetype_button = filetype_button
        if self.saving:
            filename_box = TextFieldWrapped(self.box_width)
            filename_box.change_action = self.update_filename
            filename_box._enter_action = filename_box.enter_action
            filename_box.enter_action = self.enter_action
            self.filename_box = filename_box
            if suffixes:
                ctrls.append(
                    Row([
                        Column([label, filename_box], align='l', spacing=0),
                        Column([filetype_label, filetype_button],
                               align='l',
                               spacing=0)
                    ], ))
            else:
                ctrls.append(
                    Column([label, filename_box], align='l', spacing=0))
        else:
            if label:
                ctrls.insert(0, label)
            if suffixes:
                ctrls.append(
                    Column([filetype_label, filetype_button],
                           align='l',
                           spacing=0))
        ok_button = Button(self.ok_label,
                           action=self.ok,
                           enable=self.ok_enable)
        self.ok_button = ok_button
        cancel_button = Button("Cancel", action=self.cancel)
        vbox = Column(ctrls, align='l', spacing=d)
        vbox.topleft = (d, d)
        y = vbox.bottom + d
        ok_button.topleft = (vbox.left, y)
        cancel_button.topright = (vbox.right, y)
        self.add(vbox)
        self.add(ok_button)
        self.add(cancel_button)
        self.shrink_wrap()
        self._directory = None
        self.directory = os.getcwd()
        # print "FileDialog: cwd =", repr(self.directory) ###
        if self.saving:
            filename_box.focus()
Exemplo n.º 8
0
def ortho_controls(ortho):
    bl = DemoButton("Lighter", ortho.lighter)
    bd = DemoButton("Darker", ortho.darker)
    row = Row([bl, bd])
    return row
Exemplo n.º 9
0
def persp_controls(persp):
    bx = DemoButton("RotX", lambda: persp.rot(0))
    by = DemoButton("RotY", lambda: persp.rot(1))
    bz = DemoButton("RotZ", lambda: persp.rot(2))
    row = Row([bx, by, bz])
    return row