Merge lp:~humitos/encuentro/filter-comboboxes into lp:encuentro

Proposed by Manuel Kaufmann
Status: Needs review
Proposed branch: lp:~humitos/encuentro/filter-comboboxes
Merge into: lp:encuentro
Diff against target: 163 lines (+74/-12)
3 files modified
encuentro/data.py (+36/-9)
encuentro/ui/central_panel.py (+4/-2)
encuentro/ui/main.py (+34/-1)
To merge this branch: bzr merge lp:~humitos/encuentro/filter-comboboxes
Reviewer Review Type Date Requested Status
Facundo Batista Needs Fixing
Review via email: mp+233211@code.launchpad.net

Description of the change

This is the old branch filter-by-section-channel but with some fixes to make it independant.

To post a comment you must log in.
Revision history for this message
Facundo Batista (facundo) wrote :

The merge is conflicting in a trivial couple of lines.

After you fix that, please consider:

- Don't store channels or sections in the config: this is a problem for when they change (because of new data) where you'll need to merge, or discard elements, etc. It doesn't worth it. Just "calculate" the list of sections and channels when the data is loaded, at init time.

- Very related to the previous one: you need three structures: the curated list of channels, the curated list of sections, and a dict where for each channel you have the list of channels (and not build it in every change).

- This line...

    channels = sorted(list(set([e.channel for _, e in self.items()])))

  ...can be written like this...

    channels = sorted(set(e.channel for e in self.values()))

  ...which is simpler, faster, and easier to read.

- You have a "import pdb" in the middle of the code!!

- Maybe it's better to add the "Todas las secciones" item in the same place you're converting the set to a list (a couple of lines above). BTW, sort that list...

- You're not using real data when building the filter_section combobox.

- On on_channel_changed you also should call set_filter(), with the selected channel, and None as the section.

If you have any doubt, let's discuss in IRC.

The rest is very nice, I think it's good improvement to the UI.

Thank you very much!!

review: Needs Fixing

Unmerged revisions

229. By Manuel Kaufmann

