当前位置: 首页>>代码示例>>Python>>正文


Python Lock.write_lock方法代码示例

本文整理汇总了Python中lock.Lock.write_lock方法的典型用法代码示例。如果您正苦于以下问题:Python Lock.write_lock方法的具体用法?Python Lock.write_lock怎么用?Python Lock.write_lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lock.Lock的用法示例。


在下文中一共展示了Lock.write_lock方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Test02_MfcLock

# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import write_lock [as 别名]
class Test02_MfcLock(unittest.TestCase):
    '''Unittest for mfc1.Lock().'''

    def setUp(self):
        '''Prepare test.'''
        self.__lock = Lock('./', 'andy')

    def test_delete_lock(self):
        '''Testing  mfc1.Lock.delete_lock().'''
        r = self.__lock.delete_lock()
        self.failUnlessEqual(first=r, second=False)

    def test_is_lock(self):
        '''Testing  mfc1.Lock.is_lock().'''
        r = self.__lock.is_lock()
        self.failUnlessEqual(first=r, second=False)

    def test_write_lock(self):
        '''Testing  mfc1.Lock.write_lock().'''
        r = self.__lock.write_lock()
        self.failUnlessEqual(first=r, second=True)
        # chek lock file.
        r = self.__lock.is_lock()
        self.failUnlessEqual(first=r, second=True)
        # delete lock file.
        r = self.__lock.delete_lock()
        self.failUnlessEqual(first=r, second=True)
开发者ID:MarcusMoeller,项目名称:mfc,代码行数:29,代码来源:unitest.py

示例2: Test02_MfcLock

# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import write_lock [as 别名]
class Test02_MfcLock(unittest.TestCase):
    '''Unittest for mfc1.Lock().'''

    def setUp(self):
        '''Prepare test.'''
        self.__lock = Lock('./', 'andy')

    def test_get_pid(self):
        '''Testing mfc1.Lock.get_pid().'''
        r = self.__lock.get_pid('mindfulclock1')
        self.failUnlessEqual(first=r, second=0)

    def test_one_instance(self):
        '''Testing mfc1.Lock.one_instance().'''
        r = self.__lock.one_instance('mindfulclock1')
        self.failUnlessEqual(first=r, second=True)

    def test_write_check_delete_lock(self):
        '''Testing write_lock(), check_lock(), delete_lock().'''
        r = self.__lock.write_lock()
        self.failUnlessEqual(first=r, second=True)
        # chek lock file.
        r = self.__lock.is_lock()
        self.failUnlessEqual(first=r, second=True)
        # delete lock file.
        r = self.__lock.delete_lock()
        self.failUnlessEqual(first=r, second=True)
开发者ID:MarcusMoeller,项目名称:mfc,代码行数:29,代码来源:unitest.py

示例3: Test02_MfcLock

# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import write_lock [as 别名]
class Test02_MfcLock(unittest.TestCase):
    """Unittest for mfc1.Lock()."""

    def setUp(self):
        """Prepare test."""
        self.lock = Lock("./", "andy")

    def test_get_pid(self):
        """Testing mfc1.Lock.get_pid()."""
        r = self.lock.get_pid("mindfulclock1")
        self.failUnlessEqual(first=r, second=0)

    def test_one_instance(self):
        """Testing mfc1.Lock.one_instance()."""
        r = self.lock.one_instance("mindfulclock1")
        self.failUnlessEqual(first=r, second=True)

    def test_write_check_delete_lock(self):
        """Testing write_lock(), check_lock(), delete_lock()."""
        r = self.lock.write_lock()
        self.failUnlessEqual(first=r, second=True)
        # chek lock file.
        r = self.lock.is_lock()
        self.failUnlessEqual(first=r, second=True)
        # delete lock file.
        r = self.lock.delete_lock()
        self.failUnlessEqual(first=r, second=True)
开发者ID:ulrich3110,项目名称:mfc,代码行数:29,代码来源:unitest.py

示例4: GUI

# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import write_lock [as 别名]

