コード例 #1
0
ファイル: notifier.py プロジェクト: SteveKnowless/Rust
    def adverts_command_CMD(self, player, cmd, args):
        ''' Adverts Command command function '''

        if args:

            if player.IsAdmin() and self.adverts_loop:

                try:

                    n = int(args[0])

                    if n:

                        self.adverts_loop.Destroy()
                        self.adverts_loop = timer.Repeat(
                            n * 60, 0, Action(self.send_advert), self.Plugin)

                        PLUGIN['ADVERTS INTERVAL'] = n

                        self.SaveConfig()

                        self.tell(
                            player, MSG['ADVERTS INTERVAL CHANGED'].format(
                                minutes=str(n)), COLOR['SYSTEM'])

                except:
                    self.tell(
                        player, MSG['SYNTAX ERROR'].format(
                            syntax='/adverts <minutes> (i.g /adverts 5)'),
                        'red')

        else:
            self.tell(
                player, MSG['SYNTAX ERROR'].format(
                    syntax='/adverts <minutes> (i.g /adverts 5)'), 'red')
コード例 #2
0
 def Start(self):
     """ <summary>
      Create and start the Dispatcher
      </summary>
     """
     # Attach a WorkerDispatcher to the current thread
     self.m_disp = ttapi.Dispatcher.AttachWorkerDispatcher()
     self.m_disp.BeginInvoke(Action(self.Init))
     self.m_disp.Run()
コード例 #3
0
    def __init__(self, vm, *args, **kwargs):
        threading.Thread.__init__(self, *args, **kwargs)
        self.vm = vm
        self.daemon = True
        self._running = True
        self.vm.RecordCommand = RelayCommand(Action(self.RecordCommand))
        self.vm.SaveCommand = RelayCommand(Action(self.SaveCommand))
        self.vm.AddCommand = RelayCommand(Action(self.AddCommand))
        self.vm.BrowseCommand = RelayCommand(Action(self.BrowseCommand))
        self.vm.DeleteCommand = RelayCommand(Action(self.DeleteCommand))
        self.vm.SelectionChanged = Action[int](self.SelectionChanged)
        self.update_list()

        # generate random string for space scaping
        import random, string
        self.space_escaping = ''.join([
            random.choice(string.ascii_letters + string.digits)
            for n in range(32)
        ])
コード例 #4
0
    def Init(self):

        self.console(LINE)

        # CONFIGURATION
        if self.Config['CONFIG_VERSION'] < LATEST_CFG or DEV:
            self.UpdateConfig()

        global MSG, PLUGIN, COLOR, STRINGS
        MSG, COLOR, PLUGIN, STRINGS = [self.Config[x] for x in ('MESSAGES','COLORS','SETTINGS', 'STRINGS')]

        self.prefix = '<%s>%s<end>' % (COLOR['PREFIX'], PLUGIN['PREFIX']) if PLUGIN['PREFIX'] else None
        self.dbname = 'rankme_db'
        self.keys = ('KILLS', 'DEATHS', 'KDR', 'SUICIDES', 'SUICIDE RATIO', 'ANIMALS', 'RANGE', 'SLEEPERS')
        self.cache = {}

        # LOAD DATABASE
        self.db = data.GetData(self.dbname)

        # CHECK ACTIVE PLAYERS
        for player in self.playerlist():
            self.check_player(player)
        self.console('* Loading database and verifying players.')

        # START AUTO-SAVE LOOP
        mins = PLUGIN['AUTO-SAVE INTERVAL']
        if mins:
            secs = mins * 60 if mins else 60
            self.adverts_loop = timer.Repeat(secs, 0, Action(self.save_data), self.Plugin)
            self.console('* Starting Auto-Save loop, set to %s minute/s' % mins)
        else:
            self.autosave_interval = None
            self.console('* Auto-Save is disabled')

        # COMMANDS
        self.cmds = []
        for cmd in [x for x in self.Config['COMMANDS'].keys()]:
            if PLUGIN['ENABLE %s CMD' % cmd]:
                self.cmds.append(cmd)
                command.AddChatCommand(self.Config['COMMANDS'][cmd], self.Plugin, '%s_CMD' % cmd.replace(' ', '_').lower())

        self.console('* Enabling commands:')
        if self.cmds:
            for cmd in self.cmds:
                self.console('  - /%s (%s)' % (self.Config['COMMANDS'][cmd], cmd.title()))
        else: self.console('  - No commands enabled')

        command.AddConsoleCommand('rankme.savedb', self.Plugin, 'save_data')
        command.AddConsoleCommand('rankme.wipedb', self.Plugin, 'console_wipe_CMD')
        command.AddChatCommand('rankme', self.Plugin, 'plugin_CMD')

        self.console(LINE)
