~lottanzb/lottanzb/trunk-packaging-10.04

« back to all changes in this revision

Viewing changes to lottanzb/gui/main.py

  • Committer: Severin Heiniger
  • Date: 2010-09-03 15:05:11 UTC
  • mfrom: (1212.1.209 trunk)
  • Revision ID: severinheiniger@gmail.com-20100903150511-rhpcpr3td53h4ihm
Sync with main.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import sys
17
17
import gtk
18
18
import webbrowser
19
 
import locale
20
19
 
21
20
import logging
22
21
LOG = logging.getLogger(__name__)
23
22
 
24
 
from os.path import join, isfile
25
 
from subprocess import Popen
26
23
from threading import Thread
27
24
 
28
25
from lottanzb.core.environ import _
 
26
from lottanzb.backend import Backend
 
27
from lottanzb.backend.sessions.local import LocalSession
 
28
from lottanzb.backend.sessions.remote import RemoteSession
29
29
from lottanzb.backend.hubs.config import ConfigHub
30
30
from lottanzb.backend.hubs.general import GeneralHub
31
 
from lottanzb.resources import is_installed, get_help
32
31
from lottanzb.config.section import ConfigSection
33
32
from lottanzb.util import gproperty
34
33
from lottanzb.util.signalmanager import SignalManager
35
34
from lottanzb.util.misc import open_directory
36
 
from lottanzb.gui import add_file, add_url, about, log, prefs
 
35
from lottanzb.gui import add_file, add_url, about, log, prefs, sessions
 
36
from lottanzb.gui.help import open_help
37
37
from lottanzb.gui.messaging import MessagingManager
38
38
from lottanzb.gui.download_list import DownloadList
39
39
from lottanzb.gui.info_bar import InfoBar
42
42
    ConduitCollection, Conduit, GObjectEndPoint, ToggleActionEndPoint)
43
43
 
44
44
class Config(ConfigSection):
 
45
    # Holds a configuration section of type `ViewConfig'.
 
46
    view = gproperty(type=object)
 
47
    
45
48
    width = gproperty(type=int, default=700)
46
49
    height = gproperty(type=int, default=350)
47
50
    x_pos = gproperty(type=int, default=100)
48
51
    y_pos = gproperty(type=int, default=100)
49
52
    maximized = gproperty(type=bool, default=False)
50
53
 
 
54
    def find_section_class(self, section):
 
55
        if section == "view":
 
56
            return ViewConfig
 
57
        
 
58
        return ConfigSection.find_section_class(self, section)
 
59
 
 
60
 
 
61
class ViewConfig(ConfigSection):
 
62
    """Holds information about what elements are visible in the main window.
 
63
    
 
64
    The boolean options have been moved to a separate configuration section
 
65
    because they are closely related and the functionality might one day be
 
66
    moved to a separate submodule called `view'.
 
67
    """
 
68
    
 
69
    toolbar = gproperty(type=bool, default=True)
 
70
    infobar = gproperty(type=bool, default=True)
 
71
    reordering_pane = gproperty(type=bool, default=True)
 
72
 
 
73
 
 
74
class WidgetVisibilityEndPoint(GObjectEndPoint):
 
75
    """An endpoint for a widget that modifies the widget's visibility given
 
76
    boolean values sent through the conduit.
 
77
    """
 
78
    
 
79
    PROPERTY = "visible"
 
80
 
51
81
 
52
82
class MainWindow(MainDelegateComponent):
53
83
    builder_file = "main_window"
63
93
        # The list of actions that may only be used if connected to an instance
64
94
        # of SABnzbd.
65
95
        self.backend_actions = [self.add, self.add_url, self.clear, self.paused,
66
 
            self.open_download_dir, self.edit_preferences]
 
96
            self.open_download_dir, self.edit_preferences,
 
97
            self.select_local_session, self.select_remote_session,
 
98
            self.open_web_interface]
67
99
        
68
100
        def on_general_hub_changed(self, *args):
69
101
            self.on_general_hub_updated(None)
74
106
    def create_ui(self):
75
107
        self.enable_rgba_support()
76
108
        self.restore_window_geometry()
 
109
        
 
110
        # Make the 'View -> Toolbar' `gtk.CheckMenuItem' functional.
 
111
        self.view_toolbar_conduit = Conduit(
 
112
            GObjectEndPoint(self.config.view, "toolbar"),
 
113
            ToggleActionEndPoint(self.view_toolbar),
 
114
            WidgetVisibilityEndPoint(self.toolbar))
 
115
        
 
116
        # Make the 'View -> Infobar' `gtk.CheckMenuItem' functional.
 
117
        self.view_infobar_conduit = Conduit(
 
118
            GObjectEndPoint(self.config.view, "infobar"),
 
119
            ToggleActionEndPoint(self.view_infobar),
 
120
            WidgetVisibilityEndPoint(self.infobar))
 
