pythonremi⽹站创建
1、将本地⽹站隐射出去
需要在路由器上配置,设置虚拟服务:服务端⼝+IP+协议(TCP),上⼀层路由设置的IP为下⼀层路由或主机的IP。
如果是在虚拟机中,选择NAT模式,设置端⼝转发,添加主机端⼝。
在windows中需要在防⽕墙中开放该端⼝,cmd——>control——>系统安全——>防⽕墙——>⾼级设置——>⼊端规则——>新建规
则——>端⼝、TCP——>允许链接——>名称——>完成。
2、remi案例
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import remi.gui as gui
from remi import start, App
from threading import Timer
class MyApp(App):
def __init__(self, *args):
super(MyApp, self).__init__(*args)
def idle(self):
self.progress.set_unt%100)
def main(self):
# the margin 0px auto centers the main container
verticalContainer = gui.Container(width=540, margin='0px auto', style={'display': 'block', 'overflow': 'hidden'})
horizontalContainer = gui.Container(width='100%', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='0px', style={'display': 'block', 'overflow
subContainerLeft = gui.Container(width=320, style={'display': 'block', 'overflow': 'auto', 'text-align': 'center'})
self.img = gui.Image('/res:logo.png', height=100, margin='10px')
lick._img_clicked)
self.table = w_from_list([('ID', 'First Name', 'Last Name'),
('101', 'Danny', 'Young'),
('102', 'Christine', 'Holand'),
('103', 'Lars', 'Gordon'),
('104', 'Roberto', 'Robitaille'),
('105', 'Maria', 'Papadopoulos')], width=300, height=200, margin='10px')
_table_row_click._table_row_click)
# the arguments are width - height - layoutOrientationOrizontal
subContainerRight = gui.Container(style={'width': '220px', 'display': 'block', 'overflow': 'auto', 'text-align': 'center'})
self.lbl = gui.Label('This is a LABEL!', width=200, height=30, margin='10px')
self.bt = gui.Button('Press me!', width=200, height=30, margin='10px')
# setting the listener for the onclick event of the button
lick._button_pressed)
< = gui.TextInput(width=200, height=30, margin='10px')
self.spin = gui.SpinBox(1, 0, 100, width=200, height=30, margin='10px')
hange._spin_change)
self.progress = gui.Progress(1, 100, width=200, height=5)
self.check = gui.CheckBoxLabel('Label checkbox', True, width=200, height=30, margin='10px')
hange._check_change)
self.btInputDiag = gui.Button('Open InputDialog', width=200, height=30, margin='10px')
lick.do(self.open_input_dialog)
self.btFileDiag = gui.Button('File Selection Dialog', width=200, height=30, margin='10px')
lick.do(self.open_fileselection_dialog)
self.btUploadFile = gui.FileUploader('./', width=200, height=30, margin='10px')
success.do(self.fileupload_on_success)
failed.do(self.fileupload_on_failed)
items = ('Danny Young','Christine Holand','Lars Gordon','Roberto Robitaille')
self.listView = w_from_list(items, width=300, height=120, margin='10px')
selection.do(self.list_view_on_selected)
self.link = gui.Link("localhost:8081", "A link to here", width=200, height=30, margin='10px')
self.dropDown = w_from_list(('DropDownItem 0', 'DropDownItem 1'),
width=200, height=20, margin='10px')
hange.do(self.drop_down_changed)
self.dropDown.select_by_value('DropDownItem 0')
self.slider = gui.Slider(10, 0, 100, 5, width=200, height=20, margin='10px')
hange.do(self.slider_changed)
self.date = gui.Date('2015-04-13', width=200, height=20, margin='10px')
hange.do(self.date_changed)
self.video = gui.Widget( _type='iframe', width=290, height=200, margin='10px')
self.video.attributes['src'] = "le/file/d/0B0J9Lq_MRyn4UFRsblR3UTBZRHc/preview"
self.video.attributes['width'] = '100%'
self.video.attributes['height'] = '100%'
self.video.attributes['controls'] = 'true'
self.video.style['border'] = 'none'
< = gui.TreeView(width='100%', height=300)
ti1 = gui.TreeItem("Item1")
ti2 = gui.TreeItem("Item2")
ti3 = gui.TreeItem("Item3")
subti1 = gui.TreeItem("Sub Item1")
subti2 = gui.TreeItem("Sub Item2")
subti3 = gui.TreeItem("Sub Item3")
subti4 = gui.TreeItem("Sub Item4")
subsubti1 = gui.TreeItem("Sub Sub Item1")
subsubti2 = gui.TreeItem("Sub Sub Item2")
python虚拟机
subsubti3 = gui.TreeItem("Sub Sub Item3")
ti2.append([subti1, subti2, subti3, subti4])
subti4.append([subsubti1, subsubti2, subsubti3])
# appending a widget to another, the first argument is a string key
subContainerRight.append([unter, self.lbl, self.bt, , self.spin, self.progress, self.check, self.btInputDiag, self.btFileDiag])        # use a defined key as we replace this widget later
fdownloader = gui.FileDownloader('download test', '../remi/res/logo.png', width=200, height=30, margin='10px')
subContainerRight.append(fdownloader, key='file_downloader')
subContainerRight.append([self.btUploadFile, self.dropDown, self.slider, lorPicker, self.date, ])
self.subContainerRight = subContainerRight
subContainerLeft.append([self.img, self.table, self.listView, self.link, self.video])
horizontalContainer.append([subContainerLeft, subContainerRight])
menu = gui.Menu(width='100%', height='30px')
m1 = gui.MenuItem('File', width=100, height=30)
m2 = gui.MenuItem('View', width=100, height=30)
m11 = gui.MenuItem('Save', width=100, height=30)
m12 = gui.MenuItem('Open', width=100, height=30)
m111 = gui.MenuItem('Save', width=100, height=30)
m112 = gui.MenuItem('Save as', width=100, height=30)
m3 = gui.MenuItem('Dialog', width=100, height=30)
menu.append([m1, m2, m3])
m1.append([m11, m12])
m11.append([m111, m112])
menubar = gui.MenuBar(width='100%', height='30px')
menubar.append(menu)
verticalContainer.append([menubar, horizontalContainer])
#this flag will be used to stop the display_counter Timer
self.stop_flag = False
# kick of regular display of counter
self.display_counter()
# returning the root widget
return verticalContainer
def display_counter(self):
if not self.stop_flag:
Timer(1, self.display_counter).start()
def menu_dialog_clicked(self, widget):
self.dialog = gui.GenericDialog(title='Dialog Box', message='Click Ok to transfer content to main page', width='500px')        self.dtextinput = gui.TextInput(width=200, height=30)
self.dtextinput.set_value('Initial Text')
self.dialog.add_field_with_label('dtextinput', 'Text Input', self.dtextinput)
self.dcheck = gui.CheckBox(False, width=200, height=30)
self.dialog.add_field_with_label('dcheck', 'Label Checkbox', self.dcheck)
values = ('Danny Young', 'Christine Holand', 'Lars Gordon', 'Roberto Robitaille')
self.dlistView = w_from_list(values, width=200, height=120)
self.dialog.add_field_with_label('dlistView', 'Listview', self.dlistView)
self.ddropdown = w_from_list(('DropDownItem 0', 'DropDownItem 1'),
width=200, height=20)
self.dialog.add_field_with_label('ddropdown', 'Dropdown', self.ddropdown)
self.dspinbox = gui.SpinBox(min=0, max=5000, width=200, height=20)
self.dspinbox.set_value(50)
self.dialog.add_field_with_label('dspinbox', 'Spinbox', self.dspinbox)
self.dslider = gui.Slider(10, 0, 100, 5, width=200, height=20)
self.dspinbox.set_value(50)
self.dialog.add_field_with_label('dslider', 'Slider', self.dslider)
self.dcolor = gui.ColorPicker(width=200, height=20)
self.dcolor.set_value('#ffff00')
self.dialog.add_field_with_label('dcolor', 'Colour Picker', self.dcolor)
self.ddate = gui.Date(width=200, height=20)
self.ddate.set_value('2000-01-01')
self.dialog.add_field_with_label('ddate', 'Date', self.ddate)
firm_dialog.do(self.dialog_confirm)
self.dialog.show(self)
def dialog_confirm(self, widget):
result = _field('dtextinput').get_value()
result = _field('dcheck').get_value()
self.check.set_value(result)
result = _field('ddropdown').get_value()
self.dropDown.select_by_value(result)
result = _field('dspinbox').get_value()
self.spin.set_value(result)
result = _field('dslider').get_value()
self.slider.set_value(result)
result = _field('dcolor').get_value()
result = _field('ddate').get_value()
self.date.set_value(result)
result = _field('dlistView').get_value()
self.listView.select_by_value(result)
# listener function
def on_img_clicked(self, widget):
self.lbl.set_text('Image clicked!')
def on_table_row_click(self, table, row, item):
self.lbl.set_text('Table Item clicked: ' + _text())
def on_button_pressed(self, widget):
self.lbl.set_text('Button pressed! ')
self.bt.set_text('Hi!')
def on_text_area_change(self, widget, newValue):
self.lbl.set_text('Text Area value changed!')
def on_spin_change(self, widget, newValue):
self.lbl.set_text('SpinBox changed, new value: ' + str(newValue))
def on_check_change(self, widget, newValue):
self.lbl.set_text('CheckBox changed, new value: ' + str(newValue))
def open_input_dialog(self, widget):
self.inputDialog = gui.InputDialog('Input Dialog', 'Your name?',
initial_value='type here',
width=500)
firm_value.do(
<_input_dialog_confirm)
# here is returned the Input Dialog widget, and it will be shown
self.inputDialog.show(self)
self.inputDialog.show(self)
def on_input_dialog_confirm(self, widget, value):
self.lbl.set_text('Hello ' + value)
def open_fileselection_dialog(self, widget):
self.fileselectionDialog = gui.FileSelectionDialog('File Selection Dialog', 'Select files and folders', False,                                                          '.')
firm_value.do(
<_fileselection_dialog_confirm)
# here is returned the Input Dialog widget, and it will be shown
self.fileselectionDialog.show(self)
def on_fileselection_dialog_confirm(self, widget, filelist):
# a list() of filenames and folders is returned
self.lbl.set_text('Selected files: %s' % ','.join(filelist))
if len(filelist):
f = filelist[0]
# replace the last download link
fdownloader = gui.FileDownloader("download selected", f, width=200, height=30)
self.subContainerRight.append(fdownloader, key='file_downloader')
def list_view_on_selected(self, widget, selected_item_key):
""" The selection event of the listView, returns a key of the clicked event.
You can retrieve the item rapidly
"""
self.lbl.set_text('List selection: ' + self.listView.children[selected_item_key].get_text())
def drop_down_changed(self, widget, value):
self.lbl.set_text('New Combo value: ' + value)
def slider_changed(self, widget, value):
self.lbl.set_text('New slider value: ' + str(value))
def color_picker_changed(self, widget, value):
self.lbl.set_text('New color value: ' + value)
def date_changed(self, widget, value):
self.lbl.set_text('New date value: ' + value)
def menu_save_clicked(self, widget):
self.lbl.set_text('Menu clicked: Save')
def menu_saveas_clicked(self, widget):
self.lbl.set_text('Menu clicked: Save As')
def menu_open_clicked(self, widget):
self.lbl.set_text('Menu clicked: Open')
def menu_view_clicked(self, widget):
self.lbl.set_text('Menu clicked: View')
def fileupload_on_success(self, widget, filename):
self.lbl.set_text('File upload success: ' + filename)
def fileupload_on_failed(self, widget, filename):
self.lbl.set_text('File upload failed: ' + filename)
def on_close(self):
""" _close event to stop the Timer.
"""
self.stop_flag = True
super(MyApp, self).on_close()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。