コード例 #5
0
#  
# Copyright (c) Stefan Schukat. All rights reserved.  
# Licensed under the MIT License. See LICENSE file in the project root for full license information.  
#  

import clr
clr.AddReference("UILibrary") 
import UILibrary
from System import Action

def CallBack():
    """Button click event handler"""
    print("Button clicked!")

MainForm = UILibrary.MainForm()
MainForm.PythonCallBack = Action(CallBack)
MainForm.ShowDialog()
コード例 #6
0
ファイル: utils.py プロジェクト: eloff/silvershell
def dispatch(func, *args):    
    action = Action.__getitem__(*[object]*len(args))
    wpf.Dispatcher.BeginInvoke(action(func), Array[object](args))
コード例 #7
0
ファイル: rankme.py プロジェクト: wilddip/oxideplugins
    def Init(self):
        '''Hook called when the plugin initializes '''

        # Update System
        self.UpdateConfig()

        global MSG, PLUGIN, COLORS, CMDS, LISTS, STRINGS
        MSG, COLORS, PLUGIN, CMDS, LISTS, STRINGS = [self.Config[x] for x in \
        ('MESSAGES', 'COLORS', 'SETTINGS', 'COMMANDS', 'LISTS', 'STRINGS')]

        self.prefix = '<%s>%s<end>' % (
            COLORS['PREFIX'], PLUGIN['PREFIX']) if PLUGIN['PREFIX'] else ''
        self.db = data.GetData(DBNAME)
        self.autosave_loop = False
        self.helis_cache = {}
        self.timers = {}
        self.keys = {
            'pvpkills': 0,
            'npckills': 0,
            'deaths': 0,
            'kdr': 0.0,
            'suicides': 0,
            'sdr': 0.0,
            'sleepers': 0,
            'animals': 0,
            'pvpdistance': 0.0,
            'pvedistance': 0.0,
            'resources': 0,
            'wounded': 0,
            'rockets': 0,
            'arrows': 0,
            'bullets': 0,
            'helis': 0,
            'explosives': 0,
            'barrels': 0,
            'healed': 0,
            'crafted': 0,
            'demolished': 0,
            'built': 0,
            'repaired': 0,
            'upgraded': 0,
            'turrets': 0,
            'bprevealed': 0
        }

        # Zones Manager zones whitelist
        self.zones = PLUGIN['ZONES WHITELIST']
        if isinstance(self.zones, str):
            self.zones = [self.zones]
        self.zones = {i: [] for i in self.zones}

        # Initiate Database
        for i in BasePlayer.activePlayerList:

            self.store_player(i)

        # Start Timers
        for i in (('AUTO-SAVE', self.save_data), ('TOP3 ADVERT',
                                                  self.top_advert)):

            name, func = i

            # Is System Enabled?
            if PLUGIN['ENABLE ' + name]:
                a = name + ' INTERVAL'
                if a in PLUGIN:
                    mins = PLUGIN[a]
                    secs = mins * 60 if mins else 60
                    self.timers[name] = timer.Repeat(secs, 0, Action(func),
                                                     self.Plugin)

        # Commands System
        n = 0
        for cmd in CMDS:
            if PLUGIN['ENABLE %s' % cmd]:
                n += 1
                if isinstance(CMDS[cmd], tuple):
                    for i in CMDS[cmd]:
                        command.AddChatCommand(
                            i, self.Plugin,
                            '%s_CMD' % cmd.replace(' ', '_').lower())
                else:
                    command.AddChatCommand(
                        CMDS[cmd], self.Plugin,
                        '%s_CMD' % cmd.replace(' ', '_').lower())

        # Plugin Command
        command.AddChatCommand('rankme', self.Plugin, 'plugin_CMD')

        command.AddConsoleCommand('rankme.savedata', self.Plugin,
                                  'Console_Save_CMD')
        command.AddConsoleCommand('rankme.resetdata', self.Plugin,
                                  'Console_Reset_CMD')
