Exemplo n.º 1
0
    def __init__(self):
        super(SplitPanelBasicExample, self).__init__()

        # First a vertical SplitPanel
        vert = VerticalSplitPanel()
        vert.setHeight('450px')
        vert.setWidth('100%')
        vert.setSplitPosition(150, ISizeable.UNITS_PIXELS)
        self.addComponent(vert)

        # add a label to the upper area
        vert.addComponent(Label(self.brownFox))

        # Add a horizontal SplitPanel to the lower area
        horiz = HorizontalSplitPanel()
        horiz.setSplitPosition(50)  # percent
        vert.addComponent(horiz)

        # left component:
        horiz.addComponent(Label(self.brownFox))

        # right component:
        horiz.addComponent(Label(self.brownFox))

        # Lock toggle button
        toggleLocked = CheckBox('Splits locked', LockListener(vert, horiz))
        toggleLocked.setImmediate(True)
        self.addComponent(toggleLocked)
Exemplo n.º 2
0
 def initLayout(self):
     splitPanel = HorizontalSplitPanel()
     self.setMainWindow(Window('Address Book', splitPanel))
     left = VerticalLayout()
     left.setSizeFull()
     left.addComponent(self._contactList)
     self._contactList.setSizeFull()
     left.setExpandRatio(self._contactList, 1)
     splitPanel.addComponent(left)
     splitPanel.addComponent(self._contactEditor)
     self._contactEditor.setSizeFull()
     self._contactEditor.getLayout().setMargin(True)
     self._contactEditor.setImmediate(True)
     self._bottomLeftCorner.setWidth('100%')
     left.addComponent(self._bottomLeftCorner)
Exemplo n.º 3
0
    def __init__(self):
        super(SplitPanelBasicExample, self).__init__()

        # First a vertical SplitPanel
        vert = VerticalSplitPanel()
        vert.setHeight('450px')
        vert.setWidth('100%')
        vert.setSplitPosition(150, ISizeable.UNITS_PIXELS)
        self.addComponent(vert)

        # add a label to the upper area
        vert.addComponent(Label(self.brownFox))

        # Add a horizontal SplitPanel to the lower area
        horiz = HorizontalSplitPanel()
        horiz.setSplitPosition(50)  # percent
        vert.addComponent(horiz)

        # left component:
        horiz.addComponent(Label(self.brownFox))

        # right component:
        horiz.addComponent(Label(self.brownFox))

        # Lock toggle button
        toggleLocked = CheckBox('Splits locked', LockListener(vert, horiz))
        toggleLocked.setImmediate(True)
        self.addComponent(toggleLocked)
Exemplo n.º 4
0
 def initLayout(self):
     splitPanel = HorizontalSplitPanel()
     self.setMainWindow(Window('Address Book', splitPanel))
     left = VerticalLayout()
     left.setSizeFull()
     left.addComponent(self._contactList)
     self._contactList.setSizeFull()
     left.setExpandRatio(self._contactList, 1)
     splitPanel.addComponent(left)
     splitPanel.addComponent(self._contactEditor)
     self._contactEditor.setSizeFull()
     self._contactEditor.getLayout().setMargin(True)
     self._contactEditor.setImmediate(True)
     self._bottomLeftCorner.setWidth('100%')
     left.addComponent(self._bottomLeftCorner)
Exemplo n.º 5
0
    def __init__(self, app):
        super(SamplerWindow, self).__init__()

        self._app = app

        self._currentList = FeatureGrid(self._app)
        self._featureView = FeatureView()
        self._currentFeature = ObjectProperty(None, Feature)

        self._mainSplit = None
        self._navigationTree = None
#        self._webAnalytics = GoogleAnalytics('UA-658457-6', 'none')
        # "backbutton"
        self._uriFragmentUtility = UriFragmentUtility()

        # breadcrumbs
        self._breadcrumbs = BreadCrumbs(self)

        self._previousSample = None
        self._nextSample = None
        self._search = None
        self.theme = None

        # Main top/expanded-bottom layout
        mainExpand = VerticalLayout()
        self.setContent(mainExpand)
        self.setSizeFull()
        mainExpand.setSizeFull()
        self.setCaption(self._TITLE)
        self.setTheme(self._app._currentApplicationTheme)

        # topbar (navigation)
        nav = HorizontalLayout()
        mainExpand.addComponent(nav)
        nav.setHeight('44px')
        nav.setWidth('100%')
        nav.setStyleName('topbar')
        nav.setSpacing(True)
        nav.setMargin(False, True, False, False)

        # Upper left logo
        logo = self.createLogo()
        nav.addComponent(logo)
        nav.setComponentAlignment(logo, Alignment.MIDDLE_LEFT)

        # Breadcrumbs
        nav.addComponent(self._breadcrumbs)
        nav.setExpandRatio(self._breadcrumbs, 1)
        nav.setComponentAlignment(self._breadcrumbs, Alignment.MIDDLE_LEFT)

        # invisible analytics -component
