def __init__(self): Window.__init__(self, enable_resize=True) self.set_position(gtk.WIN_POS_CENTER) self.set_default_size(290, 512) titlebar = Titlebar(["min", "max", "close"], app_name="Baidu Hi for Linux") titlebar.min_button.connect("clicked", lambda w: self.min_window()) titlebar.max_button.connect("clicked", lambda w: self.toggle_max_window()) titlebar.close_button.connect("clicked", lambda w: gtk.main_quit()) self.add_move_event(titlebar.drag_box) self.add_toggle_event(titlebar.drag_box) banner_image = gtk.image_new_from_file(get_banner_image()) banner_box = set_widget_gravity(banner_image, (0,0,0,0), (10, 0, 0, 0)) user_box, self.user_entry = self.create_combo_entry("帐号:") passwd_box, self.passwd_entry = self.create_combo_entry("密码:") self.remember_passwd = CheckButton("记住密码") self.automatic_login = CheckButton("自动登录") self.status_box, self.status_combo_box = self.create_combo_widget("状态:", [(key, None) for key in "在线 忙碌 离开 隐身".split()], 0) check_box = gtk.HBox(spacing=10) check_box.pack_start(self.remember_passwd, False, False) check_box.pack_start(self.automatic_login, False, False) body_table = gtk.Table(5, 1) body_table.set_row_spacings(10) body_table.attach(banner_box, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=gtk.FILL) body_table.attach(user_box, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=gtk.FILL, xpadding=8) body_table.attach(passwd_box, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=gtk.FILL, xpadding=8) # body_table.attach(self.status_box, 0, 1, 3, 4, xoptions=gtk.FILL, yoptions=gtk.FILL, xpadding=8) body_table.attach(check_box, 0, 1, 4, 5, xoptions=gtk.FILL, yoptions=gtk.FILL) body_box_align = set_widget_gravity(set_widget_center(body_table), (1, 1, 0.5, 0.5), (0, 0, 30, 30)) self.login_button = Button("登录") self.login_button.set_size_request(95, 30) login_button_align = set_widget_gravity(set_widget_center(self.login_button), (1, 1, 0.5, 0.5), (30, 30, 0, 0)) main_box = gtk.VBox() main_box.connect("expose-event", self.draw_border_mask) main_box.pack_start(body_box_align, False, True) main_box.pack_start(login_button_align, False, True) self.window_frame.pack_start(titlebar, False, True) self.window_frame.pack_start(main_box)
def create_combo_entry(self, label_content, entry_content=""): vbox = gtk.VBox() vbox.set_spacing(5) label = Label(label_content) text_entry = TextEntry(entry_content) text_entry.set_size(198, 26) entry_box = set_widget_center(text_entry) vbox.pack_start(label, False, False) vbox.pack_start(entry_box, False, False) return vbox, text_entry