Skip to content

Commit

Permalink
Channel write toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
halcy committed Aug 13, 2018
1 parent 34413a3 commit 14e3d08
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
23 changes: 18 additions & 5 deletions AnsiImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,19 @@ def move_cursor(self, x = None, y = None, relative = True):

return moved

def set_write_allowed(self, char = None, fore = None, back = None):
"""
Set or unset write-allow flags for character, foreground or background
"""
if char != None:
self.write_allowed[0] = char

if fore != None:
self.write_allowed[1] = fore

if back != None:
self.write_allowed[2] = back

def set_cell(self, char = None, fore = None, back = None, x = None, y = None, ignore_allowed = False):
"""
Sets the values of a character cell to the given values. Only replaces
Expand All @@ -331,15 +344,15 @@ def set_cell(self, char = None, fore = None, back = None, x = None, y = None, ig

if ignore_allowed == False and self.write_allowed[0] == False:
char = None
prev_val[0] = None
prev_val[2][0] = None

if ignore_allowed == False and self.write_allowed[1] == False:
char = None
prev_val[1] = None
fore = None
prev_val[2][1] = None

if ignore_allowed == False and self.write_allowed[2] == False:
char = None
prev_val[2] = None
back = None
prev_val[2][2] = None

if char != None:
prev_val[2][0] = self.ansi_image[y][x][0]
Expand Down
31 changes: 31 additions & 0 deletions MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ def createMenuBar(self):
self.actionCut = QtWidgets.QAction("Cut", self)
self.actionPaste = QtWidgets.QAction("Paste", self)

self.actionWriteChar = QtWidgets.QAction("Write character", self)
self.actionWriteChar.setCheckable(True)
self.actionWriteChar.setChecked(True)

self.actionWriteFore = QtWidgets.QAction("Write foreground", self)
self.actionWriteFore.setCheckable(True)
self.actionWriteFore.setChecked(True)

self.actionWriteBack = QtWidgets.QAction("Write background", self)
self.actionWriteBack.setCheckable(True)
self.actionWriteBack.setChecked(True)

menuView = self.menuBar().addMenu("View")
self.toggleTransparent = QtWidgets.QAction("Transparent", self)
self.toggleTransparent.setCheckable(True)
Expand Down Expand Up @@ -96,6 +108,10 @@ def createMenuBar(self):
menuEdit.addAction(self.actionCopy)
menuEdit.addAction(self.actionCut)
menuEdit.addAction(self.actionPaste)
menuEdit.addSeparator()
menuEdit.addAction(self.actionWriteChar)
menuEdit.addAction(self.actionWriteFore)
menuEdit.addAction(self.actionWriteBack)

menuView.addAction(self.toggleTransparent)
menuView.addAction(self.toggleHideCursor)
Expand Down Expand Up @@ -229,6 +245,10 @@ def connectEvents(self):
self.actionPaste.triggered.connect(self.clipboardPaste)
self.actionPaste.setShortcut(QtGui.QKeySequence.Paste)

self.actionWriteChar.triggered.connect(self.changeWriteStatus)
self.actionWriteFore.triggered.connect(self.changeWriteStatus)
self.actionWriteBack.triggered.connect(self.changeWriteStatus)

self.toggleTransparent.triggered.connect(self.changeTransparent)
self.toggleHideCursor.triggered.connect(self.changeHideCursor)

Expand Down Expand Up @@ -777,6 +797,17 @@ def clipboardPaste(self):
except:
pass


def changeWriteStatus(self):
"""
Change which channels we are writing to.
"""
self.ansiImage.set_write_allowed(
self.actionWriteChar.isChecked(),
self.actionWriteFore.isChecked(),
self.actionWriteBack.isChecked()
)

def resizeCanvas(self):
"""
Get size via dialog and resize
Expand Down

0 comments on commit 14e3d08

Please sign in to comment.