#        nav.addComponent(self._webAnalytics)

        # "backbutton"
        nav.addComponent(self._uriFragmentUtility)

        self._uriFragmentUtility.addListener(UriListener(self),
                IFragmentChangedListener)

        # Main left/right split; hidden menu tree
        self._mainSplit = HorizontalSplitPanel()
        self._mainSplit.setSizeFull()
        self._mainSplit.setStyleName('main-split')
        mainExpand.addComponent(self._mainSplit)
        mainExpand.setExpandRatio(self._mainSplit, 1)

        # Select theme
        themeSelect = self.createThemeSelect()
        nav.addComponent(themeSelect)
        nav.setComponentAlignment(themeSelect, Alignment.MIDDLE_LEFT)

        # Layouts for top area buttons
        quicknav = HorizontalLayout()
        arrows = HorizontalLayout()
        nav.addComponent(quicknav)
        nav.addComponent(arrows)
        nav.setComponentAlignment(quicknav, Alignment.MIDDLE_LEFT)
        nav.setComponentAlignment(arrows, Alignment.MIDDLE_LEFT)
        quicknav.setStyleName('segment')
        arrows.setStyleName('segment')

        # Previous sample
        self._previousSample = self.createPrevButton()
        arrows.addComponent(self._previousSample)

        # Next sample
        self._nextSample = self.createNextButton()
        arrows.addComponent(self._nextSample)

        # "Search" combobox
        searchComponent = self.createSearch()
        quicknav.addComponent(searchComponent)

        # Menu tree, initially shown
        menuLayout = CssLayout()
        allSamples = ActiveLink('All Samples', ExternalResource('#'))
        menuLayout.addComponent(allSamples)
        self._navigationTree = self.createMenuTree()
        menuLayout.addComponent(self._navigationTree)
        self._mainSplit.setFirstComponent(menuLayout)

        # Show / hide tree
        treeSwitch = self.createTreeSwitch()
        quicknav.addComponent(treeSwitch)

        self.addListener(WindowCloseListener(self, self._app),
                window.ICloseListener)
        self.updateFeatureList(self._currentList)
Exemplo n.º 6
0
class SamplerWindow(Window):
    """The main window for Sampler, contains the full application UI."""

    _TITLE = 'Muntjac Sampler'

    def __init__(self, app):
        super(SamplerWindow, self).__init__()

        self._app = app

        self._currentList = FeatureGrid(self._app)
        self._featureView = FeatureView()
        self._currentFeature = ObjectProperty(None, Feature)

        self._mainSplit = None
        self._navigationTree = None
#        self._webAnalytics = GoogleAnalytics('UA-658457-6', 'none')
        # "backbutton"
        self._uriFragmentUtility = UriFragmentUtility()

        # breadcrumbs
        self._breadcrumbs = BreadCrumbs(self)

        self._previousSample = None
        self._nextSample = None
        self._search = None
        self.theme = None

        # Main top/expanded-bottom layout
        mainExpand = VerticalLayout()
        self.setContent(mainExpand)
        self.setSizeFull()
        mainExpand.setSizeFull()
        self.setCaption(self._TITLE)
        self.setTheme(self._app._currentApplicationTheme)

        # topbar (navigation)
        nav = HorizontalLayout()
        mainExpand.addComponent(nav)
        nav.setHeight('44px')
        nav.setWidth('100%')
        nav.setStyleName('topbar')
        nav.setSpacing(True)
        nav.setMargin(False, True, False, False)

        # Upper left logo
        logo = self.createLogo()
        nav.addComponent(logo)
        nav.setComponentAlignment(logo, Alignment.MIDDLE_LEFT)

        # Breadcrumbs
        nav.addComponent(self._breadcrumbs)
        nav.setExpandRatio(self._breadcrumbs, 1)
        nav.setComponentAlignment(self._breadcrumbs, Alignment.MIDDLE_LEFT)

        # invisible analytics -component
#        nav.addComponent(self._webAnalytics)

        # "backbutton"
        nav.addComponent(self._uriFragmentUtility)

        self._uriFragmentUtility.addListener(UriListener(self),
                IFragmentChangedListener)

        # Main left/right split; hidden menu tree
        self._mainSplit = HorizontalSplitPanel()
        self._mainSplit.setSizeFull()
        self._mainSplit.setStyleName('main-split')
        mainExpand.addComponent(self._mainSplit)
        mainExpand.setExpandRatio(self._mainSplit, 1)

        # Select theme
        themeSelect = self.createThemeSelect()
        nav.addComponent(themeSelect)
        nav.setComponentAlignment(themeSelect, Alignment.MIDDLE_LEFT)

        # Layouts for top area buttons
        quicknav = HorizontalLayout()
        arrows = HorizontalLayout()
        nav.addComponent(quicknav)
        nav.addComponent(arrows)
        nav.setComponentAlignment(quicknav, Alignment.MIDDLE_LEFT)
        nav.setComponentAlignment(arrows, Alignment.MIDDLE_LEFT)
        quicknav.setStyleName('segment')
        arrows.setStyleName('segment')

        # Previous sample
        self._previousSample = self.createPrevButton()
        arrows.addComponent(self._previousSample)

        # Next sample
        self._nextSample = self.createNextButton()
        arrows.addComponent(self._nextSample)

        # "Search" combobox
        searchComponent = self.createSearch()
        quicknav.addComponent(searchComponent)

        # Menu tree, initially shown
        menuLayout = CssLayout()
        allSamples = ActiveLink('All Samples', ExternalResource('#'))
        menuLayout.addComponent(allSamples)
        self._navigationTree = self.createMenuTree()
        menuLayout.addComponent(self._navigationTree)
        self._mainSplit.setFirstComponent(menuLayout)

        # Show / hide tree
        treeSwitch = self.createTreeSwitch()
        quicknav.addComponent(treeSwitch)

        self.addListener(WindowCloseListener(self, self._app),
                window.ICloseListener)
        self.updateFeatureList(self._currentList)


    def detach(self):
        super(SamplerWindow, self).detach()
        self._search.setContainerDataSource(None)
        self._navigationTree.setContainerDataSource(None)


    def removeSubwindows(self):
        wins = self.getChildWindows()
        if None is not wins:
            for w in wins:
                self.removeWindow(w)


    def setFeature(self, arg):
        """Displays a Feature(Set) or displays a Feature(Set) matching the
        given path, or the main view if no matching Feature(Set) is found.

        @param arg:
                   Either the Feature(Set) to show or the path of the
                   Feature(Set) to show
        """
        if isinstance(arg, basestring):
            path = arg
            f = FeatureSet.FEATURES.getFeature(path)
            self.setFeature(f)
        else:
            f = arg
            if f == FeatureSet.FEATURES:
                # "All" is no longer in the tree, use null instead
                f = None
            self._currentFeature.setValue(f)
            fragment = f.getFragmentName() if f is not None else ''

