diff options
| author | Liming An <limingx.l.an@intel.com> | 2012-03-20 17:38:02 +0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-03-20 15:21:34 +0000 |
| commit | 5e0461c0e0233700d5c9f36aee450cc091a1aeec (patch) | |
| tree | 1caecba1407e00fd381114caeeeac810437f1196 | |
| parent | 4dc552a216a3432a6e4f7441f3552a1acaaed03e (diff) | |
| download | poky-5e0461c0e0233700d5c9f36aee450cc091a1aeec.tar.gz | |
Hob: Fixed the hobwidget code and make it like a pythonista
fixed the 'for..in..' range dance code, and use the 'iterator' approach to replaced the index for quote the 'children' list
(From Poky rev: 74e7286a4e875eda5e8abeb5db1015031d21c35f)
(Bitbake rev: 3dc443663b97515a54b70c9047a9b22c6b8a0c14)
Signed-off-by: Liming An <limingx.l.an@intel.com>
Signed-off-by: Shane Wang <shane.wang@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | bitbake/lib/bb/ui/crumbs/hobwidget.py | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/hobwidget.py b/bitbake/lib/bb/ui/crumbs/hobwidget.py index 71f0629714..4c4b059267 100644 --- a/bitbake/lib/bb/ui/crumbs/hobwidget.py +++ b/bitbake/lib/bb/ui/crumbs/hobwidget.py | |||
| @@ -309,7 +309,7 @@ class HobTabBar(gtk.DrawingArea): | |||
| 309 | self.tab_h_ratio = 52 * 1.0/53 | 309 | self.tab_h_ratio = 52 * 1.0/53 |
| 310 | self.set_size_request(self.width, self.height) | 310 | self.set_size_request(self.width, self.height) |
| 311 | 311 | ||
| 312 | self.current_child = 0 | 312 | self.current_child = None |
| 313 | self.font = self.get_style().font_desc | 313 | self.font = self.get_style().font_desc |
| 314 | self.font.set_size(pango.SCALE * 13) | 314 | self.font.set_size(pango.SCALE * 13) |
| 315 | self.update_children_text_layout_and_bg_color() | 315 | self.update_children_text_layout_and_bg_color() |
| @@ -339,10 +339,10 @@ class HobTabBar(gtk.DrawingArea): | |||
| 339 | if self.is_focus() or event.type == gtk.gdk.BUTTON_PRESS: | 339 | if self.is_focus() or event.type == gtk.gdk.BUTTON_PRESS: |
| 340 | x, y = event.get_coords() | 340 | x, y = event.get_coords() |
| 341 | # check which tab be clicked | 341 | # check which tab be clicked |
| 342 | for i, child in enumerate(self.children): | 342 | for child in self.children: |
| 343 | if (child["x"] < x) and (x < child["x"] + self.tab_width) \ | 343 | if (child["x"] < x) and (x < child["x"] + self.tab_width) \ |
| 344 | and (child["y"] < y) and (y < child["y"] + self.tab_height): | 344 | and (child["y"] < y) and (y < child["y"] + self.tab_height): |
| 345 | self.current_child = i | 345 | self.current_child = child |
| 346 | result = True | 346 | result = True |
| 347 | break | 347 | break |
| 348 | 348 | ||
| @@ -353,7 +353,7 @@ class HobTabBar(gtk.DrawingArea): | |||
| 353 | self.grab_focus() | 353 | self.grab_focus() |
| 354 | 354 | ||
| 355 | if result == True: | 355 | if result == True: |
| 356 | page = self.children[self.current_child]["toggled_page"] | 356 | page = self.current_child["toggled_page"] |
| 357 | self.emit("tab-switched", page) | 357 | self.emit("tab-switched", page) |
| 358 | self.tab_pressed = True | 358 | self.tab_pressed = True |
| 359 | self.queue_draw() | 359 | self.queue_draw() |
| @@ -383,16 +383,16 @@ class HobTabBar(gtk.DrawingArea): | |||
| 383 | pangolayout = self.create_pango_layout(child["title"]) | 383 | pangolayout = self.create_pango_layout(child["title"]) |
| 384 | pangolayout.set_font_description(self.font) | 384 | pangolayout.set_font_description(self.font) |
| 385 | child["title_layout"] = pangolayout | 385 | child["title_layout"] = pangolayout |
| 386 | child[i]["r"] = color.red | 386 | child["r"] = color.red |
| 387 | child[i]["g"] = color.green | 387 | child["g"] = color.green |
| 388 | child[i]["b"] = color.blue | 388 | child["b"] = color.blue |
| 389 | 389 | ||
| 390 | def append_tab_child(self, title, page): | 390 | def append_tab_child(self, title, page): |
| 391 | num = len(self.children) + 1 | 391 | num = len(self.children) + 1 |
| 392 | self.tab_width = self.tab_width * len(self.children) / num | 392 | self.tab_width = self.tab_width * len(self.children) / num |
| 393 | 393 | ||
| 394 | i = 0 | 394 | i = 0 |
| 395 | for child in self.children: | 395 | for i, child in enumerate(self.children): |
| 396 | child["x"] = self.tab_x + i * self.tab_width | 396 | child["x"] = self.tab_x + i * self.tab_width |
| 397 | i += 1 | 397 | i += 1 |
| 398 | 398 | ||
| @@ -414,6 +414,9 @@ class HobTabBar(gtk.DrawingArea): | |||
| 414 | "indicator_number" : 0, | 414 | "indicator_number" : 0, |
| 415 | } | 415 | } |
| 416 | self.children.append(new_one) | 416 | self.children.append(new_one) |
| 417 | # set the default current child | ||
| 418 | if not self.current_child: | ||
| 419 | self.current_child = new_one | ||
| 417 | 420 | ||
| 418 | def on_draw(self, widget, event): | 421 | def on_draw(self, widget, event): |
| 419 | cr = widget.window.cairo_create() | 422 | cr = widget.window.cairo_create() |
| @@ -425,11 +428,12 @@ class HobTabBar(gtk.DrawingArea): | |||
| 425 | 428 | ||
| 426 | self.draw_background(cr) | 429 | self.draw_background(cr) |
| 427 | self.draw_toggled_tab(cr) | 430 | self.draw_toggled_tab(cr) |
| 428 | self.draw_tab_text(cr) | ||
| 429 | 431 | ||
| 430 | for i, child in enumerate(self.children): | 432 | for child in self.children: |
| 431 | if child["indicator_show"] == True: | 433 | if child["indicator_show"] == True: |
| 432 | self.draw_indicator(cr, i) | 434 | self.draw_indicator(cr, child) |
| 435 | |||
| 436 | self.draw_tab_text(cr) | ||
| 433 | 437 | ||
| 434 | def draw_background(self, cr): | 438 | def draw_background(self, cr): |
| 435 | style = self.get_style() | 439 | style = self.get_style() |
| @@ -476,14 +480,15 @@ class HobTabBar(gtk.DrawingArea): | |||
| 476 | # center pos | 480 | # center pos |
| 477 | off_x = (self.tab_width - fontw) / 2 | 481 | off_x = (self.tab_width - fontw) / 2 |
| 478 | off_y = (self.tab_height - fonth) / 2 | 482 | off_y = (self.tab_height - fonth) / 2 |
| 479 | x = child[i]["x"] + off_x | 483 | x = child["x"] + off_x |
| 480 | y = child[i]["y"] + off_y | 484 | y = child["y"] + off_y |
| 481 | self.window.draw_layout(self.style.fg_gc[gtk.STATE_NORMAL], int(x), int(y), pangolayout) | 485 | self.window.draw_layout(self.style.fg_gc[gtk.STATE_NORMAL], int(x), int(y), pangolayout) |
| 482 | 486 | ||
| 483 | def draw_toggled_tab(self, cr): | 487 | def draw_toggled_tab(self, cr): |
| 484 | i = self.current_child | 488 | if not self.current_child: |
| 485 | x = self.children[i]["x"] | 489 | return |
| 486 | y = self.children[i]["y"] | 490 | x = self.current_child["x"] |
| 491 | y = self.current_child["y"] | ||
| 487 | width = self.tab_width | 492 | width = self.tab_width |
| 488 | height = self.tab_height | 493 | height = self.tab_height |
| 489 | style = self.get_style() | 494 | style = self.get_style() |
| @@ -515,10 +520,10 @@ class HobTabBar(gtk.DrawingArea): | |||
| 515 | cr.arc(x + r, y + r, r, math.pi, 1.5*math.pi) | 520 | cr.arc(x + r, y + r, r, math.pi, 1.5*math.pi) |
| 516 | cr.fill() | 521 | cr.fill() |
| 517 | 522 | ||
| 518 | def draw_indicator(self, cr, i): | 523 | def draw_indicator(self, cr, child): |
| 519 | tab_x = self.children[i]["x"] | 524 | tab_x = child["x"] |
| 520 | tab_y = self.children[i]["y"] | 525 | tab_y = child["y"] |
| 521 | number = self.children[i]["indicator_number"] | 526 | number = child["indicator_number"] |
| 522 | dest_w = int(32 * self.tab_w_ratio) | 527 | dest_w = int(32 * self.tab_w_ratio) |
| 523 | dest_h = int(32 * self.tab_h_ratio) | 528 | dest_h = int(32 * self.tab_h_ratio) |
| 524 | if dest_h < self.tab_height: | 529 | if dest_h < self.tab_height: |
| @@ -541,13 +546,13 @@ class HobTabBar(gtk.DrawingArea): | |||
| 541 | cr.move_to(x, y) | 546 | cr.move_to(x, y) |
| 542 | self.window.draw_layout(self.style.fg_gc[gtk.STATE_NORMAL], int(x), int(y), layout) | 547 | self.window.draw_layout(self.style.fg_gc[gtk.STATE_NORMAL], int(x), int(y), layout) |
| 543 | 548 | ||
| 544 | def show_indicator_icon(self, i, number): | 549 | def show_indicator_icon(self, child, number): |
| 545 | self.children[i]["indicator_show"] = True | 550 | child["indicator_show"] = True |
| 546 | self.children[i]["indicator_number"] = number | 551 | child["indicator_number"] = number |
| 547 | self.queue_draw() | 552 | self.queue_draw() |
| 548 | 553 | ||
| 549 | def hide_indicator_icon(self, i): | 554 | def hide_indicator_icon(self, child): |
| 550 | self.children[i]["indicator_show"] = False | 555 | child["indicator_show"] = False |
| 551 | self.queue_draw() | 556 | self.queue_draw() |
| 552 | 557 | ||
| 553 | def set_blank_size(self, x, y, w, h): | 558 | def set_blank_size(self, x, y, w, h): |
| @@ -618,18 +623,18 @@ class HobNotebook(gtk.VBox): | |||
| 618 | self.tb.show() | 623 | self.tb.show() |
| 619 | 624 | ||
| 620 | def show_indicator_icon(self, title, number): | 625 | def show_indicator_icon(self, title, number): |
| 621 | for i, child in enumerate(self.tabbar.children): | 626 | for child in self.tabbar.children: |
| 622 | if child["toggled_page"] == -1: | 627 | if child["toggled_page"] == -1: |
| 623 | continue | 628 | continue |
| 624 | if child["title"] == title: | 629 | if child["title"] == title: |
| 625 | self.tabbar.show_indicator_icon(i, number) | 630 | self.tabbar.show_indicator_icon(child, number) |
| 626 | 631 | ||
| 627 | def hide_indicator_icon(self, title): | 632 | def hide_indicator_icon(self, title): |
| 628 | for i, child in enumerate(self.tabbar.children): | 633 | for child in self.tabbar.children: |
| 629 | if child["toggled_page"] == -1: | 634 | if child["toggled_page"] == -1: |
| 630 | continue | 635 | continue |
| 631 | if child["title"] == title: | 636 | if child["title"] == title: |
| 632 | self.tabbar.hide_indicator_icon(i) | 637 | self.tabbar.hide_indicator_icon(child) |
| 633 | 638 | ||
| 634 | def tab_switched_cb(self, widget, page): | 639 | def tab_switched_cb(self, widget, page): |
| 635 | self.notebook.set_current_page(page) | 640 | self.notebook.set_current_page(page) |
