def __init__(self, dial_group=None, window_group=None, window_title="", additional_text=None, actionok=None, actioncancel=None): Gtk.Dialog.__init__(self, window_title, None, Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)) if window_group is not None: window_group.add_window(self) self.set_resizable(False) self.connect("close", self.respond, actionok, actioncancel) self.connect("response", self.respond, actionok, actioncancel) self.connect("window-state-event", self.window_attn) self.set_default_response(Gtk.ResponseType.OK) hbox = Gtk.HBox(False, 20) hbox.set_border_width(20) self.vbox.pack_start(hbox, True, True, 0) hbox.show() image = Gtk.Image() image.set_from_stock(Gtk.STOCK_DIALOG_WARNING, Gtk.IconSize.DIALOG) hbox.pack_start(image, True, True, 0) image.show() vbox = Gtk.VBox() vbox.set_spacing(8) hbox.pack_start(vbox, True, True, 0) vbox.show() if additional_text is not None: if type(additional_text) is str: additional_text = additional_text.splitlines() for each in additional_text: label = Gtk.Label() attrlist = Pango.AttrList() attrlist.insert(Pango.AttrSize(12500, 0, len(each))) label.set_attributes(attrlist) label.set_text(each) vbox.add(label) label.show() if dial_group is not None: dial_group.add(self) self.dial_group = dial_group
def get_calculated_dimensions(self, context, rect): angle = 2 * math.pi * self._rotation / 360.0 if self._context == None: label = Gtk.Label() self._context = label.create_pango_context() pango_context = self._context attrs = Pango.AttrList() attrs.insert(Pango.AttrWeight(self._weight, 0, len(self._text))) attrs.insert(Pango.AttrStyle(self._slant, 0, len(self._text))) attrs.insert(Pango.AttrUnderline(self._underline, 0, len(self._text))) if self._size != None: attrs.insert(Pango.AttrSize(1000 * self._size, 0, len(self._text))) if self._layout == None: self._layout = Pango.Layout(pango_context) layout = self._layout layout.set_text(self._text) layout.set_attributes(attrs) #find out where to draw the layout and calculate the maximum width width = rect.width if self._anchor in [ANCHOR_BOTTOM_LEFT, ANCHOR_TOP_LEFT, ANCHOR_LEFT_CENTER]: width = rect.width - self._position[0] elif self._anchor in [ANCHOR_BOTTOM_RIGHT, ANCHOR_TOP_RIGHT, ANCHOR_RIGHT_CENTER]: width = self._position[0] text_width, text_height = layout.get_pixel_size() width = width * math.cos(angle) width = min(width, self._max_width) if self._wrap: layout.set_wrap(Pango.WrapMode.WORD_CHAR) layout.set_width(int(1000 * width)) x, y = get_text_pos(layout, self._position, self._anchor, angle) if not self._fixed: #Find already drawn labels that would intersect with the current one #and adjust position to avoid intersection. text_width, text_height = layout.get_pixel_size() real_width = abs(text_width * math.cos(angle)) + abs(text_height * math.sin(angle)) real_height = abs(text_height * math.cos(angle)) + abs(text_width * math.sin(angle)) other_labels = get_registered_labels() this_rect = (int(x), int(y), int(real_width), int(real_height)) for label in other_labels: label_rect = label.get_allocation() intersection = this_rect.intersect(label_rect) if intersection.width == 0 and intersection.height == 0: continue y_diff = 0 if label_rect.y <= y and label_rect.y + label_rect.height >= y: y_diff = y - label_rect.y + label_rect.height elif label_rect.y > y and label_rect.y < y + real_height: y_diff = label_rect.y - real_height - y y += y_diff #calculate the dimensions text_width, text_height = layout.get_pixel_size() real_width = abs(text_width * math.cos(angle)) + abs(text_height * math.sin(angle)) real_height = abs(text_height * math.cos(angle)) + abs(text_width * math.sin(angle)) return real_width, real_height