forked from Sorunome/DesktopDerpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
desktopderpy.py
executable file
·217 lines (193 loc) · 6.04 KB
/
desktopderpy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env python3
## -*- coding: utf-8 -*-
import os,cairo,random
from gi.repository import Gtk,Gdk,GObject
PROGDIR = os.path.dirname(os.path.realpath(__file__))+'/'
def addMenuItem(menu,item,fn):
mItem = Gtk.MenuItem(item)
mItem.show()
menu.append(mItem)
mItem.connect('activate',fn)
class Derpy:
def __init__(self):
self.window = Gtk.Window()
self.window.set_decorated(False)
self.window.set_keep_above(True)
self.window.hide()
self.window.set_skip_taskbar_hint(True)
if self.window.get_screen().get_rgba_visual() != None and self.window.get_screen().is_composited():
self.window.set_visual(self.window.get_screen().get_rgba_visual())
self.window.set_app_paintable(True)
self.window.connect('draw',self.area_draw)
else:
print('no transparency support')
self.width = 106
self.height = 94
self.xVel = 0
self.yVel = 0
self.action = 'stand'
self.direction = 'right'
self.extra = ''
self.wing = False
self.sleep = False
self.drag = False
self.xPos = (Gdk.Screen.get_default().get_width() / 2) - (self.width / 2)
self.yPos = (Gdk.Screen.get_default().get_height() / 2) - (self.height / 2)
self.lazy = 3
self.wingActions = ['stand','walking']
self.actionsStand = ['hover','hover','hoverupsidedown','sleep','stand','stand','sit','sit','sit','sit','sit']
self.actionsMove = ['fly','fly','flyupsidedown','walking','walking','walking','walking']
self.actionsFly = ['fly','fly','fly','flyupsidedown']
self.window.move(self.xPos,self.yPos)
self.gif = Gtk.Image()
self.set_image()
self.window.add(self.gif)
#add rightclick menu
self.rightclickMenu = Gtk.Menu()
#addMenuItem(rightclickMenu,'Backup',self.extra_backup)
addMenuItem(self.rightclickMenu,'Sleep',self.sleep_toggle)
addMenuItem(self.rightclickMenu,'Quit',Gtk.main_quit)
self.window.connect('button-press-event',self.button_press)
self.window.connect('button-release-event',self.button_release)
self.window.connect('motion-notify-event',self.mouse_move)
self.window.show_all()
self.set_draw_frame_timer()
self.set_rand_event_timer()
def button_press(self,widget,event):
if event.button == 3:
self.rightclickMenu.popup(parent_menu_shell = None,parent_menu_item = None,func = None,data = None,button = event.button,activate_time = event.time)
if event.button == 1:
self.x_offset = event.x_root - self.xPos
self.y_offset = event.y_root - self.yPos
self.xVel = 0
self.yVel = 0
self.xPos = event.x_root - 51
self.yPos = event.y_root - 7
self.action = 'drag'
self.extra = ''
self.drag = True
self.set_image()
self.draw_frame()
def button_release(self,widget,event):
if event.button == 1:
self.drag = False
self.xPos = event.x_root - self.x_offset
self.yPos = event.y_root - self.y_offset
if self.sleep:
self.action = 'sleep'
self.set_image()
else:
self.action = 'stand'
self.set_rand_event_timer()
self.set_draw_frame_timer()
self.set_actions()
def mouse_move(self,widget,event):
if self.drag:
self.xPos = event.x_root - 51
self.yPos = event.y_root - 7
self.draw_frame()
def set_rand_event_timer(self):
GObject.timeout_add(random.randint(3000,6000),self.rand_event)
def set_draw_frame_timer(self):
GObject.timeout_add(1000/30,self.draw_frame)
def set_actions(self):
if self.xVel < 0:
self.direction = 'left'
elif self.xVel > 0:
self.direction = 'right'
if self.xVel==0 and self.yVel==0:
self.action = random.choice(self.actionsStand)
elif self.yVel==0:
self.action = random.choice(self.actionsMove)
else:
self.action = random.choice(self.actionsFly)
if random.randint(1,10)==1:
self.wing = not self.wing
if self.action=='sit':
self.extra = random.choice(['_long','_short'])
else:
self.extra = ''
self.set_image()
def rand_event(self):
if not (self.sleep or self.drag):
oldXVel = self.xVel
oldYVel = self.yVel
frozen = False
if oldXVel == 0 and oldYVel == 0:
if random.randint(1, self.lazy) > 1:
frozen = True
limit = 30 if self.action == 'sit' else 10
if self.lazy < limit:
self.lazy += 1
if self.lazy == limit:
print('Derpy is a lazy pony')
else:
self.lazy = 3
if not frozen:
if random.randint(1,2)==1:
self.xVel = random.choice([-2,0,2])
if random.randint(1,2)==1:
self.yVel = random.choice([-2,0,2])
if oldXVel!=self.xVel or oldYVel!=self.yVel or not frozen:
self.set_actions()
if not self.sleep:
self.set_rand_event_timer()
return False
def sleep_toggle(self,widget):
self.sleep = not self.sleep
print(self.sleep)
if self.sleep:
self.yVel = 0
self.xVel = 0
self.action = 'sleep'
self.extra = ''
self.set_image()
else:
self.action = 'stand'
self.set_rand_event_timer()
self.set_draw_frame_timer()
self.set_actions()
def draw_frame(self):
self.xPos += self.xVel
if self.xPos < 0:
self.xPos = 0
self.xVel = 0
if not self.drag:
self.set_actions()
elif self.xPos > (Gdk.Screen.get_default().get_width() - self.width):
self.xPos = Gdk.Screen.get_default().get_width() - self.width
self.xVel = 0
if not self.drag:
self.set_actions()
self.yPos += self.yVel
if self.yPos < 0:
self.yPos = 0
self.yVel = 0
if not self.drag:
self.set_actions()
elif self.yPos > (Gdk.Screen.get_default().get_height() - self.height):
self.yPos = Gdk.Screen.get_default().get_height() - self.height
self.yVel = 0
if not self.drag:
self.set_actions()
self.window.move(self.xPos,self.yPos)
return not (self.sleep or self.drag)
def area_draw(self,widget,cr):
cr.set_source_rgba(0,0,0,0)
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_operator(cairo.OPERATOR_OVER)
def set_image(self):
name = 'derpy_'+self.action
if self.wing and (self.action in self.wingActions):
name += '_wing'
name += '_'+self.direction+self.extra+'.gif'
self.window.resize(self.width,self.height)
self.gif.set_from_file(PROGDIR+name)
self.gif.show()
print(PROGDIR+name)
def main(self):
Gtk.main()
if __name__ == '__main__':
derpy = Derpy()
derpy.main()