コード例 #8
0
ファイル: notifier.py プロジェクト: SteveKnowless/Rust
    def Init(self):
        ''' Hook called when the plugin initializes '''

        self.con(LINE)

        if self.Config['CONFIG_VERSION'] < LATEST_CFG or DEV:

            self.UpdateConfig()

        else:
            self.con('* Configuration file is up to date')

        global MSG, PLUGIN, COLOR, CMDS, ADVERTS, RULES, TIMED
        MSG, COLOR, PLUGIN, CMDS, ADVERTS, RULES, TIMED = [self.Config[x] for x in \
        ('MESSAGES', 'COLORS', 'SETTINGS', 'COMMANDS', 'ADVERTS', 'RULES', 'SCHEDULED MESSAGES')]

        self.prefix = '<%s>%s<end>' % (
            COLOR['PREFIX'], PLUGIN['PREFIX']) if PLUGIN['PREFIX'] else ''
        self.players = {}
        self.connected = []
        self.lastadvert = 0
        self.adverts_loop = False
        self.timed_loop = False

        self.countries = data.GetData('notifier_countries_db')
        self.countries.update(self.countries_dict())
        data.SaveData('notifier_countries_db')

        if not PLUGIN['ENABLE PLUGIN ICON']:

            global PROFILE
            PROFILE = '0'

        for player in self.activelist():
            self.OnPlayerInit(player, False)

        if PLUGIN['ENABLE ADVERTS']:

            mins = PLUGIN['ADVERTS INTERVAL']
            secs = mins * 60 if mins else 60

            self.adverts_loop = timer.Repeat(secs, 0, Action(self.send_advert),
                                             self.Plugin)

            self.con('* Starting Adverts timer, set to %s minute/s' % mins)

        else:
            self.con('* Adverts are disabled')

        if PLUGIN['ENABLE SCHEDULED MESSAGES']:

            self.timed_loop = timer.Repeat(60, 0,
                                           Action(self.scheduled_messages),
                                           self.Plugin)

            self.con('* Starting Scheduled Messages timer')

        else:
            self.con('* Scheduled Messages are disabled')

        n = 0

        self.con('* Enabling commands:')

        for cmd in CMDS:

            if PLUGIN['ENABLE %s' % cmd]:

                n += 1

                if isinstance(CMDS[cmd], tuple):

                    for i in CMDS[cmd]:

                        command.AddChatCommand(
                            i, self.Plugin,
                            '%s_CMD' % cmd.replace(' ', '_').lower())

                    self.con('  - %s (/%s)' %
                             (cmd.title(), ', /'.join(CMDS[cmd])))

                else:

                    command.AddChatCommand(
                        CMDS[cmd], self.Plugin,
                        '%s_CMD' % cmd.replace(' ', '_').lower())

                    self.con('  - %s (/%s)' % (cmd.title(), CMDS[cmd]))

        if not n: self.con('  - No commands are enabled')

        command.AddChatCommand('notifier', self.Plugin, 'plugin_CMD')

        self.con(LINE)