#            self._webAnalytics.trackPageview(fragment)
            self._uriFragmentUtility.setFragment(fragment, False)
            self._breadcrumbs.setPath( self._app.getFullPathFor(f) )

            self._previousSample.setEnabled(f is not None)
            self._nextSample.setEnabled(not self._app._allFeatures.isLastId(f))

            self.updateFeatureList(self._currentList)

            self.setCaption((f.getName() + ': ' if f is not None else '')
                    + self._TITLE)

    # SamplerWindow helpers

    def createSearch(self):
        self._search = ComboBox()
        self._search.setWidth('160px')
        self._search.setNewItemsAllowed(False)
        self._search.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS)
        self._search.setNullSelectionAllowed(True)
        self._search.setImmediate(True)
        self._search.setInputPrompt('Search samples...')
        self._search.setContainerDataSource( self._app._allFeatures )

        for idd in self._app._allFeatures.getItemIds():
            if isinstance(idd, FeatureSet):
                pass  # FIXME: 'SamplerApplication' has no attribute 'getResourceAsStream'
#                self._search.setItemIcon(idd,
#                        ClassResource('folder.gif', self._app))

        self._search.addListener(SearchListener(self),
                prop.IValueChangeListener)

        # TODO add icons for section/sample
        # PopupView pv = new PopupView("", search) { public void
        # changeVariables(Object source, Map variables) {
        # super.changeVariables(source, variables); if (isPopupVisible()) {
        # search.focus(); } } };

        pv = PopupView('<span></span>', self._search)

        pv.addListener(PopupListener(self),
                IPopupVisibilityListener)
        pv.setStyleName('quickjump')
        pv.setDescription('Quick jump')

        return pv


    def createThemeSelect(self):
        self.theme = ComboBox()
        self.theme.setWidth('32px')
        self.theme.setNewItemsAllowed(False)
        self.theme.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS)
        self.theme.setImmediate(True)
        self.theme.setNullSelectionAllowed(False)
        for themeName in self._app._THEMES:
            idd = self._app._SAMPLER_THEME_NAME + '-' + themeName
            self.theme.addItem(idd)
            self.theme.setItemCaption(idd,
                    themeName[:1].upper() + (themeName[1:]) + ' theme')
            self.theme.setItemIcon(idd, _EMPTY_THEME_ICON)
        currentWindowTheme = self.getTheme()
        self.theme.setValue(currentWindowTheme)
        self.theme.setItemIcon(currentWindowTheme, _SELECTED_THEME_ICON)

        self.theme.addListener(ThemeChangeListener(self, self._app),
                prop.IValueChangeListener)
        self.theme.setStyleName('theme-select')
        self.theme.setDescription('Select Theme')
        return self.theme


    def createLogo(self):
        logo = NativeButton('', LogoClickListener(self))
        logo.setDescription('Home')
        logo.setStyleName(BaseTheme.BUTTON_LINK)
        logo.addStyleName('logo')
        return logo


    def createNextButton(self):
        b = NativeButton('', NextClickListener(self, self._app))
        b.setStyleName('next')
        b.setDescription('Jump to the next sample')
        return b


    def createPrevButton(self):
        b = NativeButton('', PrevClickListener(self, self._app))
        b.setEnabled(False)
        b.setStyleName('previous')
        b.setDescription('Jump to the previous sample')
        return b


    def createTreeSwitch(self):
        b = NativeButton()
        b.setStyleName('tree-switch')
        b.addStyleName('down')
        b.setDescription('Toggle sample tree visibility')

        b.addListener(TreeClickListener(self),
                button.IClickListener)
        self._mainSplit.setSplitPosition(250, ISizeable.UNITS_PIXELS)
        return b


    def createMenuTree(self):
        tree = Tree()
        tree.setImmediate(True)
        tree.setStyleName('menu')
        tree.setContainerDataSource(self._app._allFeatures)

        self._currentFeature.addListener(FeatureChangeListener(self, tree),
                prop.IValueChangeListener)
        for f in FeatureSet.FEATURES.getFeatures():
            tree.expandItemsRecursively(f)
        tree.expandItemsRecursively(FeatureSet.FEATURES)

        tree.addListener(TreeChangeListener(self),
                prop.IValueChangeListener)

        tree.setItemStyleGenerator(TreeStyleGenerator())
        return tree


    def updateFeatureList(self, lst):
        self._currentList = lst
        val = self._currentFeature.getValue()
        if val is None:
            self._currentList.setFeatureContainer(self._app._allFeatures)
            self._mainSplit.setSecondComponent(self._currentList)
        elif isinstance(val, FeatureSet):
            self._currentList.setFeatureContainer(val.getContainer(True))
            self._mainSplit.setSecondComponent(self._currentList)
        else:
            self._mainSplit.setSecondComponent(self._featureView)
            self._featureView.setFeature(val)
