Skip to content

Commit

Permalink
Adds EventGhostEnduringEvent class
Browse files Browse the repository at this point in the history
Currently there is no means of knowing what kind of event has been triggered. This modification fixes that problem. A different icon is now used to identify an enduring event from a standard one. This will make it far easier for the user to implement looping code to perform actions in succession.  

I was pretty crafty in how i display the icon. because i not only wanted to have the icon changed in the log but also in the tree as well. once an event has been triggered and set as an enduring event it will change the icon in the tree. when an event is added to the tree it will check and see if that event has been flagged as an enduring event. if so it will change the new events icon accordingly. an XML attribute of EventType is added to the save data to identify the icon to use.
  • Loading branch information
kdschlosser committed Jun 22, 2018
1 parent ba8443f commit 74e7451
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 2 deletions.
35 changes: 35 additions & 0 deletions eg/Classes/EventGhostEnduringEvent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
#
# This file is part of EventGhost.
# Copyright © 2005-2016 EventGhost Project <http://www.eventghost.org/>
#
# EventGhost is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 2 of the License, or (at your option)
# any later version.
#
# EventGhost is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with EventGhost. If not, see <http://www.gnu.org/licenses/>.

# Local imports
import eg


class EventGhostEnduringEvent(eg.EventGhostEvent):
icon = eg.Icons.ENDURING_EVENT_ICON

def __init__(self, suffix="", payload=None, prefix="Main", source=eg):
eventString = prefix + "." + suffix

if eventString in eg.eventTable:
for item in eg.eventTable[eventString]:
if item.icon == eg.Icons.EVENT_ICON:
item.icon = eg.Icons.ENDURING_EVENT_ICON
item.Refresh()

eg.EventGhostEvent.__init__(self, suffix, payload, prefix, source)
1 change: 1 addition & 0 deletions eg/Classes/EventGhostEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class EventGhostEvent(object):
"""
skipEvent = False
icon = eg.Icons.EVENT_ICON

def __init__(self, suffix="", payload=None, prefix="Main", source=eg):
self.string = prefix + "." + suffix
Expand Down
42 changes: 42 additions & 0 deletions eg/Classes/EventItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# Local imports
import eg
from TreeLink import TreeLink
from TreeItem import HINT_MOVE_AFTER, HINT_MOVE_BEFORE_OR_AFTER, TreeItem

class Text(eg.TranslatableStrings):
Expand All @@ -41,7 +42,13 @@ class EventItem(TreeItem):
}

def __init__(self, parent, node):
if (
'EventType' in node.attrib and
node.attrib['EventType'] == 'Enduring'
):
self.icon = eg.Icons.ENDURING_EVENT_ICON
TreeItem.__init__(self, parent, node)

self.RegisterEvent(self.name)

def Configure(self, name):
Expand Down Expand Up @@ -75,6 +82,30 @@ def GetBasePath(self):
# so we also have no base path
return ""

def GetData(self):
"""
This method returns the needed data to construct its XML
representation.
The return values should be:
1. a list of (name, value) tuples of the attributes
2. the text of the node
"""
attr = []
if self.name:
attr.append(('Name', self.name))
if self.dependants or TreeLink.inUndo:
attr.append(('id', self.xmlId))
if not self.isEnabled:
attr.append(('Enabled', 'False'))
if self.icon == eg.Icons.ENDURING_EVENT_ICON:
attr.append(('EventType', 'Enduring'))
else:
attr.append(('EventType', 'Event'))

attr.append(('XML_Guid', str(self.guid)))
return attr, None

def GetDescription(self):
return ""

Expand All @@ -87,6 +118,17 @@ def RegisterEvent(self, eventString):
eventTable[eventString] = []
eventTable[eventString].append(self)

if (
self.icon != eg.Icons.ENDURING_EVENT_ICON and
'?' not in self.name and
'*' not in self.name
):
for item in eventTable[eventString][:-1]:
if item.icon == eg.Icons.ENDURING_EVENT_ICON:
self.icon = eg.Icons.ENDURING_EVENT_ICON
self.Refresh()
break

@eg.AssertInActionThread
def RenameTo(self, newName):
self.UnRegisterEvent(self.name)
Expand Down
3 changes: 2 additions & 1 deletion eg/Classes/EventThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

# some shortcuts
EventGhostEvent = eg.EventGhostEvent
EventGhostEnduringEvent = eg.EventGhostEnduringEvent
actionThread = eg.actionThread
ActionThreadCall = actionThread.Call

Expand Down Expand Up @@ -90,7 +91,7 @@ def TriggerEnduringEvent(
prefix="Main",
source=eg
):
event = EventGhostEvent(suffix, payload, prefix, source)
event = EventGhostEnduringEvent(suffix, payload, prefix, source)
if event.source in self.filters:
for filterFunc in self.filters[event.source]:
if filterFunc(event) is True:
Expand Down
2 changes: 1 addition & 1 deletion eg/Classes/Log.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def LogEvent(self, event):
mesg = eventstring + ' ' + repr(payload)
else:
mesg = eventstring
self.Write(mesg + "\n", eg.EventItem.icon, eventstring)
self.Write(mesg + "\n", event.icon, eventstring)

def NativeLogOn(self, value):
self.NativeLog = value
Expand Down
1 change: 1 addition & 0 deletions eg/Icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def PilToBitmap(pil):
DISABLED_ICON = PathIcon(join(IMAGES_PATH, "disabled.png"))
PLUGIN_ICON = PathIcon(join(IMAGES_PATH, "plugin.png"))
EVENT_ICON = PathIcon(join(IMAGES_PATH, "event.png"))
ENDURING_EVENT_ICON = PathIcon(join(IMAGES_PATH, "enduring_event.png"))
ACTION_ICON = PathIcon(join(IMAGES_PATH, "action.png"))
MACRO_ICON = PathIcon(join(IMAGES_PATH, "macro.png"))
ADD_ICON = PathIcon(join(IMAGES_PATH, 'add.png'))
Expand Down
Binary file added images/enduring_event.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 74e7451

Please sign in to comment.