Changeset 326

Show
Ignore:
Timestamp:
06/23/06 19:40:28 (3 years ago)
Author:
nicfit
Message:

Active/inactive control fixes when tabs are removed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main_window.py

    r325 r326  
    7474                                                      self._audio_control) 
    7575 
    76         self._active_playlist = None 
     76        # The active control is the one that has ownership of the AudioControl 
     77        self._active_control = None 
     78 
    7779        # Load playlists 
    7880        playlists = mesk.config.getlist(mesk.CONFIG_MAIN, 'playlists') 
     
    98100 
    99101            self.add_notebook_control(pl_ctrl) 
    100             if not self._active_playlist
    101                 self.set_control_active(pl_ctrl) 
     102            if not self._active_control
     103                self.set_active_control(pl_ctrl) 
    102104 
    103105        self._pref_window = None 
     
    107109 
    108110    def _on_playlist_ctrl_changed(self, ctrl): 
    109         if ctrl == self._active_playlist
     111        if ctrl == self._active_control
    110112            if not len(ctrl.get_playlist()): 
    111113                self._album_cover_control.clear() 
     
    113115    def _on_control_request_active(self, ctrl): 
    114116        # A control is requesting the AudioControl.  Grant it. 
    115         self.set_control_active(ctrl) 
    116  
    117     def set_control_active(self, ctrl): 
    118         if ctrl == self._active_playlist
     117        self.set_active_control(ctrl) 
     118 
     119    def set_active_control(self, ctrl): 
     120        if ctrl == self._active_control
    119121            return 
    120122        self._audio_control.stop() 
    121         if self._active_playlist
    122             self._active_playlist.set_active(False, None) 
    123  
    124         self._active_playlist = ctrl 
    125         pl = self._active_playlist.get_playlist() 
     123        if self._active_control
     124            self._active_control.set_active(False, None) 
     125 
     126        self._active_control = ctrl 
     127        pl = self._active_control.get_playlist() 
    126128        self._audio_control.set_playlist(pl) 
    127         self._active_playlist.set_active(True, self._audio_control) 
     129        self._active_control.set_active(True, self._audio_control) 
    128130 
    129131    def add_notebook_control(self, ctrl): 
     
    134136        if self._notebook.get_n_pages() > 1: 
    135137            self._notebook.set_show_tabs(True) 
     138        # This list order does not necessarily correspond to the tab order 
    136139        self._controls.append(ctrl) 
    137140 
    138141    def remove_notebook_control(self, ctrl): 
    139         # FIXME: Transition active tab if necessary 
    140         page = self._notebook.page_num(ctrl.widget) 
     142        if self._notebook.get_n_pages() == 1: 
     143            raise RuntimeError('Notebook MUST have at least one page') 
     144 
     145        page_num = self._notebook.page_num(ctrl.widget) 
     146        new_active = False 
     147 
     148        # Transition active tab if necessary 
     149        if ctrl == self._active_control: 
     150            new_active = True 
     151            ctrl.set_active(False) 
     152 
     153        # Remove 
    141154        self._controls.remove(ctrl) 
    142         self._notebook.remove_page(page
     155        self._notebook.remove_page(page_num
    143156        if self._notebook.get_n_pages() == 1: 
    144157            self._notebook.set_show_tabs(False) 
    145158 
     159        # Set the new active control 
     160        if new_active: 
     161            page = self._notebook.get_current_page() 
     162            page = self._notebook.get_nth_page(page) 
     163            ctrl = self._get_control_from_widget(page) 
     164            self.set_active_control(ctrl) 
     165 
     166    def _get_control_from_widget(self, widget): 
     167        for ctrl in self._controls: 
     168            if ctrl.widget == widget: 
     169                return ctrl 
     170        return None 
     171 
     172    def get_focused_control(self): 
     173        curr = self._notebook.get_current_page() 
     174        page_widget = self._notebook.get_nth_page(curr) 
     175        return self._get_control_from_widget(page_widget) 
     176 
    146177    def _on_window_focus_in_event(self, window, event): 
    147         active_control = self.get_showing_control() 
    148         if active_control: 
    149             active_control.set_focused() 
     178        active_control = self.get_focused_control() 
     179        active_control.set_focused() 
    150180 
    151181    def _on_notebook_switch_page(self, notebook, page, page_num): 
     
    157187    def _on_tab_close_button_clicked(self, widget, ctrl): 
    158188        self.remove_notebook_control(ctrl) 
    159  
    160     def get_showing_control(self): 
    161         curr = self._notebook.get_current_page() 
    162         page_widget = self._notebook.get_nth_page(curr) 
    163         return self._get_control_from_widget(page_widget) 
    164  
    165     def _get_control_from_widget(self, widget): 
    166         for ctrl in self._controls: 
    167             if ctrl.widget == widget: 
    168                 return ctrl 
    169         return None 
    170189 
    171190    def show(self): 
     
    283302            if (event.keyval == gtk.keysyms.w and 
    284303                self._notebook.get_n_pages() > 1): 
    285                 self.remove_notebook_control(self.get_showing_control()) 
     304                self.remove_notebook_control(self.get_focused_control()) 
    286305                return True 
    287306        return False 
     
    319338                               _('Volume %d%%') % (vol * 100)) 
    320339 
     340 
  • trunk/src/mesk_gui.glade

    r325 r326  
    4545 
    4646                  <child> 
    47                     <widget class="GtkMenuItem" id="open_playlist"> 
    48                       <property name="visible">True</property> 
    49                       <property name="label" translatable="yes">Open Playlist</property> 
     47                    <widget class="GtkImageMenuItem" id="new_playlist"> 
     48                      <property name="visible">True</property> 
     49                      <property name="label" translatable="yes">New</property> 
     50                      <property name="use_underline">True</property> 
     51                      <signal name="activate" handler="on_new_playlist_activate" last_modification_time="Fri, 23 Jun 2006 03:17:11 GMT"/> 
     52 
     53                      <child internal-child="image"> 
     54                        <widget class="GtkImage" id="image91"> 
     55                          <property name="visible">True</property> 
     56                          <property name="stock">gtk-new</property> 
     57                          <property name="icon_size">1</property> 
     58                          <property name="xalign">0.5</property> 
     59                          <property name="yalign">0.5</property> 
     60                          <property name="xpad">0</property> 
     61                          <property name="ypad">0</property> 
     62                        </widget> 
     63                      </child> 
     64                    </widget> 
     65                  </child> 
     66 
     67                  <child> 
     68                    <widget class="GtkImageMenuItem" id="open_playlist"> 
     69                      <property name="visible">True</property> 
     70                      <property name="label" translatable="yes">Open...</property> 
    5071                      <property name="use_underline">True</property> 
    5172                      <signal name="activate" handler="on_open_playlist_activate" last_modification_time="Fri, 23 Jun 2006 03:17:11 GMT"/> 
    52                     </widget> 
    53                   </child> 
    54  
    55                   <child> 
    56                     <widget class="GtkMenuItem" id="new_playlist"> 
    57                       <property name="visible">True</property> 
    58                       <property name="label" translatable="yes">New Playlist</property> 
    59                       <property name="use_underline">True</property> 
    60                       <signal name="activate" handler="on_new_playlist_activate" last_modification_time="Fri, 23 Jun 2006 03:17:11 GMT"/> 
     73 
     74                      <child internal-child="image"> 
     75                        <widget class="GtkImage" id="image92"> 
     76                          <property name="visible">True</property> 
     77                          <property name="stock">gtk-open</property> 
     78                          <property name="icon_size">1</property> 
     79                          <property name="xalign">0.5</property> 
     80                          <property name="yalign">0.5</property> 
     81                          <property name="xpad">0</property> 
     82                          <property name="ypad">0</property> 
     83                        </widget> 
     84                      </child> 
    6185                    </widget> 
    6286                  </child> 
     
    99123 
    100124                      <child internal-child="image"> 
    101                         <widget class="GtkImage" id="image69"> 
     125                        <widget class="GtkImage" id="image93"> 
    102126                          <property name="visible">True</property> 
    103127                          <property name="stock">gtk-preferences</property> 
     
    158182 
    159183                      <child internal-child="image"> 
    160                         <widget class="GtkImage" id="image70"> 
     184                        <widget class="GtkImage" id="image94"> 
    161185                          <property name="visible">True</property> 
    162186                          <property name="stock">gtk-help</property> 
     
    179203 
    180204                      <child internal-child="image"> 
    181                         <widget class="GtkImage" id="image71"> 
     205                        <widget class="GtkImage" id="image95"> 
    182206                          <property name="visible">True</property> 
    183207                          <property name="stock">gtk-about</property> 
  • trunk/src/playlist_control.py

    r318 r326  
    239239 
    240240    def set_active(self, active = True, audio_ctrl = None): 
     241 
    241242        if not active: 
     243            if self._audio_control: 
     244                self._audio_control.stop() 
    242245            self._audio_control = None 
    243246        else: