Форум сайта python.su
@hybrid_property def min_term(self): return func.datediff(func.adddate(func.adddate(func.now(), self.min_term_d), text('interval '+self.min_term_m+' month')), func.now())
text('interval mytable.min_term_m month'))
import urllib import os target = open('safinat.mp3', "wb") conn = urllib.urlopen('http://stream2.radiostyle.ru:8002/safinat') while True: target.write(conn.read(1024))
import pyglet import time class SingleImageAnimation(pyglet.window.Window): def __init__(self, width=600, height=600): pyglet.window.Window.__init__(self, width=width, height=height, resizable = True) self.drawableObjects = [] self.rising = False self.ballSprite = None self.createDrawableObjects() self.adjustWindowSize() def createDrawableObjects(self): ball_img = pyglet.image.load('images/car.png') ball_img.anchor_x = ball_img.width / 2 ball_img.anchor_y = ball_img.height / 2 self.ballSprite = pyglet.sprite.Sprite(ball_img) self.ballSprite.position = (self.ballSprite.width + 100,self.ballSprite.height*2 - 50) self.drawableObjects.append(self.ballSprite) def adjustWindowSize(self): w = self.ballSprite.width * 3 h = self.ballSprite.height * 3 self.width = w self.height = h def moveObjects(self, t): if self.ballSprite.y - 100 < 0: self.rising = True elif self.ballSprite.y > self.ballSprite.height*2 - 50: self.rising = False if not self.rising: self.ballSprite.y -= 5 self.ballSprite.rotation -= 6 else: self.ballSprite.y += 5 self.ballSprite.rotation += 5 def on_draw(self): self.clear() for d in self.drawableObjects: d.draw() win = SingleImageAnimation() # Set window background color to gray. pyglet.gl.glClearColor(0.5, 0.5, 0.5, 1) pyglet.clock.schedule_interval(win.moveObjects, 1.0/20) pyglet.app.run()
from PyQt4 import QtCore, QtGui import sys app = QtGui.QApplication(sys.argv) QtGui.qApp = app pointListBox = QtGui.QTreeWidget() header=QtGui.QTreeWidgetItem(["Tree","First","secondo"]) #... pointListBox.setHeaderItem(header) #Another alternative is setHeaderLabels(["Tree","First",...]) root = QtGui.QTreeWidgetItem(pointListBox, ["root"]) A = QtGui.QTreeWidgetItem(root, ["A"]) barA = QtGui.QTreeWidgetItem(A, ["bar", "i", "ii"]) bazA = QtGui.QTreeWidgetItem(A, ["baz", "a", "b"]) pointListBox.show() sys.exit(app.exec_())
>>> from celery.task.control import inspect
>>> i = inspect()
>>> i.active()
hostconf_dbname = "database" hostconf_dbaddr="127.0.0.1" ... db = MySQLDatabase(hostconf_dbname, host=hostconf_dbaddr, user=hostconf_dbuser, passwd=hostconf_dbpass) db.connect() class BaseModel(Model): class Meta: database = db
git clone git://github.com/fireshell/linux_raid1.git
class Request( models.Model ): applicant = models.ForeignKey( Employee, verbose_name = 'Заявитель') service = models.ForeignKey( Service, verbose_name = 'Услуга' ) branch = models.ManyToManyField( Branch, null=True, blank = True, verbose_name = 'Подразделения') role = models.ForeignKey( Role, null=True, blank = True, verbose_name = 'Роль (уровень доступа)' ) comment = models.ForeignKey( Comment, blank = True, null = True, verbose_name = 'Комментарий' )
Segmentation fault (core dumped) ------------------ (program exited with code: 139) Press return to continue
#!/usr/bin/python #-*- coding: UTF-8 -*- import os, ipaddr, wx if os.name == 'nt': import subprocess from time import sleep class TextFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, size=(80, 200), style=(wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.SIMPLE_BORDER))) panel = wx.Panel(self, -1, style=wx.NO_BORDER) panel.SetBackgroundColour(wx.BLACK) panel.SetForegroundColour(wx.GREEN) my_text = '' for item in online: my_text = my_text + item + '\n' basicLabel = wx.StaticText(panel, -1, my_text) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.timer.Start(10000) def OnTimer(self, evt): self.Close(True) def StartGui(): app = wx.PySimpleApp() frame = TextFrame() frame.Show() app.MainLoop() my_net = ipaddr.IPv4Network('192.168.1.0/28') my_ip = '192.168.1.2' buf = [] while True: online = [] for cur_ip in my_net.iterhosts(): cur_ip = str(cur_ip) if my_ip != cur_ip: if os.name == 'nt': ping = subprocess.Popen(["ping", '-n', '1', cur_ip], stdout = subprocess.PIPE, stderr = subprocess.PIPE) ans, error = ping.communicate() if 'TTL=' in ans: online.append(cur_ip) else: p = os.popen('ping -c 1 ' + cur_ip) ans = p.read() p.close() if 'ttl=' in ans: online.append(cur_ip) a = [new_ip for new_ip in online if new_ip not in buf] buf = online if a: StartGui()
win32gui.SetForegroundWindow(program[0]) win32gui.SetActiveWindow(program[0])
def make_window_active(my_title): if sys_type=='win': toplist = [] winlist = [] def enum_callback(hwnd, results): winlist.append((hwnd, win32gui.GetWindowText(hwnd))) win32gui.EnumWindows(enum_callback, toplist) program = [(hwnd, title) for hwnd, title in winlist if my_title in title.lower()] # just grab the first window that matches if len(program)>=1: program = program[0] # use the window handle to set focus win32gui.SetForegroundWindow(program[0]) win32gui.SetActiveWindow(program[0])