Exemple #1
0
 def ApplyAttributes(self, attributes):
     Window.ApplyAttributes(self, attributes)
     uicore.layer.systemmenu.FadeBGOut()
     uicore.layer.systemmenu.Hide()
     uicore.layer.inflight.Disable()
     mainCont = Container(name='mainCont',
                          parent=self.sr.main,
                          align=uiconst.CENTER,
                          state=uiconst.UI_NORMAL,
                          width=200,
                          height=60)
     self.savedValue = gfxsettings.Get(gfxsettings.GFX_BRIGHTNESS)
     self.currentValue = self.savedValue
     self.gammaSlider = Slider(name='gammaSlider',
                               parent=mainCont,
                               minValue=0.5,
                               maxValue=1.5,
                               startValue=1.0,
                               onsetvaluefunc=self.OnMySliderMoved,
                               setlabelfunc=self.UpdateSliderLabel)
     self.gammaSlider.SetValue(self.ConvertValue(self.currentValue), True)
     buttonGroup = ButtonGroup(name='buttonGroup',
                               parent=mainCont,
                               align=uiconst.CENTERBOTTOM,
                               buttonPadding=10)
     buttonGroup.AddButton(
         localization.GetByLabel('UI/Common/Buttons/Save'), self.Save)
     buttonGroup.AddButton(
         localization.GetByLabel('UI/SystemMenu/ResetSettings/Reset'),
         self.Reset)
     buttonGroup.AddButton(
         localization.GetByLabel('UI/Common/Buttons/Cancel'), self.Cancel)
 def ApplyAttributes(self, attributes):
     Container.ApplyAttributes(self, attributes)
     label = attributes.label
     value = attributes.value
     maxValue = attributes.maxValue
     callback = attributes.callback
     Label(parent=self, align=uiconst.TOLEFT, width=10, text=label, fontsize=15, top=-3)
     self.slider = Slider(parent=self, align=uiconst.TOLEFT_PROP, width=0.95, padLeft=3, minValue=0.0, maxValue=maxValue, startVal=value, onsetvaluefunc=callback)
Exemple #3
0
def TestGammaSlider():
    winID = 'TestGammaSlider_windID'
    uicontrols.Window.CloseIfOpen(windowID=winID)
    wnd = uicontrols.Window.Open(windowID=winID)
    wnd.SetTopparentHeight(0)
    wnd.SetMinSize([300, 50])
    wnd.SetCaption('Gamma slider PROTOTYPE')
    mainCont = uiprimitives.Container(name='mainCont', parent=uiutil.GetChild(wnd, 'main'), align=uiconst.CENTER, state=uiconst.UI_NORMAL, width=200, height=10)
    gammaSlider = Slider(name='gammaSlider', parent=mainCont, minValue=0.5, maxValue=1.5, startValue=1.0, onsetvaluefunc=OnMySliderMoved, endsliderfunc=OnMySliderReleased)
    currentVal = trinity.settings.GetValue('eveSpaceSceneGammaBrightness')
    gammaSlider.SetValue(currentVal, True)
class ValueSelector(Container):
    default_name = 'ValueSelector'

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        label = attributes.label
        value = attributes.value
        maxValue = attributes.maxValue
        callback = attributes.callback
        Label(parent=self,
              align=uiconst.TOLEFT,
              width=10,
              text=label,
              fontsize=15,
              top=-3)
        self.slider = Slider(parent=self,
                             align=uiconst.TOLEFT_PROP,
                             width=0.95,
                             padLeft=3,
                             minValue=0.0,
                             maxValue=maxValue,
                             startVal=value,
                             onsetvaluefunc=callback)

    def SetValue(self, value):
        self.slider.SetValue(value, updateHandle=True, triggerCallback=False)
    def MakeSliderTextRow(self,
                          label,
                          minValue,
                          maxValue,
                          startValue,
                          stepping,
                          setValueFunc=None,
                          endSliderFunc=None):
        sliderWidth = 100
        sliderValueWidth = 30
        sliderLabelWidth = 120
        rowPadding = (5, 2, 10, 2)
        size = EveLabelSmall.MeasureTextSize(label, width=sliderLabelWidth)
        rowHeight = size[1]
        rowContainer = Container(name='TextRowContainer',
                                 parent=self.rightContainer,
                                 align=uiconst.TOTOP,
                                 alignMode=uiconst.TOTOP,
                                 height=rowHeight,
                                 padding=rowPadding)
        EveLabelSmall(name='sliderlabel',
                      align=uiconst.TOLEFT,
                      parent=rowContainer,
                      text=label,
                      width=sliderLabelWidth)
        increments = []
        currentValue = minValue
        while currentValue <= maxValue:
            increments.append(currentValue)
            currentValue = currentValue + stepping

        valueLabel = EveLabelSmall(name='sliderValuelabel',
                                   left=sliderWidth,
                                   align=uiconst.CENTERRIGHT,
                                   text=str(startValue),
                                   width=sliderValueWidth)

        def UpdateLabel(slider):
            valueLabel.text = str(slider.GetValue())

        Slider(name='niceSlider',
               align=uiconst.CENTERRIGHT,
               parent=rowContainer,
               minValue=minValue,
               maxValue=maxValue,
               width=sliderWidth,
               showLabel=False,
               startVal=startValue,
               isEvenIncrementsSlider=True,
               increments=increments,
               onsetvaluefunc=UpdateLabel,
               endsliderfunc=endSliderFunc)
        rowContainer.children.append(valueLabel)
        return rowContainer
Exemple #6
0
    def InitButtons(self):
        buttons = [['Play', self.MoviePlay, 'ui_38_16_228'],
         ['Pause', self.MoviePause, 'ui_38_16_238'],
         ['Stop', self.MovieStop, 'ui_38_16_111'],
         ['Toggle Sound', self.MovieAudioToggle, 'ui_38_16_90'],
         ['Set Aspect', self.SetMovieAspect, 'ui_38_16_1']]
        for button in buttons:
            hint, function, iconID = button
            btn = uiprimitives.Container(name=hint, align=uiconst.TOLEFT, width=BTNSIZE, left=const.defaultPadding, parent=self.sr.bottomframe)
            uicontrols.Frame(parent=btn, color=(1.0, 1.0, 1.0, 0.125))
            icon = uicontrols.Icon(icon=iconID, parent=btn, size=BTNSIZE, align=uiconst.CENTER)
            icon.OnClick = function
            icon.hint = hint
            icon.OnMouseEnter = (self.ShowSelected, icon, 1)
            icon.OnMouseExit = (self.ShowSelected, icon, 0)
            icon.sr.hilite = uiprimitives.Fill(parent=btn, name='hilite', state=uiconst.UI_HIDDEN)

        textWidth = 353
        self.textBlock = uiprimitives.Container(parent=self.sr.bottomframe, align=uiconst.TOALL, left=const.defaultPadding)
        self.slider = Slider(name='mySlider', parent=self.textBlock, align=uiconst.TOLEFT, width=100, minValue=0.0, maxValue=100.0, startVal=0.0, endsliderfunc=self._OnSlider)
        self.textBtm = uicontrols.Label(text='', parent=self.textBlock, align=uiconst.TOALL, left=const.defaultPadding, height=0, top=1, fontsize=10, letterspace=1, linespace=9, uppercase=1, state=uiconst.UI_NORMAL)
Exemple #7
0
 def _SetupDurationPanel(self, parent):
     maxSeconds = int(BENCHMARK_MAX_DURATION_IN_MS / 1000)
     defaultSeconds = int(BENCHMARK_DEFAULT_DURATION_IN_MS / 1000)
     self.durationSlider = Slider(
         name='mySlider',
         parent=parent,
         minValue=1,
         maxValue=maxSeconds,
         startVal=defaultSeconds,
         increments=[i + 1 for i in xrange(maxSeconds)],
         onsetvaluefunc=self._OnTimeChanged,
         align=uiconst.TOTOP,
         padLeft=10,
         padRight=10)
     self.progress = Gauge(name='progress',
                           parent=parent,
                           color=Color.WHITE,
                           align=uiconst.TOTOP,
                           padTop=20,
                           padLeft=10,
                           padRight=10)
     self._OnTimeChanged(self.durationSlider)
