Что можно улучшить? Что можно добавить? Есть ли аналоги, которыми можно пользоваться, выкинув этот самописный ужас?
#!/usr/bin/python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk,Gdk
gi.require_version('Wnck', '3.0')
from gi.repository import Wnck
filter_str = ""
def filter_func(model, itr, data):
return model[itr][1].find(filter_str) > -1
def refilter(self):
global filter_str
filter_str=self.get_text()
filter_m.refilter()
def check_esc(self, event):
if event.keyval == Gdk.KEY_Escape:
Gtk.main_quit()
def bring_the_shit_up(self):
time=Gtk.get_current_event_time()
filter_m[0][0].get_workspace().activate(time)
filter_m[0][0].activate(time)
Gtk.main_quit()
def selected(selection):
time=Gtk.get_current_event_time()
model, itr = selection.get_selected()
filter_m[itr][0].get_workspace().activate(time)
filter_m[itr][0].activate(time)
Gtk.main_quit()
screen=Wnck.Screen.get_default()
screen.force_update()
window_list=screen.get_windows()
window_list=filter(lambda x: x.get_window_type()==Wnck.WindowType.NORMAL, window_list)
names=map(lambda x: [x, x.get_name()], window_list)
list_store=Gtk.ListStore(Wnck.Window, str)
map(lambda x: list_store.append(x), names)
renderer=Gtk.CellRendererText()
column = Gtk.TreeViewColumn("TTTT", renderer, text=1)
column.set_widget(Gtk.Label())
filter_m = list_store.filter_new()
filter_m.set_visible_func(filter_func)
combobox=Gtk.TreeView.new_with_model(filter_m)
combobox.append_column(column)
entry=Gtk.SearchEntry()
grid=Gtk.Grid()
grid.attach(entry, 0, 0, 8, 10)
grid.attach_next_to(combobox, entry, Gtk.PositionType.BOTTOM, 1, 1)
entry.connect("search-changed", refilter)
entry.connect("activate", bring_the_shit_up)
select_obj=combobox.get_selection()
select_obj.connect("changed", selected)
win = Gtk.Window()
win.add(grid)
win.connect("destroy", Gtk.main_quit)
win.connect("key-release-event", check_esc)
win.show_all()
Gtk.main()