Skip to content

Commit

Permalink
add coords info
Browse files Browse the repository at this point in the history
  • Loading branch information
jmimu committed Aug 19, 2014
1 parent 12b38c8 commit 9a55bf7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dock_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
from PyQt4 import QtCore
from PyQt4 import QtGui

from widget import Button
from widget import Button, Label


class ToolsWidget(QtGui.QWidget):
""" widget cantaining tools buttons """
def __init__(self, project):
QtGui.QWidget.__init__(self)
self.project = project
### coordinates ###
self.coords = Label("Cursor coordinates")
self.coords.setText("x\ny");
### tools buttons ###
self.penB = Button("pen (1)", "icons/tool_pen.png", self.penClicked, True)
self.penB.setChecked(True)
Expand All @@ -23,6 +26,7 @@ def __init__(self, project):
### Layout ###
layout = QtGui.QVBoxLayout()
layout.setSpacing(0)
layout.addWidget(self.coords)
layout.addWidget(self.penB)
layout.addWidget(self.pipetteB)
layout.addWidget(self.fillB)
Expand Down
12 changes: 12 additions & 0 deletions pixeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __init__(self, project):
self.setMinimumSize(400, 400)
self.scene.setSceneRect(0, 0,
self.project.size.width(), self.project.size.height())
# coords info
self.coords=None
# background
self.setBackgroundBrush(QtGui.QBrush(self.project.bgColor))
self.bg = self.scene.addPixmap(
Expand Down Expand Up @@ -262,6 +264,15 @@ def mousePressEvent(self, event):
def mouseMoveEvent(self, event):
self.penItem.show()
self.penItem.setPos(self.pointToFloat(self.mapToScene(event.pos())))
# show cursor coordinates
pos = self.pointToInt(self.mapToScene(event.pos()))
if (pos.x()>=0 and pos.y()>=0 \
and pos.x()<self.project.size.width() \
and pos.y()<self.project.size.height()):
self.coords.setText("x %(x)03d\ny %(y)03d"%{"x":pos.x(),"y":pos.y()});
else:
self.coords.setText("x\ny");

l = self.project.curLayer
# pan
if event.buttons() == QtCore.Qt.MidButton:
Expand Down Expand Up @@ -363,6 +374,7 @@ def __init__(self):
toolsDock = Dock(self.toolsWidget, "tools", lock)
toolsDock.setObjectName("toolsDock")
self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, toolsDock)
self.scene.coords=toolsDock.widget().coords

optionsDock = Dock(self.optionsWidget, "options", lock)
optionsDock.setObjectName("optionsDock")
Expand Down
7 changes: 7 additions & 0 deletions widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def lock(self, state):
self.setAllowedAreas(QtCore.Qt.AllDockWidgetAreas)


class Label(QtGui.QLabel):
""" Label """
def __init__(self, tooltip):
QtGui.QLabel.__init__(self)
self.setToolTip(tooltip)


class Button(QtGui.QToolButton):
""" button """
def __init__(self, tooltip, icon, connection, checkable=False):
Expand Down

0 comments on commit 9a55bf7

Please sign in to comment.