Exemple #8
0
    def ShowUI(self):
        uicontrols.Window.CloseIfOpen(windowID=self.windowID)
        wnd = uicontrols.Window.Open(windowID=self.windowID)
        wnd.SetTopparentHeight(0)
        wnd.SetMinSize([500, 500])
        wnd.SetCaption(self.name)
        main = wnd.GetMainArea()
        sofDB = blue.resMan.LoadObject(
            'res:/dx9/model/spaceobjectfactory/data.red')
        self.sofFactions = []
        for i in xrange(len(sofDB.faction)):
            self.sofFactions.append((sofDB.faction[i].name, i))

        self.sofFactions.sort()
        self.sofHulls = []
        for i in xrange(len(sofDB.hull)):
            self.sofHulls.append((sofDB.hull[i].name, i))

        self.sofHulls.sort()
        self.sofRaces = []
        for i in xrange(len(sofDB.race)):
            self.sofRaces.append((sofDB.race[i].name, i))

        self.sofRaces.sort()
        self.sofMaterials = []
        for i in xrange(len(sofDB.material)):
            self.sofMaterials.append((sofDB.material[i].name, i))

        self.sofMaterials.sort()
        self.sofMaterials.insert(0, ('None', -1))
        self.sofVariants = []
        for i in xrange(len(sofDB.generic.variants)):
            self.sofVariants.append((sofDB.generic.variants[i].name, i))

        self.sofVariants.sort()
        self.sofVariants.insert(0, ('None', -1))
        self.sofPatterns = []
        for i in xrange(len(sofDB.pattern)):
            self.sofPatterns.append((sofDB.pattern[i].name, i))

        self.sofPatterns.sort()
        self.sofPatterns.insert(0, ('None', -1))
        headerCont = Container(name='headerCont',
                               parent=main,
                               align=uiconst.TOTOP,
                               height=30)
        gridCont = GridContainer(name='mainCont',
                                 parent=main,
                                 align=uiconst.TOBOTTOM,
                                 height=250,
                                 lines=5,
                                 columns=3)
        buttonConts = {}
        for y in xrange(gridCont.lines):
            for x in xrange(gridCont.columns):
                buttonConts[x, y] = Container(parent=gridCont)

        self.dnaLabel = EveLabelSmall(name='dnaLabel',
                                      align=uiconst.CENTER,
                                      parent=headerCont,
                                      text='')
        self.copyDnaButton = Button(name='copy_dna_button',
                                    align=uiconst.CENTER,
                                    parent=buttonConts[(0, 4)],
                                    label='Copy DNA',
                                    func=self._OnCopyDnaButton)
        self.applyButton = Button(name='apply_button',
                                  align=uiconst.CENTER,
                                  parent=buttonConts[(1, 4)],
                                  label='Apply',
                                  func=self._OnApplyButton)
        patternParent = Container(name='patternParent',
                                  parent=buttonConts[(0, 3)],
                                  align=uiconst.CENTER,
                                  height=18,
                                  width=175)
        self.patternCombo = Combo(name='pattern_combo',
                                  align=uiconst.TOLEFT,
                                  width=150,
                                  parent=patternParent,
                                  label='Pattern:',
                                  options=self.sofPatterns,
                                  callback=self.OnPatternComboChange,
                                  select=self.GetComboListIndex(
                                      self.sofPatterns, self.currentPattern))
        factionParent = Container(name='factionParent',
                                  parent=buttonConts[(0, 2)],
                                  align=uiconst.CENTER,
                                  height=18,
                                  width=175)
        self.factionCombo = Combo(name='faction_combo',
                                  align=uiconst.TOLEFT,
                                  width=150,
                                  parent=factionParent,
                                  label='Faction:',
                                  options=self.sofFactions,
                                  callback=self.OnFactionComboChange,
                                  select=self.GetComboListIndex(
                                      self.sofFactions, self.currentFaction))
        self.factionConstraint = Checkbox(
            name='faction_constraint',
            align=uiconst.TOLEFT,
            width=75,
            padLeft=10,
            parent=factionParent,
            text='Constrained',
            callback=self.OnFactionConstraintChanged)
        hullParent = Container(name='hullParent',
                               parent=buttonConts[(0, 1)],
                               align=uiconst.CENTER,
                               height=18,
                               width=175)
        self.hullCombo = Combo(name='hull_combo',
                               align=uiconst.TOLEFT,
                               width=150,
                               parent=hullParent,
                               label='Hull:',
                               options=self.sofHulls,
                               callback=self.OnHullComboChange,
                               select=self.GetComboListIndex(
                                   self.sofHulls, self.currentHull))
        self.hullConstraint = Checkbox(name='hull_constraint',
                                       align=uiconst.TOLEFT,
                                       width=75,
                                       padLeft=10,
                                       parent=hullParent,
                                       text='Constrained',
                                       callback=self.OnHullConstraintChanged)
        raceParent = Container(name='raceParent',
                               parent=buttonConts[(0, 0)],
                               align=uiconst.CENTER,
                               height=18,
                               width=175)
        self.raceCombo = Combo(name='race_combo',
                               align=uiconst.TOLEFT,
                               width=150,
                               parent=raceParent,
                               label='Race:',
                               options=self.sofRaces,
                               callback=self.OnRaceComboChange,
                               select=self.GetComboListIndex(
                                   self.sofRaces, self.currentRace))
        self.raceConstraint = Checkbox(name='race_constraint',
                                       align=uiconst.TOLEFT,
                                       width=75,
                                       padLeft=10,
                                       parent=raceParent,
                                       text='Constrained',
                                       callback=self.OnRaceConstraintChanged)
        self.matCombo1 = Combo(name='material_combo1',
                               align=uiconst.CENTER,
                               width=150,
                               parent=buttonConts[(1, 0)],
                               label='Material 1:',
                               options=self.sofMaterials,
                               callback=self.OnMat1ComboChange,
                               select=self.GetComboListIndex(
                                   self.sofMaterials, self.currentMat[0]))
        self.matCombo2 = Combo(name='material_combo2',
                               align=uiconst.CENTER,
                               width=150,
                               parent=buttonConts[(1, 1)],
                               label='Material 2:',
                               options=self.sofMaterials,
                               callback=self.OnMat2ComboChange,
                               select=self.GetComboListIndex(
                                   self.sofMaterials, self.currentMat[1]))
        self.matCombo3 = Combo(name='material_combo3',
                               align=uiconst.CENTER,
                               width=150,
                               parent=buttonConts[(1, 2)],
                               label='Material 3:',
                               options=self.sofMaterials,
                               callback=self.OnMat3ComboChange,
                               select=self.GetComboListIndex(
                                   self.sofMaterials, self.currentMat[2]))
        self.matCombo4 = Combo(name='material_combo4',
                               align=uiconst.CENTER,
                               width=150,
                               parent=buttonConts[(1, 3)],
                               label='Material 4:',
                               options=self.sofMaterials,
                               callback=self.OnMat4ComboChange,
                               select=self.GetComboListIndex(
                                   self.sofMaterials, self.currentMat[3]))
        self.dirtSlider = Slider(name='dirt_slider',
                                 align=uiconst.CENTER,
                                 label='Dirt',
                                 parent=buttonConts[(2, 0)],
                                 width=200,
                                 minValue=0.0,
                                 maxValue=100.0,
                                 startVal=50.0,
                                 setlabelfunc=self.UpdateDirtSliderLabel,
                                 onsetvaluefunc=self.OnDirtSliderChange,
                                 endsliderfunc=self.OnDirtSliderChange)
        materialSetIdContainer = Container(name='materialSetContainer',
                                           parent=buttonConts[(2, 1)],
                                           align=uiconst.CENTER,
                                           height=18,
                                           width=175)
        self.materialSetIDCombo = Combo(name='materialsetid_edit',
                                        align=uiconst.TOLEFT,
                                        label='Masterial Set ID',
                                        parent=materialSetIdContainer,
                                        options=[],
                                        callback=self.OnMaterialSetIDChange)
        self._FilterMaterialSet(False)
        self.materialSetFilteredByRace = Checkbox(
            name='materialSetFilter',
            align=uiconst.TOLEFT,
            width=150,
            padLeft=10,
            parent=materialSetIdContainer,
            text='Filter By Race',
            callback=self.OnMaterialSetFiltered)
        self.resPathInsertEdit = SinglelineEdit(
            name='respathinsert_edit',
            align=uiconst.CENTER,
            label='resPathInsert',
            parent=buttonConts[(2, 2)],
            width=100,
            setvalue='',
            OnFocusLost=self.OnResPathInsertChange,
            OnReturn=self.OnResPathInsertChange)
        self.variantCombo = Combo(name='variant_combo',
                                  align=uiconst.CENTER,
                                  width=150,
                                  parent=buttonConts[(2, 3)],
                                  label='Variants:',
                                  options=self.sofVariants,
                                  callback=self.OnVariantComboChange,
                                  select=self.GetComboListIndex(
                                      self.sofVariants, self.currentVariant))
        self.previewCont = PreviewContainer(parent=main, align=uiconst.TOALL)
        self.previewCont.PreviewSofDna(self.GetPreviewDna())