121
        
 
122
        # Make the 'View -> Reordering Pane' `gtk.CheckMenuItem' functional.
 
123
        # Because the actual reordering pane is dynamically added to the window
 
124
        # when LottaNZB is connected to SABnzbd, the corresponding end point
 
125
        # will also be added and removed dynamically.
 
126
        # This is required so that the check menu items is still functional
 
127
        # even if LottaNZB is not connected to SABnzbd.
 
128
        self.view_reordering_pane_conduit = Conduit(
 
129
            GObjectEndPoint(self.config.view, "reordering_pane"),
 
130
            ToggleActionEndPoint(self.view_reordering_pane))
 
131
        
 
132
        self.view_reordering_pane_endpoint = None
 
133
        
 
134
        self.select_local_session.set_property("visible", False)
77
135
    
78
136
    def attach_to_backend(self, backend):
79
137
        self.general_hub = self._component_manager.load(GeneralHub)
91
149
        from lottanzb.gui.messaging import (download_import,
92
150
            postprocessing_priority, servers)
93
151
        
94
 
        info_bar = self._component_manager.load(InfoBar)
 
152
        infobar = self._component_manager.load(InfoBar)
95
153
        download_list = self._component_manager.load(DownloadList)
96
154
        manager = self._component_manager.load(MessagingManager)
97
155
        
98
 
        self.attach_slave(self.info_bar, info_bar)
 
156
        self.attach_slave(self.infobar, infobar)
99
157
        self.attach_slave(self.download_list, download_list)
100
158
        self.attach_slave(self.message, manager)
101
159
        
 
160
        self.view_reordering_pane_endpoint = WidgetVisibilityEndPoint(
 
161
            download_list.reordering_pane)
 
162
        self.view_reordering_pane_conduit.add_endpoint(
 
163
            self.view_reordering_pane_endpoint)
 
164
        
102
165
        self.toolbar_remove.set_related_action(download_list.remove)
 
166
        self.select_local_session.set_property("visible",
 
167
            not isinstance(backend.session, LocalSession))
103
168
    
104
169
    def detach_from_backend(self):
105
170
        self.detach_all_slaves()
106
171
        self.session_signals.disconnect_all()
107
172
        self.session_conduits.remove_all()
108
173
        
 
174
        if self.view_reordering_pane_endpoint:
 
175
            self.view_reordering_pane_conduit.remove_endpoint(
 
176
                self.view_reordering_pane_endpoint)
 
177
        
109
178
        self._component_manager.unload(DownloadList)
110
179
        self._component_manager.unload(MessagingManager)
111
180
        
192
261
        
193
262
        Thread(target=sys.exit).run()
194
263
    
 
264
    def show_session_selection_dialog(self, session_type):
 
265
        self._component_manager.unload(Backend)
 
266
        
 
267
        dialog = self._component_manager.load(sessions.SelectionDialog)
 
268
        dialog.preselect_session_type(session_type)
 
269
    
 
270
    def on_select_local_session__activate(self, widget):
 
271
        self.show_session_selection_dialog(LocalSession)
 
272
    
 
273
    def on_select_remote_session__activate(self, widget):
 
274
        self.show_session_selection_dialog(RemoteSession)
 
275
    
 
276
    def on_open_web_interface__activate(self, widget):
 
277
        """Open the SABnzbd web interface in a browser tab."""
 
278
        
 
279
        backend = self._component_manager.get(Backend)
 
280
        url = backend.interface.connection_info.url
 
281
        
 
282
        webbrowser.open_new_tab(url)
 
283
    
195
284
    def on_edit_preferences__activate(self, widget):
196
285
        """Open the preferences dialog."""
197
286
        
206
295
        window.show(self.get_toplevel())
207
296
    
208
297
    def on_show_help_content__activate(self, widget):
209
 
        try:
210
 
            if not is_installed():
211
 
                for l in [locale.getlocale()[0][:2], "C"]:
212
 
                    help_file = get_help(join(l, "lottanzb.xml"))
213
 
                    
214
 
                    if isfile(help_file):
215
 
                        Popen(["yelp", help_file])
216
 
                        return
217
 
            else:
218
 
                default_screen = gtk.gdk.screen_get_default()
219
 
                event_time = gtk.get_current_event_time()
220
 
                
221
 
                gtk.show_uri(default_screen, "ghelp:lottanzb", event_time)
222
 
        except:
223
 
            webbrowser.open_new_tab("http://www.lottanzb.org/help")
 
298
        open_help()
224
299
    
225
300
    def on_show_about_dialog__activate(self, widget):
226
301
        dialog = self._component_manager.load(about.Dialog)