Console interface to Storyboard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.9 KiB

# Copyright 2014 OpenStack Foundation
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import urwid
import mywid
import sync
import view.change_list
class ProjectRow(urwid.Button):
project_focus_map = {None: 'reversed',
'unreviewed-project': 'reversed-unreviewed-project',
'subscribed-project': 'reversed-subscribed-project',
'unsubscribed-project': 'reversed-unsubscribed-project',
def selectable(self):
return True
def __init__(self, project, callback=None):
super(ProjectRow, self).__init__('', on_press=callback, user_data=project.key)
self.project_key = project.key
name = urwid.Text(u' '
self.unreviewed_changes = urwid.Text(u'')
self.reviewed_changes = urwid.Text(u'')
col = urwid.Columns([
('fixed', 4, self.unreviewed_changes),
('fixed', 4, self.reviewed_changes),
self.row_style = urwid.AttrMap(col, '')
self._w = urwid.AttrMap(self.row_style, None, focus_map=self.project_focus_map)
def update(self, project):
if project.subscribed:
if len(project.unreviewed_changes) > 0:
style = 'unreviewed-project'
style = 'subscribed-project'
style = 'unsubscribed-project'
self.row_style.set_attr_map({None: style})
class ProjectListView(urwid.WidgetWrap):
help = mywid.GLOBAL_HELP + """
This Screen
<l> Toggle whether only subscribed projects or all projects are listed.
<s> Toggle the subscription flag for the currently selected project.
def __init__(self, app):
super(ProjectListView, self).__init__(urwid.Pile([])) = app
self.subscribed = True
self.project_rows = {}
self.listbox = urwid.ListBox(urwid.SimpleFocusListWalker([]))
self._w.contents.append((app.header, ('pack', 1)))
self._w.contents.append((urwid.Divider(),('pack', 1)))
self._w.contents.append((self.listbox, ('weight', 1)))
def isEmpty(self):
if self.project_rows:
return False
return True
def refresh(self):
if self.subscribed:
self.title = u'Subscribed Projects'
self.title = u'All Projects'
unseen_keys = set(self.project_rows.keys())
with as session:
i = 0
for project in session.getProjects(subscribed=self.subscribed):
row = self.project_rows.get(project.key)
if not row:
row = ProjectRow(project, self.onSelect)
self.listbox.body.insert(i, row)
self.project_rows[project.key] = row
i += 1
for key in unseen_keys:
row = self.project_rows[key]
del self.project_rows[key]
def toggleSubscribed(self, project_key):
with as session:
project = session.getProject(project_key)
project.subscribed = not project.subscribed
ret = project.subscribed
return ret
def onSelect(self, button, project_key):, project_key))
def keypress(self, size, key):
if key=='l':
self.subscribed = not self.subscribed
return None
if key=='s':
if not len(self.listbox.body):
return None
pos = self.listbox.focus_position
project_key = self.listbox.body[pos].project_key
subscribed = self.toggleSubscribed(project_key)
if subscribed:
return None
return super(ProjectListView, self).keypress(size, key)