Exemplo n.º 7
0
    def init(self):
        # We'll build the whole UI here, since the application will not
        # contain any logic. Otherwise it would be more practical to
        # separate parts of the UI into different classes and methods.

        # Main (browser) window, needed in all Muntjac applications
        rootLayout = VerticalLayout()
        root = Window('MuntjacTunes', rootLayout)

        # We'll attach the window to the browser view already here, so
        # we won't forget it later.
        self.setMainWindow(root)

        root.showNotification(('This is an example of how you can do layouts '
                'in Muntjac.<br/>It is not a working sound player.'),
                Notification.TYPE_HUMANIZED_MESSAGE)

        # Our root window contains one VerticalLayout, let's make
        # sure it's 100% sized, and remove unwanted margins
        rootLayout.setSizeFull()
        rootLayout.setMargin(False)

        # Top area, containing playback and volume controls, play status,
        # view modes and search
        top = HorizontalLayout()
        top.setWidth('100%')
        top.setMargin(False, True, False, True)  # Enable horizontal margins
        top.setSpacing(True)

        # Let's attach that one straight away too
        root.addComponent(top)

        # Create the placeholders for all the components in the top area
        playback = HorizontalLayout()
        volume = HorizontalLayout()
        status = HorizontalLayout()
        viewmodes = HorizontalLayout()
        search = ComboBox()

        # Add the components and align them properly
        top.addComponent(playback)
        top.addComponent(volume)
        top.addComponent(status)
        top.addComponent(viewmodes)
        top.addComponent(search)
        top.setComponentAlignment(playback, Alignment.MIDDLE_LEFT)
        top.setComponentAlignment(volume, Alignment.MIDDLE_LEFT)
        top.setComponentAlignment(status, Alignment.MIDDLE_CENTER)
        top.setComponentAlignment(viewmodes, Alignment.MIDDLE_LEFT)
        top.setComponentAlignment(search, Alignment.MIDDLE_LEFT)

        # We want our status area to expand if the user resizes the root
        # window, and we want it to accommodate as much space as there is
        # available. All other components in the top layout should stay fixed
        # sized, so we don't need to specify any expand ratios for them (they
        # will automatically revert to zero after the following line).
        top.setExpandRatio(status, 1.0)

        # Playback controls
        prev = NativeButton('Previous')
        play = NativeButton('Play/pause')
        nextt = NativeButton('Next')
        playback.addComponent(prev)
        playback.addComponent(play)
        playback.addComponent(nextt)
        # Set spacing between the buttons
        playback.setSpacing(True)

        # Volume controls
        mute = NativeButton('mute')
        vol = Slider()
        vol.setOrientation(Slider.ORIENTATION_HORIZONTAL)
        vol.setWidth('100px')
        maxx = NativeButton('max')
        volume.addComponent(mute)
        volume.addComponent(vol)
        volume.addComponent(maxx)

        # Status area
        status.setWidth('80%')
        status.setSpacing(True)

        toggleVisualization = NativeButton('Mode')
        timeFromStart = Label('0:00')

        # We'll need another layout to show currently playing track and
        # progress
        trackDetails = VerticalLayout()
        trackDetails.setWidth('100%')
        track = Label('Track Name')
        album = Label('Album Name - Artist')
        track.setWidth(None)
        album.setWidth(None)
        progress = Slider()
        progress.setOrientation(Slider.ORIENTATION_HORIZONTAL)
        progress.setWidth('100%')
        trackDetails.addComponent(track)
        trackDetails.addComponent(album)
        trackDetails.addComponent(progress)
        trackDetails.setComponentAlignment(track, Alignment.TOP_CENTER)
        trackDetails.setComponentAlignment(album, Alignment.TOP_CENTER)

        timeToEnd = Label('-4:46')
        jumpToTrack = NativeButton('Show')

        # Place all components to the status layout and align them properly
        status.addComponent(toggleVisualization)
        status.setComponentAlignment(toggleVisualization,
                Alignment.MIDDLE_LEFT)
        status.addComponent(timeFromStart)
        status.setComponentAlignment(timeFromStart, Alignment.BOTTOM_LEFT)
        status.addComponent(trackDetails)
        status.addComponent(timeToEnd)
        status.setComponentAlignment(timeToEnd, Alignment.BOTTOM_LEFT)
        status.addComponent(jumpToTrack)
        status.setComponentAlignment(jumpToTrack, Alignment.MIDDLE_LEFT)

        # Then remember to specify the expand ratio
        status.setExpandRatio(trackDetails, 1.0)

        # View mode buttons
        viewAsTable = NativeButton('Table')
        viewAsGrid = NativeButton('Grid')
        coverflow = NativeButton('Coverflow')
        viewmodes.addComponent(viewAsTable)
        viewmodes.addComponent(viewAsGrid)
        viewmodes.addComponent(coverflow)

        # That covers the top bar. Now let's move on to the sidebar
        # and track listing

        # We'll need one splitpanel to separate the sidebar and track listing
        bottom = HorizontalSplitPanel()
        root.addComponent(bottom)

        # The splitpanel is by default 100% x 100%, but we'll need to
        # adjust our main window layout to accommodate the height
        root.getContent().setExpandRatio(bottom, 1.0)

        # Give the sidebar less space than the listing
        bottom.setSplitPosition(200, ISizeable.UNITS_PIXELS)

        # Let's add some content to the sidebar
        # First, we need a layout to but all components in
        sidebar = VerticalLayout()
        sidebar.setSizeFull()
        bottom.setFirstComponent(sidebar)

        # Then we need some labels and buttons, and an album cover image The
        # labels and buttons go into their own vertical layout, since we want
        # the 'sidebar' layout to be expanding (cover image in the bottom).
        # VerticalLayout is by default 100% wide.
        selections = VerticalLayout()
        library = Label('Library')
        music = NativeButton('Music')
        music.setWidth('100%')

        store = Label('Store')
        muntjacTunesStore = NativeButton('MuntjacTunes Store')
        muntjacTunesStore.setWidth('100%')
        purchased = NativeButton('Purchased')
        purchased.setWidth('100%')

        playlists = Label('Playlists')
        genius = NativeButton('Geniues')
        genius.setWidth('100%')
        recent = NativeButton('Recently Added')
        recent.setWidth('100%')

        # Lets add them to the 'selections' layout
        selections.addComponent(library)
        selections.addComponent(music)
        selections.addComponent(store)
        selections.addComponent(muntjacTunesStore)
        selections.addComponent(purchased)
        selections.addComponent(playlists)
        selections.addComponent(genius)
        selections.addComponent(recent)

        # Then add the selections to the sidebar, and set it expanding
        sidebar.addComponent(selections)
        sidebar.setExpandRatio(selections, 1.0)

        # Then comes the cover artwork (we'll add the actual image in the
        # themeing section)
        cover = Embedded('Currently Playing')
        sidebar.addComponent(cover)

        # And lastly, we need the track listing table It should fill the whole
        # left side of our bottom layout
        listing = Table()
        listing.setSizeFull()
        listing.setSelectable(True)
        bottom.setSecondComponent(listing)

        # Add the table headers
        listing.addContainerProperty('Name', str, '')
        listing.addContainerProperty('Time', str, '0:00')
        listing.addContainerProperty('Artist', str, '')
        listing.addContainerProperty('Album', str, '')
        listing.addContainerProperty('Genre', str, '')
        listing.addContainerProperty('Rating', NativeSelect, NativeSelect())

        # Lets populate the table with random data
        tracks = ['Red Flag', 'Millstone', 'Not The Sun', 'Breath',
                'Here We Are', 'Deep Heaven', 'Her Voice Resides',
                'Natural Tan', 'End It All', 'Kings', 'Daylight Slaving',
                'Mad Man', 'Resolve', 'Teargas', 'African Air', 'Passing Bird']
        times = ['4:12', '6:03', '5:43', '4:32', '3:42', '4:45', '2:56',
                '9:34', '2:10', '3:44', '5:49', '6:30', '5:18', '7:42',
                '3:13', '2:52']
        artists = ['Billy Talent', 'Brand New', 'Breaking Benjamin',
                'Becoming The Archetype', 'Bullet For My Valentine',
                'Chasing Victory', 'Chimaira', 'Danko Jones', 'Deadlock',
                'Deftones', 'From Autumn To Ashes', 'Haste The Day',
                'Four Year Strong', 'In Flames', 'Kemopetrol', 'John Legend']
        albums = ['Once Again', 'The Caitiff Choir', 'The Devil And God',
                'Light Grenades', 'Dicthonomy', 'Back In Black', 'Dreamer',
                'Come Clarity', 'Year Zero', 'Frames', 'Fortress', 'Phobia',
                'The Poison', 'Manifesto', 'White Pony', 'The Big Dirty']
        genres = ['Rock', 'Metal', 'Hardcore', 'Indie', 'Pop', 'Alternative',
                'Blues', 'Jazz', 'Hip Hop', 'Electronica', 'Punk', 'Hard Rock',
                'Dance', 'R\'n\'B', 'Gospel', 'Country']

        for i in range(100):
            s = NativeSelect()
            s.addItem('1 star')
            s.addItem('2 stars')
            s.addItem('3 stars')
            s.addItem('4 stars')
            s.addItem('5 stars')
            s.select('%d stars' % (i % 5))
            index = i % 16
            listing.addItem([tracks[index], times[index],
                    artists[index], albums[index], genres[index], s], i)

        # We'll align the track time column to right as well
        listing.setColumnAlignment('Time', Table.ALIGN_RIGHT)

        # TODO: the footer

        # Now what's left to do? Themeing of course.
        self.setTheme('vaadintunes')

        # Let's give a namespace to our application window. This way, if
        # someone uses the same theme for different applications, we don't
        # get unwanted style conflicts.
        root.setStyleName('tTunes')

        top.setStyleName('top')
        top.setHeight('75px')  # Same as the background image height

        playback.setStyleName('playback')
        playback.setMargin(False, True, False, False)  # Add right-side margin
        play.setStyleName('play')
        nextt.setStyleName('next')
        prev.setStyleName('prev')
        playback.setComponentAlignment(prev, Alignment.MIDDLE_LEFT)
        playback.setComponentAlignment(nextt, Alignment.MIDDLE_LEFT)

        volume.setStyleName('volume')
        mute.setStyleName('mute')
        maxx.setStyleName('max')
        vol.setWidth('78px')

        status.setStyleName('status')
        status.setMargin(True)
        status.setHeight('46px')  # Height of the background image

        toggleVisualization.setStyleName('toggle-vis')
        jumpToTrack.setStyleName('jump')

        viewAsTable.setStyleName('viewmode-table')
        viewAsGrid.setStyleName('viewmode-grid')
        coverflow.setStyleName('viewmode-coverflow')

        sidebar.setStyleName('sidebar')

        music.setStyleName('selected')

        cover.setSource(ThemeResource('images/album-cover.jpg'))
        # Because this is an image, it will retain it's aspect ratio
        cover.setWidth('100%')
