Beispiel #1
0
 def __init__(self, startX=0, startY=0):
     Canvas.__init__(self, startX, startY, 122, 122)
     self.textCalendar = [
         '', 'Su Mo Tu We Th Fr Sa', '', '', '', '', '', ''
     ]
     self.fillArea = [-1, -1, -1]
     self.lastYearAndMonth = [-1, -1]
     self.up = False
     self.timezone = 8
Beispiel #2
0
    def create_ui(self):
        self.canvas = Canvas(self.colorModel)

        self.create_menu_bar()
        self.statusBar()

        self.area = CanvasView(self.canvas)
        self.area.setAlignment(Qt.AlignCenter)

        self.setCentralWidget(self.area)

        # Popup box
        self.info_popup = InfoPopup(self.pattern)
Beispiel #3
0
    def __init__(self):
        #self.id = random.uniform(0, 999999999)
        Rectangle.__init__(self)
        self.handler = Handler()
        self.magnetos = Magnetos()
        self.offset = Point()
        self.pivot = Point()
        self.selected = False
        self.resizing = False
        self.direction = NONE
        self.control = AUTOMATIC
        self.z = 0

        self.hints = False
        from ui.canvas import Canvas
        self.canvas = Canvas()
        self.handler.is_testing = self.canvas.is_testing

        self.dash = []
        self.thickness = 1.0

        self.fill_style = COLOR
        self.fill_color = Color(0.25, 0.25, 0.25, 0.25)
        self.stroke_color = Color(0.25, 0.25, 0.25, 1.0)
        self.gradient = Gradient()
Beispiel #4
0
    def __init__(self, application):
        gtk.HPaned.__init__(self)
        from ui.canvas import Canvas
        self.canvas = Canvas(application)
        self.properties = Properties(application)

        self.canvas.connect("select", self.select)
        self.canvas.connect("finalize", self.finalize)
        self.canvas.connect("edit-child", self.edit_child)
        self.canvas.connect("scroll-event", self.wheel)

        box = gtk.VBox()

        self.notification = Notification()

        code_editor = None

        if '--source-editor-test' in sys.argv:
            while True:
                try:
                    from ui.code_editor import CodeEditor
                except:
                    self.notification.notificate(_("No module GtkSourceView installed"), ERROR)
                    self.pack1(box, True, False)
                    break

                panel = gtk.VPaned()
                panel.pack1(box, True, False)
                code_editor = CodeEditor(application)
                code_editor.editor.set_language("sql")
                panel.pack2(code_editor, False, True)
                self.pack1(panel, True, False)
                break
        else:
            self.pack1(box, True, False)

        self.pack2(self.properties, False, True)

        top = gtk.HBox()
        box.pack_start(top, False, False)

        top.pack_start(self.notification, False, False)

        layer_selector = LayerSelector()
        alignment = gtk.Alignment(1.0, 0.5)
        alignment.add(layer_selector)
        top.pack_start(alignment, True, True)

        separator = gtk.VSeparator()
        top.pack_start(separator, False, False)

        self.image = gtk.Image()
        self.image.set_from_stock(CONTRACT_PROPERTIES, gtk.ICON_SIZE_MENU)
        button = gtk.Button()
        button.set_image(self.image)
        button.set_relief(gtk.RELIEF_NONE)
        button.connect("clicked", self.toggle_properties)
        top.pack_start(button, False, False)

        table = gtk.Table()
        box.add(table)

        bottom = gtk.HBox()
        box.pack_start(bottom, False, False)

        self.climber = Climber(self.canvas)
        bottom.pack_start(self.climber, False, False)

        pager = Pager(self.canvas)
        alignment = gtk.Alignment(1.0, 0.5)
        alignment.add(pager)
        bottom.pack_start(alignment, True, True)

        self.horizontal_ruler = HorizontalRuler()
        self.horizontal_ruler.connect("append-tag", self.append_tag)
        self.horizontal_ruler.connect("move-tag", self.move_tag)
        table.attach(self.horizontal_ruler, 1, 2, 0, 1, gtk.FILL | gtk.EXPAND, 0)

        self.vertical_ruler = VerticalRuler()
        self.vertical_ruler.connect("append-tag", self.append_tag)
        self.vertical_ruler.connect("move-tag", self.move_tag)
        table.attach(self.vertical_ruler, 0, 1, 1, 2, 0, gtk.FILL | gtk.EXPAND)

        area = gtk.ScrolledWindow()
        area.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        adjustment = area.get_vadjustment()
        adjustment.connect("value-changed", self.scroll, VERTICAL)
        adjustment = area.get_hadjustment()
        adjustment.connect("value-changed", self.scroll, HORIZONTAL)
        table.attach(area, 1, 2, 1, 2, gtk.FILL | gtk.EXPAND, gtk.FILL | gtk.EXPAND)

        self.canvas.code_editor = code_editor
        self.canvas.horizontal_ruler = self.horizontal_ruler
        self.canvas.vertical_ruler = self.vertical_ruler
        self.connect("realize", self.realize, area)
Beispiel #5
0
class Editor(gtk.HPaned):
    """This class represents the main editor"""

    def __init__(self, application):
        gtk.HPaned.__init__(self)
        from ui.canvas import Canvas
        self.canvas = Canvas(application)
        self.properties = Properties(application)

        self.canvas.connect("select", self.select)
        self.canvas.connect("finalize", self.finalize)
        self.canvas.connect("edit-child", self.edit_child)
        self.canvas.connect("scroll-event", self.wheel)

        box = gtk.VBox()

        self.notification = Notification()

        code_editor = None

        if '--source-editor-test' in sys.argv:
            while True:
                try:
                    from ui.code_editor import CodeEditor
                except:
                    self.notification.notificate(_("No module GtkSourceView installed"), ERROR)
                    self.pack1(box, True, False)
                    break

                panel = gtk.VPaned()
                panel.pack1(box, True, False)
                code_editor = CodeEditor(application)
                code_editor.editor.set_language("sql")
                panel.pack2(code_editor, False, True)
                self.pack1(panel, True, False)
                break
        else:
            self.pack1(box, True, False)

        self.pack2(self.properties, False, True)

        top = gtk.HBox()
        box.pack_start(top, False, False)

        top.pack_start(self.notification, False, False)

        layer_selector = LayerSelector()
        alignment = gtk.Alignment(1.0, 0.5)
        alignment.add(layer_selector)
        top.pack_start(alignment, True, True)

        separator = gtk.VSeparator()
        top.pack_start(separator, False, False)

        self.image = gtk.Image()
        self.image.set_from_stock(CONTRACT_PROPERTIES, gtk.ICON_SIZE_MENU)
        button = gtk.Button()
        button.set_image(self.image)
        button.set_relief(gtk.RELIEF_NONE)
        button.connect("clicked", self.toggle_properties)
        top.pack_start(button, False, False)

        table = gtk.Table()
        box.add(table)

        bottom = gtk.HBox()
        box.pack_start(bottom, False, False)

        self.climber = Climber(self.canvas)
        bottom.pack_start(self.climber, False, False)

        pager = Pager(self.canvas)
        alignment = gtk.Alignment(1.0, 0.5)
        alignment.add(pager)
        bottom.pack_start(alignment, True, True)

        self.horizontal_ruler = HorizontalRuler()
        self.horizontal_ruler.connect("append-tag", self.append_tag)
        self.horizontal_ruler.connect("move-tag", self.move_tag)
        table.attach(self.horizontal_ruler, 1, 2, 0, 1, gtk.FILL | gtk.EXPAND, 0)

        self.vertical_ruler = VerticalRuler()
        self.vertical_ruler.connect("append-tag", self.append_tag)
        self.vertical_ruler.connect("move-tag", self.move_tag)
        table.attach(self.vertical_ruler, 0, 1, 1, 2, 0, gtk.FILL | gtk.EXPAND)

        area = gtk.ScrolledWindow()
        area.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        adjustment = area.get_vadjustment()
        adjustment.connect("value-changed", self.scroll, VERTICAL)
        adjustment = area.get_hadjustment()
        adjustment.connect("value-changed", self.scroll, HORIZONTAL)
        table.attach(area, 1, 2, 1, 2, gtk.FILL | gtk.EXPAND, gtk.FILL | gtk.EXPAND)

        self.canvas.code_editor = code_editor
        self.canvas.horizontal_ruler = self.horizontal_ruler
        self.canvas.vertical_ruler = self.vertical_ruler
        self.connect("realize", self.realize, area)

    def realize(self, widget, area):
        area.add_with_viewport(self.canvas)
        self.canvas.show()

    def toggle_properties(self, *args):
        properties = self.get_children()[1]
        if self.properties.get_visible():
            self.image.set_from_stock(EXPAND_PROPERTIES, gtk.ICON_SIZE_MENU)
            properties.hide()
        else:
            self.image.set_from_stock(CONTRACT_PROPERTIES, gtk.ICON_SIZE_MENU)
            properties.show()

    def append_tag(self, widget, tag):
        self.canvas.guides.add_tag(tag)
        self.canvas.update()

    def move_tag(self, widget, tag):
        self.canvas.queue_draw()

    def select(self, widget, child):
        self.update(child)

    def finalize(self, widget, child):
        self.update(child)

    def update(self, child):
        self.properties.select(child.__name__, child)

    def edit_child(self, widget, child):
        pass
        #print "edit", child

    def wheel(self, widget, event):
        if event.state & gtk.gdk.CONTROL_MASK:
            if event.direction == gtk.gdk.SCROLL_UP:
                self.canvas.zoom_in()
                self.climber.update()
            elif event.direction == gtk.gdk.SCROLL_DOWN:
                self.canvas.zoom_out()
                self.climber.update()
            self.horizontal_ruler.zoom = self.canvas.zoom
            return True

    def scroll(self, adjustment, direction):
        offset = adjustment.get_value()
        if direction == VERTICAL:
            self.canvas.vertical_ruler.offset = offset
        elif direction == HORIZONTAL:
            self.canvas.horizontal_ruler.offset = offset

    def key_press(self, widget, event):
        pass

    def _select(self, widget, child, buffer):
        #print "Selected object \"%s\"" % child.__name__
        #if child.__name__ == "Table":
        #if child.__name__ == "Text":
        #   if not child.x and not child.y:
        #     return

        #  textpad = TextPad()
        #  textpad.set_size_request(150, -1)
        #  textpad.show_all()
        #  self.canvas.put(textpad, child.x + self.canvas.origin.x, child.y + self.canvas.origin.y)
        if child.__name__ == "Text":
            text = child.get_property("text")
            #print "putting text \"%s\"" % text
            buffer.handler_disconnect(self.disconnect_handler)
            buffer.set_text(text)
            self.disconnect_handler = buffer.connect("changed", self.changed)

    def set_paper(self):
        for page in self.canvas.document.pages:
            page.x = 25
            page.y = 25

            page.width = 800
            page.height = 1500

            page.top = 25
            page.left = 25
            page.bottom = 25
            page.right = 25

            page.active = True

            self.canvas.grid.active = True
            self.canvas.grid.size = 16 # 31 # 32

            self.canvas.guides.active = True
            self.canvas.guides.size = 16 * 8 # 128

            self.canvas.grid.snap = True
Beispiel #6
0
 def __init__(self, startX=0, startY=0, width=-1, height=-1):
     Canvas.__init__(self, startX, startY, width, height)
Beispiel #7
0
 def __init__(self, startX=0, startY=0, width=-1, height=-1):
     Canvas.__init__(self, startX, startY, width, height)
     self.width = 250 - startX + 1
     self.height = 122
Beispiel #8
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        # TODO Changed the way __init__ is called, verify this is equivalent
        # QMainWindow.__init__(self, parent)
        super(MainWindow, self).__init__()

        self.setWindowTitle("Viewer for Janome Embroidery Files [*]")

        # Pattern-related attributes
        self.stitches_only = True
        self.path = ""
        self.pattern = None
        self.canvas = None
        self.area = None
        self.colorModel = PatternColorModel(QColor(Qt.white))
        # TODO SIGNAL
        # self.connect(self.colorModel, SIGNAL("colorChanged()"), self.setModified)

        self.create_ui()

    def create_ui(self):
        self.canvas = Canvas(self.colorModel)

        self.create_menu_bar()
        self.statusBar()

        self.area = CanvasView(self.canvas)
        self.area.setAlignment(Qt.AlignCenter)

        self.setCentralWidget(self.area)

        # Popup box
        self.info_popup = InfoPopup(self.pattern)

    def create_menu_bar(self):
        main_menu = self.menuBar()
        file_menu = main_menu.addMenu("&File")
        viewMenu = main_menu.addMenu("&View")
        toolsMenu = main_menu.addMenu("&Tools")

        # File menu - Open File
        open_file_action = QAction("Open File...", self)
        open_file_action.setStatusTip("Open a JEF file")
        open_file_action.setShortcut(QKeySequence.Open)
        open_file_action.triggered.connect(self.open_file_dialog)
        file_menu.addAction(open_file_action)

        # File menu - Save As
        save_file_action = QAction("Save &As...", self)
        save_file_action.setStatusTip("Save a JEF file")
        save_file_action.setShortcut(QKeySequence.SaveAs)
        save_file_action.triggered.connect(self.save_file_dialog)
        file_menu.addAction(save_file_action)

        # File menu - Quit
        quit_action = QAction("Quit", self)
        quit_action.setStatusTip("Exit application")
        quit_action.setShortcut(QKeySequence.Close)
        # TODO Change method self.close
        quit_action.triggered.connect(self.close)
        file_menu.addAction(quit_action)

        # View menu - Zoom
        zoom_reset_action = QAction("&Zoom", self)
        zoom_reset_action.setStatusTip("Reset Zoom")
        zoom_reset_action.setShortcut('Z')
        zoom_reset_action.triggered.connect(self.canvas.zoom_reset)
        viewMenu.addAction(zoom_reset_action)

        # View menu - Zoom In
        zoom_in_action = QAction("Zoom &In", self)
        zoom_in_action.setStatusTip("Zoom in closer")
        zoom_in_action.setShortcut(QKeySequence.ZoomIn)
        zoom_in_action.triggered.connect(self.canvas.zoom_in)
        viewMenu.addAction(zoom_in_action)

        # View menu - Zoom Out
        zoom_out_action = QAction("Zoom &Out", self)
        zoom_out_action.setStatusTip("Zoom out wider")
        zoom_out_action.setShortcut(QKeySequence.ZoomOut)
        zoom_out_action.triggered.connect(self.canvas.zoom_out)
        viewMenu.addAction(zoom_out_action)

        # View menu - Info Popup
        info_popup_action = QAction("Info...", self)
        info_popup_action.setStatusTip("Display information popup")
        info_popup_action.setShortcut(QKeySequence.Replace)
        info_popup_action.triggered.connect(self.open_info_popup)
        viewMenu.addAction(info_popup_action)

        # Tools menu - color dock
        # TODO add tools menu options
        toolsMenu.addAction(self._create_color_dock_widget())

    def _create_color_dock_widget(self):
        self.colorDockWidget = ColorDockWidget(self.colorModel, self)
        self.addDockWidget(Qt.RightDockWidgetArea, self.colorDockWidget)
        self.colorDockWidget.hide()
        return self.colorDockWidget.toggleViewAction()

    def open_file_dialog(self):
        # TODO check for no file selected on open
        # TODO unicode
        # path = unicode(
        #     QFileDialog.getOpenFileName(
        #         self, self.tr("Open File"), os.path.split(self.path)[0],
        #         self.tr("Janome Embroidery Files (*.jef *.JEF)"))
        # )
        # getOpenFileName() returns a tuple with [0[ = absolute filename, [1] = filter. We only want the name.
        path = QFileDialog.getOpenFileName(
            self, "Open File", os.path.dirname(self.path),
            "Janome Embroidery Files (*.jef *.JEF)")
        if path:

            self.open_file(path[0])

    def open_file(self, path):
        # TODO unicode
        # path = unicode(path)
        self.pattern = jef.Pattern(path)
        # TODO Check this
        self.info_popup.update_values(self.pattern)
        qApp.setOverrideCursor(Qt.WaitCursor)
        self.path = path
        self.colorDockWidget.set_pattern(self.pattern)
        self.canvas.setRenderer(
            Renderer(self.pattern, self.colorModel, self.stitches_only))
        self.setWindowTitle(
            "{} - Viewer for Janome Embroidery Files [*]".format(path))
        qApp.restoreOverrideCursor()

    def save_file_dialog(self):
        # TODO unicode
        # path = unicode(
        #     QFileDialog.getSaveFileName(
        #         self, self.tr("Save File"), os.path.split(self.path)[0],
        #         self.tr("Janome Embroidery Files (*.jef *.JEF)"))
        # )
        # getSaveFileName() returns a tuple with [0[ = absolute filename, [1] = filter. We only want the name.
        path = QFileDialog.getSaveFileName(
            self, "Save File", os.path.dirname(self.path),
            "Janome Embroidery Files (*.jef *.JEF)")

        if path:
            self.save_file(path[0])

    def save_file(self, path):
        # TODO unicode
        # path = unicode(path)

        qApp.setOverrideCursor(Qt.WaitCursor)
        saved = self.pattern.save(path)
        qApp.restoreOverrideCursor()

        if saved:
            self.setWindowModified(False)
            self.path = path
            self.setWindowTitle(
                "{} - Viewer for Janome Embroidery Files [*]".format(path))
        else:
            QMessageBox.warning(self, "Failed to save file.")

    def open_info_popup(self):
        self.info_popup.show()

    def toggle_info_popup(self):
        self.info_popup.hide()
Beispiel #9
0
    def __init__(self, application):
        gtk.HPaned.__init__(self)
        from ui.canvas import Canvas
        self.canvas = Canvas(application)
        self.properties = Properties(application)

        self.canvas.connect("select", self.select)
        self.canvas.connect("finalize", self.finalize)
        self.canvas.connect("edit-child", self.edit_child)
        self.canvas.connect("scroll-event", self.wheel)

        box = gtk.VBox()

        self.notification = Notification()

        code_editor = None

        if '--source-editor-test' in sys.argv:
            while True:
                try:
                    from ui.code_editor import CodeEditor
                except:
                    self.notification.notificate(
                        _("No module GtkSourceView installed"), ERROR)
                    self.pack1(box, True, False)
                    break

                panel = gtk.VPaned()
                panel.pack1(box, True, False)
                code_editor = CodeEditor(application)
                code_editor.editor.set_language("sql")
                panel.pack2(code_editor, False, True)
                self.pack1(panel, True, False)
                break
        else:
            self.pack1(box, True, False)

        self.pack2(self.properties, False, True)

        top = gtk.HBox()
        box.pack_start(top, False, False)

        top.pack_start(self.notification, False, False)

        layer_selector = LayerSelector()
        alignment = gtk.Alignment(1.0, 0.5)
        alignment.add(layer_selector)
        top.pack_start(alignment, True, True)

        separator = gtk.VSeparator()
        top.pack_start(separator, False, False)

        self.image = gtk.Image()
        self.image.set_from_stock(CONTRACT_PROPERTIES, gtk.ICON_SIZE_MENU)
        button = gtk.Button()
        button.set_image(self.image)
        button.set_relief(gtk.RELIEF_NONE)
        button.connect("clicked", self.toggle_properties)
        top.pack_start(button, False, False)

        table = gtk.Table()
        box.add(table)

        bottom = gtk.HBox()
        box.pack_start(bottom, False, False)

        self.climber = Climber(self.canvas)
        bottom.pack_start(self.climber, False, False)

        pager = Pager(self.canvas)
        alignment = gtk.Alignment(1.0, 0.5)
        alignment.add(pager)
        bottom.pack_start(alignment, True, True)

        self.horizontal_ruler = HorizontalRuler()
        self.horizontal_ruler.connect("append-tag", self.append_tag)
        self.horizontal_ruler.connect("move-tag", self.move_tag)
        table.attach(self.horizontal_ruler, 1, 2, 0, 1, gtk.FILL | gtk.EXPAND,
                     0)

        self.vertical_ruler = VerticalRuler()
        self.vertical_ruler.connect("append-tag", self.append_tag)
        self.vertical_ruler.connect("move-tag", self.move_tag)
        table.attach(self.vertical_ruler, 0, 1, 1, 2, 0, gtk.FILL | gtk.EXPAND)

        area = gtk.ScrolledWindow()
        area.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        adjustment = area.get_vadjustment()
        adjustment.connect("value-changed", self.scroll, VERTICAL)
        adjustment = area.get_hadjustment()
        adjustment.connect("value-changed", self.scroll, HORIZONTAL)
        table.attach(area, 1, 2, 1, 2, gtk.FILL | gtk.EXPAND,
                     gtk.FILL | gtk.EXPAND)

        self.canvas.code_editor = code_editor
        self.canvas.horizontal_ruler = self.horizontal_ruler
        self.canvas.vertical_ruler = self.vertical_ruler
        self.connect("realize", self.realize, area)
