From 3a8e524ba561656da8bc3c44774665123b523c58 Mon Sep 17 00:00:00 2001 From: llaske Date: Mon, 15 Jul 2013 20:31:54 +0000 Subject: Continue Gtk3 porting --- diff --git a/activity.py b/activity.py index 5db4b52..731b878 100644 --- a/activity.py +++ b/activity.py @@ -92,6 +92,7 @@ class RootsActivity(activity.Activity): page=toolbarentry, icon_name='cell-format') toolbox.toolbar.insert(self.entry_toolbar_button, -1) + self.entry_toolbar_button.connect('clicked', self.entry_toolbar_clicked) self.set_toolbar_box(toolbox) toolbox.show() @@ -127,31 +128,6 @@ class RootsActivity(activity.Activity): toolbarsample.insert(tool, -1) toolbarsample.show() - self.detail_btnaddparent = ToolButton('addparent') - self.detail_btnaddparent.set_tooltip(_('Add parents')) - self.detail_btnaddparent.connect('clicked', self.addparent_clicked) - self.detail_btnaddparent.show() - toolbox.toolbar.insert(self.detail_btnaddparent, -1) - self.detail_btnaddbrother = ToolButton('addbrother') - self.detail_btnaddbrother.set_tooltip(_('Add brother')) - self.detail_btnaddbrother.connect('clicked', self.addbrother_clicked) - self.detail_btnaddbrother.show() - toolbox.toolbar.insert(self.detail_btnaddbrother, -1) - self.detail_btnaddunion = ToolButton('addunion') - self.detail_btnaddunion.set_tooltip(_('Add union')) - self.detail_btnaddunion.connect('clicked', self.addunion_clicked) - self.detail_btnaddunion.show() - toolbox.toolbar.insert(self.detail_btnaddunion, -1) - self.detail_btnaddchild = ToolButton('addchild') - self.detail_btnaddchild.set_tooltip(_('Add child')) - self.detail_btnaddchild.connect('clicked', self.addchild_clicked) - self.detail_btnaddchild.show() - toolbox.toolbar.insert(self.detail_btnaddchild, -1) - self.detail_btndelete = ToolButton('delete') - self.detail_btndelete.set_tooltip(_('Delete')) - self.detail_btndelete.connect('clicked', self.delete_clicked) - self.detail_btndelete.show() - toolbox.toolbar.insert(self.detail_btndelete, -1) separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) @@ -162,13 +138,6 @@ class RootsActivity(activity.Activity): toolbox.toolbar.insert(stop_button, -1) stop_button.show() - #self.imagezone = Gtk.Image() - #self.imagezone.set_size_request(250, 200) - #self.imagezone.set_from_pixbuf(GdkPixbuf.Pixbuf.new_from_file('images/napolean.png')) - #toolitem = Gtk.ToolItem() - #toolitem.add(self.imagezone) - #toolbarentry.insert(toolitem, -1) - button = ToolButton('edit-paste') button.set_tooltip(_("Click here to paste an image")) button.connect('clicked', self.image_release_button) @@ -186,8 +155,10 @@ class RootsActivity(activity.Activity): chkbox = Gtk.HBox(False) self.detail_chkmale = Gtk.RadioButton(None, _("Male")) self.detail_chkmale.connect("toggled", self.sexradio_checked, 'M') + self.detail_chkmale.set_active(True) self.detail_chkmale.show() self.detail_chkfemale = Gtk.RadioButton(self.detail_chkmale, _("Female")) + self.detail_chkfemale.join_group(self.detail_chkmale) self.detail_chkfemale.connect("toggled", self.sexradio_checked, 'F') self.detail_chkfemale.show() chkbox.add(self.detail_chkmale) @@ -198,13 +169,31 @@ class RootsActivity(activity.Activity): toolitem.show() toolbarentry.insert(toolitem, -1) toolitem.show() - self.detail_description = Gtk.Entry() - self.detail_description.set_size_request(430, 50) - self.detail_description.connect("changed", self.description_changed) - self.detail_description.show() - toolitem = Gtk.ToolItem() - toolitem.add(self.detail_description) - toolbarentry.insert(toolitem, -1) + self.detail_btnaddparent = ToolButton('addparent') + self.detail_btnaddparent.set_tooltip(_('Add parents')) + self.detail_btnaddparent.connect('clicked', self.addparent_clicked) + self.detail_btnaddparent.show() + toolbarentry.insert(self.detail_btnaddparent, -1) + self.detail_btnaddbrother = ToolButton('addbrother') + self.detail_btnaddbrother.set_tooltip(_('Add brother')) + self.detail_btnaddbrother.connect('clicked', self.addbrother_clicked) + self.detail_btnaddbrother.show() + toolbarentry.insert(self.detail_btnaddbrother, -1) + self.detail_btnaddunion = ToolButton('addunion') + self.detail_btnaddunion.set_tooltip(_('Add union')) + self.detail_btnaddunion.connect('clicked', self.addunion_clicked) + self.detail_btnaddunion.show() + toolbarentry.insert(self.detail_btnaddunion, -1) + self.detail_btnaddchild = ToolButton('addchild') + self.detail_btnaddchild.set_tooltip(_('Add child')) + self.detail_btnaddchild.connect('clicked', self.addchild_clicked) + self.detail_btnaddchild.show() + toolbarentry.insert(self.detail_btnaddchild, -1) + self.detail_btndelete = ToolButton('delete') + self.detail_btndelete.set_tooltip(_('Delete')) + self.detail_btndelete.connect('clicked', self.delete_clicked) + self.detail_btndelete.show() + toolbarentry.insert(self.detail_btndelete, -1) # Create drawing area self.zoomlevel = 0 @@ -219,10 +208,22 @@ class RootsActivity(activity.Activity): # Create detail view self.box = Gtk.HBox(False) + vbox = Gtk.VBox(False, 10) + vbox.set_size_request(200, 780) self.imagezone = Gtk.Image() - self.imagezone.set_size_request(50, 50) - self.imagezone.set_from_pixbuf(GdkPixbuf.Pixbuf.new_from_file('images/napolean.png')) - self.box.pack_start(self.imagezone, True, True, 0) + self.imagezone.set_size_request(200, 200) + self.image_paste = GdkPixbuf.Pixbuf.new_from_file('images/edit-paste.svg') + self.image_hand1 = GdkPixbuf.Pixbuf.new_from_file('images/hand1.png') + self.imagezone.set_from_pixbuf(self.image_hand1) + self.detail_description = Gtk.TextView() + self.detail_description.set_wrap_mode(Gtk.WrapMode.WORD) + self.detail_description.set_size_request(200, 200) + self.detail_description.get_buffer().connect("changed", self.description_changed) + self.detail_description.show() + vbox.show() + vbox.pack_start(self.imagezone, False, True, 10) + vbox.pack_start(self.detail_description, True, True, 10) + self.box.pack_start(vbox, True, True, 0) self.box.pack_start(self.area, True, True, 0) self.set_canvas(self.box) @@ -282,7 +283,7 @@ class RootsActivity(activity.Activity): self.detail_name.set_sensitive(False) self.detail_description.set_sensitive(False) self.detail_name.set_text("") - self.detail_description.set_text("") + self.detail_description.get_buffer().set_text("") self.detail_chkmale.set_active(True) self.detail_chkmale.set_sensitive(False) self.detail_chkfemale.set_sensitive(False) @@ -298,7 +299,7 @@ class RootsActivity(activity.Activity): self.detail_name.set_sensitive(True) self.detail_name.grab_focus() self.detail_description.set_sensitive(True) - self.detail_description.set_text(person.description) + self.detail_description.get_buffer().set_text(person.description) self.detail_name.set_text(person.name) if person.sex == 'M': self.detail_chkmale.set_active(True) @@ -430,8 +431,9 @@ class RootsActivity(activity.Activity): "Description has changed, change the matching person description" if self.selected == None: return + buffer = self.detail_description.get_buffer() self.selected.description = \ - self.detail_description.get_text() + buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), True) self.redraw() @@ -508,6 +510,11 @@ class RootsActivity(activity.Activity): self.show_detail(None) + def entry_toolbar_clicked(self, event): + _logger.debug("Show detail forced, selected="+str(self.selected)) + self.box.queue_draw() + + def redraw(self): "Redraw area" self.area.queue_draw() @@ -517,24 +524,45 @@ class RootsActivity(activity.Activity): "Draw the image zone" gc = self.imagezone.get_window().cairo_create() pc = self.create_pango_context() + dy = 54 + if self.entry_toolbar_button.is_expanded(): + dy = dy + 54 # Draw border rect = self.imagezone.get_allocation() - gc.rectangle(0, 0, rect.width, rect.height) + gc.rectangle(0, dy, rect.width, rect.height) gc.set_source_rgb(*const.bg_color) gc.stroke() # Draw image if self.selected is None: image = self.image_hand1 + _logger.debug("need to draw hand1") else: if self.selected.image is None: image = self.image_paste + _logger.debug("need to draw paste") else: image = self.selected.image - x = (rect.width - image.get_width())/2 - y = (rect.height - image.get_height())/2 - Gdk.cairo_set_source_pixbuf(gc, image, x, y); + _logger.debug("need to draw image") + width, height = image.get_width(), image.get_height() + if width > rect.width: + scalew = rect.width + scaleh = (rect.width * height ) / width + else: + if height > rect.height: + scaleh = rect.height + scalew = ( rect.height * width ) / height + else: + scalew = width + scaleh = height + #_logger.debug("rectangle is "+str(rect.width)+"x"+str(rect.height)) + #_logger.debug("image is "+str(width)+"x"+str(height)) + #_logger.debug("scale is "+str(scalew)+"x"+str(scaleh)) + newimage = image.scale_simple(scalew, scaleh, 0) + x = (rect.width - scalew)/2 + y = (rect.height - scaleh)/2 + dy + Gdk.cairo_set_source_pixbuf(gc, newimage, x, y); gc.paint() # Draw text @@ -544,9 +572,9 @@ class RootsActivity(activity.Activity): else: text = _("Click here to paste an image") layout = Pango.Layout(pc) - layout.set_text(text) + layout.set_text(text, len(text)) layout.set_width(rect.width*Pango.SCALE) - layout.set_alignment(Pango.ALIGN_CENTER) + layout.set_alignment(Pango.Alignment.CENTER) gc.set_source_rgb(0, 0, 0) gc.move_to(0, y + image.get_height()) PangoCairo.update_layout(gc, layout) -- cgit v0.9.1