def send(self): self.headers.append(('Content-type','text/html')) if self.requestMethod!="POST": self.responseCode= "400 Bad Request" #Should actually be 405 self.response = "This page can be accessed by POST only" self.responseCode = "200 OK" if RequestHandler.core.yowsupStarted==0: self.response = Skin.completeHTML("Yowsup has not been started. Can't send messages till it has. <a href='/startYowsup'>Start Yowsup</a>") return phone = self.HTTPSession["phone"] messagearg = self.post.get("message",None) recipientarg = self.post.get("recipient",None) if messagearg==None or recipientarg==None or phone==None: self.response = "Invalid arguments" else: recipient = recipientarg[0] message = {"recipient":recipient, "messageText":messagearg[0],"sender":phone} RequestHandler.core.sender.sendMessage(message) url = 'chat?with=%s'%(recipient) self.response = Skin.metaRedirect(url,"Sending... Redirecting you to the chat page.")
def index(self): self.headers.append(('Content-type', 'text/html')) self.responseCode = "200 OK" if self.HTTPSession.get("phone", False) != False: self.response = Skin.index() else: self.response = Skin.loginForm()
def index(self): self.headers.append(('Content-type','text/html')) self.responseCode="200 OK" if self.HTTPSession.get("phone",False)!=False: self.response = Skin.index() else: self.response = Skin.loginForm()
def send(self): self.headers.append(('Content-type', 'text/html')) if self.requestMethod != "POST": self.responseCode = "400 Bad Request" #Should actually be 405 self.response = "This page can be accessed by POST only" self.responseCode = "200 OK" if RequestHandler.core.yowsupStarted == 0: self.response = Skin.completeHTML( "Yowsup has not been started. Can't send messages till it has. <a href='/startYowsup'>Start Yowsup</a>" ) return phone = self.HTTPSession["phone"] messagearg = self.post.get("message", None) recipientarg = self.post.get("recipient", None) if messagearg == None or recipientarg == None or phone == None: self.response = "Invalid arguments" else: recipient = recipientarg[0] message = { "recipient": recipient, "messageText": messagearg[0], "sender": phone } RequestHandler.core.sender.sendMessage(message) url = 'chat?with=%s' % (recipient) self.response = Skin.metaRedirect( url, "Sending... Redirecting you to the chat page.")
def wrapUp(self): self.responseCode = "200 OK" if self.requestMethod == "POST": confirm = self.post.get("confirmWrapUp", False) if confirm: RequestHandler.core.wrapUp("User requested wrap up") self.response = Skin.completeHTML("Wrapped up.") RequestHandler.core.dbi.close() #RequestHandler.startShutdownSequence() #if you want to shutdown after this. else: self.response = Skin.confirmWrapUpForm()
def wrapUp(self): self.responseCode="200 OK" if self.requestMethod=="POST": confirm = self.post.get("confirmWrapUp",False) if confirm: RequestHandler.core.wrapUp("User requested wrap up") self.response = Skin.completeHTML("Wrapped up.") RequestHandler.core.dbi.close() #RequestHandler.startShutdownSequence() #if you want to shutdown after this. else: self.response = Skin.confirmWrapUpForm()
def shutdownRequest(self): self.responseCode = "200 OK" if RequestHandler.core.status == Constants.INSTANCESTATUS_RUNNING: self.response = "The python instance must be wrapped up ( or atleast, Not running )before you can shut it down" return if self.requestMethod == "POST": confirm = self.post.get("confirmShutdown", False) if confirm: RequestHandler.startShutdownSequence() self.response = Skin.completeHTML("Shutting down. Bye :)") else: self.response = Skin.confirmShutdownForm()
def shutdownRequest(self): self.responseCode = "200 OK" if RequestHandler.core.status==Constants.INSTANCESTATUS_RUNNING: self.response = "The python instance must be wrapped up ( or atleast, Not running )before you can shut it down" return if self.requestMethod=="POST": confirm = self.post.get("confirmShutdown",False) if confirm: RequestHandler.startShutdownSequence() self.response = Skin.completeHTML("Shutting down. Bye :)") else: self.response = Skin.confirmShutdownForm()
def startYowsup(self): if RequestHandler.core.status==Constants.INSTANCESTATUS_RUNNING and RequestHandler.core.session.authStatus==Constants.AUTHSTATUS_LOGGEDIN: self.headers.append(("Location","/inbox")) self.responseCode ="302 Moved Temporarily" return s= self.HTTPSession if s["phone"]==None or s["AESKey"]==None: self.badRequest() return else: RequestHandler.core.initListener() RequestHandler.core.initSender() RequestHandler.core.initSession(self.HTTPSession["phone"], self.HTTPSession["AESKey"]) timeToSleep = 3 #Just so that the callbacks are completed? while RequestHandler.core.session.authStatus!=Constants.AUTHSTATUS_LOGGEDIN and RequestHandler.core.session.authStatus!=Constants.AUTHSTATUS_IDLE and timeToSleep>0: time.sleep(1) timeToSleep = timeToSleep-1 if Constants.AUTHSTATUS_LOGGEDIN == RequestHandler.core.session.authStatus: self.response = Skin.completeHTML("Logged in successfully. Proceed to <a href='/inbox'>inbox</a>") else: if Constants.AUTHSTATUS_IDLE == RequestHandler.core.session.authStatus : self.response = "Looks like it failed. Try again in some time?" else: self.response = "Logging in is taking longer than usual. Proceed to<a href='/checkStatus'>Check status to see status.</a>"
def chat(self): self.headers.append(('Content-type', 'text/html')) self.responseCode = "200 OK" otherperson = False if self.get.get( "with", False) == False else self.get.get("with")[0] me = self.HTTPSession.get("phone") if otherperson == False: self.response = "No messages from that person found" return with BlockingDBICursor(RequestHandler.core.dbi) as dbiCursor: dbiCursor.execute( "SELECT * FROM inbox WHERE sender=%s AND recipient=%s ORDER BY tstamp DESC LIMIT 20", (otherperson, me)) rec = dbiCursor.fetchall() recCount = dbiCursor.rowcount getafter = rec[recCount - 1]["tstamp"] if recCount > 0: dbiCursor.execute( "SELECT * FROM outbox WHERE sender=%s AND recipient=%s AND tstamp>%s ORDER BY tstamp DESC ", (me, otherperson, getafter)) else: dbiCursor.execute( "SELECT * FROM outbox WHERE sender=%s AND recipient=%s ORDER BY tstamp LIMIT 20", (me, otherperson, getafter)) sent = dbiCursor.fetchall() self.response = Skin.chat(otherperson, sent, rec) RequestHandler.core.dbi.done()
def startYowsup(self): if RequestHandler.core.status == Constants.INSTANCESTATUS_RUNNING and RequestHandler.core.session.authStatus == Constants.AUTHSTATUS_LOGGEDIN: self.headers.append(("Location", "/inbox")) self.responseCode = "302 Moved Temporarily" return s = self.HTTPSession if s["phone"] == None or s["AESKey"] == None: self.badRequest() return else: RequestHandler.core.initListener() RequestHandler.core.initSender() RequestHandler.core.initSession(self.HTTPSession["phone"], self.HTTPSession["AESKey"]) timeToSleep = 3 #Just so that the callbacks are completed? while RequestHandler.core.session.authStatus != Constants.AUTHSTATUS_LOGGEDIN and RequestHandler.core.session.authStatus != Constants.AUTHSTATUS_IDLE and timeToSleep > 0: time.sleep(1) timeToSleep = timeToSleep - 1 if Constants.AUTHSTATUS_LOGGEDIN == RequestHandler.core.session.authStatus: self.response = Skin.completeHTML( "Logged in successfully. Proceed to <a href='/inbox'>inbox</a>" ) else: if Constants.AUTHSTATUS_IDLE == RequestHandler.core.session.authStatus: self.response = "Looks like it failed. Try again in some time?" else: self.response = "Logging in is taking longer than usual. Proceed to<a href='/checkStatus'>Check status to see status.</a>"
def siteLogin(self): self.headers.append(('Content-type', 'text/html')) if self.requestMethod != "POST": self.response = "This page can only be accessed by POST. Please go back to the index" else: self.responseCode = "200 OK" phone = self.post.get("phone")[0] password = self.post.get("password")[0] hash = hashlib.md5(password).hexdigest() with BlockingDBICursor(RequestHandler.core.dbi) as dbiCursor: dbiCursor.execute( "SELECT phone FROM users WHERE phone=%s AND password=%s", (phone, hash)) if dbiCursor.rowcount > 0: row = dbiCursor.fetchone() self.HTTPSession["phone"] = row.get("phone") self.HTTPSession["AESKey"] = RequestHandler.core.genAESKey( password) self.response = Skin.completeHTML( "SUCCESS! <a href='startYowsup'>Start yowsup</a>") else: self.response = "Login failed" RequestHandler.core.dbi.done()
def inbox(self): self.headers.append(('Content-type','text/html')) self.responseCode = "200 OK" recipient = self.HTTPSession["phone"] #print "\n\nINBOX: recipient %s"%recipient with BlockingDBICursor(RequestHandler.core.dbi) as dbiCursor: dbiCursor.execute("SELECT sender,MAX(tstamp) AS tstamp, MIN(seen) AS allread, COUNT(seen = 0) as unreadcount FROM inbox WHERE recipient=%s GROUP BY sender ORDER BY allread DESC, tstamp DESC",(recipient)) convos = dbiCursor.fetchall() self.response = Skin.inbox(convos)
def inbox(self): self.headers.append(('Content-type', 'text/html')) self.responseCode = "200 OK" recipient = self.HTTPSession["phone"] #print "\n\nINBOX: recipient %s"%recipient with BlockingDBICursor(RequestHandler.core.dbi) as dbiCursor: dbiCursor.execute( "SELECT sender,MAX(tstamp) AS tstamp, MIN(seen) AS allread, COUNT(seen = 0) as unreadcount FROM inbox WHERE recipient=%s GROUP BY sender ORDER BY allread DESC, tstamp DESC", (recipient)) convos = dbiCursor.fetchall() self.response = Skin.inbox(convos)
def __init__(self, is_momentary, msg_type, channel, identifier, skin=Skin(), undo_step_handler=DummyUndoStepHandler(), *a, **k): super(ButtonElement, self).__init__(msg_type, channel, identifier, *a, **k) self.__is_momentary = bool(is_momentary) self._last_received_value = -1 self._undo_step_handler = undo_step_handler self._skin = skin
def siteLogin(self): self.headers.append(('Content-type','text/html')) if self.requestMethod!="POST": self.response="This page can only be accessed by POST. Please go back to the index" else: self.responseCode = "200 OK" phone= self.post.get("phone")[0] password = self.post.get("password")[0] hash = hashlib.md5(password).hexdigest() with BlockingDBICursor(RequestHandler.core.dbi) as dbiCursor: dbiCursor.execute( "SELECT phone FROM users WHERE phone=%s AND password=%s", (phone,hash) ) if dbiCursor.rowcount>0: row = dbiCursor.fetchone() self.HTTPSession["phone"] = row.get("phone") self.HTTPSession["AESKey"] = RequestHandler.core.genAESKey(password) self.response= Skin.completeHTML("SUCCESS! <a href='startYowsup'>Start yowsup</a>") else: self.response ="Login failed" RequestHandler.core.dbi.done()
def chat(self): self.headers.append(('Content-type','text/html')) self.responseCode = "200 OK" otherperson = False if self.get.get("with",False)==False else self.get.get("with")[0] me = self.HTTPSession.get("phone") if otherperson==False: self.response = "No messages from that person found" return with BlockingDBICursor(RequestHandler.core.dbi) as dbiCursor: dbiCursor.execute("SELECT * FROM inbox WHERE sender=%s AND recipient=%s ORDER BY tstamp DESC LIMIT 20", (otherperson,me)) rec = dbiCursor.fetchall() recCount=dbiCursor.rowcount getafter = rec[recCount-1]["tstamp"] if recCount>0: dbiCursor.execute("SELECT * FROM outbox WHERE sender=%s AND recipient=%s AND tstamp>%s ORDER BY tstamp DESC ", (me, otherperson,getafter)) else: dbiCursor.execute("SELECT * FROM outbox WHERE sender=%s AND recipient=%s ORDER BY tstamp LIMIT 20", (me, otherperson,getafter)) sent = dbiCursor.fetchall() self.response = Skin.chat(otherperson,sent,rec) RequestHandler.core.dbi.done()
def create_monster_skin(): if not Image_factory._Image_dict.get(Bot_type.Monster): Image_factory._Image_dict[Bot_type.Monster] = Skin( "D:\dudle_jm_img\monster3.png", "monster") return Image_factory._Image_dict[Bot_type.Monster]
def create_warrior_skin(): if not Image_factory._Image_dict.get(Bot_type.Warrior): Image_factory._Image_dict[Bot_type.Warrior] = Skin( "D:\dudle_jm_img\monster3.png", "warrior") return Image_factory._Image_dict[Bot_type.Warrior]
def __init__(self, c_instance): live = Live.Application.get_application() self._live_major_version = live.get_major_version() self._live_minor_version = live.get_minor_version() self._live_bugfix_version = live.get_bugfix_version() self._mk2_rgb = Settings.DEVICE == 'Launchpad mk2' if self._mk2_rgb: self._skin = Skin('launchpad mk2') self._side_notes = (89, 79, 69, 59, 49, 39, 29, 19) self._drum_notes = (20, 30, 31, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126) else: self._skin = Skin('launchpad') self._side_notes = (8, 24, 40, 56, 72, 88, 104, 120) self._drum_notes = (41, 42, 43, 44, 45, 46, 47, 57, 58, 59, 60, 61, 62, 63, 73, 74, 75, 76, 77, 78, 79, 89, 90, 91, 92, 93, 94, 95, 105, 106, 107) ControlSurface.__init__(self, c_instance) with self.component_guard(): self._suppress_send_midi = True self._suppress_session_highlight = True is_momentary = True if self._mk2_rgb: self._suggested_input_port = ("Launchpad", "Launchpad Mini", "Launchpad S") self._suggested_output_port = ("Launchpad", "Launchpad Mini", "Launchpad S") else: self._suggested_input_port = "Launchpad MK2" self._suggested_output_port = "Launchpad MK2" self._control_is_with_automap = False self._user_byte_write_button = ButtonElement( is_momentary, MIDI_CC_TYPE, 0, 16) self._user_byte_write_button.name = 'User_Byte_Button' self._user_byte_write_button.send_value(1) self._user_byte_write_button.add_value_listener( self._user_byte_value) self._wrote_user_byte = False self._challenge = Live.Application.get_random_int( 0, 400000000) & 2139062143 matrix = ButtonMatrixElement() matrix.name = 'Button_Matrix' for row in range(8): button_row = [] for column in range(8): if self._mk2_rgb: # for mk2 buttons are assigned "top to bottom" midi_note = (81 - (10 * row)) + column else: midi_note = row * 16 + column button = ConfigurableButtonElement(is_momentary, MIDI_NOTE_TYPE, 0, midi_note, self._skin.off) button.name = str(column) + '_Clip_' + str(row) + '_Button' button_row.append(button) matrix.add_row(tuple(button_row)) self._config_button = ButtonElement(is_momentary, MIDI_CC_TYPE, 0, 0, optimized_send_midi=False) self._config_button.add_value_listener(self._config_value) top_buttons = [ ConfigurableButtonElement(is_momentary, MIDI_CC_TYPE, 0, 104 + index, self._skin.off) for index in range(8) ] side_buttons = [ ConfigurableButtonElement(is_momentary, MIDI_NOTE_TYPE, 0, self._side_notes[index], self._skin.off) for index in range(8) ] top_buttons[0].name = 'Bank_Select_Up_Button' top_buttons[1].name = 'Bank_Select_Down_Button' top_buttons[2].name = 'Bank_Select_Left_Button' top_buttons[3].name = 'Bank_Select_Right_Button' top_buttons[4].name = 'Session_Button' top_buttons[5].name = 'User1_Button' top_buttons[6].name = 'User2_Button' top_buttons[7].name = 'Mixer_Button' side_buttons[0].name = 'Vol_Button' side_buttons[1].name = 'Pan_Button' side_buttons[2].name = 'SndA_Button' side_buttons[3].name = 'SndB_Button' side_buttons[4].name = 'Stop_Button' side_buttons[5].name = 'Trk_On_Button' side_buttons[6].name = 'Solo_Button' side_buttons[7].name = 'Arm_Button' self._osd = M4LInterface() self._osd.name = "OSD" self._selector = MainSelectorComponent(matrix, tuple(top_buttons), tuple(side_buttons), self._config_button, self._osd, self) self._selector.name = 'Main_Modes' self._do_combine() for control in self.controls: if isinstance(control, ConfigurableButtonElement): control.add_value_listener(self._button_value) self.set_highlighting_session_component( self._selector.session_component()) self._suppress_session_highlight = False self.log_message("LaunchPad95 Loaded !")
def create_civilian_skin(): if not Image_factory._Image_dict.get(Bot_type.Civilian): Image_factory._Image_dict[Bot_type.Civilian] = Skin( "D:\dudle_jm_img\monster3.png", "civilian") return Image_factory._Image_dict[Bot_type.Civilian]
def compose(self): self.response = Skin.compose()
def checkStatus(self): status = RequestHandler.core.getStatus() self.response = Skin.showStatus(status) '''
class ConfigurableButtonElement(ButtonElement): """ Special button class that can be configured with custom on- and off-values. A ConfigurableButtonElement can have states other than True or False, which can be defined by setting the 'states' property. Thus 'set_light' can take any state or skin color. """ class Colors: class DefaultButton: On = Basic.ON Off = Basic.HALF Disabled = Basic.OFF Alert = Basic.FULL_BLINK_FAST default_skin = Skin(Colors) default_states = {True: 'DefaultButton.On', False: 'DefaultButton.Off'} num_delayed_messages = 2 send_depends_on_forwarding = False def __init__(self, is_momentary, msg_type, channel, identifier, skin=None, is_rgb=False, default_states=None, *a, **k): super(ConfigurableButtonElement, self).__init__(is_momentary, msg_type, channel, identifier, *a, **k) if default_states is not None: self.default_states = default_states self.states = dict(self.default_states) self.is_rgb = is_rgb self._skin = skin or self.default_skin self._is_enabled = True self._force_next_value = False self.set_channel(NON_FEEDBACK_CHANNEL) @property def _on_value(self): return self.states[True] @property def _off_value(self): return self.states[False] @property def on_value(self): return self._try_fetch_skin_value(self._on_value) @property def off_value(self): return self._try_fetch_skin_value(self._off_value) def _try_fetch_skin_value(self, value): try: return self._skin[value] except SkinColorMissingError: return value def reset(self): self.states = dict(self.default_states) self.set_light('DefaultButton.Disabled') self.set_identifier(self._original_identifier) self.set_channel(NON_FEEDBACK_CHANNEL) self.set_enabled(True) def set_on_off_values(self, on_value, off_value): self.states[True] = on_value self.states[False] = off_value def set_force_next_value(self): self._force_next_value = True def set_enabled(self, enabled): if self._is_enabled != enabled: self._is_enabled = enabled self._request_rebuild() def is_enabled(self): return self._is_enabled def set_light(self, value): self._set_skin_light(self.states.get(value, value)) def _set_skin_light(self, value): try: color = self._skin[value] color.draw(self) except SkinColorMissingError: super(ConfigurableButtonElement, self).set_light(value) def turn_on(self): self._skin[self._on_value].draw(self) def turn_off(self): self._skin[self._off_value].draw(self) def script_wants_forwarding(self): return self._is_enabled