Skip to content

Commit

Permalink
Refactored error view
Browse files Browse the repository at this point in the history
  • Loading branch information
mzheng committed Dec 25, 2010
1 parent 12d545e commit 5a6edf9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
30 changes: 9 additions & 21 deletions pandora/PandoraSource.py
Expand Up @@ -64,7 +64,7 @@ def do_impl_get_status(self):
progress = 1
text = ""
if self.connected:
self.hide_error_area()
self.error_area.hide()
num_stations = self.stations_model.get_num_entries()
if num_stations > 1:
text = str(num_stations) + " stations"
Expand Down Expand Up @@ -151,12 +151,12 @@ def create_window(self):
paned.pack2(frame2, True, False)
self.vbox_main.pack_start(paned)

error_frame = self.create_error_area()
self.error_area = error_frame
self.error_area = widgets.ErrorView(self.__plugin, self.do_impl_activate)
error_frame = self.error_area.get_error_frame()
self.vbox_main.pack_end(error_frame, False, False)

self.vbox_main.show_all()
error_frame.hide()
self.error_area.hide()

self.add(self.vbox_main)

Expand All @@ -182,8 +182,7 @@ def create_error_area(self):

return error_frame

def on_account_settings_clicked(self, *args):
self.__plugin.create_configure_dialog(callback=self.do_impl_activate)



def connect_all(self):
Expand Down Expand Up @@ -219,7 +218,7 @@ def create_popups(self):
self.action_group.add_action(action)

manager.insert_action_group(self.action_group, 0)
popup_file = self.__plugin.find_file("pandora-ui.xml")
popup_file = self.__plugin.find_file("pandora/pandora-ui.xml")
self.ui_id = manager.add_ui_from_file(popup_file)
manager.ensure_update()

Expand All @@ -230,7 +229,7 @@ def do_impl_activate(self):
self.username, self.password = self.get_pandora_account_info()
except AccountNotSetException, (instance):
#Ask User to configure account
self.show_error_area(instance.parameter)
self.error_area.show(instance.parameter)
#Retry after user put in account
return

Expand Down Expand Up @@ -274,12 +273,12 @@ def retry_cb():
error_message = "Unable to connect. Check your Internet connection."
detail = e.message
self.__activated = False
self.show_error_area(error_message, detail)
self.error_area.show(error_message)
print e.message
elif isinstance(e, PandoraError):
error_message = "Invalid username and/or password. Check your settings."
self.__activated = False
self.show_error_area(error_message)
self.error_area.show(error_message)
print e.message
else:
print e.traceback
Expand All @@ -302,17 +301,6 @@ def get_pandora_account_info(self):
raise AccountNotSetException(error_message)
return tuple(secret.split('\n'))

def show_error_area(self, primary_message, secondary_message=None):
self.primary_error.set_text(primary_message)
if secondary_message is None:
self.secondary_error.hide()
else:
self.secondary_error.set_text(secondary_message)
self.secondary_error.show()
self.error_area.show()

def hide_error_area(self):
self.error_area.hide()


def pandora_connect(self, message="Logging in...", callback=None):
Expand Down
File renamed without changes.
42 changes: 42 additions & 0 deletions pandora/widgets/ErrorView.py
@@ -0,0 +1,42 @@
import gtk

class ErrorView(object):
def __init__(self, plugin, callback):
self.__plugin = plugin
self.callback = callback

builder_file = self.__plugin.find_file("pandora/widgets/error_area.ui")
builder = gtk.Builder()
builder.add_from_file(builder_file)
self.error_frame = builder.get_object('error_frame')
error_area = builder.get_object('error_event_box')
self.primary_error = builder.get_object('primary_message')
self.secondary_error = builder.get_object('secondary_message')
# Hack to get the tooltip background color
window = gtk.Window(gtk.WINDOW_POPUP)
window.set_name("gtk-tooltip")
window.ensure_style()
style = window.get_style()
error_area.set_style(style)
self.error_frame.set_style(style)

account_button = builder.get_object("account_settings")
account_button.connect("clicked", self.on_account_settings_clicked)

def get_error_frame(self):
return self.error_frame

def show(self, primary_message, secondary_message=None):
self.primary_error.set_text(primary_message)
if secondary_message is None:
self.secondary_error.hide()
else:
self.secondary_error.set_text(secondary_message)
self.secondary_error.show()
self.error_frame.show()

def hide(self):
self.error_frame.hide()

def on_account_settings_clicked(self, *args):
self.__plugin.create_configure_dialog(callback=self.callback)
3 changes: 2 additions & 1 deletion pandora/widgets/__init__.py
@@ -1,2 +1,3 @@
from SongEntryView import *
from StationEntryView import *
from StationEntryView import *
from ErrorView import *
File renamed without changes.

0 comments on commit 5a6edf9

Please sign in to comment.