Exemplo n.º 8
0
class SplitPanelPositioningExample(VerticalLayout):

    def __init__(self):
        super(SplitPanelPositioningExample, self).__init__()

        self.setStyleName('split-panel-positioning-example')
        self.setSpacing(True)

        controls = HorizontalLayout()
        controls.setSpacing(True)
        self.addComponent(controls)

        self._verticalSplitPanel = VerticalSplitPanel()
        self._verticalSplitPanel.setSplitPosition(100, ISizeable.UNITS_PIXELS)
        self._verticalSplitPanel.setLocked(True)
        self._verticalSplitPanel.setHeight('450px')
        self._verticalSplitPanel.setWidth('100%')
        self.addComponent(self._verticalSplitPanel)

        # Add some content to the top
        topArea = Label()
        topArea.setStyleName('top-area')
        topArea.addStyleName('measured-from-top')
        topArea.setSizeFull()
        self._verticalSplitPanel.addComponent(topArea)

        # Add a horizontal split panel in the bottom area
        self._horizontalSplitPanel = HorizontalSplitPanel()
        self._horizontalSplitPanel.setSplitPosition(30,
                ISizeable.UNITS_PERCENTAGE)
        self._horizontalSplitPanel.setSizeFull()
        self._horizontalSplitPanel.setLocked(True)
        self._verticalSplitPanel.addComponent(self._horizontalSplitPanel)

        # Add some content to the left and right sides of the vertical layout
        leftArea = Label()
        leftArea.setStyleName('left-area')
        leftArea.addStyleName('measured-from-left')
        leftArea.setSizeFull()
        self._horizontalSplitPanel.addComponent(leftArea)

        rightArea = Label()
        rightArea.setStyleName('right-area')
        rightArea.setSizeFull()
        self._horizontalSplitPanel.addComponent(rightArea)

        # Allow user to set the splitter positioning
        self._measurePositionFromLeft = OptionGroup('Horizontal split position',
                ['30% from left', '30% from right'])
        self._measurePositionFromLeft.setValue('30% from left')
        self._measurePositionFromLeft.setImmediate(True)

        l = LeftRightListener(self, leftArea, rightArea)
        self._measurePositionFromLeft.addListener(l, IValueChangeListener)
        controls.addComponent(self._measurePositionFromLeft)
        controls.setComponentAlignment(self._measurePositionFromLeft,
                Alignment.MIDDLE_CENTER)

        self._measurePositionFromTop = OptionGroup('Vertical split position',
                ['100px from top', '100px from bottom'])
        self._measurePositionFromTop.setValue('100px from top')
        self._measurePositionFromTop.setImmediate(True)

        l = TopBottomListener(self, leftArea, rightArea, topArea)
        self._measurePositionFromTop.addListener(l, IValueChangeListener)
        controls.addComponent(self._measurePositionFromTop)
        controls.setComponentAlignment(self._measurePositionFromTop,
                Alignment.MIDDLE_CENTER)
