问题列表 - 第39267页

OnHandleCreated和OnLoad之间的顺序

在Windows窗体上,这些之间是否有保证点火顺序,有谁知道?这是在.NET v2上.它似乎是前者(对不起).

谢谢

c# readonly winforms

3
推荐指数
1
解决办法
1557
查看次数

使用POST和urllib2访问Web API

我正在尝试使用POST技术访问Web API.我能够使用GET技术访问它,但API所有者告诉我某些功能仅适用于POST.不幸的是我似乎无法让POST工作.

这是适用于GET的:

API_URL = "http://example.com/api/"

def call_api(method, **kwargs):
    url = API_URL + method
    if kwargs:
        url += '?' + urllib.urlencode(kwargs)
    req = urllib2.Request(url)
    auth = 'Basic ' + base64.urlsafe_b64encode("%s:%s" % (USER, PASS))
    req.add_header('Authorization', auth)
    return urllib2.urlopen(req)
Run Code Online (Sandbox Code Playgroud)

这是什么不适用于POST(导致HTTP 400错误):

API_URL = "http://example.com/api/"

def call_api(method, **kwargs):
    url = API_URL + method
    data=''
    if kwargs:
        data=urllib.urlencode(kwargs)
    req = urllib2.Request(url, data)
    auth = 'Basic ' + base64.urlsafe_b64encode("%s:%s" % (USER, PASS))
    req.add_header('Authorization', auth)
    return urllib2.urlopen(req)
Run Code Online (Sandbox Code Playgroud)

任何人都会因为POST代码本身不正确而跳出来吗?我之前从未做过POST调用,但我读过的所有内容似乎都表明我的代码是合理的.如果我使用POST,是否有一些不同的方式我应该为授权执行add_header操作?

python post http urllib2

6
推荐指数
1
解决办法
2万
查看次数

c#参数性能

所以我有一个非常经常地调用方法作为模式的一部分.它看起来像这样:

DoWork(new TimeSpan(0, 0, 2, 0));
Run Code Online (Sandbox Code Playgroud)

或者在代码的另一部分:

DoWork(new TimeSpan(0, 0, 6, 50));
Run Code Online (Sandbox Code Playgroud)

在每种情况下,参数都不会改变,我最近醒来并找出了为每次调用创建参数的性能问题.我的解决方案是:

// instance field
TimeSpan _cachedValue = new TimeSpan(0, 0, 2, 0);
// and when called, 
DoWork(this._cachedValue)
Run Code Online (Sandbox Code Playgroud)

这一点都非常明显,我遇到的问题是将参数值存储在一个字段中...它的凌乱 - 在一个已经膨胀的类中(例如我在一个类中调用10个左右的do work方法)每个变种数千次 - 所以这十个额外的领域).

如果我可以做这样的事情,那会很酷:

DoWork([DoesNotChange()]new TimeSpan(0, 0, 2, 0));
Run Code Online (Sandbox Code Playgroud)

参数的这个理论属性表明,对于该特定调用,该值只需要计算一次,然后重复传递给方法.

这样的事情可能吗?或者我刚刚离开我的坚果?

干杯

编辑:

哇你们大家工作快,谢谢.至于我的问题,我上次应该学会不要过度简化 - 对不起.为了清楚起见,我将发布一个实际的代码段.此类用于Silverlight应用程序中的数据绑定.我正在使用PropertyChanged事件的强类型来实现可维护性:

internal class BasicDataClass : INotifyPropertyChanged
{
    private readonly Expression<Func<double>> _propertySelector;
    private double _someFieldA;
    private double _someFieldB;
    private double _someFieldC;

    public BasicDataClass()
    {
        _propertySelector = () => SomeFieldC;
    }