ComboBoxes to filter by Channel and Section

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'encuentro/data.py'
2--- encuentro/data.py 2014-08-31 03:39:40 +0000
3+++ encuentro/data.py 2014-09-03 13:13:03 +0000
4@@ -26,6 +26,7 @@
5
6 from encuentro import utils
7 from encuentro.ui import dialogs
8+from encuentro.config import config
9
10 logger = logging.getLogger('encuentro.data')
11
12@@ -148,7 +149,7 @@
13 self.filename = filename
14 self.downtype = downtype
15
16- def filter_params(self, text, only_downloaded):
17+ def filter_params(self, text, only_downloaded, channel, section):
18 """Return the filtering params.
19
20 If should filter, it will return (pos1, pos2) (both in None if it only
21@@ -158,15 +159,16 @@
22 # need downloaded ones, sorry
23 return
24
25- t = self.normalized_title
26- pos1 = t.find(text)
27- if pos1 == -1:
28- # need to match text, sorry
29- return
30+ if channel in (self.channel, None) and section in (self.section, None):
31+ t = self.normalized_title
32+ pos1 = t.find(text)
33+ if pos1 == -1:
34+ # need to match text, sorry
35+ return
36
37- # return boundaries
38- pos2 = pos1 + len(text)
39- return (pos1, pos2)
40+ # return boundaries
41+ pos2 = pos1 + len(text)
42+ return (pos1, pos2)
43
44 def __str__(self):
45 args = (self.episode_id, self.state, self.channel,
46@@ -300,6 +302,31 @@
47 """Return the iter items of the data."""
48 return self.data.iteritems()
49
50+ def channels(self):
51+ channels = config.get('channels', None)
52+ if channels is None:
53+ channels = sorted(list(set([e.channel for _, e in self.items()])))
54+ config[config.SYSTEM]['channels'] = channels
55+ channels.insert(0, u'Todos los canales')
56+ return channels
57+
58+ def sections(self, channel):
59+ sections = config.get('sections', None)
60+ if sections is None:
61+ sections = {}
62+ for c in self.channels():
63+ sections[c] = set()
64+ for _, e in self.items():
65+ sections[e.channel].add(e.section)
66+ for k in sections:
67+ sections[k] = list(sections[k])
68+ config[config.SYSTEM]['sections'] = sections
69+ try:
70+ sections[channel].insert(0, u'Todas las secciones')
71+ except KeyError:
72+ import ipdb;ipdb.set_trace()
73+ return sections[channel]
74+
75 def save(self):
76 """Save to disk."""
77 to_save = (self.last_programs_version, self.data)
78
79=== modified file 'encuentro/ui/central_panel.py'
80--- encuentro/ui/central_panel.py 2014-08-26 01:57:46 +0000
81+++ encuentro/ui/central_panel.py 2014-09-03 13:13:03 +0000
82@@ -378,13 +378,15 @@
83 for i in xrange(item.columnCount()):
84 item.setBackgroundColor(i, color)
85
86- def set_filter(self, text, only_downloaded=False):
87+ def set_filter(self, text, only_downloaded=False,
88+ channel=None, section=None):
89 """Apply a filter to the episodes list."""
90 text = data.prepare_to_filter(text)
91 for episode_id, item in self._item_map.iteritems():
92 episode = self.main_window.programs_data[episode_id]
93
94- params = episode.filter_params(text, only_downloaded)
95+ params = episode.filter_params(
96+ text, only_downloaded, channel, section)
97 if params is None:
98 item.setHidden(True)
99 else:
100
101=== modified file 'encuentro/ui/main.py'
102--- encuentro/ui/main.py 2014-05-02 14:03:39 +0000
103+++ encuentro/ui/main.py 2014-09-03 13:13:03 +0000
104@@ -32,6 +32,7 @@
105 from PyQt4.QtGui import (
106 QAction,
107 QCheckBox,
108+ QComboBox,
109 QLabel,
110 QLineEdit,
111 QMessageBox,
112@@ -244,6 +245,19 @@
113 spacer = QWidget()
114 spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
115 toolbar.addWidget(spacer)
116+
117+ self.filter_channel = QComboBox()
118+ self.channels = self.programs_data.channels()
119+ self.filter_channel.addItems(self.channels)
120+ self.filter_channel.currentIndexChanged.connect(
121+ self.on_channel_changed)
122+ toolbar.addWidget(self.filter_channel)
123+
124+ self.filter_section = QComboBox()
125+ self.filter_section.addItems([u'Todas las secciones'])
126+ self.filter_section.currentIndexChanged.connect(self.on_filter_changed)
127+ toolbar.addWidget(self.filter_section)
128+
129 toolbar.addWidget(QLabel(u"Filtro: "))
130 self.filter_line = QLineEdit()
131 self.filter_line.setMaximumWidth(150)
132@@ -270,11 +284,30 @@
133 dlg.exec_()
134 self._review_need_something_indicator()
135
136+ def _get_filter_channel(self):
137+ if self.filter_channel.currentIndex() == 0:
138+ return None
139+ else:
140+ return self.filter_channel.currentText()
141+
142+ def _get_filter_section(self):
143+ if self.filter_section.currentIndex() == 0:
144+ return None
145+ else:
146+ return self.filter_section.currentText()
147+
148+ def on_channel_changed(self, _):
149+ self.filter_section.clear()
150+ channel = self._get_filter_channel()
151+ sections = self.programs_data.sections(channel)
152+ self.filter_section.addItems(sections)
153+
154 def on_filter_changed(self, _):
155 """The filter text has changed, apply it in the episodes list."""
156 text = self.filter_line.text()
157 cbox = self.filter_cbox.checkState()
158- self.episodes_list.set_filter(text, cbox)
159+ self.episodes_list.set_filter(
160+ text, cbox, self._get_filter_channel(), self._get_filter_section())
161
162 # after applying filter, nothing is selected, so check buttons
163 # (easiest way to clean them all)

Subscribers

People subscribed via source and target branches