Exemplo n.º 9
0
    def __init__(self, app):
        super(SamplerWindow, self).__init__()

        self._app = app

        self._currentList = FeatureGrid(self._app)
        self._featureView = FeatureView()
        self._currentFeature = ObjectProperty(None, Feature)

        self._mainSplit = None
        self._navigationTree = None
        #        self._webAnalytics = GoogleAnalytics('UA-658457-6', 'none')
        # "backbutton"
        self._uriFragmentUtility = UriFragmentUtility()

        # breadcrumbs
        self._breadcrumbs = BreadCrumbs(self)

        self._previousSample = None
        self._nextSample = None
        self._search = None
        self.theme = None

        # Main top/expanded-bottom layout
        mainExpand = VerticalLayout()
        self.setContent(mainExpand)
        self.setSizeFull()
        mainExpand.setSizeFull()
        self.setCaption(self._TITLE)
        self.setTheme(self._app._currentApplicationTheme)

        # topbar (navigation)
        nav = HorizontalLayout()
        mainExpand.addComponent(nav)
        nav.setHeight('44px')
        nav.setWidth('100%')
        nav.setStyleName('topbar')
        nav.setSpacing(True)
        nav.setMargin(False, True, False, False)

        # Upper left logo
        logo = self.createLogo()
        nav.addComponent(logo)
        nav.setComponentAlignment(logo, Alignment.MIDDLE_LEFT)

        # Breadcrumbs
        nav.addComponent(self._breadcrumbs)
        nav.setExpandRatio(self._breadcrumbs, 1)
        nav.setComponentAlignment(self._breadcrumbs, Alignment.MIDDLE_LEFT)

        # invisible analytics -component
        #        nav.addComponent(self._webAnalytics)

        # "backbutton"
        nav.addComponent(self._uriFragmentUtility)

        self._uriFragmentUtility.addListener(UriListener(self),
                                             IFragmentChangedListener)

        # Main left/right split; hidden menu tree
        self._mainSplit = HorizontalSplitPanel()
        self._mainSplit.setSizeFull()
        self._mainSplit.setStyleName('main-split')
        mainExpand.addComponent(self._mainSplit)
        mainExpand.setExpandRatio(self._mainSplit, 1)

        # Select theme
        themeSelect = self.createThemeSelect()
        nav.addComponent(themeSelect)
        nav.setComponentAlignment(themeSelect, Alignment.MIDDLE_LEFT)

        # Layouts for top area buttons
        quicknav = HorizontalLayout()
        arrows = HorizontalLayout()
        nav.addComponent(quicknav)
        nav.addComponent(arrows)
        nav.setComponentAlignment(quicknav, Alignment.MIDDLE_LEFT)
        nav.setComponentAlignment(arrows, Alignment.MIDDLE_LEFT)
        quicknav.setStyleName('segment')
        arrows.setStyleName('segment')

        # Previous sample
        self._previousSample = self.createPrevButton()
        arrows.addComponent(self._previousSample)

        # Next sample
        self._nextSample = self.createNextButton()
        arrows.addComponent(self._nextSample)

        # "Search" combobox
        searchComponent = self.createSearch()
        quicknav.addComponent(searchComponent)

        # Menu tree, initially shown
        menuLayout = CssLayout()
        allSamples = ActiveLink('All Samples', ExternalResource('#'))
        menuLayout.addComponent(allSamples)
        self._navigationTree = self.createMenuTree()
        menuLayout.addComponent(self._navigationTree)
        self._mainSplit.setFirstComponent(menuLayout)

        # Show / hide tree
        treeSwitch = self.createTreeSwitch()
        quicknav.addComponent(treeSwitch)

        self.addListener(WindowCloseListener(self, self._app),
                         window.ICloseListener)
        self.updateFeatureList(self._currentList)