    /// <summary>
    /// This …
Run Code Online (Sandbox Code Playgroud)

c# parameters

2
推荐指数
1
解决办法
483
查看次数

Windows的禁用文件和文件夹名称的完整列表

在Windows上,禁止使用com1.txt或lpt1.txt等文件名.是否存在Windows上所有禁用文件和文件夹名称的列表(或文件和文件夹名称中的禁止字符,如:?...)

windows

7
推荐指数
2
解决办法
8757
查看次数

正则表达式用于识别非负值1..99

我正在寻找一个正则表达式,它可以接受1到99之间的任何值,并且不接受任何负值.到目前为止,我有:

"regex":/^[A-Za-z0-9]{3}[0-9]{6,}$/,
Run Code Online (Sandbox Code Playgroud)

regex

0
推荐指数
1
解决办法
2237
查看次数

如何使用Selenium测试JQuery UI可排序小部件?

我们有一个使用JQuery UI Sortable的可排序列表,我们正在尝试使用Selenium自动化.

看起来dragAndDrop函数应该可以工作,但是当我们调用它时,UI不会改变.但是,如果我们用firebug查看DOM,我们会看到列表元素DID的顺序发生了变化.它似乎只是不刷新的UI.

知道如何让它工作吗?

selenium drag-and-drop jquery-ui ui-automation jquery-ui-sortable

5
推荐指数
1
解决办法
3475
查看次数

创建一个检查属性窗口,按钮驱动为JDialog

我原来问的并没有明确说明我的问题/问题,所以我会更好地解释.我有一个JButton,设置一个JDialog可见.JDialog将WindowListener其设置为在windowDeactivated()事件中不可见,该事件在用户在对话框外单击时触发.按钮ActionListener检查对话框是否为可见,如果为true则隐藏它,如果为false则显示该对话框.

windowDeactivated()只要用户在对话框外单击,就会始终触发是否单击按钮.我遇到的问题是当用户单击按钮关闭对话框时.该对话框由关闭WindowListener,然后ActionListener尝试显示它.

如果windowDeactivated()没有setVisible(false),则对话框仍然打开,但在父窗口后面.我要求的是如何访问里面的点击位置windowDeactivated().如果我知道用户点击了按钮并且windowDeactivated()可以跳过隐藏对话框,那么按钮ActionListener会看到它仍然可见并隐藏它.

public PropertiesButton extends JButton {

    private JDialog theWindow;

    public PropertiesButton() {
        theWindow = new JDialog();
        theWindow.setUndecorated(true);
        theWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        theWindow.add(new JMenuCheckBoxItem("Something"));
        theWindow.addWindowListener(new WindowListener() {
            // just an example, need to implement other methods
            public void windowDeactivated(WindowEvent e) {
                theWindow.setVisible(false);
            }
        });
        this.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (theWindow.isVisible()) {
                    theWindow.setVisible(false);
                } else { …

java swing jdialog jbutton jpopupmenu

8
推荐指数
1
解决办法
1423
查看次数

字节到KiloBytes

我正在检索文档目录中所有文件的大小.我正在使用这种方法attributesOfItemAtPath.它很成功.但我得到的是字节和类的输出NSNumber.它看起来不太好看.

所以,我需要以KB或MB的形式获取输出,我必须将它们转换NSString为以便将其存储在一个中,NSDictionary因为我必须在TableView中显示它.请帮我这样做.谢谢.

这是我的代码..

directoryContent = [[NSMutableArray alloc] init];
    for (NSString *path in paths){
filesDictionary  =[[NSMutableDictionary alloc] init];
filesSize = [[NSNumber alloc] init]; 
filesSize = [filesDictionary objectForKey:NSFileSize];
filesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:filesSize, @"filesSize", nil];
[directoryContent addObject:[filesDictionary copy]];
}
Run Code Online (Sandbox Code Playgroud)

我正在使用以下代码绑定tableView中无法正常工作的大小.

cell.lblSize.text = (NSString *) [[directoryContent objectAtIndex:listIndex] objectForKey:@"filesSize"];
Run Code Online (Sandbox Code Playgroud)

帮我将文件大小从byte转换为KiloByte并将其显示在tableView中.先感谢您..

iphone filesize

2
推荐指数
2
解决办法
3535
查看次数

Android按钮在setText之后失去文本对齐

我正在使用xml绘制旋转进度指示器以及一些文本.在屏幕的底部,我有一个带有两个按钮的TableLayout,它们在页面中居,每个文本也居中.

<RelativeLayout
        android:id="@+id/progresscontainer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_horizontal">


        <ProgressBar android:id="@+id/progress_bar" 
            style="?android:attr/progressBarStyleSmall" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:paddingRight="10dp" />

        <TextView android:id="@+id/progress_text" 
            android:layout_toRightOf="@id/progress_bar"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="First text" />

</RelativeLayout>

<TableLayout
    android:id="@+id/buttonbar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:paddingTop="3dip"
    android:background="@color/buttonbar"
    android:stretchColumns="0,1">

    <TableRow>

        <Button android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button1" />

        <Button android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button2" />

    </TableRow>

</TableLayout>
Run Code Online (Sandbox Code Playgroud)

在代码中,我有一个runnable,几秒钟之后更改progress_text TextView上的文本.

private Runnable mTimeTask = new Runnable() {

   public void run() {
       TextView progressText = (TextView) findViewById(R.id.progress_text);
       progressText.setText("Second text");
   }

};
Run Code Online (Sandbox Code Playgroud)

问题是在这个setText()之后,一旦我专注于其中一个按钮,文本就会失去它的居中对齐并一直向左移动.我究竟做错了什么?

android text button alignment

2
推荐指数
1
解决办法
2960
查看次数

<script>标签是否需要'type'属性?

我见过这两个:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
Run Code Online (Sandbox Code Playgroud)

还有这个:

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
Run Code Online (Sandbox Code Playgroud)

type属性是否以任何方式重要?

html

139
推荐指数
6
解决办法
3万
查看次数