#.........这里部分代码省略.........

        '''
        # Title
        t = _(u'Text notification')
        label = wx.StaticText(self, label=t)
        # Text entry, read default, create entry.
        t = self.data.user['text']
        self.msgtext = wx.TextCtrl(self,
                                     value=t,
                                     style=wx.TE_MULTILINE)
        # Layout.
        vsiz = wx.BoxSizer(wx.VERTICAL)
        vsiz.Add(label, 0, wx.EXPAND | wx.LEFT, self.bdist)
        vsiz.Add(self.msgtext, 1, wx.EXPAND | wx.ALL, self.bdist)
        return(vsiz)

    def lock_file(self):
        '''Handle the mc1.Lock object. Public objects:
        lock = mfc1.Lock
        lockstate = Status of the lock file.
                    '' = No status.
                    'written' = Lock file is written
                    'deleted' = Lock file is deleted
                    'exit' = Program exit

        '''
        userid = wx.GetUserId()
        wxpath = wx.StandardPaths.Get()
        userdir = wxpath.GetDocumentsDir()
        self.lock = Lock(path=userdir, userid=userid)
        self.lockstate = ''
        if self.lock.one_instance('mindfulclock1'):
            # One instance.
            self.lock.write_lock()
            self.lockstate = 'written'
        else:
            # More than one instance.
            if self.start_question():
                # Start the clock.
                self.lock.write_lock()
                self.lockstate = 'written'
            else:
                # Exit the program.
                self.lockstate = 'exit'

    def on_change(self, event):
        '''Event for button, change sound file.'''
        # Set filename, directory path, wildcards and title.
        t = _(u'file')
        w1 = 'OGG- %s (*.ogg)|*.ogg' % (t)
        w2 = 'MP3- %s (*.mp3)|*.mp3' % (t)
        w3 = 'WAV- %s (*.wav)|*.wav' % (t)
        #~ wcard =
        # Show open dialog, get user datas.
        dlg = wx.FileDialog(self,
                            _(u'Select the sound file'),
                            os.path.dirname(self.sound),
                            os.path.basename(self.sound),
                            '%s|%s|%s' % (w1, w2, w3),
                            wx.FD_OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            # Clicked ok, set path, destroy dialog.
            path = dlg.GetPath()
            dlg.Destroy()
            # Set path to text entry and sound attribute.
            self.sound = path
开发者ID:MarcusMoeller,项目名称:mfc,代码行数:70,代码来源:gui.py

示例5: GUI

# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import write_lock [as 别名]
class GUI(wx.Frame):
    """mfc1.GUI(tna, clock, menu, tbicon)

    GUI of the MindfulClock.
    tna = True, False, start in the taskbar notification area.
    clock = True, False, start clock automatically.
    menu = True, False, show the time not beside te indicator.
    tbicon = True, False, use instead of appindicator wx.TaskBarIcon.

    """

    def __init__(self, tna, clock, menu, tbicon):
        # Data object.
        self.__data = Data()
        # Package directory
        self.__dir = self.determine_path()
        # Internationalisation
        self.set_in18()
        # Load saved datas.
        self.config_load()
        # Get frame title, frame size and icon.
        title = self.__data.get_sys("frame_title")
        size = self.__data.get_user("frame_size")
        icon = os.path.join(self.__dir, self.__data.get_sys("icon_name"))
        # Subclass
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title=title, size=size)
        # Lock file
        userid = wx.GetUserId()
        wxpath = wx.StandardPaths.Get()
        userdir = wxpath.GetDocumentsDir()
        self.__lock = Lock(path=userdir, userid=userid)
        self.__lockwrite = False
        if self.__lock.is_lock():
            # Lock file exist.
            if self.start_question():
                # Start the clock.
                self.__lock.write_lock()
                self.__lockwrite = True
            else:
                # Exit the program.
                self.Close()
        else:
            # Lock file don't exist.
            self.__lock.write_lock()
            self.__lockwrite = True
        # Icon
        if icon.endswith(".png"):
            self.SetIcon(wx.Icon(name=icon, type=wx.BITMAP_TYPE_PNG))
        # GUI border style and distance between widgets.
        bstyl = self.__data.get_sys("gui_borderstyle")
        guiborders = {
            "simple": wx.SIMPLE_BORDER,
            "raised": wx.RAISED_BORDER,
            "sunken": wx.SUNKEN_BORDER,
            "no": wx.NO_BORDER,
        }
        if bstyl in guiborders:
            self.__bstyl = guiborders[bstyl]
        else:
            self.__bstyl = wx.SIMPLE_BORDER
        self.__bdist = self.__data.get_sys("gui_borderdist")
        if not self.__bdist:
            self.__bdist = 5
        # Set attributes for time interval and sound file.
        self.__interval = self.__data.get_user("interval")
        self.__sound = os.path.join(self.__dir, self.__data.get_user("sound"))
        # time interval.
        intervalbox = self.init_interval()
        # Text notification.
        textbox = self.init_text()
        # Sound notification.
        soundbox = self.init_sound()
        # Clock control.
        controlbox = self.init_buttons()
        # Timer
        self.__timer = wx.Timer(self, 1)
        self.Bind(event=wx.EVT_TIMER, handler=self.on_timer, source=self.__timer)
        # Clock status
        self.__clockstatus = False
        # Exit bindings.
        self.Bind(event=wx.EVT_CLOSE, handler=self.on_system_close)
        # Layout
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(item=intervalbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=self.__bdist)
        vbox.Add(item=textbox, proportion=1, flag=wx.EXPAND | wx.ALL, border=self.__bdist)
        vbox.Add(item=soundbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=self.__bdist)
        vbox.Add(item=controlbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=self.__bdist)
        self.SetSizer(vbox)
        # Disable stop & pause button
        self.__btnstop.Enable(False)
        self.__btnpause.Enable(False)
        # Clock not paused.
        self.__pausetime = -99
        # System tray from command line options
        if tna:
            # Start in the taskbar.
            self.__tna = True
        else:
            if self.__miniopt.GetValue():
                # Checkbox is set, start in the taskbar.
#.........这里部分代码省略.........
开发者ID:ulrich3110,项目名称:mfc,代码行数:103,代码来源:gui.py


注:本文中的lock.Lock.write_lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。