Exemplo n.º 10
0
class SamplerWindow(Window):
    """The main window for Sampler, contains the full application UI."""

    _TITLE = 'Muntjac Sampler'

    def __init__(self, app):
        super(SamplerWindow, self).__init__()

        self._app = app

        self._currentList = FeatureGrid(self._app)
        self._featureView = FeatureView()
        self._currentFeature = ObjectProperty(None, Feature)

        self._mainSplit = None
        self._navigationTree = None
        #        self._webAnalytics = GoogleAnalytics('UA-658457-6', 'none')
        # "backbutton"
        self._uriFragmentUtility = UriFragmentUtility()

        # breadcrumbs
        self._breadcrumbs = BreadCrumbs(self)

        self._previousSample = None
        self._nextSample = None
        self._search = None
        self.theme = None

        # Main top/expanded-bottom layout
        mainExpand = VerticalLayout()
        self.setContent(mainExpand)
        self.setSizeFull()
        mainExpand.setSizeFull()
        self.setCaption(self._TITLE)
        self.setTheme(self._app._currentApplicationTheme)

        # topbar (navigation)
        nav = HorizontalLayout()
        mainExpand.addComponent(nav)
        nav.setHeight('44px')
        nav.setWidth('100%')
        nav.setStyleName('topbar')
        nav.setSpacing(True)
        nav.setMargin(False, True, False, False)

        # Upper left logo
        logo = self.createLogo()
        nav.addComponent(logo)
        nav.setComponentAlignment(logo, Alignment.MIDDLE_LEFT)

        # Breadcrumbs
        nav.addComponent(self._breadcrumbs)
        nav.setExpandRatio(self._breadcrumbs, 1)
        nav.setComponentAlignment(self._breadcrumbs, Alignment.MIDDLE_LEFT)

        # invisible analytics -component
        #        nav.addComponent(self._webAnalytics)

        # "backbutton"
        nav.addComponent(self._uriFragmentUtility)

        self._uriFragmentUtility.addListener(UriListener(self),
                                             IFragmentChangedListener)

        # Main left/right split; hidden menu tree
        self._mainSplit = HorizontalSplitPanel()
        self._mainSplit.setSizeFull()
        self._mainSplit.setStyleName('main-split')
        mainExpand.addComponent(self._mainSplit)
        mainExpand.setExpandRatio(self._mainSplit, 1)

        # Select theme
        themeSelect = self.createThemeSelect()
        nav.addComponent(themeSelect)
        nav.setComponentAlignment(themeSelect, Alignment.MIDDLE_LEFT)

        # Layouts for top area buttons
        quicknav = HorizontalLayout()
        arrows = HorizontalLayout()
        nav.addComponent(quicknav)
        nav.addComponent(arrows)
        nav.setComponentAlignment(quicknav, Alignment.MIDDLE_LEFT)
        nav.setComponentAlignment(arrows, Alignment.MIDDLE_LEFT)
        quicknav.setStyleName('segment')
        arrows.setStyleName('segment')

        # Previous sample
        self._previousSample = self.createPrevButton()
        arrows.addComponent(self._previousSample)

        # Next sample
        self._nextSample = self.createNextButton()
        arrows.addComponent(self._nextSample)

        # "Search" combobox
        searchComponent = self.createSearch()
        quicknav.addComponent(searchComponent)

        # Menu tree, initially shown
        menuLayout = CssLayout()
        allSamples = ActiveLink('All Samples', ExternalResource('#'))
        menuLayout.addComponent(allSamples)
        self._navigationTree = self.createMenuTree()
        menuLayout.addComponent(self._navigationTree)
        self._mainSplit.setFirstComponent(menuLayout)

        # Show / hide tree
        treeSwitch = self.createTreeSwitch()
        quicknav.addComponent(treeSwitch)

        self.addListener(WindowCloseListener(self, self._app),
                         window.ICloseListener)
        self.updateFeatureList(self._currentList)

    def detach(self):
        super(SamplerWindow, self).detach()
        self._search.setContainerDataSource(None)
        self._navigationTree.setContainerDataSource(None)

    def removeSubwindows(self):
        wins = self.getChildWindows()
        if None is not wins:
            for w in wins:
                self.removeWindow(w)

    def setFeature(self, arg):
        """Displays a Feature(Set) or displays a Feature(Set) matching the
        given path, or the main view if no matching Feature(Set) is found.

        @param arg:
                   Either the Feature(Set) to show or the path of the
                   Feature(Set) to show
        """
        if isinstance(arg, basestring):
            path = arg
            f = FeatureSet.FEATURES.getFeature(path)
            self.setFeature(f)
        else:
            f = arg
            if f == FeatureSet.FEATURES:
                # "All" is no longer in the tree, use null instead
                f = None
            self._currentFeature.setValue(f)
            fragment = f.getFragmentName() if f is not None else ''

            #            self._webAnalytics.trackPageview(fragment)
            self._uriFragmentUtility.setFragment(fragment, False)
            self._breadcrumbs.setPath(self._app.getFullPathFor(f))

            self._previousSample.setEnabled(f is not None)
            self._nextSample.setEnabled(not self._app._allFeatures.isLastId(f))

            self.updateFeatureList(self._currentList)

            self.setCaption((f.getName() + ': ' if f is not None else '') +
                            self._TITLE)

    # SamplerWindow helpers

    def createSearch(self):
        self._search = ComboBox()
        self._search.setWidth('160px')
        self._search.setNewItemsAllowed(False)
        self._search.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS)
        self._search.setNullSelectionAllowed(True)
        self._search.setImmediate(True)
        self._search.setInputPrompt('Search samples...')
        self._search.setContainerDataSource(self._app._allFeatures)

        for idd in self._app._allFeatures.getItemIds():
            if isinstance(idd, FeatureSet):
                pass  # FIXME: 'SamplerApplication' has no attribute 'getResourceAsStream'