コード例 #9
0
ファイル: notifier.py プロジェクト: gragonvlad/plugins
    def Init(self):

        self.console('Loading Plugin')
        self.console(LINE)

        if self.Config['CONFIG_VERSION'] < LATEST_CFG or DEV:
            self.UpdateConfig()

        global MSG, PLUGIN, COLOR
        MSG = self.Config['MESSAGES']
        COLOR = self.Config['COLORS']
        PLUGIN = self.Config['SETTINGS']

        self.prefix = '<color=%s>%s</color>' % (
            COLOR['PREFIX'], PLUGIN['PREFIX']) if PLUGIN['PREFIX'] else None
        self.cache = {}
        self.connected = []
        self.lastadvert = 0

        self.countries = data.GetData('notifier_countries_db')
        self.countries.update(self.countries_dict())
        data.SaveData('notifier_countries_db')
        self.console('* Updating countries database')

        for player in self.player_list():
            self.cache_player(player.net.connection)
            self.get_country(player, False)
            self.connected.append(self.player_id(player))
        self.console('* Caching active players')

        if PLUGIN['ENABLE ADVERTS']:
            mins = PLUGIN['ADVERTS INTERVAL']
            secs = mins * 60 if mins else 60
            self.adverts_loop = timer.Repeat(secs, 0, Action(self.send_advert),
                                             self.Plugin)
            self.console('* Starting Adverts loop, set to %s minute/s' % mins)
        else:
            self.adverts_loop = None
            self.console('* Adverts are disabled')

        self.cmds = []
        self.console('* Enabling commands:')
        if PLUGIN['ENABLE RULES CMD']:
            self.console('  - /%s (Server Rules)' %
                         ', /'.join(self.Config['COMMANDS']['RULES']))
            for cmd in self.Config['COMMANDS']['RULES']:
                command.AddChatCommand(cmd, self.Plugin, 'rules_CMD')
            self.cmds.append('RULES')

        for cmd in [x for x in self.Config['COMMANDS'].keys() if x != 'RULES']:
            if PLUGIN['ENABLE %s CMD' % cmd]:
                self.cmds.append(cmd)
                command.AddChatCommand(
                    self.Config['COMMANDS'][cmd], self.Plugin,
                    '%s_CMD' % cmd.replace(' ', '_').lower())

        n = '%s' % self.Title.lower()
        command.AddChatCommand(n, self.Plugin, 'plugin_CMD')

        if self.cmds:
            for cmd in [x for x in self.cmds if x != 'RULES']:
                self.console('  - /%s (%s)' %
                             (self.Config['COMMANDS'][cmd], cmd.title()))
        else:
            self.console('  - No commands enabled')

        self.console(LINE)
コード例 #10
0
 def __init__(self):
     self.MainForm = UILibrary.MainForm()
     self.MainForm.PythonCallBack = Action(self.CallBack)
     app = WinForms.Application
     app.Run(self.MainForm)
コード例 #11
0
 def closeByOthers(self):
     print 'Progress3D closeByOthers'
     self.Dispatcher.BeginInvoke(Action(self.Close))
コード例 #12
0
            m_priceSubsciption.Settings = PriceSubscriptionSettings(
                PriceSubscriptionType.MarketDepth)
            m_priceSubsciption.FieldsUpdated += m_priceSubscription_FieldsUpdated
            m_priceSubsciption.Start()
        else:
            print("Cannot find instrument: " + e.ToString())


def ttNetApiInitHandler(api, ex):
    if ex is None:
        global m_api
        m_api = api
        api.TTAPIStatusUpdate += m_api_TTAPIStatusUpdate
        api.Start()
    else:
        print("TT.NET SDK Initialization Failed: " + ex.Message)


def Init():
    opt = TTAPIOptions(
        ServiceEnvironment.UatCert,
        "7601b8a0-dd23-2a8a-ee52-3712c53841d4:9ad4a302-5577-45c3-11db-6138b2757cca",
        5000)
    apiInitializeHandler = ApiInitializeHandler(ttNetApiInitHandler)
    TTAPI.CreateTTAPI(Dispatcher.Current, opt, apiInitializeHandler)


m_disp = Dispatcher.AttachWorkerDispatcher()
m_disp.DispatchAction(Action(Init))
m_disp.Run()
コード例 #13
0
ファイル: SampleScript02.py プロジェクト: xela30/Samples
from System.Windows import Application
from System.IO import StreamReader
from System.Threading import Thread
from System.Windows.Markup import XamlReader
from System.Reflection import Assembly
from System import Action

class ViewModel:
  numberOfSpeakers = 0
  def __init__(self, speakers):
    self.numberOfSpeakers = speakers

def getNumberOfSpeakers():
  vm = ViewModel(Application.Current.MainWindow.DataContext.Speakers.Length)
  stream = Application.Current.GetType().Assembly.GetManifestResourceStream(
    "IronPython.UI.Scripts.ResultWindow.xaml")
  reader = StreamReader(stream)
  window = XamlReader.Parse(reader.ReadToEnd())
  reader.Close()
  stream.Close()
  window.DataContext = vm
  window.FindName("CloseButton").Click += lambda s, e: window.Close()
  window.Show()

Application.Current.Dispatcher.BeginInvoke(Action(lambda: getNumberOfSpeakers()))

for i in range(0, 10):
  print str(i+1)
  Thread.Sleep(500)

print "Done!"