Exemple #9
0
class GammaSliderWindow(Window):
    default_topParentHeight = 0
    default_isCollapseable = False
    default_isKillable = False
    default_isMinimizable = False
    default_fixedWidth = 300
    default_fixedHeight = 100
    default_windowID = 'GammaSliderWindow'
    default_isPinable = False
    default_caption = localization.GetByLabel(
        'UI/SystemMenu/DisplayAndGraphics/GraphicContentSettings/Brightness')

    def ConvertValue(self, value):
        return 2.0 - value

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        uicore.layer.systemmenu.FadeBGOut()
        uicore.layer.systemmenu.Hide()
        uicore.layer.inflight.Disable()
        mainCont = Container(name='mainCont',
                             parent=self.sr.main,
                             align=uiconst.CENTER,
                             state=uiconst.UI_NORMAL,
                             width=200,
                             height=60)
        self.savedValue = gfxsettings.Get(gfxsettings.GFX_BRIGHTNESS)
        self.currentValue = self.savedValue
        self.gammaSlider = Slider(name='gammaSlider',
                                  parent=mainCont,
                                  minValue=0.5,
                                  maxValue=1.5,
                                  startValue=1.0,
                                  onsetvaluefunc=self.OnMySliderMoved,
                                  setlabelfunc=self.UpdateSliderLabel)
        self.gammaSlider.SetValue(self.ConvertValue(self.currentValue), True)
        buttonGroup = ButtonGroup(name='buttonGroup',
                                  parent=mainCont,
                                  align=uiconst.CENTERBOTTOM,
                                  buttonPadding=10)
        buttonGroup.AddButton(
            localization.GetByLabel('UI/Common/Buttons/Save'), self.Save)
        buttonGroup.AddButton(
            localization.GetByLabel('UI/SystemMenu/ResetSettings/Reset'),
            self.Reset)
        buttonGroup.AddButton(
            localization.GetByLabel('UI/Common/Buttons/Cancel'), self.Cancel)

    def UpdateSliderLabel(self, label, *_):
        label.text = ''

    def OnMySliderMoved(self, slider):
        self.currentValue = self.ConvertValue(slider.GetValue())
        trinity.settings.SetValue('eveSpaceSceneGammaBrightness',
                                  self.currentValue)

    def Reset(self, *_):
        self.gammaSlider.SetValue(1.0, True)

    def Close(self, *args, **kwds):
        Window.Close(self, *args, **kwds)
        uicore.layer.systemmenu.Show()
        uicore.layer.systemmenu.FadeBGIn()
        uicore.layer.inflight.Enable()

    def Save(self, *_):
        self.savedValue = self.currentValue
        gfxsettings.Set(gfxsettings.GFX_BRIGHTNESS,
                        self.savedValue,
                        pending=False)
        self.Close()

    def Cancel(self, *_):
        trinity.settings.SetValue('eveSpaceSceneGammaBrightness',
                                  self.savedValue)
        self.Close()
Exemple #10
0
 def ApplyAttributes(self, attributes):
     Window.ApplyAttributes(self, attributes)
     self.SetTopparentHeight(0)
     self.SetWndIcon('res:/ui/texture/icons/bigplay_64.png')
     self._stopUpdate = False
     self._onFinish = None
     self._subtitles = None
     self._finished = False
     self.bottomContainer = Container(name='bottomContainer',
                                      parent=self.sr.main,
                                      align=uiconst.TOBOTTOM,
                                      height=16,
                                      padding=const.defaultPadding)
     self.layoutAreaParent = Container(parent=self.sr.main,
                                       padding=const.defaultPadding)
     self.layoutAreaParent._OnSizeChange_NoBlock = self.RecalcLayout
     self.layoutArea = Container(parent=self.layoutAreaParent,
                                 align=uiconst.CENTER,
                                 width=100,
                                 height=100)
     self.video = StreamingVideoSprite(parent=self.layoutArea,
                                       align=uiconst.TOALL)
     self.video.OnVideoSizeAvailable = self.RecalcLayout
     self.video.OnVideoFinished = self._OnVideoFinished
     self.playPauseBtn = ButtonIcon(parent=self.bottomContainer,
                                    func=self.Play,
                                    align=uiconst.TOLEFT)
     self.muteBtn = ButtonIcon(parent=self.bottomContainer,
                               func=self.Mute,
                               align=uiconst.TOLEFT)
     self.volumeSlider = Slider(parent=self.bottomContainer,
                                width=48,
                                minValue=0,
                                maxValue=100,
                                startValue=100,
                                showLabel=False,
                                onsetvaluefunc=self.SetVolume,
                                align=uiconst.TOLEFT)
     self.volume = settings.user.ui.Get('videoPlayerVolume', 100)
     self.volumeSlider.SetValue(self.volume,
                                updateHandle=True,
                                triggerCallback=False)
     self.subtitlesBtn = ButtonIcon(parent=self.bottomContainer,
                                    func=self.SwitchSubtitles,
                                    align=uiconst.TORIGHT)
     self.showSubtitles = True
     positionContainer = Container(parent=self.bottomContainer,
                                   align=uiconst.TOALL,
                                   padding=6)
     self.positionFill = Fill(parent=Container(parent=positionContainer,
                                               state=uiconst.UI_DISABLED),
                              name='progressFill',
                              align=uiconst.TOLEFT_PROP,
                              color=(0.1804, 0.5412, 0.6392, 1))
     self.downloadedFill = Fill(parent=Container(parent=positionContainer,
                                                 state=uiconst.UI_DISABLED),
                                name='downloadFill',
                                align=uiconst.TOLEFT_PROP,
                                color=(0.4667, 0.7529, 0.8392, 1))
     Fill(parent=positionContainer,
          align=uiconst.TOALL,
          color=(1.0, 1.0, 1.0, 0.3))
     self.followUpContainer = Container(parent=self.layoutAreaParent,
                                        align=uiconst.TOALL,
                                        state=uiconst.UI_HIDDEN)
     self.sr.subtitleCont = Container(parent=self.layoutArea,
                                      name='subtitleCont',
                                      idx=0,
                                      align=uiconst.TOBOTTOM_NOPUSH,
                                      state=uiconst.UI_DISABLED,
                                      height=100)
     self.sr.subtitleCont.Flush()
     self.UpdateLayoutArea()
     uthread2.StartTasklet(self._UpdatePosition)