#                self._search.setItemIcon(idd,
#                        ClassResource('folder.gif', self._app))

        self._search.addListener(SearchListener(self),
                                 prop.IValueChangeListener)

        # TODO add icons for section/sample
        # PopupView pv = new PopupView("", search) { public void
        # changeVariables(Object source, Map variables) {
        # super.changeVariables(source, variables); if (isPopupVisible()) {
        # search.focus(); } } };

        pv = PopupView('<span></span>', self._search)

        pv.addListener(PopupListener(self), IPopupVisibilityListener)
        pv.setStyleName('quickjump')
        pv.setDescription('Quick jump')

        return pv

    def createThemeSelect(self):
        self.theme = ComboBox()
        self.theme.setWidth('32px')
        self.theme.setNewItemsAllowed(False)
        self.theme.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS)
        self.theme.setImmediate(True)
        self.theme.setNullSelectionAllowed(False)
        for themeName in self._app._THEMES:
            idd = self._app._SAMPLER_THEME_NAME + '-' + themeName
            self.theme.addItem(idd)
            self.theme.setItemCaption(
                idd, themeName[:1].upper() + (themeName[1:]) + ' theme')
            self.theme.setItemIcon(idd, _EMPTY_THEME_ICON)
        currentWindowTheme = self.getTheme()
        self.theme.setValue(currentWindowTheme)
        self.theme.setItemIcon(currentWindowTheme, _SELECTED_THEME_ICON)

        self.theme.addListener(ThemeChangeListener(self, self._app),
                               prop.IValueChangeListener)
        self.theme.setStyleName('theme-select')
        self.theme.setDescription('Select Theme')
        return self.theme

    def createLogo(self):
        logo = NativeButton('', LogoClickListener(self))
        logo.setDescription('Home')
        logo.setStyleName(BaseTheme.BUTTON_LINK)
        logo.addStyleName('logo')
        return logo

    def createNextButton(self):
        b = NativeButton('', NextClickListener(self, self._app))
        b.setStyleName('next')
        b.setDescription('Jump to the next sample')
        return b

    def createPrevButton(self):
        b = NativeButton('', PrevClickListener(self, self._app))
        b.setEnabled(False)
        b.setStyleName('previous')
        b.setDescription('Jump to the previous sample')
        return b

    def createTreeSwitch(self):
        b = NativeButton()
        b.setStyleName('tree-switch')
        b.addStyleName('down')
        b.setDescription('Toggle sample tree visibility')

        b.addListener(TreeClickListener(self), button.IClickListener)
        self._mainSplit.setSplitPosition(250, ISizeable.UNITS_PIXELS)
        return b

    def createMenuTree(self):
        tree = Tree()
        tree.setImmediate(True)
        tree.setStyleName('menu')
        tree.setContainerDataSource(self._app._allFeatures)

        self._currentFeature.addListener(FeatureChangeListener(self, tree),
                                         prop.IValueChangeListener)
        for f in FeatureSet.FEATURES.getFeatures():
            tree.expandItemsRecursively(f)
        tree.expandItemsRecursively(FeatureSet.FEATURES)

        tree.addListener(TreeChangeListener(self), prop.IValueChangeListener)

        tree.setItemStyleGenerator(TreeStyleGenerator())
        return tree

    def updateFeatureList(self, lst):
        self._currentList = lst
        val = self._currentFeature.getValue()
        if val is None:
            self._currentList.setFeatureContainer(self._app._allFeatures)
            self._mainSplit.setSecondComponent(self._currentList)
        elif isinstance(val, FeatureSet):
            self._currentList.setFeatureContainer(val.getContainer(True))
            self._mainSplit.setSecondComponent(self._currentList)
        else:
            self._mainSplit.setSecondComponent(self._featureView)
            self._featureView.setFeature(val)