2 # -*- coding: utf-8 -*-
4 # Project: J-Ben, Python front-end
5 # File: search_frame.py
7 # Created on: 1 Nov 2009
12 class SearchFrame(gtk
.VBox
):
15 gtk
.VBox
.__init
__(self
, spacing
= 5)
18 self
.queryentry
.connect("activate", self
.on_search_clicked
)
19 self
.searchbutton
.connect("clicked", self
.on_search_clicked
)
20 self
.backbutton
.connect("clicked", self
.on_back_clicked
)
21 self
.forwardbutton
.connect("clicked", self
.on_forward_clicked
)
22 self
.randombutton
.connect("clicked", self
.on_random_clicked
)
25 self
.set_border_width(5)
27 # Top box: "Enter kanji:" [________] [ Search ]
28 self
.querylabel
= gtk
.Label(_("Enter query:"))
29 self
.queryentry
= gtk
.Entry()
31 self
.searchbutton
= gtk
.Button(_("_Search"))
32 btnbox
= gtk
.HButtonBox()
34 btnbox
.set_layout(gtk
.BUTTONBOX_START
)
35 btnbox
.pack_start(self
.searchbutton
)
37 topbox
= gtk
.HBox(spacing
= 5)
38 topbox
.pack_start(self
.querylabel
, expand
= False)
39 topbox
.pack_start(self
.queryentry
)
40 topbox
.pack_start(btnbox
, expand
= False)
41 self
.pack_start(topbox
, expand
= False)
43 # Middle box: a GTKTextView wrapped in a GTKScrolledWindow
44 self
.output
= gtk
.TextView()
45 self
.output
.set_editable(False)
46 self
.output
.set_wrap_mode(gtk
.WRAP_WORD_CHAR
)
47 self
.on_search_clicked(None)
48 outputwindow
= gtk
.ScrolledWindow()
49 outputwindow
.set_shadow_type(gtk
.SHADOW_ETCHED_IN
)
50 outputwindow
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_AUTOMATIC
)
51 outputwindow
.add(self
.output
)
52 self
.pack_start(outputwindow
)
54 # Bottom box: [__Back__] [Forward_] [_Random_] [# ] "of # kanji"
55 self
.backbutton
= gtk
.Button(stock
= gtk
.STOCK_GO_BACK
)
56 self
.forwardbutton
= gtk
.Button(stock
= gtk
.STOCK_GO_FORWARD
)
57 self
.randombutton
= gtk
.Button(_("_Random"))
58 self
.indexentry
= gtk
.Entry()
59 self
.indexentry
.set_width_chars(5)
60 self
.indexentry
.set_max_length(5)
61 self
.indexlabel
= gtk
.Label(_("of 0 items"))
63 btnbox2
= gtk
.HButtonBox()
64 btnbox2
.set_spacing(5)
65 btnbox2
.set_layout(gtk
.BUTTONBOX_START
)
66 btnbox2
.pack_start(self
.backbutton
)
67 btnbox2
.pack_start(self
.forwardbutton
)
68 btnbox2
.pack_start(self
.randombutton
)
70 bottombox
= gtk
.HBox(spacing
= 5)
71 bottombox
.pack_start(btnbox2
, expand
= False)
72 bottombox
.pack_end(self
.indexlabel
, expand
= False)
73 bottombox
.pack_end(self
.indexentry
, expand
= False)
74 self
.pack_start(bottombox
, expand
= False)
76 def on_search_clicked(self
, widget
):
77 query
= self
.queryentry
.get_text().strip()
79 self
.output
.get_buffer().set_text(
80 _("No query has been entered."))
83 self
.output
.get_buffer().set_text(
84 _("ERROR: Could not connect to database parser."))
86 results
= self
.dict.search(query
)
87 out_str
= u
"\n".join(k
.to_string() for k
in results
)
89 out_str
= _(u
"No entries found.")
90 self
.output
.get_buffer().set_text(out_str
)
92 def on_back_clicked(self
, widget
):
93 print "%s.on_back_clicked" % str(self
)
95 def on_forward_clicked(self
, widget
):
96 print "%s.on_forward_clicked" % str(self
)
98 def on_random_clicked(self
, widget
):
99 print "%s.on_random_clicked" % str(self
)
101 def set_dict(self
, d
):