Exemple #11
0
class VideoPlayerWindow(Window):
    default_caption = 'Video'
    default_minSize = (500, 400)
    default_windowID = 'VideoPlayer'

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        self.SetTopparentHeight(0)
        self.SetWndIcon('res:/ui/texture/icons/bigplay_64.png')
        self._stopUpdate = False
        self._onFinish = None
        self._subtitles = None
        self._finished = False
        self.bottomContainer = Container(name='bottomContainer',
                                         parent=self.sr.main,
                                         align=uiconst.TOBOTTOM,
                                         height=16,
                                         padding=const.defaultPadding)
        self.layoutAreaParent = Container(parent=self.sr.main,
                                          padding=const.defaultPadding)
        self.layoutAreaParent._OnSizeChange_NoBlock = self.RecalcLayout
        self.layoutArea = Container(parent=self.layoutAreaParent,
                                    align=uiconst.CENTER,
                                    width=100,
                                    height=100)
        self.video = StreamingVideoSprite(parent=self.layoutArea,
                                          align=uiconst.TOALL)
        self.video.OnVideoSizeAvailable = self.RecalcLayout
        self.video.OnVideoFinished = self._OnVideoFinished
        self.playPauseBtn = ButtonIcon(parent=self.bottomContainer,
                                       func=self.Play,
                                       align=uiconst.TOLEFT)
        self.muteBtn = ButtonIcon(parent=self.bottomContainer,
                                  func=self.Mute,
                                  align=uiconst.TOLEFT)
        self.volumeSlider = Slider(parent=self.bottomContainer,
                                   width=48,
                                   minValue=0,
                                   maxValue=100,
                                   startValue=100,
                                   showLabel=False,
                                   onsetvaluefunc=self.SetVolume,
                                   align=uiconst.TOLEFT)
        self.volume = settings.user.ui.Get('videoPlayerVolume', 100)
        self.volumeSlider.SetValue(self.volume,
                                   updateHandle=True,
                                   triggerCallback=False)
        self.subtitlesBtn = ButtonIcon(parent=self.bottomContainer,
                                       func=self.SwitchSubtitles,
                                       align=uiconst.TORIGHT)
        self.showSubtitles = True
        positionContainer = Container(parent=self.bottomContainer,
                                      align=uiconst.TOALL,
                                      padding=6)
        self.positionFill = Fill(parent=Container(parent=positionContainer,
                                                  state=uiconst.UI_DISABLED),
                                 name='progressFill',
                                 align=uiconst.TOLEFT_PROP,
                                 color=(0.1804, 0.5412, 0.6392, 1))
        self.downloadedFill = Fill(parent=Container(parent=positionContainer,
                                                    state=uiconst.UI_DISABLED),
                                   name='downloadFill',
                                   align=uiconst.TOLEFT_PROP,
                                   color=(0.4667, 0.7529, 0.8392, 1))
        Fill(parent=positionContainer,
             align=uiconst.TOALL,
             color=(1.0, 1.0, 1.0, 0.3))
        self.followUpContainer = Container(parent=self.layoutAreaParent,
                                           align=uiconst.TOALL,
                                           state=uiconst.UI_HIDDEN)
        self.sr.subtitleCont = Container(parent=self.layoutArea,
                                         name='subtitleCont',
                                         idx=0,
                                         align=uiconst.TOBOTTOM_NOPUSH,
                                         state=uiconst.UI_DISABLED,
                                         height=100)
        self.sr.subtitleCont.Flush()
        self.UpdateLayoutArea()
        uthread2.StartTasklet(self._UpdatePosition)

    def _OnVideoFinished(self):
        for each in self.followUpContainer.children[:]:
            each.Close()

        self._finished = True
        self.playPauseBtn.SetTexturePath('res:/ui/texture/icons/replay.png')
        if self._onFinish:
            self.followUpContainer.SetState(uiconst.UI_NORMAL)
            self.layoutArea.SetState(uiconst.UI_HIDDEN)
            self._onFinish(self.followUpContainer)

    def PlayVideo(self, path, title=None, subtitles=None, onFinish=None):
        self.playPauseBtn.SetTexturePath('res:/ui/texture/icons/pause.png')
        self.muteBtn.SetTexturePath('res:/ui/texture/icons/73_16_35.png')
        self.subtitlesBtn.SetTexturePath('res:/ui/texture/icons/73_16_10.png')
        self.layoutArea.SetState(uiconst.UI_NORMAL)
        self.followUpContainer.SetState(uiconst.UI_HIDDEN)
        self.video.SetVideoPath(path)
        self.video.SetVolume(float(self.volume) / 100.0)
        self.volumeSlider.SetValue(self.volume,
                                   updateHandle=True,
                                   triggerCallback=False)
        self.SetCaption(
            title if title is not None else VideoPlayerWindow.default_caption)
        self._onFinish = onFinish
        self._finished = False
        self._replayArgs = (path, title, subtitles, onFinish)
        if subtitles is None:
            self._subtitles = None
        else:
            self._subtitles = Subtitles(subtitles)

    def Close(self, *args, **kwds):
        self._stopUpdate = True
        self.video = None
        Window.Close(self, *args, **kwds)

    def _UpdatePosition(self):
        while not self._stopUpdate:
            if self.video:
                duration = float((self.video.duration or 1) / 1000000)
                if duration == 0:
                    duration = 1
                mediaTime = min(
                    float((self.video.mediaTime or 0) / 1000000) / duration, 1)
                downloadedTime = min(
                    float(
                        (self.video.downloadedTime or 0) / 1000000) / duration,
                    1)
                if mediaTime == 0:
                    self.positionFill.Hide()
                else:
                    self.positionFill.Show()
                    self.positionFill.width = mediaTime
                if downloadedTime == 0:
                    self.downloadedFill.Hide()
                else:
                    self.downloadedFill.Show()
                    self.downloadedFill.width = downloadedTime
                self._UpdateSubtitles()
            uthread2.Sleep(0.1)

    def _UpdateSubtitles(self):
        if self._subtitles is None or not self.showSubtitles:
            return
        currentTime = self.video.mediaTime or 0
        currentTime /= 1000000
        self.sr.subtitleCont.Flush()
        text = self._subtitles.GetSubtitle(currentTime)
        if text is not None:
            EveCaptionLarge(text=u'<center>%s' % text,
                            parent=self.sr.subtitleCont,
                            color=(0.75, 0.75, 0.75, 1),
                            align=uiconst.TOBOTTOM_NOPUSH,
                            bold=False,
                            state=uiconst.UI_DISABLED)
            l = EveCaptionLarge(text=u'<center>%s' % text,
                                parent=self.sr.subtitleCont,
                                color=(0, 0, 0, 1),
                                align=uiconst.TOBOTTOM,
                                bold=False,
                                state=uiconst.UI_DISABLED)
            l.renderObject.spriteEffect = trinity.TR2_SFX_GLOW

    def UpdateLayoutArea(self):
        size = self.video.GetVideoSize()
        if not size:
            return
        areaWidth, areaHeight = self.layoutAreaParent.GetAbsoluteSize()
        xFitScale = areaWidth / float(size[0])
        yFitScale = areaHeight / float(size[1])
        scaling = min(xFitScale, yFitScale)
        self.layoutArea.width = int(size[0] * scaling)
        self.layoutArea.height = int(size[1] * scaling)

    def RecalcLayout(self, *args):
        self.UpdateLayoutArea()

    def Play(self, *args):
        if self._finished:
            self._finished = False
            self.PlayVideo(*self._replayArgs)
        elif self.video.isPaused:
            self.video.Play()
            self.playPauseBtn.SetTexturePath('res:/ui/texture/icons/pause.png')
        else:
            self.video.Pause()
            self.playPauseBtn.SetTexturePath('res:/ui/texture/icons/play.png')

    def Mute(self, *args):
        if self.video.isMuted:
            self.video.UnmuteAudio()
            self.volumeSlider.SetValue(self.volume,
                                       updateHandle=True,
                                       triggerCallback=False)
            self.muteBtn.SetTexturePath('res:/ui/texture/icons/73_16_35.png')
        else:
            self.video.MuteAudio()
            self.volumeSlider.SetValue(0,
                                       updateHandle=True,
                                       triggerCallback=False)
            self.muteBtn.SetTexturePath('res:/ui/texture/icons/73_16_37.png')

    def SetVolume(self, slider):
        self.video.SetVolume(float(slider.value) / 100.0)
        self.volume = slider.value
        settings.user.ui.Set('videoPlayerVolume', self.volume)
        if self.volume:
            self.muteBtn.SetTexturePath('res:/ui/texture/icons/73_16_35.png')

    def SwitchSubtitles(self):
        self.showSubtitles = not self.showSubtitles
        if self.showSubtitles:
            self.subtitlesBtn.opacity = 1.0
        else:
            self.subtitlesBtn.opacity = 0.2
            self.sr.subtitleCont.Flush()