Beispiel #10
0
class Editor(gtk.HPaned):
    """This class represents the main editor"""
    def __init__(self, application):
        gtk.HPaned.__init__(self)
        from ui.canvas import Canvas
        self.canvas = Canvas(application)
        self.properties = Properties(application)

        self.canvas.connect("select", self.select)
        self.canvas.connect("finalize", self.finalize)
        self.canvas.connect("edit-child", self.edit_child)
        self.canvas.connect("scroll-event", self.wheel)

        box = gtk.VBox()

        self.notification = Notification()

        code_editor = None

        if '--source-editor-test' in sys.argv:
            while True:
                try:
                    from ui.code_editor import CodeEditor
                except:
                    self.notification.notificate(
                        _("No module GtkSourceView installed"), ERROR)
                    self.pack1(box, True, False)
                    break

                panel = gtk.VPaned()
                panel.pack1(box, True, False)
                code_editor = CodeEditor(application)
                code_editor.editor.set_language("sql")
                panel.pack2(code_editor, False, True)
                self.pack1(panel, True, False)
                break
        else:
            self.pack1(box, True, False)

        self.pack2(self.properties, False, True)

        top = gtk.HBox()
        box.pack_start(top, False, False)

        top.pack_start(self.notification, False, False)

        layer_selector = LayerSelector()
        alignment = gtk.Alignment(1.0, 0.5)
        alignment.add(layer_selector)
        top.pack_start(alignment, True, True)

        separator = gtk.VSeparator()
        top.pack_start(separator, False, False)

        self.image = gtk.Image()
        self.image.set_from_stock(CONTRACT_PROPERTIES, gtk.ICON_SIZE_MENU)
        button = gtk.Button()
        button.set_image(self.image)
        button.set_relief(gtk.RELIEF_NONE)
        button.connect("clicked", self.toggle_properties)
        top.pack_start(button, False, False)

        table = gtk.Table()
        box.add(table)

        bottom = gtk.HBox()
        box.pack_start(bottom, False, False)

        self.climber = Climber(self.canvas)
        bottom.pack_start(self.climber, False, False)

        pager = Pager(self.canvas)
        alignment = gtk.Alignment(1.0, 0.5)
        alignment.add(pager)
        bottom.pack_start(alignment, True, True)

        self.horizontal_ruler = HorizontalRuler()
        self.horizontal_ruler.connect("append-tag", self.append_tag)
        self.horizontal_ruler.connect("move-tag", self.move_tag)
        table.attach(self.horizontal_ruler, 1, 2, 0, 1, gtk.FILL | gtk.EXPAND,
                     0)

        self.vertical_ruler = VerticalRuler()
        self.vertical_ruler.connect("append-tag", self.append_tag)
        self.vertical_ruler.connect("move-tag", self.move_tag)
        table.attach(self.vertical_ruler, 0, 1, 1, 2, 0, gtk.FILL | gtk.EXPAND)

        area = gtk.ScrolledWindow()
        area.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        adjustment = area.get_vadjustment()
        adjustment.connect("value-changed", self.scroll, VERTICAL)
        adjustment = area.get_hadjustment()
        adjustment.connect("value-changed", self.scroll, HORIZONTAL)
        table.attach(area, 1, 2, 1, 2, gtk.FILL | gtk.EXPAND,
                     gtk.FILL | gtk.EXPAND)

        self.canvas.code_editor = code_editor
        self.canvas.horizontal_ruler = self.horizontal_ruler
        self.canvas.vertical_ruler = self.vertical_ruler
        self.connect("realize", self.realize, area)

    def realize(self, widget, area):
        area.add_with_viewport(self.canvas)
        self.canvas.show()

    def toggle_properties(self, *args):
        properties = self.get_children()[1]
        if self.properties.get_visible():
            self.image.set_from_stock(EXPAND_PROPERTIES, gtk.ICON_SIZE_MENU)
            properties.hide()
        else:
            self.image.set_from_stock(CONTRACT_PROPERTIES, gtk.ICON_SIZE_MENU)
            properties.show()

    def append_tag(self, widget, tag):
        self.canvas.guides.add_tag(tag)
        self.canvas.update()

    def move_tag(self, widget, tag):
        self.canvas.queue_draw()

    def select(self, widget, child):
        self.update(child)

    def finalize(self, widget, child):
        self.update(child)

    def update(self, child):
        self.properties.select(child.__name__, child)

    def edit_child(self, widget, child):
        pass
        #print "edit", child

    def wheel(self, widget, event):
        if event.state & gtk.gdk.CONTROL_MASK:
            if event.direction == gtk.gdk.SCROLL_UP:
                self.canvas.zoom_in()
                self.climber.update()
            elif event.direction == gtk.gdk.SCROLL_DOWN:
                self.canvas.zoom_out()
                self.climber.update()
            self.horizontal_ruler.zoom = self.canvas.zoom
            return True

    def scroll(self, adjustment, direction):
        offset = adjustment.get_value()
        if direction == VERTICAL:
            self.canvas.vertical_ruler.offset = offset
        elif direction == HORIZONTAL:
            self.canvas.horizontal_ruler.offset = offset

    def key_press(self, widget, event):
        pass

    def _select(self, widget, child, buffer):
        #print "Selected object \"%s\"" % child.__name__
        #if child.__name__ == "Table":
        #if child.__name__ == "Text":
        #   if not child.x and not child.y:
        #     return

        #  textpad = TextPad()
        #  textpad.set_size_request(150, -1)
        #  textpad.show_all()
        #  self.canvas.put(textpad, child.x + self.canvas.origin.x, child.y + self.canvas.origin.y)
        if child.__name__ == "Text":
            text = child.get_property("text")
            #print "putting text \"%s\"" % text
            buffer.handler_disconnect(self.disconnect_handler)
            buffer.set_text(text)
            self.disconnect_handler = buffer.connect("changed", self.changed)

    def set_paper(self):
        for page in self.canvas.document.pages:
            page.x = 25
            page.y = 25

            page.width = 800
            page.height = 1500

            page.top = 25
            page.left = 25
            page.bottom = 25
            page.right = 25

            page.active = True

            self.canvas.grid.active = True
            self.canvas.grid.size = 16  # 31 # 32

            self.canvas.guides.active = True
            self.canvas.guides.size = 16 * 8  # 128

            self.canvas.grid.snap = True