def UpdateGrid(self, hits): N = BUNDLE_NUM_ROWS * BUNDLE_NUM_COLS items_to_add = min(N, self.nrhits) if self.nrhits > N: items_to_add -= 1 self.parent.Freeze() children = self.grid.GetChildren() didChange = len(children) < min(N, self.nrhits) if not didChange: if DEBUG: print >> sys.stderr, "*** BundlePanel.UpdateGrid: total nr items did not change, updating labels only" #total nr items did not change for i in range(min(len(children), items_to_add)): link_static_text = children[i].GetWindow() if link_static_text and getattr(link_static_text, 'SetLabel', False): link_static_text.SetLabel(hits[i]['name']) link_static_text.action = hits[i] else: didChange = True break if self.nrhits > N: more_caption = '(%s more...)' % (self.nrhits - N + 1) link_static_text = children[i+1].GetWindow() if link_static_text and getattr(link_static_text, 'SetLabel', False): link_static_text.SetLabel(more_caption) link_static_text.Unbind(wx.EVT_LEFT_UP) link_static_text.Bind(wx.EVT_LEFT_UP, self.OnMoreClick) else: didChange = True if didChange: self.grid.ShowItems(False) self.grid.Clear(deleteWindows = True) for i in range(items_to_add): hit = hits[i] new_text = LinkStaticText(self.parent, hit['name'], icon = False, icon_type = 'tree', icon_align = wx.ALIGN_LEFT, font_increment = self.font_increment, font_colour = BUNDLE_FONT_COLOR) new_text.Bind(wx.EVT_LEFT_UP, self.OnBundleLinkClick) new_text.SetMinSize((1,-1)) new_text.action = hit self.grid.Add(new_text, 0, wx.EXPAND) if self.nrhits > N: caption = '(%s more...)' % (self.nrhits - N + 1) more_label = LinkStaticText(self.parent, caption, icon = False, icon_align = wx.ALIGN_LEFT, font_increment = self.font_increment, font_colour = BUNDLE_FONT_COLOR) more_label.Bind(wx.EVT_LEFT_UP, self.OnMoreClick) self.grid.Add(more_label, 0, wx.EXPAND) self.parent_listitem.AddEvents(self.grid) if self.state != self.COLLAPSED: self.ShowGrid(False) self.parent.Thaw()
def SetBundleState(self, newstate, refresh=True, reset=False): if newstate is None: auto_guess = self.guiutility.utility.config.Read('use_bundle_magic', "boolean") newstate = Bundler.ALG_OFF # default stored_state = None if not reset: keywords = self.torrentsearch_manager.getSearchKeywords()[0] if keywords != '': try: stored_state = self.bundle_db.getPreference(keywords) except: pass #if db interaction fails, ignore local_override = stored_state is not None if local_override: newstate = stored_state elif auto_guess: newstate = Bundler.ALG_MAGIC self.bundlestate = newstate self.selected_bundle_mode = None self.Freeze() if newstate != Bundler.ALG_OFF: self.bundlestatetext.SetLabel(' by %s' % self.bundlestates_str[newstate]) else: self.bundlestatetext.SetLabel(' is %s' % self.bundlestates_str[newstate]) self.torrentsearch_manager.setBundleMode(newstate, refresh) self.bundleSizer.ShowItems(False) self.bundleSizer.Clear(deleteWindows = True) self.bundletexts = [] self.bundleSizer.Add(StaticText(self, -1, 'Bundle by ')) for i, state in enumerate(self.bundlestates): if newstate == state: text = StaticText(self, -1, self.bundlestates_str[state]) self.bundleSizer.Add(text) self.bundletexts.append(text) else: link = LinkStaticText(self, self.bundlestates_str[state], "wand.png") link.ShowIcon(False) link.SetIconToolTipString('Selected by Magic') link.Bind(wx.EVT_LEFT_UP, self.OnRebundle) link.action = state self.bundleSizer.Add(link) self.bundletexts.append(link) if i+1 < len(self.bundlestates): self.bundleSizer.AddSpacer((1, -1)) self.Layout() self.Thaw()
def UpdateGrid(self, hits, noChange=False): N = BUNDLE_NUM_ROWS * BUNDLE_NUM_COLS items_to_add = min(N, self.nrhits) if self.nrhits > N: items_to_add -= 1 self.parent.Freeze() children = self.grid.GetChildren() didChange = len(children) < min(N, self.nrhits) if not didChange: if DEBUG: print >> sys.stderr, "*** BundlePanel.UpdateGrid: total nr items did not change, updating labels only" #total nr items did not change for i in range(items_to_add): link_static_text = children[i].GetWindow() or children[i].GetSizer() if link_static_text and getattr(link_static_text, 'SetLabel', False): link_static_text.SetLabel(hits[i].name) link_static_text.action = hits[i] else: didChange = True break if self.nrhits > N: more_caption = '(%s more...)' % (self.nrhits - N + 1) link_static_text = children[i+1].GetWindow() or children[i+1].GetSizer() if link_static_text and getattr(link_static_text, 'SetLabel', False): link_static_text.SetLabel(more_caption) link_static_text.Unbind(wx.EVT_LEFT_UP) link_static_text.Bind(wx.EVT_LEFT_UP, self.OnMoreClick) else: didChange = True if didChange: if DEBUG: print >> sys.stderr, "*** BundlePanel.UpdateGrid: something did change rebuilding grid", len(children),min(N, self.nrhits) curRows = len(children) / BUNDLE_NUM_COLS newRows = min(self.nrhits / BUNDLE_NUM_COLS, BUNDLE_NUM_ROWS) rowsChanged = curRows != newRows self.grid.ShowItems(False) self.grid.Clear(deleteWindows = True) for i in range(items_to_add): hit = hits[i] new_text = LinkStaticText(self.parent, hit.name, icon = False, icon_type = 'tree', icon_align = wx.ALIGN_LEFT, font_increment = self.font_increment, font_colour = BUNDLE_FONT_COLOR) new_text.Bind(wx.EVT_LEFT_UP, self.OnBundleLinkClick) new_text.SetMinSize((1,-1)) new_text.action = hit self.grid.Add(new_text, 0, wx.EXPAND) if self.nrhits > N: caption = '(%s more...)' % (self.nrhits - N + 1) more_label = LinkStaticText(self.parent, caption, icon = False, icon_align = wx.ALIGN_LEFT, font_increment = self.font_increment, font_colour = BUNDLE_FONT_COLOR) more_label.Bind(wx.EVT_LEFT_UP, self.OnMoreClick) self.grid.Add(more_label, 0, wx.EXPAND) self.parent_listitem.AddEvents(self.grid) if self.state != self.COLLAPSED: self.ShowGrid(False) if rowsChanged and not noChange: self.parent_listitem.OnChange() self.parent.Thaw() return didChange