Exemple #12
0
class BinkVideoViewer(uicontrols.Window):
    __guid__ = 'form.InsiderBinkVideoViewer'
    __neocommenuitem__ = (('Video Player', 'InsiderBinkVideoViewer'), True, ROLE_GML)

    def ApplyAttributes(self, attributes):
        uicontrols.Window.ApplyAttributes(self, attributes)
        w, h = (450, 230)
        self.HideMainIcon()
        self.SetTopparentHeight(0)
        self.SetMinSize([w, h])
        self.SetHeight(h)
        self.SetCaption('Video Player')
        margin = const.defaultPadding
        self.sr.innermain = uiprimitives.Container(name='inner', left=margin, top=margin, parent=self.sr.main)
        self.sr.bottomframe = uiprimitives.Container(name='bottom', align=uiconst.TOBOTTOM, parent=self.sr.innermain, height=BTNSIZE, left=margin, top=margin, clipChildren=1)
        self.sr.rightframe = uiprimitives.Container(name='right', align=uiconst.TORIGHT, parent=self.sr.innermain, width=150, left=margin, top=margin, clipChildren=1)
        self.sr.movieCont = uiprimitives.Container(name='movieCont', align=uiconst.TOALL, parent=self.sr.innermain, pos=(margin,
         margin,
         margin,
         margin))
        uicontrols.Frame(parent=self.sr.innermain, color=(1.0, 1.0, 1.0, 0.2), idx=0)
        uicontrols.Frame(parent=self.sr.movieCont, color=(1.0, 1.0, 1.0, 0.2), idx=0)
        self.videoDir = blue.paths.ResolvePath(u'res:/') + 'video'
        self.node = None
        self.playing = False
        self.movieWidth = ASPECT_X
        self.movieHeight = ASPECT_Y
        self.InitButtons()
        self.InitScroll()

    def CloseByUser(self, *args):
        if getattr(self, 'movie', None) and self.movie:
            self.movie.Close()
        self.Close()

    def OnResizeUpdate(self, *args):
        if self and not self.destroyed:
            self.sr.resizeTimer = base.AutoTimer(250, self.OnEndScale_)

    def OnEndScale_(self, *args):
        self.sr.resizeTimer = None
        dimWidth, dimHeight = self.GetSize(self.movieWidth, self.movieHeight)
        if getattr(self, 'movie', None) is not None:
            self.movie.width = dimWidth
            self.movie.height = dimHeight

    def InitButtons(self):
        buttons = [['Play', self.MoviePlay, 'ui_38_16_228'],
         ['Pause', self.MoviePause, 'ui_38_16_238'],
         ['Stop', self.MovieStop, 'ui_38_16_111'],
         ['Toggle Sound', self.MovieAudioToggle, 'ui_38_16_90'],
         ['Set Aspect', self.SetMovieAspect, 'ui_38_16_1']]
        for button in buttons:
            hint, function, iconID = button
            btn = uiprimitives.Container(name=hint, align=uiconst.TOLEFT, width=BTNSIZE, left=const.defaultPadding, parent=self.sr.bottomframe)
            uicontrols.Frame(parent=btn, color=(1.0, 1.0, 1.0, 0.125))
            icon = uicontrols.Icon(icon=iconID, parent=btn, size=BTNSIZE, align=uiconst.CENTER)
            icon.OnClick = function
            icon.hint = hint
            icon.OnMouseEnter = (self.ShowSelected, icon, 1)
            icon.OnMouseExit = (self.ShowSelected, icon, 0)
            icon.sr.hilite = uiprimitives.Fill(parent=btn, name='hilite', state=uiconst.UI_HIDDEN)

        textWidth = 353
        self.textBlock = uiprimitives.Container(parent=self.sr.bottomframe, align=uiconst.TOALL, left=const.defaultPadding)
        self.slider = Slider(name='mySlider', parent=self.textBlock, align=uiconst.TOLEFT, width=100, minValue=0.0, maxValue=100.0, startVal=0.0, endsliderfunc=self._OnSlider)
        self.textBtm = uicontrols.Label(text='', parent=self.textBlock, align=uiconst.TOALL, left=const.defaultPadding, height=0, top=1, fontsize=10, letterspace=1, linespace=9, uppercase=1, state=uiconst.UI_NORMAL)

    def _OnSlider(self, slider):
        if getattr(self, 'movie', None) is None or self.movie.duration is None:
            return
        self.movie.Seek(long(slider.GetValue() / 100.0 * self.movie.duration))

    def UpdateText(self):
        node = self.node
        if node is not None:
            btmText = 'Time: %s / %s' % (int(self.GetCurrentMovieTime()), int(self.GetDuration()))
            self.textBtm.text = btmText
            if not self.slider.dragging:
                if self.GetDuration():
                    self.slider.SetValue(self.GetCurrentMovieTime() / self.GetDuration() * 100.0, updateHandle=True)
                else:
                    self.slider.SetValue(0, updateHandle=True)

    def GetCurrentMovieTime(self):
        if getattr(self, 'movie', None) is None:
            return 0
        if self.movie.mediaTime is None:
            return 0
        return float(self.movie.mediaTime / 1000000) / 1000

    def GetDuration(self):
        if getattr(self, 'movie', None) is None:
            return 0
        if self.movie.duration is None:
            return 0
        return float(self.movie.duration / 1000000) / 1000

    def ShowSelected(self, btn, toggle, *args):
        btn.sr.hilite.state = [uiconst.UI_HIDDEN, uiconst.UI_DISABLED][toggle]

    def MoviePlay(self, btn = None, *args):
        if self.node is None:
            return
        if getattr(self, 'movie', None) is not None:
            self.movie.Play()
            uthread.new(self.MoviePlaying)
        else:
            self.Populate()
            self.MoviePlay()

    def MoviePause(self, btn = None, stop = False, *args):
        if stop:
            if getattr(self, 'movie', None) is not None:
                self.movie.Pause()
                self.playing = False
                return
        if getattr(self, 'movie', None) is not None and not self.movie.isFinished and not self.movie.isPaused:
            self.movie.Pause()
        elif getattr(self, 'movie', None) is not None and not self.movie.isFinished and self.movie.isPaused:
            self.MoviePlay()

    def MovieStop(self, btn = None, *args):
        if getattr(self, 'movie', None) is not None:
            self.movie.Pause()
            self.sr.movieCont.Flush()
            uicontrols.Frame(parent=self.sr.movieCont, color=(1.0, 1.0, 1.0, 0.2), idx=0)
            self.movie = None
            self.playing = False

    def MoviePlaying(self):
        while self and not self.destroyed:
            self.UpdateText()
            if getattr(self, 'movie', None) is not None:
                self.playing = True
                if self.movie.isFinished:
                    self.sr.movieCont.Flush()
                    uicontrols.Frame(parent=self.sr.movieCont, color=(1.0, 1.0, 1.0, 0.2), idx=0)
                    self.playing = False
                elif self.movie.isPaused:
                    self.playing = False
            blue.pyos.synchro.SleepWallclock(20)

    def MovieAudioToggle(self, btn = None, *args):
        if getattr(self, 'movie', None) is not None:
            if self.movie.isMuted:
                self.movie.UnmuteAudio()
            else:
                self.movie.MuteAudio()

    def SetMovieAspect(self, btn = None, *args):
        popup = ModifyAspectRatioPopup(caption='Set aspect ratio...', width=self.movieWidth, height=self.movieHeight)
        ret = popup.Wnd()
        if ret is not None:
            width = int(ret['width'])
            height = int(ret['height'])
            dimWidth, dimHeight = self.GetSize(width, height)
            if getattr(self, 'movie', None) is not None:
                self.movieWidth = width
                self.movieHeight = height
                self.movie.width = dimWidth
                self.movie.height = dimHeight

    def Populate(self, path = None):
        self.sr.movieCont.Flush()
        uicontrols.Frame(parent=self.sr.movieCont, color=(1.0, 1.0, 1.0, 0.2), idx=0)
        dimWidth, dimHeight = self.GetSize(self.movieWidth, self.movieHeight)
        if path is not None:
            moviePath = path
        else:
            moviePath = str(self.node.resPath)
        self.path = moviePath
        self.movie = StreamingVideoSprite(parent=self.sr.movieCont, width=dimWidth, height=dimHeight, align=uiconst.CENTER, state=uiconst.UI_DISABLED, videoPath=moviePath)

    def GetSize(self, vidWidth = ASPECT_X, vidHeight = ASPECT_Y):
        x, y, contWidth, contHeight = self.sr.movieCont.GetAbsolute()
        dimWidth, dimHeight = self.GetVideoDimensions(contWidth, contHeight, vidWidth, vidHeight)
        return (dimWidth, dimHeight)

    def GetVideoDimensions(self, contWidth, contHeight, vidResWidth, vidResHeight):
        margin = const.defaultPadding
        dimWidth = vidResWidth
        dimHeight = vidResHeight
        contFactor = float(contWidth) / float(contHeight)
        vidResFactor = float(vidResWidth) / float(vidResHeight)
        if vidResFactor > contFactor:
            widthFactor = float(contWidth) / float(vidResWidth)
            dimWidth *= widthFactor
            dimHeight *= widthFactor
        elif vidResFactor < contFactor:
            heightFactor = float(contHeight) / float(vidResHeight)
            dimWidth *= heightFactor
            dimHeight *= heightFactor
        else:
            dimWidth = contWidth
            dimHeight = contHeight
        return (int(dimWidth), int(dimHeight))

    def GetFileListFromDirectories(self, path):
        for root, dirs, files in os.walk(path):
            for filename in files:
                if filename.lower().endswith('.webm'):
                    yield root + '\\' + filename

    def InitScroll(self):
        self.scroll = uicontrols.Scroll(parent=self.sr.rightframe, padding=(const.defaultPadding,
         const.defaultPadding,
         const.defaultPadding,
         const.defaultPadding))
        self.scroll.sr.id = 'VideoList'
        videos = []
        for video in ['https://cdn1.eveonline.com/academy/001-EVEFA-YourPlaceinNewEden.webm'] + list(self.GetFileListFromDirectories(self.videoDir)):
            if video.startswith('https://'):
                fileName = video[video.rindex('/') + 1:]
                resPath = video
            else:
                normPath = os.path.normpath(video)
                fileName = os.path.basename(normPath)
                resPath = blue.paths.ResolvePathToRoot('res', normPath).replace(':', '')
            videos.append(listentry.Get('Generic', {'label': fileName,
             'hint': resPath,
             'resPath': resPath,
             'fileName': fileName,
             'OnClick': self.ScrollClick,
             'OnDblClick': self.ScrollDblClick}))

        self.scroll.Load(contentList=videos, headers=['Filename'], fixedEntryHeight=18)

    def ScrollClick(self, node, *args):
        if not self.playing:
            self.node = node.sr.node
            self.movie = None
            self.UpdateText()

    def ScrollDblClick(self, node, *args):
        if getattr(self, 'movie', None) is not None:
            self.MoviePause(stop=True)
        path = str(node.sr.node.resPath)
        self.node = node.sr.node
        self.Populate(path=path)
        self.MoviePlay()
Exemple #13
0
 def SetupDScanUI(self, directionBox):
     directionSettingsBox = Container(name='direction', parent=directionBox, align=uiconst.TOTOP, height=70, clipChildren=True, padLeft=2)
     self.sr.dirscroll = Scroll(name='dirscroll', parent=directionBox)
     self.sr.dirscroll.sr.id = 'scanner_dirscroll'
     presetGrid = LayoutGrid(parent=directionSettingsBox, columns=2, state=uiconst.UI_PICKCHILDREN, align=uiconst.TOPLEFT, left=0, top=3)
     paddingBtwElements = 8
     checked = settings.user.ui.Get('scannerusesoverviewsettings', 0)
     self.sr.useoverview = Checkbox(text=GetByLabel('UI/Inflight/Scanner/UsePreset'), parent=presetGrid, configName='', retval=0, checked=checked, left=0, align=uiconst.TOPLEFT, callback=self.UseOverviewChanged, width=320, wrapLabel=False)
     presetSelected = settings.user.ui.Get('scanner_presetInUse', None)
     presetOptions = self.GetPresetOptions()
     self.presetsCombo = Combo(label='', parent=presetGrid, options=presetOptions, name='comboTabOverview', select=presetSelected, align=uiconst.TOPLEFT, width=120, left=10, callback=self.OnProfileInUseChanged)
     if not checked:
         self.presetsCombo.Disable()
         self.presetsCombo.opacity = 0.5
         self.sr.useoverview.sr.label.opacity = 0.5
     self.rangeCont = Container(parent=directionSettingsBox, name='rangeCont', align=uiconst.TOTOP, height=24, top=self.sr.useoverview.height)
     self.angleCont = Container(parent=directionSettingsBox, name='rangeCont', align=uiconst.TOTOP, height=24)
     textLeft = 2
     rangeText = GetByLabel('UI/Inflight/Scanner/Range')
     rangeLabel = EveLabelSmall(text=rangeText, parent=self.rangeCont, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, left=textLeft)
     angleText = GetByLabel('UI/Inflight/Scanner/Angle')
     angleLabel = EveLabelSmall(text=angleText, parent=self.angleCont, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, left=textLeft)
     innerLeft = max(rangeLabel.textwidth, angleLabel.textwidth) + paddingBtwElements + textLeft
     innerRangeCont = Container(parent=self.rangeCont, align=uiconst.TOALL, padLeft=innerLeft)
     innderAngleCont = Container(parent=self.angleCont, align=uiconst.TOALL, padLeft=innerLeft)
     maxAuRange = 14.3
     startingKmValue = settings.user.ui.Get('dir_scanrange', const.AU * maxAuRange)
     startingAuValue = ConvertKmToAu(startingKmValue)
     distanceSliderCont = Container(name='distanceSliderCont', parent=innerRangeCont, align=uiconst.CENTERLEFT, state=uiconst.UI_PICKCHILDREN, pos=(0, -1, 100, 18))
     smallestAU = ConvertKmToAu(1000000)
     self.distanceSlider = Slider(name='distanceSlider', parent=distanceSliderCont, sliderID='distanceSlider', minValue=0, maxValue=maxAuRange, endsliderfunc=self.EndSetDistanceSliderValue, onsetvaluefunc=self.OnSetDistanceSliderValue, increments=[smallestAU,
      1,
      5,
      10,
      maxAuRange], height=20, barHeight=10)
     self.distanceSlider.label.display = False
     self.distanceSlider.SetValue(startingAuValue, updateHandle=True, useIncrements=False)
     left = distanceSliderCont.width + paddingBtwElements
     maxAuRangeInKm = ConvertAuToKm(maxAuRange)
     self.dir_rangeinput = SinglelineEdit(name='dir_rangeinput', parent=innerRangeCont, ints=(0, maxAuRangeInKm), setvalue=startingKmValue, align=uiconst.CENTERLEFT, pos=(left,
      0,
      90,
      0), maxLength=len(str(maxAuRangeInKm)) + 1, OnReturn=self.DirectionSearch)
     self.dir_rangeinput.OnChar = self.OnKmChar
     self.dir_rangeinput.OnMouseWheel = self.OnMouseWheelKm
     self.dir_rangeinput.ChangeNumericValue = self.ChangeNumericValueKm
     kmText = GetByLabel('UI/Inflight/Scanner/UnitKMAndSeparator')
     left = self.dir_rangeinput.left + self.dir_rangeinput.width + paddingBtwElements / 2
     kmLabel = EveLabelSmall(text=kmText, parent=innerRangeCont, align=uiconst.CENTERLEFT, pos=(left,
      0,
      0,
      0), state=uiconst.UI_DISABLED)
     left = kmLabel.left + kmLabel.textwidth + paddingBtwElements
     self.dir_rangeinputAu = SinglelineEdit(name='dir_rangeinputAu', parent=innerRangeCont, setvalue=startingAuValue, floats=(0, maxAuRange, 1), align=uiconst.CENTERLEFT, pos=(left,
      0,
      45,
      0), maxLength=4, OnReturn=self.DirectionSearch)
     self.dir_rangeinputAu.OnChar = self.OnAuChar
     self.dir_rangeinputAu.OnMouseWheel = self.OnMouseWheelAu
     self.dir_rangeinputAu.ChangeNumericValue = self.ChangeNumericValueAu
     auText = GetByLabel('UI/Inflight/Scanner/UnitAU')
     left = self.dir_rangeinputAu.left + self.dir_rangeinputAu.width + paddingBtwElements / 2
     auLabel = EveLabelSmall(text=auText, parent=innerRangeCont, align=uiconst.CENTERLEFT, pos=(left,
      0,
      0,
      0), state=uiconst.UI_DISABLED)
     angleSliderCont = Container(name='sliderCont', parent=innderAngleCont, align=uiconst.CENTERLEFT, state=uiconst.UI_PICKCHILDREN, pos=(0, -1, 100, 18))
     self.angleSliderLabel = EveLabelSmall(text='', parent=innderAngleCont, align=uiconst.CENTERLEFT, pos=(0, 0, 0, 0), state=uiconst.UI_DISABLED)
     startingAngle = settings.user.ui.Get('scan_angleSlider', 360)
     startingAngle = max(0, min(startingAngle, 360))
     self.degreeCone = PieCircle(parent=innderAngleCont, left=0, align=uiconst.CENTERLEFT, setValue=startingAngle)
     self.degreeCone.opacity = 0.3
     self.scanangle = DegToRad(startingAngle)
     angleSlider = Slider(name='angleSlider', parent=angleSliderCont, sliderID='angleSlider', startVal=startingAngle, minValue=5, maxValue=360, increments=[5,
      15,
      30,
      60,
      90,
      180,
      360], isEvenIncrementsSlider=True, endsliderfunc=self.EndSetAngleSliderValue, height=20, barHeight=10, setlabelfunc=self.UpdateAngleSliderLabel)
     left = angleSliderCont.width + paddingBtwElements
     self.angleSliderLabel.left = left + 5
     self.degreeCone.left = left + 35
     buttonText = GetByLabel('UI/Inflight/Scanner/Scan')
     scanButton = Button(parent=innderAngleCont, label=buttonText, align=uiconst.CENTERLEFT, pos=(4, 0, 0, 0), func=self.DirectionSearch)
     scanButton.left = auLabel.left + auLabel.textwidth - scanButton.width
Exemple #14
0
class DirectionalScanner(Window):
    __notifyevents__ = ['OnSessionChanged', 'OnOverviewPresetSaved']
    default_windowID = 'directionalScanner'
    default_width = 400
    default_height = 350
    default_minSize = (350, 175)
    default_captionLabelPath = 'UI/Inflight/Scanner/DirectionalScan'

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        self.scanSvc = sm.GetService('scanSvc')
        self.busy = False
        self.scanresult = []
        self.scanangle = DegToRad(90)
        self.scope = 'inflight'
        self.SetTopparentHeight(0)
        self.SetWndIcon(None)
        self.HideMainIcon()
        directionBox = Container(name='direction', parent=self.sr.main, align=uiconst.TOALL, left=const.defaultPadding, width=const.defaultPadding, top=const.defaultPadding, height=const.defaultPadding)
        self.SetupDScanUI(directionBox)

    def SetupDScanUI(self, directionBox):
        directionSettingsBox = Container(name='direction', parent=directionBox, align=uiconst.TOTOP, height=70, clipChildren=True, padLeft=2)
        self.sr.dirscroll = Scroll(name='dirscroll', parent=directionBox)
        self.sr.dirscroll.sr.id = 'scanner_dirscroll'
        presetGrid = LayoutGrid(parent=directionSettingsBox, columns=2, state=uiconst.UI_PICKCHILDREN, align=uiconst.TOPLEFT, left=0, top=3)
        paddingBtwElements = 8
        checked = settings.user.ui.Get('scannerusesoverviewsettings', 0)
        self.sr.useoverview = Checkbox(text=GetByLabel('UI/Inflight/Scanner/UsePreset'), parent=presetGrid, configName='', retval=0, checked=checked, left=0, align=uiconst.TOPLEFT, callback=self.UseOverviewChanged, width=320, wrapLabel=False)
        presetSelected = settings.user.ui.Get('scanner_presetInUse', None)
        presetOptions = self.GetPresetOptions()
        self.presetsCombo = Combo(label='', parent=presetGrid, options=presetOptions, name='comboTabOverview', select=presetSelected, align=uiconst.TOPLEFT, width=120, left=10, callback=self.OnProfileInUseChanged)
        if not checked:
            self.presetsCombo.Disable()
            self.presetsCombo.opacity = 0.5
            self.sr.useoverview.sr.label.opacity = 0.5
        self.rangeCont = Container(parent=directionSettingsBox, name='rangeCont', align=uiconst.TOTOP, height=24, top=self.sr.useoverview.height)
        self.angleCont = Container(parent=directionSettingsBox, name='rangeCont', align=uiconst.TOTOP, height=24)
        textLeft = 2
        rangeText = GetByLabel('UI/Inflight/Scanner/Range')
        rangeLabel = EveLabelSmall(text=rangeText, parent=self.rangeCont, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, left=textLeft)
        angleText = GetByLabel('UI/Inflight/Scanner/Angle')
        angleLabel = EveLabelSmall(text=angleText, parent=self.angleCont, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, left=textLeft)
        innerLeft = max(rangeLabel.textwidth, angleLabel.textwidth) + paddingBtwElements + textLeft
        innerRangeCont = Container(parent=self.rangeCont, align=uiconst.TOALL, padLeft=innerLeft)
        innderAngleCont = Container(parent=self.angleCont, align=uiconst.TOALL, padLeft=innerLeft)
        maxAuRange = 14.3
        startingKmValue = settings.user.ui.Get('dir_scanrange', const.AU * maxAuRange)
        startingAuValue = ConvertKmToAu(startingKmValue)
        distanceSliderCont = Container(name='distanceSliderCont', parent=innerRangeCont, align=uiconst.CENTERLEFT, state=uiconst.UI_PICKCHILDREN, pos=(0, -1, 100, 18))
        smallestAU = ConvertKmToAu(1000000)
        self.distanceSlider = Slider(name='distanceSlider', parent=distanceSliderCont, sliderID='distanceSlider', minValue=0, maxValue=maxAuRange, endsliderfunc=self.EndSetDistanceSliderValue, onsetvaluefunc=self.OnSetDistanceSliderValue, increments=[smallestAU,
         1,
         5,
         10,
         maxAuRange], height=20, barHeight=10)
        self.distanceSlider.label.display = False
        self.distanceSlider.SetValue(startingAuValue, updateHandle=True, useIncrements=False)
        left = distanceSliderCont.width + paddingBtwElements
        maxAuRangeInKm = ConvertAuToKm(maxAuRange)
        self.dir_rangeinput = SinglelineEdit(name='dir_rangeinput', parent=innerRangeCont, ints=(0, maxAuRangeInKm), setvalue=startingKmValue, align=uiconst.CENTERLEFT, pos=(left,
         0,
         90,
         0), maxLength=len(str(maxAuRangeInKm)) + 1, OnReturn=self.DirectionSearch)
        self.dir_rangeinput.OnChar = self.OnKmChar
        self.dir_rangeinput.OnMouseWheel = self.OnMouseWheelKm
        self.dir_rangeinput.ChangeNumericValue = self.ChangeNumericValueKm
        kmText = GetByLabel('UI/Inflight/Scanner/UnitKMAndSeparator')
        left = self.dir_rangeinput.left + self.dir_rangeinput.width + paddingBtwElements / 2
        kmLabel = EveLabelSmall(text=kmText, parent=innerRangeCont, align=uiconst.CENTERLEFT, pos=(left,
         0,
         0,
         0), state=uiconst.UI_DISABLED)
        left = kmLabel.left + kmLabel.textwidth + paddingBtwElements
        self.dir_rangeinputAu = SinglelineEdit(name='dir_rangeinputAu', parent=innerRangeCont, setvalue=startingAuValue, floats=(0, maxAuRange, 1), align=uiconst.CENTERLEFT, pos=(left,
         0,
         45,
         0), maxLength=4, OnReturn=self.DirectionSearch)
        self.dir_rangeinputAu.OnChar = self.OnAuChar
        self.dir_rangeinputAu.OnMouseWheel = self.OnMouseWheelAu
        self.dir_rangeinputAu.ChangeNumericValue = self.ChangeNumericValueAu
        auText = GetByLabel('UI/Inflight/Scanner/UnitAU')
        left = self.dir_rangeinputAu.left + self.dir_rangeinputAu.width + paddingBtwElements / 2
        auLabel = EveLabelSmall(text=auText, parent=innerRangeCont, align=uiconst.CENTERLEFT, pos=(left,
         0,
         0,
         0), state=uiconst.UI_DISABLED)
        angleSliderCont = Container(name='sliderCont', parent=innderAngleCont, align=uiconst.CENTERLEFT, state=uiconst.UI_PICKCHILDREN, pos=(0, -1, 100, 18))
        self.angleSliderLabel = EveLabelSmall(text='', parent=innderAngleCont, align=uiconst.CENTERLEFT, pos=(0, 0, 0, 0), state=uiconst.UI_DISABLED)
        startingAngle = settings.user.ui.Get('scan_angleSlider', 360)
        startingAngle = max(0, min(startingAngle, 360))
        self.degreeCone = PieCircle(parent=innderAngleCont, left=0, align=uiconst.CENTERLEFT, setValue=startingAngle)
        self.degreeCone.opacity = 0.3
        self.scanangle = DegToRad(startingAngle)
        angleSlider = Slider(name='angleSlider', parent=angleSliderCont, sliderID='angleSlider', startVal=startingAngle, minValue=5, maxValue=360, increments=[5,
         15,
         30,
         60,
         90,
         180,
         360], isEvenIncrementsSlider=True, endsliderfunc=self.EndSetAngleSliderValue, height=20, barHeight=10, setlabelfunc=self.UpdateAngleSliderLabel)
        left = angleSliderCont.width + paddingBtwElements
        self.angleSliderLabel.left = left + 5
        self.degreeCone.left = left + 35
        buttonText = GetByLabel('UI/Inflight/Scanner/Scan')
        scanButton = Button(parent=innderAngleCont, label=buttonText, align=uiconst.CENTERLEFT, pos=(4, 0, 0, 0), func=self.DirectionSearch)
        scanButton.left = auLabel.left + auLabel.textwidth - scanButton.width

    def GetPresetOptions(self):
        p = sm.GetService('overviewPresetSvc').GetAllPresets().keys()
        options = []
        for name in p:
            defaultName = sm.GetService('overviewPresetSvc').GetDefaultOverviewName(name)
            if defaultName:
                options.append((' ' + defaultName.lower(), (defaultName, name)))
            else:
                displayName = sm.GetService('overviewPresetSvc').GetPresetDisplayName(name)
                options.append((displayName.lower(), (displayName, name)))

        options = SortListOfTuples(options)
        options.insert(0, (GetByLabel('UI/Inflight/Scanner/UseActiveOverviewSettings'), None))
        return options

    def OnOverviewPresetSaved(self):
        presetSelected = settings.user.ui.Get('scanner_presetInUse', None)
        presetOptions = self.GetPresetOptions()
        self.presetsCombo.LoadOptions(entries=presetOptions, select=presetSelected)

    def UpdateAngleSliderLabel(self, label, sliderID, displayName, value):
        self.angleSliderLabel.text = GetByLabel('UI/Inflight/Scanner/AngleDegrees', value=value)
        self.degreeCone.SetDegree(value)

    def OnKmChar(self, char, flag):
        returnValue = SinglelineEdit.OnChar(self.dir_rangeinput, char, flag)
        self.KmValueChanged()
        return returnValue

    def OnMouseWheelKm(self, *args):
        SinglelineEdit.MouseWheel(self.dir_rangeinput, *args)
        self.KmValueChanged()

    def ChangeNumericValueKm(self, *args):
        SinglelineEdit.ChangeNumericValue(self.dir_rangeinputAu, *args)
        self.AuValueChanged()

    def KmValueChanged(self):
        kmValue = self.dir_rangeinput.GetValue()
        auValue = ConvertKmToAu(kmValue)
        self.dir_rangeinputAu.SetValue(auValue)
        self.distanceSlider.SetValue(auValue, updateHandle=True, useIncrements=False)

    def OnAuChar(self, char, flag):
        returnValue = SinglelineEdit.OnChar(self.dir_rangeinputAu, char, flag)
        self.AuValueChanged()
        return returnValue

    def OnMouseWheelAu(self, *args):
        SinglelineEdit.MouseWheel(self.dir_rangeinputAu, *args)
        self.AuValueChanged()

    def ChangeNumericValueAu(self, *args):
        SinglelineEdit.ChangeNumericValue(self.dir_rangeinputAu, *args)
        self.AuValueChanged()

    def AuValueChanged(self):
        auValue = self.dir_rangeinputAu.GetValue()
        kmValue = ConvertAuToKm(auValue)
        self.dir_rangeinput.SetValue(kmValue)
        self.distanceSlider.SetValue(auValue, updateHandle=True, useIncrements=False)

    def UpdateDistanceFromSlider(self):
        auValue = self.distanceSlider.GetValue()
        kmValue = ConvertAuToKm(auValue)
        self.dir_rangeinput.SetValue(kmValue)
        self.dir_rangeinputAu.SetValue(auValue)

    def EndSetDistanceSliderValue(self, *args):
        self.UpdateDistanceFromSlider()
        uthread.new(self.DirectionSearch)

    def OnSetDistanceSliderValue(self, slider, *args):
        if not slider.dragging:
            return
        self.UpdateDistanceFromSlider()

    def EndSetAngleSliderValue(self, slider):
        angleValue = slider.GetValue()
        self.degreeCone.SetDegree(angleValue)
        self.SetMapAngle(DegToRad(angleValue))
        settings.user.ui.Set('scan_angleSlider', angleValue)
        uthread.new(self.DirectionSearch)

    def _OnClose(self, *args):
        self.SetMapAngle(0)

    def DirectionSearch(self, *args):
        if self.destroyed or self.busy:
            return
        self.busy = True
        self.ShowLoad()
        self.scanresult = []
        if self.sr.useoverview.checked:
            selectedValue = self.presetsCombo.GetValue()
            if selectedValue is None:
                selectedValue = sm.GetService('overviewPresetSvc').GetActiveOverviewPresetName()
            filters = sm.GetService('overviewPresetSvc').GetValidGroups(presetName=selectedValue)
        camera = sm.GetService('sceneManager').GetRegisteredCamera(None, defaultOnActiveCamera=True)
        if not camera:
            self.busy = False
            self.HideLoad()
            raise RuntimeError('No camera found?!')
        vec = geo2.QuaternionTransformVector(camera.rotationAroundParent, (0, 0, -1))
        vec = geo2.Vec3Normalize(vec)
        rnge = self.dir_rangeinput.GetValue()
        try:
            result = self.scanSvc.ConeScan(self.scanangle, rnge * 1000, vec[0], vec[1], vec[2])
        except (UserError, RuntimeError) as err:
            result = None
            self.busy = False
            self.HideLoad()
            raise err

        settings.user.ui.Set('dir_scanrange', rnge)
        if result:
            bp = sm.GetService('michelle').GetBallpark()
            if bp:
                for rec in result:
                    if self.sr.useoverview.checked:
                        if rec.groupID not in filters:
                            continue
                    if rec.id in bp.balls:
                        self.scanresult.append([None, bp.balls[rec.id], rec])
                    else:
                        self.scanresult.append([None, None, rec])

        self.ShowDirectionalSearchResult()
        self.busy = False
        self.HideLoad()

    def ShowDirectionalSearchResult(self, *args):
        self.listtype = 'location'
        scrolllist = []
        if self.scanresult and len(self.scanresult):
            myball = None
            ballpark = sm.GetService('michelle').GetBallpark()
            if ballpark:
                myball = ballpark.GetBall(eve.session.shipid)
            prime = []
            for result in self.scanresult:
                slimItem, ball, celestialRec = result
                if not slimItem and celestialRec:
                    prime.append(celestialRec.id)

            if prime:
                cfg.evelocations.Prime(prime)
            for slimItem, ball, celestialRec in self.scanresult:
                if self is None or self.destroyed:
                    return
                if slimItem:
                    typeinfo = cfg.invtypes.Get(slimItem.typeID)
                    entryname = GetSlimItemName(slimItem)
                    itemID = slimItem.itemID
                    typeID = slimItem.typeID
                    if not entryname:
                        entryname = typeinfo.Group().name
                elif celestialRec:
                    typeinfo = cfg.invtypes.Get(celestialRec.typeID)
                    if typeinfo.groupID == const.groupHarvestableCloud:
                        entryname = GetByLabel('UI/Inventory/SlimItemNames/SlimHarvestableCloud', typeinfo.name)
                    elif typeinfo.categoryID == const.categoryAsteroid:
                        entryname = GetByLabel('UI/Inventory/SlimItemNames/SlimAsteroid', typeinfo.name)
                    else:
                        entryname = cfg.evelocations.Get(celestialRec.id).name
                    if not entryname:
                        entryname = typeinfo.name
                    itemID = celestialRec.id
                    typeID = celestialRec.typeID
                else:
                    continue
                if ball is not None:
                    dist = ball.surfaceDist
                    diststr = FmtDist(dist, maxdemicals=1)
                else:
                    dist = 0
                    diststr = '-'
                groupID = cfg.invtypes.Get(typeID).groupID
                if not eve.session.role & (service.ROLE_GML | service.ROLE_WORLDMOD):
                    if groupID == const.groupCloud:
                        continue
                data = KeyVal()
                data.label = '%s<t>%s<t>%s' % (entryname, typeinfo.name, diststr)
                data.entryName = entryname
                data.typeName = typeinfo.name
                data.Set('sort_%s' % GetByLabel('UI/Common/Distance'), dist)
                data.columnID = 'directionalResultGroupColumn'
                data.result = result
                data.itemID = itemID
                data.typeID = typeID
                data.GetMenu = self.DirectionalResultMenu
                scrolllist.append(listentry.Get('DirectionalScanResults', data=data))
                blue.pyos.BeNice()

        if not len(scrolllist):
            data = KeyVal()
            data.label = GetByLabel('UI/Inflight/Scanner/DirectionalNoResult')
            data.hideLines = 1
            scrolllist.append(listentry.Get('Generic', data=data))
            headers = []
        else:
            headers = [GetByLabel('UI/Common/Name'), GetByLabel('UI/Common/Type'), GetByLabel('UI/Common/Distance')]
        self.sr.dirscroll.Load(contentList=scrolllist, headers=headers)

    def DirectionalResultMenu(self, entry, *args):
        if entry.sr.node.itemID:
            return sm.GetService('menu').CelestialMenu(entry.sr.node.itemID, typeID=entry.sr.node.typeID)
        return []

    def SetMapAngle(self, angle):
        if angle is not None:
            self.scanangle = angle
        wnd = MapBrowserWnd.GetIfOpen()
        if wnd:
            wnd.SetTempAngle(angle)

    def EndSetSliderValue(self, *args):
        uthread.new(self.DirectionSearch)

    def UseOverviewChanged(self, checked):
        if self.sr.useoverview.checked:
            self.presetsCombo.Enable()
            self.presetsCombo.opacity = 1
            self.sr.useoverview.sr.label.opacity = 1
        else:
            self.presetsCombo.Disable()
            self.presetsCombo.opacity = 0.5
            self.sr.useoverview.sr.label.opacity = 0.5
        settings.user.ui.Set('scannerusesoverviewsettings', self.sr.useoverview.checked)
        self.DirectionSearch()

    def OnProfileInUseChanged(self, *args):
        value = self.presetsCombo.GetValue()
        settings.user.ui.Set('scanner_presetInUse', value)
        self.DirectionSearch()